program abc44
 implicit none
 integer(8)::N,ia,ib,ans=0,r
 integer(8),allocatable::A(:)
 read(*,*)N
 allocate(A(N))
 read(*,*)(A(ia),ia=1,N)
 r=A(1)
 do ib=2,N
  if(r>A(ib))then
   ans=ans+r-A(ib)
  else
   r=A(ib)
  end if
 end do
 print'(i0)',ans
 deallocate(A)
end program abc44
; 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
@_QFEans = internal unnamed_addr global i64 0
@_QQcl.f9e5f9f1b013d0ff0d211f6aaf126fa5 = linkonce constant [72 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_756/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

; Function Attrs: mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite)
declare void @free(ptr allocptr nocapture noundef) local_unnamed_addr #1

define void @_QQmain() local_unnamed_addr {
  %1 = alloca i64, align 8
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.f9e5f9f1b013d0ff0d211f6aaf126fa5, i32 5)
  %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 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.f9e5f9f1b013d0ff0d211f6aaf126fa5, i32 7)
  %10 = load i64, ptr %1, align 8, !tbaa !3
  %11 = icmp sgt i64 %10, 0
  br i1 %11, label %.lr.ph, label %._crit_edge

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

._crit_edge:                                      ; preds = %.lr.ph, %0
  %17 = call i32 @_FortranAioEndIoStatement(ptr %9)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %18 = load i64, ptr %1, align 8, !tbaa !3
  %19 = add i64 %18, -1
  %20 = icmp sgt i64 %19, 0
  br i1 %20, label %.lr.ph225.preheader, label %._crit_edge226

.lr.ph225.preheader:                              ; preds = %._crit_edge
  %_QFEans.promoted = load i64, ptr @_QFEans, align 8, !tbaa !3
  %21 = load i64, ptr %.unpack, align 8, !tbaa !3
  %xtraiter = and i64 %19, 1
  %22 = icmp eq i64 %18, 2
  br i1 %22, label %._crit_edge226.loopexit.unr-lcssa, label %.lr.ph225.preheader.new

.lr.ph225.preheader.new:                          ; preds = %.lr.ph225.preheader
  %unroll_iter = and i64 %19, -2
  br label %.lr.ph225

.lr.ph225:                                        ; preds = %39, %.lr.ph225.preheader.new
  %23 = phi i64 [ 2, %.lr.ph225.preheader.new ], [ %41, %39 ]
  %.0223 = phi i64 [ %21, %.lr.ph225.preheader.new ], [ %.1.1, %39 ]
  %24 = phi i64 [ %_QFEans.promoted, %.lr.ph225.preheader.new ], [ %40, %39 ]
  %niter = phi i64 [ 0, %.lr.ph225.preheader.new ], [ %niter.next.1, %39 ]
  %25 = add i64 %23, -1
  %26 = getelementptr i64, ptr %.unpack, i64 %25
  %27 = load i64, ptr %26, align 8, !tbaa !3
  %28 = icmp sgt i64 %.0223, %27
  br i1 %28, label %29, label %.lr.ph225.1

29:                                               ; preds = %.lr.ph225
  %30 = sub i64 %.0223, %27
  %31 = add i64 %30, %24
  store i64 %31, ptr @_QFEans, align 8, !tbaa !3
  br label %.lr.ph225.1

.lr.ph225.1:                                      ; preds = %.lr.ph225, %29
  %32 = phi i64 [ %31, %29 ], [ %24, %.lr.ph225 ]
  %.1 = phi i64 [ %.0223, %29 ], [ %27, %.lr.ph225 ]
  %33 = getelementptr i64, ptr %.unpack, i64 %23
  %34 = load i64, ptr %33, align 8, !tbaa !3
  %35 = icmp sgt i64 %.1, %34
  br i1 %35, label %36, label %39

36:                                               ; preds = %.lr.ph225.1
  %37 = sub i64 %.1, %34
  %38 = add i64 %37, %32
  store i64 %38, ptr @_QFEans, align 8, !tbaa !3
  br label %39

39:                                               ; preds = %36, %.lr.ph225.1
  %40 = phi i64 [ %38, %36 ], [ %32, %.lr.ph225.1 ]
  %.1.1 = phi i64 [ %.1, %36 ], [ %34, %.lr.ph225.1 ]
  %41 = add nuw i64 %23, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge226.loopexit.unr-lcssa.loopexit, label %.lr.ph225

._crit_edge226.loopexit.unr-lcssa.loopexit:       ; preds = %39
  %42 = or i64 %23, 1
  br label %._crit_edge226.loopexit.unr-lcssa

._crit_edge226.loopexit.unr-lcssa:                ; preds = %._crit_edge226.loopexit.unr-lcssa.loopexit, %.lr.ph225.preheader
  %.unr = phi i64 [ 1, %.lr.ph225.preheader ], [ %42, %._crit_edge226.loopexit.unr-lcssa.loopexit ]
  %.0223.unr = phi i64 [ %21, %.lr.ph225.preheader ], [ %.1.1, %._crit_edge226.loopexit.unr-lcssa.loopexit ]
  %.unr228 = phi i64 [ %_QFEans.promoted, %.lr.ph225.preheader ], [ %40, %._crit_edge226.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge226, label %.lr.ph225.epil

.lr.ph225.epil:                                   ; preds = %._crit_edge226.loopexit.unr-lcssa
  %43 = getelementptr i64, ptr %.unpack, i64 %.unr
  %44 = load i64, ptr %43, align 8, !tbaa !3
  %45 = icmp sgt i64 %.0223.unr, %44
  br i1 %45, label %46, label %._crit_edge226

46:                                               ; preds = %.lr.ph225.epil
  %47 = sub i64 %.0223.unr, %44
  %48 = add i64 %47, %.unr228
  store i64 %48, ptr @_QFEans, align 8, !tbaa !3
  br label %._crit_edge226

._crit_edge226:                                   ; preds = %._crit_edge226.loopexit.unr-lcssa, %46, %.lr.ph225.epil, %._crit_edge
  %49 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.f9e5f9f1b013d0ff0d211f6aaf126fa5, i32 16)
  %50 = load i64, ptr @_QFEans, align 8, !tbaa !3
  %51 = call i1 @_FortranAioOutputInteger64(ptr %49, i64 %50)
  %52 = call i32 @_FortranAioEndIoStatement(ptr %49)
  %.unpack187 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  call void @free(ptr %.unpack187)
  store ptr null, ptr @_QFEa.0, align 8, !tbaa !7
  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 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { mustprogress nounwind willreturn allockind("free") memory(argmem: readwrite, inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #2 = { 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}
