program brick_break
    implicit none
    integer(4):: n, i, ni
    integer(4), allocatable:: a(:)

    read*, n
    allocate(a(n))
    read*, a(:)

    ni = 0
    i = 1
    do i=1,n
        if (a(i) == ni+1) ni = ni + 1
    end do

    if (ni == 0) then
        print*, -1
    else
        print*, n-ni
    endif
end program brick_break
; 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.0 = internal unnamed_addr global ptr null
@_QFEa.8 = internal unnamed_addr global i64 0
@_QQcl.1393920db8fbfb5ac235af32969182e8 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_2824/source.f\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

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 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.1393920db8fbfb5ac235af32969182e8, i32 6)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = load i32, ptr %2, align 4, !tbaa !3
  %7 = call i32 @llvm.smax.i32(i32 %6, i32 0)
  %8 = zext i32 %7 to i64
  %9 = shl nuw nsw i64 %8, 2
  %10 = call ptr @malloc(i64 %9)
  store ptr %10, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %8, ptr @_QFEa.8, align 8, !tbaa !7
  %11 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.1393920db8fbfb5ac235af32969182e8, i32 8)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack90.unpack.unpack92 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  %12 = call i64 @llvm.smax.i64(i64 %.unpack90.unpack.unpack92, i64 0)
  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 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 %12, 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
  %13 = call i1 @_FortranAioInputDescriptor(ptr %11, ptr nonnull %1)
  %14 = call i32 @_FortranAioEndIoStatement(ptr %11)
  %15 = load i32, ptr %2, align 4, !tbaa !3
  %16 = icmp sgt i32 %15, 0
  br i1 %16, label %.lr.ph, label %._crit_edge.thread

.lr.ph:                                           ; preds = %0
  %17 = zext i32 %15 to i64
  %.unpack95 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %xtraiter = and i64 %17, 3
  %18 = icmp ult i32 %15, 4
  br i1 %18, label %._crit_edge.unr-lcssa, label %.lr.ph.new

.lr.ph.new:                                       ; preds = %.lr.ph
  %unroll_iter = and i64 %17, 4294967292
  br label %19

19:                                               ; preds = %19, %.lr.ph.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.new ], [ %indvars.iv.next.3, %19 ]
  %.0107 = phi i32 [ 0, %.lr.ph.new ], [ %spec.select.3, %19 ]
  %niter = phi i64 [ 0, %.lr.ph.new ], [ %niter.next.3, %19 ]
  %20 = add nsw i64 %indvars.iv, -1
  %21 = getelementptr i32, ptr %.unpack95, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !3
  %23 = add i32 %.0107, 1
  %24 = icmp eq i32 %22, %23
  %spec.select = select i1 %24, i32 %23, i32 %.0107
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = getelementptr i32, ptr %.unpack95, i64 %indvars.iv
  %26 = load i32, ptr %25, align 4, !tbaa !3
  %27 = add i32 %spec.select, 1
  %28 = icmp eq i32 %26, %27
  %spec.select.1 = select i1 %28, i32 %27, i32 %spec.select
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %29 = getelementptr i32, ptr %.unpack95, i64 %indvars.iv.next
  %30 = load i32, ptr %29, align 4, !tbaa !3
  %31 = add i32 %spec.select.1, 1
  %32 = icmp eq i32 %30, %31
  %spec.select.2 = select i1 %32, i32 %31, i32 %spec.select.1
  %33 = getelementptr i32, ptr %.unpack95, i64 %indvars.iv.next.1
  %34 = load i32, ptr %33, align 4, !tbaa !3
  %35 = add i32 %spec.select.2, 1
  %36 = icmp eq i32 %34, %35
  %spec.select.3 = select i1 %36, i32 %35, i32 %spec.select.2
  %indvars.iv.next.3 = add nuw nsw i64 %indvars.iv, 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.unr-lcssa, label %19

._crit_edge.unr-lcssa:                            ; preds = %19, %.lr.ph
  %spec.select.lcssa.ph = phi i32 [ undef, %.lr.ph ], [ %spec.select.3, %19 ]
  %indvars.iv.unr = phi i64 [ 1, %.lr.ph ], [ %indvars.iv.next.3, %19 ]
  %.0107.unr = phi i32 [ 0, %.lr.ph ], [ %spec.select.3, %19 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.epil.preheader

.epil.preheader:                                  ; preds = %._crit_edge.unr-lcssa, %.epil.preheader
  %indvars.iv.epil = phi i64 [ %indvars.iv.next.epil, %.epil.preheader ], [ %indvars.iv.unr, %._crit_edge.unr-lcssa ]
  %.0107.epil = phi i32 [ %spec.select.epil, %.epil.preheader ], [ %.0107.unr, %._crit_edge.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.epil.preheader ], [ 0, %._crit_edge.unr-lcssa ]
  %37 = add nsw i64 %indvars.iv.epil, -1
  %38 = getelementptr i32, ptr %.unpack95, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !3
  %40 = add i32 %.0107.epil, 1
  %41 = icmp eq i32 %39, %40
  %spec.select.epil = select i1 %41, i32 %40, i32 %.0107.epil
  %indvars.iv.next.epil = add nuw nsw i64 %indvars.iv.epil, 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 = %.epil.preheader, %._crit_edge.unr-lcssa
  %spec.select.lcssa = phi i32 [ %spec.select.lcssa.ph, %._crit_edge.unr-lcssa ], [ %spec.select.epil, %.epil.preheader ]
  %42 = icmp eq i32 %spec.select.lcssa, 0
  br i1 %42, label %._crit_edge.thread, label %45

._crit_edge.thread:                               ; preds = %0, %._crit_edge
  %43 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.1393920db8fbfb5ac235af32969182e8, i32 17)
  %44 = call i1 @_FortranAioOutputInteger32(ptr %43, i32 -1)
  br label %50

45:                                               ; preds = %._crit_edge
  %46 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.1393920db8fbfb5ac235af32969182e8, i32 19)
  %47 = load i32, ptr %2, align 4, !tbaa !3
  %48 = sub i32 %47, %spec.select.lcssa
  %49 = call i1 @_FortranAioOutputInteger32(ptr %46, i32 %48)
  br label %50

50:                                               ; preds = %._crit_edge.thread, %45
  %.sink = phi ptr [ %43, %._crit_edge.thread ], [ %46, %45 ]
  %51 = call i32 @_FortranAioEndIoStatement(ptr %.sink)
  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 @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

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

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { 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}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
