program sample
implicit none
integer(8) :: i,j,maxdivision
integer(8) :: x,y,count
real(8),allocatable :: a(:),b(:)

read(*,*) x,y

allocate(a(x))

read(*,*) a

count=0

do i=1,x-1
	if (a(i)+a(i+1)>y) then
	count = count+a(i)+a(i+1)-y
	a(i+1)=y-a(i)
		if (a(i+1)<0) then
		a(i)=a(i)+a(i+1)
		a(i+1) = 0
		end if
	end if
end do

write(*,*) count
!write(*,*) a

end program sample
; 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.9e3b5ca1aa1bb194c1da1af2d55b92d5 = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_7712/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 = alloca i64, align 8
  %4 = tail call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.9e3b5ca1aa1bb194c1da1af2d55b92d5, i32 7)
  %5 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %2, i32 8)
  %6 = call i1 @_FortranAioInputInteger(ptr %4, ptr nonnull %3, i32 8)
  %7 = call i32 @_FortranAioEndIoStatement(ptr %4)
  %8 = load i64, ptr %2, align 8, !tbaa !3
  %9 = call i64 @llvm.smax.i64(i64 %8, i64 0)
  %10 = shl i64 %9, 3
  %11 = call ptr @malloc(i64 %10)
  store ptr %11, ptr @_QFEa.0, align 8, !tbaa !7
  store i64 %9, ptr @_QFEa.8, align 8, !tbaa !7
  %12 = call ptr @_FortranAioBeginExternalListInput(i32 -1, ptr nonnull @_QQcl.9e3b5ca1aa1bb194c1da1af2d55b92d5, i32 11)
  %.unpack = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %.unpack244.unpack.unpack246 = 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 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 28, 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 %.unpack244.unpack.unpack246, 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
  %13 = call i1 @_FortranAioInputDescriptor(ptr %12, ptr nonnull %1)
  %14 = call i32 @_FortranAioEndIoStatement(ptr %12)
  %15 = load i64, ptr %2, align 8, !tbaa !3
  %16 = add i64 %15, -1
  %17 = icmp sgt i64 %16, 0
  br i1 %17, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0
  %.unpack249 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  br label %18

18:                                               ; preds = %.lr.ph, %40
  %19 = phi i64 [ 1, %.lr.ph ], [ %23, %40 ]
  %.0285 = phi i64 [ 0, %.lr.ph ], [ %.1, %40 ]
  %20 = add i64 %19, -1
  %21 = getelementptr double, ptr %.unpack249, i64 %20
  %22 = load double, ptr %21, align 8, !tbaa !3
  %23 = add nuw i64 %19, 1
  %24 = getelementptr double, ptr %.unpack249, i64 %19
  %25 = load double, ptr %24, align 8, !tbaa !3
  %26 = fadd contract double %22, %25
  %27 = load i64, ptr %3, align 8, !tbaa !3
  %28 = sitofp i64 %27 to double
  %29 = fcmp ogt double %26, %28
  br i1 %29, label %30, label %40

30:                                               ; preds = %18
  %31 = sitofp i64 %.0285 to double
  %32 = fadd contract double %22, %31
  %33 = fadd contract double %32, %25
  %34 = fsub contract double %33, %28
  %35 = fptosi double %34 to i64
  %36 = fsub contract double %28, %22
  store double %36, ptr %24, align 8, !tbaa !3
  %37 = fcmp olt double %36, 0.000000e+00
  br i1 %37, label %38, label %40

38:                                               ; preds = %30
  %39 = fadd contract double %22, %36
  store double %39, ptr %21, align 8, !tbaa !3
  store double 0.000000e+00, ptr %24, align 8, !tbaa !3
  br label %40

40:                                               ; preds = %38, %30, %18
  %.1 = phi i64 [ %35, %38 ], [ %35, %30 ], [ %.0285, %18 ]
  %exitcond.not = icmp eq i64 %23, %15
  br i1 %exitcond.not, label %._crit_edge, label %18

._crit_edge:                                      ; preds = %40, %0
  %.0.lcssa = phi i64 [ 0, %0 ], [ %.1, %40 ]
  %41 = call ptr @_FortranAioBeginExternalListOutput(i32 -1, ptr nonnull @_QQcl.9e3b5ca1aa1bb194c1da1af2d55b92d5, i32 26)
  %42 = call i1 @_FortranAioOutputInteger64(ptr %41, i64 %.0.lcssa)
  %43 = call i32 @_FortranAioEndIoStatement(ptr %41)
  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

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}
