program prob6
    implicit none
    integer::n, i, p
    integer, allocatable::c(:)
    read(*,*) n
    allocate(c(0:n))
    c = 0
    do i = 1, n
        read(*,*) p
        if(c(p) == 0 .and. c(p-1) == 0) then
            c(p) = 1
        else if(c(p) == 0) then
            c(p) = c(p-1) + 1
        end if
    end do
    write(*,*) n - maxval(c)
    deallocate(c)
    stop
end program
; 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"

@_QFEc.0 = internal unnamed_addr global ptr null
@_QFEc.7 = internal unnamed_addr global i64 1
@_QFEc.8 = internal unnamed_addr global i64 0
@_QQcl.a4620834c17b6a28d629c35d95146f26 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_5957/source.f\00"
@_QQcl.16373402fa3425c6e46827601abb88fa = linkonce constant [76 x i8] c"array left hand side must be allocated when the right hand side is a scalar\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite)
declare noalias noundef ptr @malloc(i64 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #2 {
  %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 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.a4620834c17b6a28d629c35d95146f26, i32 5)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 4)
  %6 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %7 = load i32, ptr %2, align 4, !tbaa !3
  %8 = call i32 @llvm.smax.i32(i32 %7, i32 -1)
  %9 = sext i32 %8 to i64
  %10 = add nsw i64 %9, 1
  %11 = shl nuw nsw i64 %10, 2
  %12 = call ptr @malloc(i64 %11)
  %13 = icmp eq i64 %10, 0
  %14 = zext i1 %13 to i64
  store ptr %12, ptr @_QFEc.0, align 8, !tbaa !7
  store i64 %14, ptr @_QFEc.7, align 8, !tbaa !7
  store i64 %10, ptr @_QFEc.8, align 8, !tbaa !7
  %.not = icmp eq ptr %12, null
  br i1 %.not, label %19, label %.preheader

.preheader:                                       ; preds = %0
  %15 = icmp sgt i32 %7, -1
  br i1 %15, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %.preheader
  %16 = add nsw i64 %9, 2
  %smin = call i64 @llvm.smin.i64(i64 %10, i64 1)
  %17 = sub nuw nsw i64 %16, %smin
  %18 = shl nuw nsw i64 %17, 2
  call void @llvm.memset.p0.i64(ptr nonnull align 4 %12, i8 0, i64 %18, i1 false), !tbaa !3
  br label %.loopexit

19:                                               ; preds = %0
  %20 = call {} @_FortranAReportFatalUserError(ptr nonnull @_QQcl.16373402fa3425c6e46827601abb88fa, ptr nonnull @_QQcl.a4620834c17b6a28d629c35d95146f26, i32 7)
  %.unpack380.unpack.unpack = load i64, ptr @_QFEc.7, align 8, !tbaa !7
  %21 = select i1 %13, i64 1, i64 %.unpack380.unpack.unpack
  store ptr null, ptr @_QFEc.0, align 8, !tbaa !7
  store i64 %21, ptr @_QFEc.7, align 8, !tbaa !7
  store i64 %10, ptr @_QFEc.8, align 8, !tbaa !7
  %.pre = load i32, ptr %2, align 4, !tbaa !3
  br label %.loopexit

.loopexit:                                        ; preds = %.lr.ph.preheader, %19
  %22 = phi i32 [ %7, %.lr.ph.preheader ], [ %.pre, %19 ]
  %23 = icmp sgt i32 %22, 0
  br i1 %23, label %.lr.ph394.preheader, label %._crit_edge

.lr.ph394.preheader:                              ; preds = %.loopexit
  %24 = zext i32 %22 to i64
  br label %.lr.ph394

.lr.ph394:                                        ; preds = %.lr.ph394.preheader, %45
  %25 = phi i64 [ %46, %45 ], [ %24, %.lr.ph394.preheader ]
  %26 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.a4620834c17b6a28d629c35d95146f26, i32 9)
  %27 = call i1 @_FortranAioInputInteger(ptr %26, ptr nonnull %3, i32 4)
  %28 = call i32 @_FortranAioEndIoStatement(ptr %26)
  %.unpack361 = load ptr, ptr @_QFEc.0, align 8, !tbaa !7
  %.unpack368.unpack.unpack = load i64, ptr @_QFEc.7, align 8, !tbaa !7
  %29 = load i32, ptr %3, align 4, !tbaa !3
  %30 = sext i32 %29 to i64
  %31 = sub i64 %30, %.unpack368.unpack.unpack
  %32 = getelementptr i32, ptr %.unpack361, i64 %31
  %33 = load i32, ptr %32, align 4, !tbaa !3
  %34 = add i32 %29, -1
  %35 = sext i32 %34 to i64
  %36 = sub i64 %35, %.unpack368.unpack.unpack
  %37 = getelementptr i32, ptr %.unpack361, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !3
  %39 = or i32 %38, %33
  %40 = icmp eq i32 %39, 0
  br i1 %40, label %.sink.split, label %41

41:                                               ; preds = %.lr.ph394
  %42 = icmp eq i32 %33, 0
  br i1 %42, label %43, label %45

43:                                               ; preds = %41
  %44 = add i32 %38, 1
  br label %.sink.split

.sink.split:                                      ; preds = %.lr.ph394, %43
  %.sink = phi i32 [ %44, %43 ], [ 1, %.lr.ph394 ]
  store i32 %.sink, ptr %32, align 4, !tbaa !3
  br label %45

