program c
  integer :: N,i,mx,mx1
  integer,allocatable :: A(:),left(:,:)
  read(*,*) N
  allocate(A(N))
  do i=1,N
  read(*,*) A(i)
  enddo
  allocate(left(N,2))
  mx=maxval(A)
  left(1,1)=A(1)
  left(1,2)=A(N)
  do i=2,N
     left(i,1)=max(left(i-1,1),A(i))
     left(i,2)=max(left(i-1,2),A(N-i+1))
  enddo

  do i=1,N
     if(mx.eq.A(i)) then
        if(i.eq.1) then
           write(*,'(i0)') left(N-1,2)
        elseif(i.eq.N) then
           write(*,'(i0)') left(N-1,1)
        else
           write(*,'(i0)') max(left(i-1,1),left(N-i,2))
        endif
     else
        write(*,'(i0)') mx
     endif
  enddo

end program c
; 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
@_QFEleft.0 = internal unnamed_addr global ptr null
@_QFEleft.8 = internal unnamed_addr global i64 0
@_QQcl.719a29ee42c508254a48092d170aaf77 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_3732/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_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 i32, align 4
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.719a29ee42c508254a48092d170aaf77, i32 4)
  %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 = call i32 @llvm.smax.i32(i32 %5, i32 0)
  %7 = zext i32 %6 to i64
  %8 = shl nuw nsw i64 %7, 2
  %9 = call ptr @malloc(i64 %8)
  store ptr %9, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %7, ptr @_QFEa.8, align 8, !tbaa !7
  %10 = icmp sgt i32 %5, 0
  br i1 %10, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %0
  %11 = zext i32 %5 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %.lr.ph
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader ], [ %indvars.iv.next, %.lr.ph ]
  %12 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.719a29ee42c508254a48092d170aaf77, i32 7)
  %.unpack732 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %13 = add nsw i64 %indvars.iv, -1
  %14 = getelementptr i32, ptr %.unpack732, i64 %13
  %15 = call i1 @_FortranAioInputInteger(ptr %12, ptr %14, i32 4)
  %16 = call i32 @_FortranAioEndIoStatement(ptr %12)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv, %11
  br i1 %exitcond.not, label %._crit_edge.loopexit, label %.lr.ph

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr %1, align 4, !tbaa !3
  %.unpack.pre = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack555.unpack.unpack557.pre = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  %.pre760 = call i32 @llvm.smax.i32(i32 %.pre, i32 0)
  %.pre761 = zext i32 %.pre760 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %0
  %.pre-phi762 = phi i64 [ %.pre761, %._crit_edge.loopexit ], [ %7, %0 ]
  %.unpack555.unpack.unpack557 = phi i64 [ %.unpack555.unpack.unpack557.pre, %._crit_edge.loopexit ], [ %7, %0 ]
  %.unpack616.peel = phi ptr [ %.unpack.pre, %._crit_edge.loopexit ], [ %9, %0 ]
  %17 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %5, %0 ]
  %18 = shl nuw nsw i64 %.pre-phi762, 3
  %19 = call ptr @malloc(i64 %18)
  store ptr %19, ptr @_QFEleft.0, align 8, !tbaa !7
  store i64 %.pre-phi762, ptr @_QFEleft.8, align 8, !tbaa !7
  %20 = icmp sgt i64 %.unpack555.unpack.unpack557, 0
  br i1 %20, label %.lr.ph.i.preheader, label %_FortranAMaxvalInteger4x1_contract_simplified.exit

.lr.ph.i.preheader:                               ; preds = %._crit_edge
  %min.iters.check = icmp ult i64 %.unpack555.unpack.unpack557, 8
  br i1 %min.iters.check, label %.lr.ph.i.preheader770, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.i.preheader
  %n.vec = and i64 %.unpack555.unpack.unpack557, -8
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %vector.ph ], [ %24, %vector.body ]
  %vec.phi767 = phi <4 x i32> [ <i32 -2147483648, i32 -2147483648, i32 -2147483648, i32 -2147483648>, %vector.ph ], [ %25, %vector.body ]
  %21 = shl i64 %index, 2
  %22 = getelementptr i8, ptr %.unpack616.peel, i64 %21
  %wide.load = load <4 x i32>, ptr %22, align 4, !tbaa !3
  %23 = getelementptr i32, ptr %22, i64 4
  %wide.load768 = load <4 x i32>, ptr %23, align 4, !tbaa !3
  %24 = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %wide.load, <4 x i32> %vec.phi)
  %25 = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %wide.load768, <4 x i32> %vec.phi767)
  %index.next = add nuw i64 %index, 8
  %26 = icmp eq i64 %index.next, %n.vec
  br i1 %26, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %rdx.minmax.select = call <4 x i32> @llvm.smax.v4i32(<4 x i32> %24, <4 x i32> %25)
  %27 = call i32 @llvm.vector.reduce.smax.v4i32(<4 x i32> %rdx.minmax.select)
  %cmp.n = icmp eq i64 %.unpack555.unpack.unpack557, %n.vec
  br i1 %cmp.n, label %_FortranAMaxvalInteger4x1_contract_simplified.exit, label %.lr.ph.i.preheader770

