program balance
  implicit none
  integer :: n, w(100), s1, s2, m, i
  w = 0
  read(*,*) n
  read(*,*) w(1:n)
  s1 = 0
  s2 = sum(w(1:n))
  m = 10000000
  do i = 1, n
    s1 = s1+w(i)
    s2 = s2-w(i)
    m = min(m,abs(s2-s1))
  end do
  write(*,'(i0)') m
  stop
end program balance
; 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 = internal global [100 x i32] undef
@_QQcl.597aadc4346d6d822bddd9755c641064 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_4089/source.f\00"
@_QQcl.28693029 = linkonce constant [4 x i8] c"(i0)"
@_QQEnvironmentDefaults = local_unnamed_addr constant ptr null

; Function Attrs: noreturn
define void @_QQmain() local_unnamed_addr #0 {
  %1 = alloca { ptr, i64, i32, i8, i8, i8, i8, [1 x [3 x i64]] }, align 8
  %2 = alloca i32, align 4
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(400) @_QFEw, i8 0, i64 400, i1 false), !tbaa !3
  %3 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.597aadc4346d6d822bddd9755c641064, i32 5)
  %4 = call i1 @_FortranAioInputInteger(ptr %3, ptr nonnull %2, i32 4)
  %5 = call i32 @_FortranAioEndIoStatement(ptr %3)
  %6 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.597aadc4346d6d822bddd9755c641064, i32 6)
  %7 = load i32, ptr %2, align 4, !tbaa !3
  %8 = call i32 @llvm.smax.i32(i32 %7, i32 0)
  %9 = zext i32 %8 to i64
  store ptr @_QFEw, 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 4, 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 9, 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 %9, 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 4, ptr %.fca.7.0.2.gep, align 8, !tbaa !7
  %10 = call i1 @_FortranAioInputDescriptor(ptr %6, ptr nonnull %1)
  %11 = call i32 @_FortranAioEndIoStatement(ptr %6)
  %12 = load i32, ptr %2, align 4, !tbaa !3
  %13 = call i32 @llvm.smax.i32(i32 %12, i32 0)
  %14 = zext i32 %13 to i64
  %.not = icmp slt i32 %12, 1
  br i1 %.not, label %._crit_edge, label %.lr.ph.i.preheader

.lr.ph.i.preheader:                               ; preds = %0
  %min.iters.check = icmp ult i32 %13, 8
  br i1 %min.iters.check, label %.lr.ph.i.preheader43, label %vector.ph

vector.ph:                                        ; preds = %.lr.ph.i.preheader
  %n.vec = and i64 %14, 2147483640
  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> [ zeroinitializer, %vector.ph ], [ %18, %vector.body ]
  %vec.phi41 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %19, %vector.body ]
  %15 = shl i64 %index, 2
  %16 = getelementptr i8, ptr @_QFEw, i64 %15
  %wide.load = load <4 x i32>, ptr %16, align 16, !tbaa !3
  %17 = getelementptr i32, ptr %16, i64 4
  %wide.load42 = load <4 x i32>, ptr %17, align 16, !tbaa !3
  %18 = add <4 x i32> %wide.load, %vec.phi
  %19 = add <4 x i32> %wide.load42, %vec.phi41
  %index.next = add nuw i64 %index, 8
  %20 = icmp eq i64 %index.next, %n.vec
  br i1 %20, label %middle.block, label %vector.body, !llvm.loop !9

middle.block:                                     ; preds = %vector.body
  %bin.rdx = add <4 x i32> %19, %18
  %21 = call i32 @llvm.vector.reduce.add.v4i32(<4 x i32> %bin.rdx)
  %cmp.n = icmp eq i64 %n.vec, %14
  br i1 %cmp.n, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i.preheader43

