program main
  implicit none
  integer(16) i,Mst, Mcash, N
  integer(16),allocatable :: A(:)
  read(*, *) N
  allocate(A(N))
  read(*, *) (A(i), i = 1,N)
  Mst = 0
  Mcash = 1000
  do i = 1,N-1
    if (A(i) > A(i+1)) then
      Mcash = Mcash + A(i)*Mst
      Mst = 0
    else
      Mst = Mst + (Mcash/A(i))
      Mcash = Mcash-(Mcash/A(i))*A(i)
    end if
  end do
  Mcash = Mcash + A(N)*Mst
  write(*, *) Mcash
end program main
; 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.e648e7cd4d658c582e7917500e882574 = linkonce constant [72 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_916/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 i128, align 8
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e648e7cd4d658c582e7917500e882574, i32 5)
  %3 = call i1 @_FortranAioInputInteger(ptr %2, ptr nonnull %1, i32 16)
  %4 = call i32 @_FortranAioEndIoStatement(ptr %2)
  %5 = load i128, ptr %1, align 8, !tbaa !3
  %6 = trunc i128 %5 to i64
  %7 = call i64 @llvm.smax.i64(i64 %6, i64 0)
  %8 = shl i64 %7, 4
  %9 = call ptr @malloc(i64 %8)
  store ptr %9, ptr @_QFEa.0, align 8, !tbaa !7
  %10 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.e648e7cd4d658c582e7917500e882574, i32 7)
  %11 = load i128, ptr %1, align 8, !tbaa !3
  %12 = trunc i128 %11 to i64
  %13 = icmp sgt i64 %12, 0
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %14 = phi i64 [ %18, %.lr.ph ], [ 1, %0 ]
  %.unpack179 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %15 = add i64 %14, -1
  %16 = getelementptr i128, ptr %.unpack179, i64 %15
  %17 = call i1 @_FortranAioInputInteger(ptr %10, ptr %16, i32 16)
  %18 = add nuw i64 %14, 1
  %exitcond.not = icmp eq i64 %14, %12
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %0
  %19 = call i32 @_FortranAioEndIoStatement(ptr %10)
  %20 = load i128, ptr %1, align 8, !tbaa !3
  %21 = trunc i128 %20 to i64
  %22 = add i64 %21, -1
  %23 = icmp sgt i64 %22, 0
  %.unpack167 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  br i1 %23, label %.lr.ph194, label %._crit_edge195

.lr.ph194:                                        ; preds = %._crit_edge, %44
  %24 = phi i64 [ %45, %44 ], [ %22, %._crit_edge ]
  %25 = phi i128 [ %30, %44 ], [ 1, %._crit_edge ]
  %.0192 = phi i128 [ %.1, %44 ], [ 0, %._crit_edge ]
  %.0141191 = phi i128 [ %.1142, %44 ], [ 1000, %._crit_edge ]
  %26 = trunc i128 %25 to i64
  %27 = add i64 %26, -1
  %28 = getelementptr i128, ptr %.unpack167, i64 %27
  %29 = load i128, ptr %28, align 8, !tbaa !3
  %30 = add nuw nsw i128 %25, 1
  %31 = trunc i128 %30 to i64
  %32 = add i64 %31, -1
  %33 = getelementptr i128, ptr %.unpack167, i64 %32
  %34 = load i128, ptr %33, align 8, !tbaa !3
  %35 = icmp sgt i128 %29, %34
  br i1 %35, label %36, label %39

36:                                               ; preds = %.lr.ph194
  %37 = mul i128 %29, %.0192
  %38 = add i128 %37, %.0141191
  br label %44

39:                                               ; preds = %.lr.ph194
  %40 = sdiv i128 %.0141191, %29
  %41 = add i128 %40, %.0192
  %42 = mul i128 %40, %29
  %43 = sub i128 %.0141191, %42
  br label %44

44:                                               ; preds = %36, %39
  %.1142 = phi i128 [ %38, %36 ], [ %43, %39 ]
  %.1 = phi i128 [ 0, %36 ], [ %41, %39 ]
  %45 = add i64 %24, -1
  %46 = icmp sgt i64 %45, 0
  br i1 %46, label %.lr.ph194, label %._crit_edge195

._crit_edge195:                                   ; preds = %44, %._crit_edge
  %.0141.lcssa = phi i128 [ 1000, %._crit_edge ], [ %.1142, %44 ]
  %.0.lcssa = phi i128 [ 0, %._crit_edge ], [ %.1, %44 ]
  %47 = add i64 %21, -1
  %48 = getelementptr i128, ptr %.unpack167, i64 %47
  %49 = load i128, ptr %48, align 8, !tbaa !3
  %50 = mul i128 %49, %.0.lcssa
  %51 = add i128 %50, %.0141.lcssa
  %52 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.e648e7cd4d658c582e7917500e882574, i32 20)
  %53 = call i1 @_FortranAioOutputInteger128(ptr %52, i128 %51)
  %54 = call i32 @_FortranAioEndIoStatement(ptr %52)
  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 @_FortranAioOutputInteger128(ptr, i128) 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}