.lr.ph.i.preheader770:                            ; preds = %.lr.ph.i.preheader, %middle.block
  %.ph = phi i32 [ -2147483648, %.lr.ph.i.preheader ], [ %27, %middle.block ]
  %.ph771 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader770, %.lr.ph.i
  %28 = phi i32 [ %33, %.lr.ph.i ], [ %.ph, %.lr.ph.i.preheader770 ]
  %29 = phi i64 [ %34, %.lr.ph.i ], [ %.ph771, %.lr.ph.i.preheader770 ]
  %30 = shl i64 %29, 2
  %31 = getelementptr i8, ptr %.unpack616.peel, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !3
  %33 = call i32 @llvm.smax.i32(i32 %32, i32 %28)
  %34 = add nuw nsw i64 %29, 1
  %exitcond.not.i = icmp eq i64 %34, %.unpack555.unpack.unpack557
  br i1 %exitcond.not.i, label %_FortranAMaxvalInteger4x1_contract_simplified.exit, label %.lr.ph.i, !llvm.loop !12

_FortranAMaxvalInteger4x1_contract_simplified.exit: ; preds = %.lr.ph.i, %middle.block, %._crit_edge
  %.lcssa.i = phi i32 [ -2147483648, %._crit_edge ], [ %27, %middle.block ], [ %33, %.lr.ph.i ]
  %35 = load i32, ptr %.unpack616.peel, align 4, !tbaa !3
  store i32 %35, ptr %19, align 4, !tbaa !3
  %36 = sext i32 %17 to i64
  %37 = add nsw i64 %36, -1
  %38 = getelementptr i32, ptr %.unpack616.peel, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !3
  %40 = getelementptr i32, ptr %19, i64 %.pre-phi762
  store i32 %39, ptr %40, align 4, !tbaa !3
  %41 = icmp sgt i32 %17, 1
  br i1 %41, label %.lr.ph744, label %.preheader

.lr.ph744:                                        ; preds = %_FortranAMaxvalInteger4x1_contract_simplified.exit
  %42 = add nuw i32 %17, 1
  br label %61

.preheader:                                       ; preds = %61, %_FortranAMaxvalInteger4x1_contract_simplified.exit
  %43 = icmp sgt i32 %17, 0
  br i1 %43, label %.lr.ph745.preheader, label %._crit_edge746

.lr.ph745.preheader:                              ; preds = %.preheader
  %44 = load i32, ptr %.unpack616.peel, align 4, !tbaa !3
  %45 = icmp eq i32 %.lcssa.i, %44
  br i1 %45, label %49, label %46

46:                                               ; preds = %.lr.ph745.preheader
  %47 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.719a29ee42c508254a48092d170aaf77, i32 28)
  %48 = call i1 @_FortranAioOutputInteger32(ptr %47, i32 %.lcssa.i)
  br label %59

49:                                               ; preds = %.lr.ph745.preheader
  %50 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.719a29ee42c508254a48092d170aaf77, i32 21)
  %.unpack660.peel = load ptr, ptr @_QFEleft.0, align 8, !tbaa !7
  %.unpack667.unpack.unpack670.peel = load i64, ptr @_QFEleft.8, align 8, !tbaa !7
  %51 = load i32, ptr %1, align 4, !tbaa !3
  %52 = add i32 %51, -1
  %53 = sext i32 %52 to i64
  %54 = add i64 %.unpack667.unpack.unpack670.peel, -1
  %55 = add i64 %54, %53
  %56 = getelementptr i32, ptr %.unpack660.peel, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !3
  %58 = call i1 @_FortranAioOutputInteger32(ptr %50, i32 %57)
  br label %59

59:                                               ; preds = %49, %46
  %.sink = phi ptr [ %50, %49 ], [ %47, %46 ]
  %60 = call i32 @_FortranAioEndIoStatement(ptr %.sink)
  %exitcond755.peel.not = icmp eq i32 %17, 1
  br i1 %exitcond755.peel.not, label %._crit_edge746, label %.lr.ph745

