program lru_puzzle
  implicit none
  integer :: n, m, q, a(100000) = 0, i, k
  integer :: x = 0, p(100000) = 0, r(100000) = 0, c(0:100000) = 0
  logical :: u(100000) = .false.
  read(*,*) n, m
  read(*,*) q
  read(*,*) a(1:q)
  do i = q, 1, -1
    if (u(a(i))) cycle
    x = x+1
    p(x) = a(i)
    u(a(i)) = .true.
  end do
  do i = 1, m
    if (u(i)) cycle
    x = x+1
    p(x) = i
  end do
  do i = 1, m
    r(p(i)) = i
  end do
  c(0) = n
  do i = q, 1, -1
    k = r(a(i))
    if (c(k-1) > 0) then
      c(k-1) = c(k-1)-1
      c(k) = c(k)+1
    end if
  end do
  k = 0
  do while (c(k) == 0)
    k = k+1
  end do
  do i = k+1, m-1
    if (p(i) > p(i+1)) then
      write(*,'(a)') "No"
      stop
    end if
  end do
  write(*,'(a)') "Yes"
end program lru_puzzle
; ModuleID = 'FIRModule'
source_filename = "FIRModule"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-linux-gnu"

@_QFEa = internal global [100000 x i32] zeroinitializer
@_QFEc = internal unnamed_addr global [100001 x i32] zeroinitializer
@_QFEp = internal unnamed_addr global [100000 x i32] zeroinitializer
@_QFEr = internal unnamed_addr global [100000 x i32] zeroinitializer
@_QFEu = internal unnamed_addr global [100000 x i32] zeroinitializer
@_QFEx = internal unnamed_addr global i32 0
@_QQcl.d7f698da8bc85e1a73d64db692e64283 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_7874/source.f\00"
@_QQcl.286129 = linkonce constant [3 x i8] c"(a)"
@_QQcl.4E6F = linkonce constant [2 x i8] c"No"
@_QQcl.596573 = linkonce constant [3 x i8] c"Yes"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.d7f698da8bc85e1a73d64db692e64283, i32 6)
  %6 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %3, i32 4)
  %7 = call i1 @_FortranAioInputInteger(ptr %5, ptr nonnull %2, i32 4)
  %8 = call i32 @_FortranAioEndIoStatement(ptr %5)
  %9 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.d7f698da8bc85e1a73d64db692e64283, i32 7)
  %10 = call i1 @_FortranAioInputInteger(ptr %9, ptr nonnull %4, i32 4)
  %11 = call i32 @_FortranAioEndIoStatement(ptr %9)
  %12 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.d7f698da8bc85e1a73d64db692e64283, i32 8)
  %13 = load i32, ptr %4, align 4, !tbaa !3
  %14 = call i32 @llvm.smax.i32(i32 %13, i32 0)
  %15 = zext i32 %14 to i64
  store ptr @_QFEa, ptr %1, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 4, ptr %.fca.1.gep, align 8, !tbaa !7
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  store i8 9, ptr %.fca.4.gep, align 1, !tbaa !7
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  %.fca.7.0.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  %.fca.7.0.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 1
  store i64 %15, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 2
  store i64 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %16 = call i1 @_FortranAioInputDescriptor(ptr %12, ptr nonnull %1)
  %17 = call i32 @_FortranAioEndIoStatement(ptr %12)
  %18 = load i32, ptr %4, align 4, !tbaa !3
  %19 = sext i32 %18 to i64
  %_QFEx.promoted = load i32, ptr @_QFEx, align 4, !tbaa !3
  %20 = icmp sgt i32 %18, 0
  br i1 %20, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %36
  %21 = phi i64 [ %38, %36 ], [ %19, %0 ]
  %22 = phi i32 [ %37, %36 ], [ %_QFEx.promoted, %0 ]
  %sext51 = shl i64 %21, 32
  %23 = ashr exact i64 %sext51, 32
  %24 = add nsw i64 %23, -1
  %25 = getelementptr [100000 x i32], ptr @_QFEa, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !3
  %27 = sext i32 %26 to i64
  %28 = add nsw i64 %27, -1
  %29 = getelementptr [100000 x i32], ptr @_QFEu, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !3
  %.not28 = icmp eq i32 %30, 0
  br i1 %.not28, label %31, label %36

31:                                               ; preds = %.lr.ph
  %32 = add i32 %22, 1
  store i32 %32, ptr @_QFEx, align 4, !tbaa !3
  %33 = sext i32 %32 to i64
  %34 = add nsw i64 %33, -1
  %35 = getelementptr [100000 x i32], ptr @_QFEp, i64 0, i64 %34
  store i32 %26, ptr %35, align 4, !tbaa !3
  store i32 1, ptr %29, align 4, !tbaa !3
  br label %36

