program sample
  implicit none
  integer(8) :: n,i,b
integer(8),allocatable :: a(:)
 
read(*,*) n
allocate(a(n))
do i=1,n
read(*,*) a(i)
end do
 
b=1
do i=1,n
   b=a(b)
   if(b==2)then
      write(*,*) i
      stop
   endif   
end do
 
write(*,*) -1
 
end program sample
; 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
@_QQcl.85f7f9e92e737800423d9f928bdc2a9d = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_7173/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 i64, align 8
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.85f7f9e92e737800423d9f928bdc2a9d, i32 6)
  %3 = call i1 @_FortranAioInputInteger(ptr %2, ptr nonnull %1, i32 8)
  %4 = call i32 @_FortranAioEndIoStatement(ptr %2)
  %5 = load i64, ptr %1, align 8, !tbaa !3
  %6 = call i64 @llvm.smax.i64(i64 %5, i64 0)
  %7 = shl i64 %6, 3
  %8 = call ptr @malloc(i64 %7)
  store ptr %8, ptr @_QFEa.0, align 8, !tbaa !7
  %9 = icmp sgt i64 %5, 0
  br i1 %9, label %.lr.ph, label %._crit_edge97

.lr.ph:                                           ; preds = %0, %.lr.ph
  %10 = phi i64 [ %16, %.lr.ph ], [ 1, %0 ]
  %11 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.85f7f9e92e737800423d9f928bdc2a9d, i32 9)
  %.unpack79 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %12 = add i64 %10, -1
  %13 = getelementptr i64, ptr %.unpack79, i64 %12
  %14 = call i1 @_FortranAioInputInteger(ptr %11, ptr %13, i32 8)
  %15 = call i32 @_FortranAioEndIoStatement(ptr %11)
  %16 = add nuw i64 %10, 1
  %exitcond.not = icmp eq i64 %10, %5
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph
  %.pre = load i64, ptr %1, align 8, !tbaa !3
  %17 = icmp sgt i64 %.pre, 0
  br i1 %17, label %.lr.ph96, label %._crit_edge97

.lr.ph96:                                         ; preds = %._crit_edge
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  br label %18

18:                                               ; preds = %.lr.ph96, %28
  %.094 = phi i64 [ 1, %.lr.ph96 ], [ %29, %28 ]
  %.05593 = phi i64 [ 1, %.lr.ph96 ], [ %21, %28 ]
  %19 = add i64 %.05593, -1
  %20 = getelementptr i64, ptr %.unpack, i64 %19
  %21 = load i64, ptr %20, align 8, !tbaa !3
  %22 = icmp eq i64 %21, 2
  br i1 %22, label %23, label %28

23:                                               ; preds = %18
  %24 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.85f7f9e92e737800423d9f928bdc2a9d, i32 16)
  %25 = call i1 @_FortranAioOutputInteger64(ptr %24, i64 %.094)
  %26 = call i32 @_FortranAioEndIoStatement(ptr %24)
  %27 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable

28:                                               ; preds = %18
  %29 = add nuw i64 %.094, 1
  %exitcond99.not = icmp eq i64 %.094, %.pre
  br i1 %exitcond99.not, label %._crit_edge97, label %18

._crit_edge97:                                    ; preds = %28, %0, %._crit_edge
  %30 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.85f7f9e92e737800423d9f928bdc2a9d, i32 21)
  %31 = call i1 @_FortranAioOutputInteger32(ptr %30, i32 -1)
  %32 = call i32 @_FortranAioEndIoStatement(ptr %30)
  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 ptr @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) 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

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}