.lr.ph.i.preheader43:                             ; preds = %.lr.ph.i.preheader, %middle.block
  %.ph = phi i32 [ 0, %.lr.ph.i.preheader ], [ %21, %middle.block ]
  %.ph44 = phi i64 [ 0, %.lr.ph.i.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.i

.lr.ph.i:                                         ; preds = %.lr.ph.i.preheader43, %.lr.ph.i
  %22 = phi i32 [ %27, %.lr.ph.i ], [ %.ph, %.lr.ph.i.preheader43 ]
  %23 = phi i64 [ %28, %.lr.ph.i ], [ %.ph44, %.lr.ph.i.preheader43 ]
  %24 = shl i64 %23, 2
  %25 = getelementptr i8, ptr @_QFEw, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !3
  %27 = add i32 %26, %22
  %28 = add nuw nsw i64 %23, 1
  %exitcond.not.i = icmp eq i64 %28, %14
  br i1 %exitcond.not.i, label %_FortranASumInteger4x1_contract_simplified.exit, label %.lr.ph.i, !llvm.loop !12

_FortranASumInteger4x1_contract_simplified.exit:  ; preds = %.lr.ph.i, %middle.block
  %.lcssa40 = phi i32 [ %21, %middle.block ], [ %27, %.lr.ph.i ]
  %29 = icmp sgt i32 %12, 0
  br i1 %29, label %.lr.ph.preheader, label %._crit_edge

.lr.ph.preheader:                                 ; preds = %_FortranASumInteger4x1_contract_simplified.exit
  %30 = zext i32 %12 to i64
  %xtraiter = and i64 %30, 1
  %31 = icmp eq i32 %12, 1
  br i1 %31, label %._crit_edge.loopexit.unr-lcssa, label %.lr.ph.preheader.new

.lr.ph.preheader.new:                             ; preds = %.lr.ph.preheader
  %unroll_iter = and i64 %30, 4294967294
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph, %.lr.ph.preheader.new
  %indvars.iv = phi i64 [ 1, %.lr.ph.preheader.new ], [ %indvars.iv.next.1, %.lr.ph ]
  %.035 = phi i32 [ %.lcssa40, %.lr.ph.preheader.new ], [ %43, %.lr.ph ]
  %.02934 = phi i32 [ 0, %.lr.ph.preheader.new ], [ %42, %.lr.ph ]
  %.03033 = phi i32 [ 10000000, %.lr.ph.preheader.new ], [ %46, %.lr.ph ]
  %niter = phi i64 [ 0, %.lr.ph.preheader.new ], [ %niter.next.1, %.lr.ph ]
  %32 = add nsw i64 %indvars.iv, -1
  %33 = getelementptr [100 x i32], ptr @_QFEw, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !3
  %35 = add i32 %34, %.02934
  %36 = sub i32 %.035, %34
  %37 = sub i32 %36, %35
  %38 = call i32 @llvm.abs.i32(i32 %37, i1 false)
  %39 = call i32 @llvm.smin.i32(i32 %.03033, i32 %38)
  %40 = getelementptr [100 x i32], ptr @_QFEw, i64 0, i64 %indvars.iv
  %41 = load i32, ptr %40, align 4, !tbaa !3
  %42 = add i32 %41, %35
  %43 = sub i32 %36, %41
  %44 = sub i32 %43, %42
  %45 = call i32 @llvm.abs.i32(i32 %44, i1 false)
  %46 = call i32 @llvm.smin.i32(i32 %39, i32 %45)
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 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_edge.loopexit.unr-lcssa.loopexit, label %.lr.ph

._crit_edge.loopexit.unr-lcssa.loopexit:          ; preds = %.lr.ph
  %47 = add nuw nsw i64 %indvars.iv, 1
  br label %._crit_edge.loopexit.unr-lcssa

._crit_edge.loopexit.unr-lcssa:                   ; preds = %._crit_edge.loopexit.unr-lcssa.loopexit, %.lr.ph.preheader
  %.lcssa.ph = phi i32 [ undef, %.lr.ph.preheader ], [ %46, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %indvars.iv.unr = phi i64 [ 0, %.lr.ph.preheader ], [ %47, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.035.unr = phi i32 [ %.lcssa40, %.lr.ph.preheader ], [ %43, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.02934.unr = phi i32 [ 0, %.lr.ph.preheader ], [ %42, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %.03033.unr = phi i32 [ 10000000, %.lr.ph.preheader ], [ %46, %._crit_edge.loopexit.unr-lcssa.loopexit ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge, label %.lr.ph.epil

.lr.ph.epil:                                      ; preds = %._crit_edge.loopexit.unr-lcssa
  %48 = getelementptr [100 x i32], ptr @_QFEw, i64 0, i64 %indvars.iv.unr
  %49 = load i32, ptr %48, align 4, !tbaa !3
  %reass.add = shl i32 %49, 1
  %50 = add i32 %.02934.unr, %reass.add
  %51 = sub i32 %.035.unr, %50
  %52 = call i32 @llvm.abs.i32(i32 %51, i1 false)
  %53 = call i32 @llvm.smin.i32(i32 %.03033.unr, i32 %52)
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph.epil, %._crit_edge.loopexit.unr-lcssa, %0, %_FortranASumInteger4x1_contract_simplified.exit
  %.030.lcssa = phi i32 [ 10000000, %_FortranASumInteger4x1_contract_simplified.exit ], [ 10000000, %0 ], [ %.lcssa.ph, %._crit_edge.loopexit.unr-lcssa ], [ %53, %.lr.ph.epil ]
  %54 = call ptr @_FortranAioBeginExternalFormattedOutput(ptr nonnull @_QQcl.28693029, i64 4, ptr null, i32 -1, ptr nonnull @_QQcl.597aadc4346d6d822bddd9755c641064, i32 15)
  %55 = call i1 @_FortranAioOutputInteger32(ptr %54, i32 %.030.lcssa)
  %56 = call i32 @_FortranAioEndIoStatement(ptr %54)
  %57 = call {} @_FortranAStopStatement(i32 0, i1 false, i1 false)
  unreachable
}

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 @_FortranAioOutputInteger32(ptr, i32) local_unnamed_addr

declare {} @_FortranAStopStatement(i32, i1, i1) local_unnamed_addr

; Function Attrs: 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 i32 @llvm.abs.i32(i32, i1 immarg) #1

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

attributes #0 = { noreturn }
attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nounwind willreturn memory(argmem: write) }
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}