36:                                               ; preds = %31, %.lr.ph
  %37 = phi i32 [ %32, %31 ], [ %22, %.lr.ph ]
  %38 = add nsw i64 %21, -1
  %39 = icmp sgt i64 %21, 1
  br i1 %39, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %36, %0
  %_QFEx.promoted30 = phi i32 [ %_QFEx.promoted, %0 ], [ %37, %36 ]
  %40 = load i32, ptr %2, align 4, !tbaa !3
  %41 = sext i32 %40 to i64
  %42 = icmp sgt i32 %40, 0
  br i1 %42, label %.lr.ph32, label %._crit_edge34

.preheader29:                                     ; preds = %54
  br i1 %42, label %.lr.ph33.preheader, label %._crit_edge34

.lr.ph33.preheader:                               ; preds = %.preheader29
  %xtraiter = and i64 %41, 1
  %43 = icmp eq i32 %40, 1
  br i1 %43, label %._crit_edge34.loopexit.unr-lcssa, label %.lr.ph33.preheader.new

.lr.ph33.preheader.new:                           ; preds = %.lr.ph33.preheader
  %unroll_iter = and i64 %41, -2
  br label %.lr.ph33

.lr.ph32:                                         ; preds = %._crit_edge, %54
  %indvars.iv = phi i64 [ %indvars.iv.next, %54 ], [ 1, %._crit_edge ]
  %44 = phi i32 [ %55, %54 ], [ %_QFEx.promoted30, %._crit_edge ]
  %45 = add nsw i64 %indvars.iv, -1
  %46 = getelementptr [100000 x i32], ptr @_QFEu, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !3
  %.not = icmp eq i32 %47, 0
  br i1 %.not, label %48, label %54

48:                                               ; preds = %.lr.ph32
  %49 = add i32 %44, 1
  store i32 %49, ptr @_QFEx, align 4, !tbaa !3
  %50 = sext i32 %49 to i64
  %51 = add nsw i64 %50, -1
  %52 = getelementptr [100000 x i32], ptr @_QFEp, i64 0, i64 %51
  %53 = trunc i64 %indvars.iv to i32
  store i32 %53, ptr %52, align 4, !tbaa !3
  br label %54