45:                                               ; preds = %.sink.split, %41
  %46 = add nsw i64 %25, -1
  %47 = icmp sgt i64 %25, 1
  br i1 %47, label %.lr.ph394, label %._crit_edge

._crit_edge:                                      ; preds = %45, %.preheader, %.loopexit
  %48 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.a4620834c17b6a28d629c35d95146f26, i32 16)
  %49 = load i32, ptr %2, align 4, !tbaa !3
  %.unpack = load ptr, ptr @_QFEc.0, align 8, !tbaa !7
  %.unpack344.unpack.unpack = load i64, ptr @_QFEc.7, align 8, !tbaa !7
  %.unpack344.unpack.unpack346 = load i64, ptr @_QFEc.8, align 8, !tbaa !7
  %50 = icmp eq i64 %.unpack344.unpack.unpack346, 0
  %51 = select i1 %50, i64 1, i64 %.unpack344.unpack.unpack
  store ptr %.unpack, 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 %51, 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 %.unpack344.unpack.unpack346, 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
  %52 = call i32 @_FortranAMaxvalInteger4x1_contract_simplified(ptr nonnull %1)
  %53 = sub i32 %49, %52
  %54 = call i1 @_FortranAioOutputInteger32(ptr %48, i32 %53)
  %55 = call i32 @_FortranAioEndIoStatement(ptr %48)
  %.unpack349 = load ptr, ptr @_QFEc.0, align 8, !tbaa !7
  call void @free(ptr %.unpack349)
  store ptr null, ptr @_QFEc.0, align 8, !tbaa !7
  store i64 1, ptr @_QFEc.7, align 8, !tbaa !7
  store i64 0, ptr @_QFEc.8, align 8, !tbaa !7
  %56 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable
}

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 {} @_FortranAReportFatalUserError(ptr, ptr, i32) local_unnamed_addr

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

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

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

define linkonce_odr i32 @_FortranAMaxvalInteger4x1_contract_simplified(ptr %0) local_unnamed_addr {
  %2 = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7, i64 0, i64 1
  %3 = load i64, ptr %2, align 8, !tbaa !7
  %4 = icmp sgt i64 %3, 0
  br i1 %4, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %1
  %5 = load ptr, ptr %0, align 8, !tbaa !7
  %6 = getelementptr { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %0, i64 0, i32 7, i64 0, i64 2
  %7 = load i64, ptr %6, align 8, !tbaa !7
  %xtraiter = and i64 %3, 3
  %8 = icmp ult i64 %3, 4
  br i1 %8, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %3, -4
  br label %9

9:                                                ; preds = %9, %.lr.ph.new
  %10 = phi i32 [ -2147483648, %.lr.ph.new ], [ %30, %9 ]
  %11 = phi i64 [ 0, %.lr.ph.new ], [ %31, %9 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %9 ]
  %12 = mul i64 %7, %11
  %13 = getelementptr i8, ptr %5, i64 %12
  %14 = load i32, ptr %13, align 4, !tbaa !3
  %15 = tail call i32 @llvm.smax.i32(i32 %14, i32 %10)
  %16 = or i64 %11, 1
  %17 = mul i64 %7, %16
  %18 = getelementptr i8, ptr %5, i64 %17
  %19 = load i32, ptr %18, align 4, !tbaa !3
  %20 = tail call i32 @llvm.smax.i32(i32 %19, i32 %15)
  %21 = or i64 %11, 2
  %22 = mul i64 %7, %21
  %23 = getelementptr i8, ptr %5, i64 %22
  %24 = load i32, ptr %23, align 4, !tbaa !3
  %25 = tail call i32 @llvm.smax.i32(i32 %24, i32 %20)
  %26 = or i64 %11, 3
  %27 = mul i64 %7, %26
  %28 = getelementptr i8, ptr %5, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !3
  %30 = tail call i32 @llvm.smax.i32(i32 %29, i32 %25)
  %31 = add nuw nsw i64 %11, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %._crit_edge.loopexit.unr-lcssa, label %9

._crit_edge.loopexit.unr-lcssa:                   ; preds = %9, %.lr.ph
  %.lcssa4.ph = phi i32 [ undef, %.lr.ph ], [ %30, %9 ]
  %.unr = phi i32 [ -2147483648, %.lr.ph ], [ %30, %9 ]
  %.unr5 = phi i64 [ 0, %.lr.ph ], [ %31, %9 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader
  %32 = phi i32 [ %37, %.epil.preheader ], [ %.unr, %._crit_edge.loopexit.unr-lcssa ]
  %33 = phi i64 [ %38, %.epil.preheader ], [ %.unr5, %._crit_edge.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.loopexit.unr-lcssa ]
  %34 = mul i64 %7, %33
  %35 = getelementptr i8, ptr %5, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !3
  %37 = tail call i32 @llvm.smax.i32(i32 %36, i32 %32)
  %38 = add nuw nsw i64 %33, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %._crit_edge, label %.epil.preheader, !llvm.loop !9

._crit_edge:                                      ; preds = %._crit_edge.loopexit.unr-lcssa, %.epil.preheader, %1
  %.lcssa = phi i32 [ -2147483648, %1 ], [ %.lcssa4.ph, %._crit_edge.loopexit.unr-lcssa ], [ %37, %.epil.preheader ]
  ret i32 %.lcssa
}

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i64 @llvm.smin.i64(i64, i64) #4

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #2 = { noreturn }
attributes #3 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nocallback nofree nounwind willreturn memory(argmem: write) }

!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}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
