program DISCO2020yB
integer(16)::N
integer(16),allocatable::A(:)
integer(16) sumA
integer(16) cost,subsum
read*,N
allocate(A(N))
read*,A
sumA=(sum(A))
cost=huge(cost)
subsum=0
do i=1,N
  subsum=subsum+A(i)
  cost=min(cost,abs(sumA-2*subsum))
end do
print"(i0)",cost
end
; 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
@_QQcl.8363d56d3d9e8ec579b369f53c59bb8c = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_2946/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 { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i128, align 8
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.8363d56d3d9e8ec579b369f53c59bb8c, i32 6)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 16)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = load i128, ptr %2, align 8, !tbaa !3
  %7 = trunc i128 %6 to i64
  %8 = call i64 @llvm.smax.i64(i64 %7, i64 0)
  %9 = shl i64 %8, 4
  %10 = call ptr @malloc(i64 %9)
  store ptr %10, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %8, ptr @_QFEa.8, align 8, !tbaa !7
  %11 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.8363d56d3d9e8ec579b369f53c59bb8c, i32 8)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack141.unpack.unpack143 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  store ptr %.unpack, ptr %1, align 8, !tbaa !7
  %.fca.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 1
  store i64 16, ptr %.fca.1.gep, align 8, !tbaa !7
  %.fca.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 2
  store i32 20180515, ptr %.fca.2.gep, align 8, !tbaa !7
  %.fca.3.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 3
  store i8 1, ptr %.fca.3.gep, align 4, !tbaa !7
  %.fca.4.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 4
  store i8 11, ptr %.fca.4.gep, align 1, !tbaa !7
  %.fca.5.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 5
  store i8 0, ptr %.fca.5.gep, align 2, !tbaa !7
  %.fca.6.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 6
  store i8 0, ptr %.fca.6.gep, align 1, !tbaa !7
  %.fca.7.0.0.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 0
  store i64 1, ptr %.fca.7.0.0.gep, align 8, !tbaa !7
  %.fca.7.0.1.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 1
  store i64 %.unpack141.unpack.unpack143, ptr %.fca.7.0.1.gep, align 8, !tbaa !7
  %.fca.7.0.2.gep = getelementptr inbounds { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, ptr %1, i64 0, i32 7, i64 0, i64 2
  store i64 16, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %12 = call i1 @_FortranAioInputDescriptor(ptr %11, ptr nonnull %1)
  %13 = call i32 @_FortranAioEndIoStatement(ptr %11)
  %.unpack146 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack153.unpack.unpack155 = load i64, ptr @_QFEa.8, align 8, !tbaa !7
  %14 = icmp sgt i64 %.unpack153.unpack.unpack155, 0
  br i1 %14, label %.lr.ph.i.preheader, label %_FortranASumInteger16x1_contract_simplified.exit

.lr.ph.i.preheader:                               ; preds = %0
  %xtraiter = and i64 %.unpack153.unpack.unpack155, 3
  %15 = icmp ult i64 %.unpack153.unpack.unpack155, 4
  br i1 %15, label %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa, label %.lr.ph.i.preheader.new

.lr.ph.i.preheader.new:                           ; preds = %.lr.ph.i.preheader
  %unroll_iter = and i64 %.unpack153.unpack.unpack155, -4
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i, %.lr.ph.i.preheader.new
  %16 = phi i128 [ 0, %.lr.ph.i.preheader.new ], [ %36, %.lr.ph.i ]
  %17 = phi i64 [ 0, %.lr.ph.i.preheader.new ], [ %37, %.lr.ph.i ]
  %niter = phi i64 [ 0, %.lr.ph.i.preheader.new ], [ %niter.next.3, %.lr.ph.i ]
  %18 = shl i64 %17, 4
  %19 = getelementptr i8, ptr %.unpack146, i64 %18
  %20 = load i128, ptr %19, align 8, !tbaa !3
  %21 = add i128 %20, %16
  %22 = shl i64 %17, 4
  %23 = or i64 %22, 16
  %24 = getelementptr i8, ptr %.unpack146, i64 %23
  %25 = load i128, ptr %24, align 8, !tbaa !3
  %26 = add i128 %25, %21
  %27 = shl i64 %17, 4
  %28 = or i64 %27, 32
  %29 = getelementptr i8, ptr %.unpack146, i64 %28
  %30 = load i128, ptr %29, align 8, !tbaa !3
  %31 = add i128 %30, %26
  %32 = shl i64 %17, 4
  %33 = or i64 %32, 48
  %34 = getelementptr i8, ptr %.unpack146, i64 %33
  %35 = load i128, ptr %34, align 8, !tbaa !3
  %36 = add i128 %35, %31
  %37 = add nuw nsw i64 %17, 4
  %niter.next.3 = add i64 %niter, 4
  %niter.ncmp.3 = icmp eq i64 %niter.next.3, %unroll_iter
  br i1 %niter.ncmp.3, label %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa, label %.lr.ph.i

_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa: ; preds = %.lr.ph.i, %.lr.ph.i.preheader
  %.lcssa175.ph = phi i128 [ undef, %.lr.ph.i.preheader ], [ %36, %.lr.ph.i ]
  %.unr = phi i128 [ 0, %.lr.ph.i.preheader ], [ %36, %.lr.ph.i ]
  %.unr176 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %37, %.lr.ph.i ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %_FortranASumInteger16x1_contract_simplified.exit, label %.lr.ph.i.epil

.lr.ph.i.epil:                                    ; preds = %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa, %.lr.ph.i.epil
  %38 = phi i128 [ %43, %.lr.ph.i.epil ], [ %.unr, %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa ]
  %39 = phi i64 [ %44, %.lr.ph.i.epil ], [ %.unr176, %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa ]
  %epil.iter = phi i64 [ %epil.iter.next, %.lr.ph.i.epil ], [ 0, %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa ]
  %40 = shl i64 %39, 4
  %41 = getelementptr i8, ptr %.unpack146, i64 %40
  %42 = load i128, ptr %41, align 8, !tbaa !3
  %43 = add i128 %42, %38
  %44 = add nuw nsw i64 %39, 1
  %epil.iter.next = add i64 %epil.iter, 1
  %epil.iter.cmp.not = icmp eq i64 %epil.iter.next, %xtraiter
  br i1 %epil.iter.cmp.not, label %_FortranASumInteger16x1_contract_simplified.exit, label %.lr.ph.i.epil, !llvm.loop !9

_FortranASumInteger16x1_contract_simplified.exit: ; preds = %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa, %.lr.ph.i.epil, %0
  %.lcssa.i = phi i128 [ 0, %0 ], [ %.lcssa175.ph, %_FortranASumInteger16x1_contract_simplified.exit.loopexit.unr-lcssa ], [ %43, %.lr.ph.i.epil ]
  %45 = load i128, ptr %2, align 8, !tbaa !3
  %46 = trunc i128 %45 to i64
  %47 = icmp sgt i64 %46, 0
  br i1 %47, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %_FortranASumInteger16x1_contract_simplified.exit, %.lr.ph
  %48 = phi i64 [ %60, %.lr.ph ], [ %46, %_FortranASumInteger16x1_contract_simplified.exit ]
  %49 = phi i32 [ %59, %.lr.ph ], [ 1, %_FortranASumInteger16x1_contract_simplified.exit ]
  %.0171 = phi i128 [ %58, %.lr.ph ], [ 170141183460469231731687303715884105727, %_FortranASumInteger16x1_contract_simplified.exit ]
  %.0124170 = phi i128 [ %54, %.lr.ph ], [ 0, %_FortranASumInteger16x1_contract_simplified.exit ]
  %50 = sext i32 %49 to i64
  %51 = add nsw i64 %50, -1
  %52 = getelementptr i128, ptr %.unpack146, i64 %51
  %53 = load i128, ptr %52, align 8, !tbaa !3
  %54 = add i128 %53, %.0124170
  %55 = shl i128 %54, 1
  %56 = sub i128 %.lcssa.i, %55
  %57 = call i128 @llvm.abs.i128(i128 %56, i1 false)
  %58 = call i128 @llvm.smin.i128(i128 %.0171, i128 %57)
  %59 = add i32 %49, 1
  %60 = add nsw i64 %48, -1
  %61 = icmp ugt i64 %48, 1
  br i1 %61, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %_FortranASumInteger16x1_contract_simplified.exit
  %.0.lcssa = phi i128 [ 170141183460469231731687303715884105727, %_FortranASumInteger16x1_contract_simplified.exit ], [ %58, %.lr.ph ]
  %62 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.8363d56d3d9e8ec579b369f53c59bb8c, i32 16)
  %63 = call i1 @_FortranAioOutputInteger128(ptr %62, i128 %.0.lcssa)
  %64 = call i32 @_FortranAioEndIoStatement(ptr %62)
  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 i1 @_FortranAioInputDescriptor(ptr, ptr) local_unnamed_addr

declare ptr @_FortranAioBeginExternalFormattedOutput(ptr, i64, ptr, 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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i128 @llvm.abs.i128(i128, i1 immarg) #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i128 @llvm.smin.i128(i128, i128) #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}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.unroll.disable"}