54:                                               ; preds = %48, %.lr.ph32
  %55 = phi i32 [ %49, %48 ], [ %44, %.lr.ph32 ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %41
  br i1 %exitcond.not, label %.preheader29, label %.lr.ph32

.lr.ph33:                                         ; preds = %.lr.ph33, %.lr.ph33.preheader.new
  %indvars.iv44 = phi i64 [ 1, %.lr.ph33.preheader.new ], [ %indvars.iv.next45.1, %.lr.ph33 ]
  %niter = phi i64 [ 0, %.lr.ph33.preheader.new ], [ %niter.next.1, %.lr.ph33 ]
  %56 = add nsw i64 %indvars.iv44, -1
  %57 = getelementptr [100000 x i32], ptr @_QFEp, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !3
  %59 = sext i32 %58 to i64
  %60 = add nsw i64 %59, -1
  %61 = getelementptr [100000 x i32], ptr @_QFEr, i64 0, i64 %60
  %62 = trunc i64 %indvars.iv44 to i32
  store i32 %62, ptr %61, align 4, !tbaa !3
  %63 = getelementptr [100000 x i32], ptr @_QFEp, i64 0, i64 %indvars.iv44
  %64 = load i32, ptr %63, align 4, !tbaa !3
  %65 = sext i32 %64 to i64
  %66 = add nsw i64 %65, -1
  %67 = getelementptr [100000 x i32], ptr @_QFEr, i64 0, i64 %66
  %68 = trunc i64 %indvars.iv44 to i32
  %69 = add i32 %68, 1
  store i32 %69, ptr %67, align 4, !tbaa !3
  %indvars.iv.next45.1 = add nuw nsw i64 %indvars.iv44, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge34.loopexit.unr-lcssa, label %.lr.ph33

._crit_edge34.loopexit.unr-lcssa:                 ; preds = %.lr.ph33, %.lr.ph33.preheader
  %indvars.iv44.unr = phi i64 [ 1, %.lr.ph33.preheader ], [ %indvars.iv.next45.1, %.lr.ph33 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge34, label %.lr.ph33.epil

.lr.ph33.epil:                                    ; preds = %._crit_edge34.loopexit.unr-lcssa
  %70 = add nsw i64 %indvars.iv44.unr, -1
  %71 = getelementptr [100000 x i32], ptr @_QFEp, i64 0, i64 %70
  %72 = load i32, ptr %71, align 4, !tbaa !3
  %73 = sext i32 %72 to i64
  %74 = add nsw i64 %73, -1
  %75 = getelementptr [100000 x i32], ptr @_QFEr, i64 0, i64 %74
  %76 = trunc i64 %indvars.iv44.unr to i32
  store i32 %76, ptr %75, align 4, !tbaa !3
  br label %._crit_edge34

._crit_edge34:                                    ; preds = %.lr.ph33.epil, %._crit_edge34.loopexit.unr-lcssa, %._crit_edge, %.preheader29
  %77 = load i32, ptr %3, align 4, !tbaa !3
  store i32 %77, ptr @_QFEc, align 16, !tbaa !3
  br i1 %20, label %.lr.ph36, label %.preheader.preheader

.lr.ph36:                                         ; preds = %._crit_edge34, %98
  %78 = phi i64 [ %99, %98 ], [ %19, %._crit_edge34 ]
  %sext = shl i64 %78, 32
  %79 = ashr exact i64 %sext, 32
  %80 = add nsw i64 %79, -1
  %81 = getelementptr [100000 x i32], ptr @_QFEa, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !3
  %83 = sext i32 %82 to i64
  %84 = add nsw i64 %83, -1
  %85 = getelementptr [100000 x i32], ptr @_QFEr, i64 0, i64 %84
  %86 = load i32, ptr %85, align 4, !tbaa !3
  %87 = add i32 %86, -1
  %88 = sext i32 %87 to i64
  %89 = getelementptr [100001 x i32], ptr @_QFEc, i64 0, i64 %88
  %90 = load i32, ptr %89, align 4, !tbaa !3
  %91 = icmp sgt i32 %90, 0
  br i1 %91, label %92, label %98

92:                                               ; preds = %.lr.ph36
  %93 = add nsw i32 %90, -1
  store i32 %93, ptr %89, align 4, !tbaa !3
  %94 = sext i32 %86 to i64
  %95 = getelementptr [100001 x i32], ptr @_QFEc, i64 0, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !3
  %97 = add i32 %96, 1
  store i32 %97, ptr %95, align 4, !tbaa !3
  br label %98

98:                                               ; preds = %92, %.lr.ph36
  %99 = add nsw i64 %78, -1
  %100 = icmp sgt i64 %78, 1
  br i1 %100, label %.lr.ph36, label %.preheader.preheader

.preheader.preheader:                             ; preds = %98, %._crit_edge34
  br label %.preheader

.preheader:                                       ; preds = %.preheader.preheader, %.preheader
  %.0 = phi i32 [ %105, %.preheader ], [ 0, %.preheader.preheader ]
  %101 = sext i32 %.0 to i64
  %102 = getelementptr [100001 x i32], ptr @_QFEc, i64 0, i64 %101
  %103 = load i32, ptr %102, align 4, !tbaa !3
  %104 = icmp eq i32 %103, 0
  %105 = add i32 %.0, 1
  br i1 %104, label %.preheader, label %106

106:                                              ; preds = %.preheader
  %107 = xor i32 %.0, -1
  %108 = add i32 %40, %107
  %109 = icmp sgt i32 %108, 0
  br i1 %109, label %.lr.ph40, label %._crit_edge41

110:                                              ; preds = %.lr.ph40
  %exitcond49.not = icmp eq i32 %115, %40
  br i1 %exitcond49.not, label %._crit_edge41, label %.lr.ph40

.lr.ph40:                                         ; preds = %106, %110
  %.02138 = phi i32 [ %115, %110 ], [ %105, %106 ]
  %111 = sext i32 %.02138 to i64
  %112 = add nsw i64 %111, -1
  %113 = getelementptr [100000 x i32], ptr @_QFEp, i64 0, i64 %112
  %114 = load i32, ptr %113, align 4, !tbaa !3
  %115 = add i32 %.02138, 1
  %116 = sext i32 %115 to i64
  %117 = add nsw i64 %116, -1
  %118 = getelementptr [100000 x i32], ptr @_QFEp, i64 0, i64 %117
  %119 = load i32, ptr %118, align 4, !tbaa !3
  %120 = icmp sgt i32 %114, %119
  br i1 %120, label %121, label %110

121:                                              ; preds = %.lr.ph40
  %122 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.286129, i64 3, ptr null, i32 -1, ptr nonnull @_QQcl.d7f698da8bc85e1a73d64db692e64283, i32 37)
  %123 = call i1 @_FortranAioOutputAscii(ptr %122, ptr nonnull @_QQcl.4E6F, i64 2)
  %124 = call i32 @_FortranAioEndIoStatement(ptr %122)
  %125 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable

._crit_edge41:                                    ; preds = %110, %106
  %126 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.286129, i64 3, ptr null, i32 -1, ptr nonnull @_QQcl.d7f698da8bc85e1a73d64db692e64283, i32 41)
  %127 = call i1 @_FortranAioOutputAscii(ptr %126, ptr nonnull @_QQcl.596573, i64 3)
  %128 = call i32 @_FortranAioEndIoStatement(ptr %126)
  ret void
}

declare ptr @_FortranAioBeginExternalListInput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioInputInteger(ptr, ptr, i32) local_unnamed_addr

declare i32 @_FortranAioEndIoStatement(ptr) local_unnamed_addr

declare i1 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputAscii(ptr, ptr, i64) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) local_unnamed_addr

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smax.i32(i32, i32) #0

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.module.flags = !{!0, !1, !2}

!0 = !{i32 2, !"Debug Info Version", i32 3}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{!4, !4, i64 0}
!4 = !{!"any data access", !5, i64 0}
!5 = !{!"any access", !6, i64 0}
!6 = !{!"Flang Type TBAA Root"}
!7 = !{!8, !8, i64 0}
!8 = !{!"descriptor member", !5, i64 0}
