program main
 implicit none
 integer*8 n,s1,s2,ans,tmp,i
 integer*8, allocatable :: w(:)
 read(*,*) n
 allocate(w(1:n))
 read(*,*)w
 s1=0
 s2=0
 do i=1,n
  s1 = s1 + w(i)
 end do
 ans = s1
 tmp = ans
 do i=1,n
  s2 = s2 + w(i)
  s1 = s1 - w(i)
  tmp = s1 - s2
  if (tmp < 0) then
   if(abs(tmp) < ans) then
    ans = abs(tmp)
   end if
   exit
  end if
  ans = tmp
 end do
 write(*,*) ans
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"

@_QFEw.0 = internal unnamed_addr global ptr null
@_QFEw.8 = internal unnamed_addr global i64 0
@_QQcl.f78104c15e3644430acccc17730f365f = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_4097/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 { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i64, align 8
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.f78104c15e3644430acccc17730f365f, i32 5)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 8)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = load i64, ptr %2, align 8, !tbaa !3
  %7 = call i64 @llvm.smax.i64(i64 %6, i64 0)
  %8 = shl i64 %7, 3
  %9 = call ptr @malloc(i64 %8)
  store ptr %9, ptr @_QFEw.0, align 8, !tbaa !7
  store i64 %7, ptr @_QFEw.8, align 8, !tbaa !7
  %10 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.f78104c15e3644430acccc17730f365f, i32 7)
  %.unpack = load ptr, ptr @_QFEw.0, align 8, !tbaa !7
  %.unpack171.unpack.unpack173 = load i64, ptr @_QFEw.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 8, 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 10, 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 %.unpack171.unpack.unpack173, 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 8, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %11 = call i1 @_FortranAioInputDescriptor(ptr %10, ptr nonnull %1)
  %12 = call i32 @_FortranAioEndIoStatement(ptr %10)
  %13 = load i64, ptr %2, align 8, !tbaa !3
  %14 = icmp sgt i64 %13, 0
  br i1 %14, label %.lr.ph, label %.loopexit

.lr.ph:                                           ; preds = %0
  %.unpack188 = load ptr, ptr @_QFEw.0, align 8, !tbaa !7
  %min.iters.check = icmp ult i64 %13, 4
  br i1 %min.iters.check, label %scalar.ph.preheader, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph
  %n.vec = and i64 %13, -4
  %ind.end = or i64 %n.vec, 1
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %17, %vector.body ]
  %vec.phi223 = phi <2 x i64> [ zeroinitializer, %vector.ph ], [ %18, %vector.body ]
  %15 = getelementptr i64, ptr %.unpack188, i64 %index
  %wide.load = load <2 x i64>, ptr %15, align 8, !tbaa !3
  %16 = getelementptr i64, ptr %15, i64 2
  %wide.load224 = load <2 x i64>, ptr %16, align 8, !tbaa !3
  %17 = add <2 x i64> %wide.load, %vec.phi
  %18 = add <2 x i64> %wide.load224, %vec.phi223
  %index.next = add nuw i64 %index, 4
  %19 = icmp eq i64 %index.next, %n.vec
  br i1 %19, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <2 x i64> %18, %17
  %20 = call i64 @llvm.vector.reduce.add.v2i64(<2 x i64> %bin.rdx)
  %cmp.n = icmp eq i64 %13, %n.vec
  br i1 %cmp.n, label %.preheader, label %scalar.ph.preheader

scalar.ph.preheader:                              ; preds = %.lr.ph, %middle.block
  %.ph = phi i64 [ 1, %.lr.ph ], [ %ind.end, %middle.block ]
  %.0147201.ph = phi i64 [ 0, %.lr.ph ], [ %20, %middle.block ]
  br label %scalar.ph

.preheader:                                       ; preds = %scalar.ph, %middle.block
  %.lcssa219 = phi i64 [ %20, %middle.block ], [ %29, %scalar.ph ]
  br i1 %14, label %.lr.ph207, label %.loopexit

.lr.ph207:                                        ; preds = %.preheader
  %.unpack176 = load ptr, ptr @_QFEw.0, align 8, !tbaa !7
  %21 = load i64, ptr %.unpack176, align 8, !tbaa !3
  %22 = sub i64 %.lcssa219, %21
  %23 = sub i64 %22, %21
  %24 = icmp slt i64 %23, 0
  br i1 %24, label %._crit_edge, label %.lr.ph221

scalar.ph:                                        ; preds = %scalar.ph.preheader, %scalar.ph
  %25 = phi i64 [ %30, %scalar.ph ], [ %.ph, %scalar.ph.preheader ]
  %.0147201 = phi i64 [ %29, %scalar.ph ], [ %.0147201.ph, %scalar.ph.preheader ]
  %26 = add i64 %25, -1
  %27 = getelementptr i64, ptr %.unpack188, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !3
  %29 = add i64 %28, %.0147201
  %30 = add nuw i64 %25, 1
  %exitcond.not = icmp eq i64 %25, %13
  br i1 %exitcond.not, label %.preheader, label %scalar.ph, !llvm.loop !12

31:                                               ; preds = %.lr.ph221
  %32 = add nuw i64 %.0148204220, 1
  %33 = getelementptr i64, ptr %.unpack176, i64 %.0148204220
  %34 = load i64, ptr %33, align 8, !tbaa !3
  %35 = add i64 %34, %42
  %36 = sub i64 %41, %34
  %37 = sub i64 %36, %35
  %38 = icmp slt i64 %37, 0
  br i1 %38, label %._crit_edge, label %.lr.ph221

._crit_edge:                                      ; preds = %31, %.lr.ph207
  %.0149203.lcssa = phi i64 [ %.lcssa219, %.lr.ph207 ], [ %40, %31 ]
  %.lcssa = phi i64 [ %23, %.lr.ph207 ], [ %37, %31 ]
  %39 = sub i64 0, %.lcssa
  %spec.select = call i64 @llvm.smin.i64(i64 %.0149203.lcssa, i64 %39)
  br label %.loopexit

.lr.ph221:                                        ; preds = %.lr.ph207, %31
  %40 = phi i64 [ %37, %31 ], [ %23, %.lr.ph207 ]
  %41 = phi i64 [ %36, %31 ], [ %22, %.lr.ph207 ]
  %42 = phi i64 [ %35, %31 ], [ %21, %.lr.ph207 ]
  %.0148204220 = phi i64 [ %32, %31 ], [ 1, %.lr.ph207 ]
  %exitcond212.not = icmp eq i64 %.0148204220, %13
  br i1 %exitcond212.not, label %.loopexit, label %31

.loopexit:                                        ; preds = %.lr.ph221, %0, %.preheader, %._crit_edge
  %.1150 = phi i64 [ %spec.select, %._crit_edge ], [ %.lcssa219, %.preheader ], [ 0, %0 ], [ %40, %.lr.ph221 ]
  %43 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.f78104c15e3644430acccc17730f365f, i32 27)
  %44 = call i1 @_FortranAioOutputInteger64(ptr %43, i64 %.1150)
  %45 = call i32 @_FortranAioEndIoStatement(ptr %43)
  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 @_FortranAioBeginExternalListOutput(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) #1

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

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(none)
declare i64 @llvm.vector.reduce.add.v2i64(<2 x i64>) #2

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) }
attributes #2 = { 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}
