program exception_handling
    implicit none
    integer(4):: n, i,m1(2), m2(2), b

    m1(:)=0;m2(:)=0
    read*, n

    do i=1,n
        read*, b
        if (b > m1(1)) then
            m2(:) = m1(:)
            m1(1) = b
            m1(2) = i
        else if(b > m2(1)) then
            m2(1) = b
            m2(2) = i
        end if
    end do

    do i=1, n
        if (i == m1(2))then
            print*, m2(1)
        else
            print*, m1(1)
        end if
    end do

end program exception_handling
; 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"

@_QQcl.74ba5095e49c001f889e4163bccf67ab = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3727/source.f\00"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

define void @_QQmain() local_unnamed_addr {
.preheader10.preheader:
  %0 = alloca i32, align 4
  %1 = alloca i32, align 4
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.74ba5095e49c001f889e4163bccf67ab, i32 6)
  %3 = call i1 @_FortranAioInputInteger(ptr %2, ptr nonnull %1, i32 4)
  %4 = call i32 @_FortranAioEndIoStatement(ptr %2)
  %5 = load i32, ptr %1, align 4, !tbaa !3
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge13

.lr.ph:                                           ; preds = %.preheader10.preheader
  %7 = zext i32 %5 to i64
  br label %8

8:                                                ; preds = %.lr.ph, %.preheader.preheader
  %.sroa.016.0 = phi i32 [ 0, %.lr.ph ], [ %.sroa.016.1, %.preheader.preheader ]
  %.sroa.517.0 = phi i32 [ 0, %.lr.ph ], [ %.sroa.517.1, %.preheader.preheader ]
  %.sroa.0.0 = phi i32 [ 0, %.lr.ph ], [ %.sroa.0.1, %.preheader.preheader ]
  %9 = phi i64 [ %7, %.lr.ph ], [ %20, %.preheader.preheader ]
  %10 = phi i32 [ 1, %.lr.ph ], [ %19, %.preheader.preheader ]
  %11 = phi i32 [ 0, %.lr.ph ], [ %18, %.preheader.preheader ]
  %12 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.74ba5095e49c001f889e4163bccf67ab, i32 9)
  %13 = call i1 @_FortranAioInputInteger(ptr %12, ptr nonnull %0, i32 4)
  %14 = call i32 @_FortranAioEndIoStatement(ptr %12)
  %15 = load i32, ptr %0, align 4, !tbaa !3
  %16 = icmp sgt i32 %15, %11
  br i1 %16, label %.preheader.preheader, label %17

17:                                               ; preds = %8
  %spec.select = call i32 @llvm.smax.i32(i32 %15, i32 %.sroa.0.0)
  br label %.preheader.preheader

.preheader.preheader:                             ; preds = %17, %8
  %.sroa.016.1 = phi i32 [ %15, %8 ], [ %.sroa.016.0, %17 ]
  %.sroa.517.1 = phi i32 [ %10, %8 ], [ %.sroa.517.0, %17 ]
  %.sroa.0.1 = phi i32 [ %.sroa.016.0, %8 ], [ %spec.select, %17 ]
  %18 = phi i32 [ %15, %8 ], [ %11, %17 ]
  %19 = add nuw i32 %10, 1
  %20 = add nsw i64 %9, -1
  %21 = icmp sgt i64 %9, 1
  br i1 %21, label %8, label %._crit_edge

._crit_edge:                                      ; preds = %.preheader.preheader
  %.pre = load i32, ptr %1, align 4, !tbaa !3
  %22 = icmp sgt i32 %.pre, 0
  br i1 %22, label %.lr.ph12, label %._crit_edge13

.lr.ph12:                                         ; preds = %._crit_edge
  %23 = zext i32 %.pre to i64
  br label %24

24:                                               ; preds = %.lr.ph12, %34
  %25 = phi i64 [ %23, %.lr.ph12 ], [ %37, %34 ]
  %26 = phi i32 [ 1, %.lr.ph12 ], [ %36, %34 ]
  %27 = icmp eq i32 %26, %.sroa.517.1
  br i1 %27, label %28, label %31

28:                                               ; preds = %24
  %29 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.74ba5095e49c001f889e4163bccf67ab, i32 22)
  %30 = call i1 @_FortranAioOutputInteger32(ptr %29, i32 %.sroa.0.1)
  br label %34

31:                                               ; preds = %24
  %32 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.74ba5095e49c001f889e4163bccf67ab, i32 24)
  %33 = call i1 @_FortranAioOutputInteger32(ptr %32, i32 %.sroa.016.1)
  br label %34

34:                                               ; preds = %28, %31
  %.sink = phi ptr [ %29, %28 ], [ %32, %31 ]
  %35 = call i32 @_FortranAioEndIoStatement(ptr %.sink)
  %36 = add nuw i32 %26, 1
  %37 = add nsw i64 %25, -1
  %38 = icmp sgt i64 %25, 1
  br i1 %38, label %24, label %._crit_edge13

._crit_edge13:                                    ; preds = %34, %.preheader10.preheader, %._crit_edge
  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 @_FortranAioOutputInteger32(ptr, i32) 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"}