61:                                               ; preds = %.lr.ph744, %61
  %indvars.iv748 = phi i64 [ 2, %.lr.ph744 ], [ %indvars.iv.next749, %61 ]
  %62 = add nsw i64 %indvars.iv748, -1
  %63 = add nsw i64 %indvars.iv748, -2
  %64 = getelementptr i32, ptr %19, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !3
  %66 = add nsw i64 %indvars.iv748, -1
  %67 = getelementptr i32, ptr %.unpack616.peel, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !3
  %69 = call i32 @llvm.smax.i32(i32 %65, i32 %68)
  %70 = getelementptr i32, ptr %19, i64 %62
  store i32 %69, ptr %70, align 4, !tbaa !3
  %71 = add nuw nsw i64 %63, %.pre-phi762
  %72 = getelementptr i32, ptr %19, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !3
  %74 = trunc i64 %indvars.iv748 to i32
  %75 = sub i32 %42, %74
  %76 = sext i32 %75 to i64
  %77 = add nsw i64 %76, -1
  %78 = getelementptr i32, ptr %.unpack616.peel, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !3
  %80 = call i32 @llvm.smax.i32(i32 %73, i32 %79)
  %81 = add nuw nsw i64 %62, %.pre-phi762
  %82 = getelementptr i32, ptr %19, i64 %81
  store i32 %80, ptr %82, align 4, !tbaa !3
  %indvars.iv.next749 = add nuw nsw i64 %indvars.iv748, 1
  %exitcond751.not = icmp eq i64 %indvars.iv748, %36
  br i1 %exitcond751.not, label %.preheader, label %61

.lr.ph745:                                        ; preds = %59, %118
  %indvars.iv752 = phi i64 [ %indvars.iv.next753, %118 ], [ 2, %59 ]
  %.unpack616 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %83 = add nsw i64 %indvars.iv752, -1
  %84 = getelementptr i32, ptr %.unpack616, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !3
  %86 = icmp eq i32 %.lcssa.i, %85
  br i1 %86, label %87, label %115

87:                                               ; preds = %.lr.ph745
  %88 = load i32, ptr %1, align 4, !tbaa !3
  %89 = zext i32 %88 to i64
  %90 = icmp eq i64 %indvars.iv752, %89
  br i1 %90, label %91, label %100

91:                                               ; preds = %87
  %92 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.719a29ee42c508254a48092d170aaf77, i32 23)
  %.unpack644 = load ptr, ptr @_QFEleft.0, align 8, !tbaa !7
  %93 = load i32, ptr %1, align 4, !tbaa !3
  %94 = add i32 %93, -1
  %95 = sext i32 %94 to i64
  %96 = add nsw i64 %95, -1
  %97 = getelementptr i32, ptr %.unpack644, i64 %96
  %98 = load i32, ptr %97, align 4, !tbaa !3
  %99 = call i1 @_FortranAioOutputInteger32(ptr %92, i32 %98)
  br label %118

100:                                              ; preds = %87
  %101 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.719a29ee42c508254a48092d170aaf77, i32 25)
  %.unpack628 = load ptr, ptr @_QFEleft.0, align 8, !tbaa !7
  %.unpack635.unpack.unpack638 = load i64, ptr @_QFEleft.8, align 8, !tbaa !7
  %102 = add nsw i64 %indvars.iv752, -2
  %103 = getelementptr i32, ptr %.unpack628, i64 %102
  %104 = load i32, ptr %103, align 4, !tbaa !3
  %105 = load i32, ptr %1, align 4, !tbaa !3
  %106 = trunc i64 %indvars.iv752 to i32
  %107 = sub i32 %105, %106
  %108 = sext i32 %107 to i64
  %109 = add i64 %.unpack635.unpack.unpack638, -1
  %110 = add i64 %109, %108
  %111 = getelementptr i32, ptr %.unpack628, i64 %110
  %112 = load i32, ptr %111, align 4, !tbaa !3
  %113 = call i32 @llvm.smax.i32(i32 %104, i32 %112)
  %114 = call i1 @_FortranAioOutputInteger32(ptr %101, i32 %113)
  br label %118

115:                                              ; preds = %.lr.ph745
  %116 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.719a29ee42c508254a48092d170aaf77, i32 28)
  %117 = call i1 @_FortranAioOutputInteger32(ptr %116, i32 %.lcssa.i)
  br label %118

118:                                              ; preds = %91, %100, %115
  %.sink765 = phi ptr [ %92, %91 ], [ %101, %100 ], [ %116, %115 ]
  %119 = call i32 @_FortranAioEndIoStatement(ptr %.sink765)
  %indvars.iv.next753 = add nuw nsw i64 %indvars.iv752, 1
  %exitcond755.not = icmp eq i64 %indvars.iv752, %36
  br i1 %exitcond755.not, label %._crit_edge746, label %.lr.ph745, !llvm.loop !13

._crit_edge746:                                   ; preds = %118, %59, %.preheader
  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 @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare <4 x i32> @llvm.smax.v4i32(<4 x i32>, <4 x i32>) #2

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i32 @llvm.vector.reduce.smax.v4i32(<4 x i32>) #3

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { nocallback nofree nosync nounwind 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, !11}
!10 = !{!"llvm.loop.isvectorized", i32 1}
!11 = !{!"llvm.loop.unroll.runtime.disable"}
!12 = distinct !{!12, !11, !10}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.peeled.count", i32 1}
