program B086
    implicit none
    integer(8) :: N
    integer(8), allocatable, dimension(:) :: a
    integer(8) :: i, j, max, Alice, Bob

    read(5,*) N
    allocate(a(N))
    read(5,*) (a(i), i = 1, N)
    Alice = 0
    Bob = 0


    do i = 1, N
        if (mod(i,2) /= 0) then
            max = maxval(a)
            Alice = Alice + max 

        else
            max = maxval(a)
            Bob = Bob + max

        end if

        j = 1
        do while (a(j) /= max)
            j = j + 1
        end do

        a(j) = 0

    end do

    write(6,*) Alice - Bob


end program B086

; 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.de316e6c3a3bfaac099cee4830b117dd = linkonce constant [73 x i8] c"/home/ubuntu/Downloads/TheStack_IR/Collated/Fortran/Source_6260/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 i64, align 8
  %2 = tail call ptr @_FortranAioBeginExternalListInput(i32 5, ptr nonnull @_QQcl.de316e6c3a3bfaac099cee4830b117dd, i32 7)
  %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
  store i64 %6, ptr @_QFEa.8, align 8, !tbaa !7
  %9 = call ptr @_FortranAioBeginExternalListInput(i32 5, ptr nonnull @_QQcl.de316e6c3a3bfaac099cee4830b117dd, i32 9)
  %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 ]
  %.unpack244 = load ptr, ptr @_QFEa.0, align 8, !tbaa !7
  %13 = add i64 %12, -1
  %14 = getelementptr i64, ptr %.unpack244, 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)
  %18 = load i64, ptr %1, align 8, !tbaa !3
  %19 = icmp sgt i64 %18, 0
  br i1 %19, label %.lr.ph278, label %._crit_edge279

.lr.ph278:                                        ; preds = %._crit_edge
  %.unpack232 = load ptr, ptr @_QFEa.0, align 8
  %.unpack239.unpack.unpack241 = load i64, ptr @_QFEa.8, align 8
  %.unpack239.unpack.unpack241.fr = freeze i64 %.unpack239.unpack.unpack241
  %20 = icmp sgt i64 %.unpack239.unpack.unpack241.fr, 0
  br i1 %20, label %.lr.ph278.split.us.preheader, label %.lr.ph278.split.split

.lr.ph278.split.us.preheader:                     ; preds = %.lr.ph278
  %min.iters.check = icmp ult i64 %.unpack239.unpack.unpack241.fr, 4
  %n.vec333 = and i64 %.unpack239.unpack.unpack241.fr, -4
  %cmp.n335 = icmp eq i64 %.unpack239.unpack.unpack241.fr, %n.vec333
  %n.vec = and i64 %.unpack239.unpack.unpack241.fr, -4
  %cmp.n = icmp eq i64 %.unpack239.unpack.unpack241.fr, %n.vec
  br label %.lr.ph278.split.us

.lr.ph278.split.us:                               ; preds = %.lr.ph278.split.us.preheader, %57
  %.0193276.us = phi i64 [ %59, %57 ], [ 1, %.lr.ph278.split.us.preheader ]
  %.0194275.us = phi i64 [ %.1.us, %57 ], [ 0, %.lr.ph278.split.us.preheader ]
  %.0195274.us = phi i64 [ %.1196.us, %57 ], [ 0, %.lr.ph278.split.us.preheader ]
  %21 = and i64 %.0193276.us, 1
  %.not.us = icmp eq i64 %21, 0
  br i1 %.not.us, label %.lr.ph.i256.us.preheader, label %.lr.ph.i.us.preheader

.lr.ph.i.us.preheader:                            ; preds = %.lr.ph278.split.us
  br i1 %min.iters.check, label %.lr.ph.i.us.preheader348, label %vector.body336

vector.body336:                                   ; preds = %.lr.ph.i.us.preheader, %vector.body336
  %index337 = phi i64 [ %index.next342, %vector.body336 ], [ 0, %.lr.ph.i.us.preheader ]
  %vec.phi338 = phi <2 x i64> [ %25, %vector.body336 ], [ <i64 -9223372036854775808, i64 -9223372036854775808>, %.lr.ph.i.us.preheader ]
  %vec.phi339 = phi <2 x i64> [ %26, %vector.body336 ], [ <i64 -9223372036854775808, i64 -9223372036854775808>, %.lr.ph.i.us.preheader ]
  %22 = shl i64 %index337, 3
  %23 = getelementptr i8, ptr %.unpack232, i64 %22
  %wide.load340 = load <2 x i64>, ptr %23, align 8, !tbaa !3
  %24 = getelementptr i64, ptr %23, i64 2
  %wide.load341 = load <2 x i64>, ptr %24, align 8, !tbaa !3
  %25 = call <2 x i64> @llvm.smax.v2i64(<2 x i64> %wide.load340, <2 x i64> %vec.phi338)
  %26 = call <2 x i64> @llvm.smax.v2i64(<2 x i64> %wide.load341, <2 x i64> %vec.phi339)
  %index.next342 = add nuw i64 %index337, 4
  %27 = icmp eq i64 %index.next342, %n.vec333
  br i1 %27, label %middle.block328, label %vector.body336, !llvm.loop !9

middle.block328:                                  ; preds = %vector.body336
  %rdx.minmax.select344 = call <2 x i64> @llvm.smax.v2i64(<2 x i64> %25, <2 x i64> %26)
  %28 = call i64 @llvm.vector.reduce.smax.v2i64(<2 x i64> %rdx.minmax.select344)
  br i1 %cmp.n335, label %_FortranAMaxvalInteger8x1_contract_simplified.exit.loopexit.us, label %.lr.ph.i.us.preheader348

.lr.ph.i.us.preheader348:                         ; preds = %.lr.ph.i.us.preheader, %middle.block328
  %.ph349 = phi i64 [ -9223372036854775808, %.lr.ph.i.us.preheader ], [ %28, %middle.block328 ]
  %.ph350 = phi i64 [ 0, %.lr.ph.i.us.preheader ], [ %n.vec333, %middle.block328 ]
  br label %.lr.ph.i.us

.lr.ph.i256.us.preheader:                         ; preds = %.lr.ph278.split.us
  br i1 %min.iters.check, label %.lr.ph.i256.us.preheader346, label %vector.body

vector.body:                                      ; preds = %.lr.ph.i256.us.preheader, %vector.body
  %index = phi i64 [ %index.next, %vector.body ], [ 0, %.lr.ph.i256.us.preheader ]
  %vec.phi = phi <2 x i64> [ %32, %vector.body ], [ <i64 -9223372036854775808, i64 -9223372036854775808>, %.lr.ph.i256.us.preheader ]
  %vec.phi326 = phi <2 x i64> [ %33, %vector.body ], [ <i64 -9223372036854775808, i64 -9223372036854775808>, %.lr.ph.i256.us.preheader ]
  %29 = shl i64 %index, 3
  %30 = getelementptr i8, ptr %.unpack232, i64 %29
  %wide.load = load <2 x i64>, ptr %30, align 8, !tbaa !3
  %31 = getelementptr i64, ptr %30, i64 2
  %wide.load327 = load <2 x i64>, ptr %31, align 8, !tbaa !3
  %32 = call <2 x i64> @llvm.smax.v2i64(<2 x i64> %wide.load, <2 x i64> %vec.phi)
  %33 = call <2 x i64> @llvm.smax.v2i64(<2 x i64> %wide.load327, <2 x i64> %vec.phi326)
  %index.next = add nuw i64 %index, 4
  %34 = icmp eq i64 %index.next, %n.vec
  br i1 %34, label %middle.block, label %vector.body, !llvm.loop !12

middle.block:                                     ; preds = %vector.body
  %rdx.minmax.select = call <2 x i64> @llvm.smax.v2i64(<2 x i64> %32, <2 x i64> %33)
  %35 = call i64 @llvm.vector.reduce.smax.v2i64(<2 x i64> %rdx.minmax.select)
  br i1 %cmp.n, label %_FortranAMaxvalInteger8x1_contract_simplified.exit259.us, label %.lr.ph.i256.us.preheader346

.lr.ph.i256.us.preheader346:                      ; preds = %.lr.ph.i256.us.preheader, %middle.block
  %.ph = phi i64 [ -9223372036854775808, %.lr.ph.i256.us.preheader ], [ %35, %middle.block ]
  %.ph347 = phi i64 [ 0, %.lr.ph.i256.us.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph.i256.us

.lr.ph.i.us:                                      ; preds = %.lr.ph.i.us.preheader348, %.lr.ph.i.us
  %36 = phi i64 [ %41, %.lr.ph.i.us ], [ %.ph349, %.lr.ph.i.us.preheader348 ]
  %37 = phi i64 [ %42, %.lr.ph.i.us ], [ %.ph350, %.lr.ph.i.us.preheader348 ]
  %38 = shl i64 %37, 3
  %39 = getelementptr i8, ptr %.unpack232, i64 %38
  %40 = load i64, ptr %39, align 8, !tbaa !3
  %41 = call i64 @llvm.smax.i64(i64 %40, i64 %36)
  %42 = add nuw nsw i64 %37, 1
  %exitcond.not.i.us = icmp eq i64 %42, %.unpack239.unpack.unpack241.fr
  br i1 %exitcond.not.i.us, label %_FortranAMaxvalInteger8x1_contract_simplified.exit.loopexit.us, label %.lr.ph.i.us, !llvm.loop !13

.lr.ph.i256.us:                                   ; preds = %.lr.ph.i256.us.preheader346, %.lr.ph.i256.us
  %43 = phi i64 [ %48, %.lr.ph.i256.us ], [ %.ph, %.lr.ph.i256.us.preheader346 ]
  %44 = phi i64 [ %49, %.lr.ph.i256.us ], [ %.ph347, %.lr.ph.i256.us.preheader346 ]
  %45 = shl i64 %44, 3
  %46 = getelementptr i8, ptr %.unpack232, i64 %45
  %47 = load i64, ptr %46, align 8, !tbaa !3
  %48 = call i64 @llvm.smax.i64(i64 %47, i64 %43)
  %49 = add nuw nsw i64 %44, 1
  %exitcond.not.i257.us = icmp eq i64 %49, %.unpack239.unpack.unpack241.fr
  br i1 %exitcond.not.i257.us, label %_FortranAMaxvalInteger8x1_contract_simplified.exit259.us, label %.lr.ph.i256.us, !llvm.loop !14

_FortranAMaxvalInteger8x1_contract_simplified.exit259.us: ; preds = %.lr.ph.i256.us, %middle.block
  %.lcssa323 = phi i64 [ %35, %middle.block ], [ %48, %.lr.ph.i256.us ]
  %50 = add i64 %.lcssa323, %.0194275.us
  br label %51

51:                                               ; preds = %_FortranAMaxvalInteger8x1_contract_simplified.exit259.us, %_FortranAMaxvalInteger8x1_contract_simplified.exit.loopexit.us
  %.1196.us = phi i64 [ %60, %_FortranAMaxvalInteger8x1_contract_simplified.exit.loopexit.us ], [ %.0195274.us, %_FortranAMaxvalInteger8x1_contract_simplified.exit259.us ]
  %.1.us = phi i64 [ %.0194275.us, %_FortranAMaxvalInteger8x1_contract_simplified.exit.loopexit.us ], [ %50, %_FortranAMaxvalInteger8x1_contract_simplified.exit259.us ]
  %.0.us = phi i64 [ %.lcssa, %_FortranAMaxvalInteger8x1_contract_simplified.exit.loopexit.us ], [ %.lcssa323, %_FortranAMaxvalInteger8x1_contract_simplified.exit259.us ]
  br label %52

52:                                               ; preds = %52, %51
  %.0192.us = phi i64 [ 1, %51 ], [ %56, %52 ]
  %53 = add i64 %.0192.us, -1
  %54 = getelementptr i64, ptr %.unpack232, i64 %53
  %55 = load i64, ptr %54, align 8, !tbaa !3
  %.not231.us = icmp eq i64 %55, %.0.us
  %56 = add i64 %.0192.us, 1
  br i1 %.not231.us, label %57, label %52

57:                                               ; preds = %52
  %58 = getelementptr i64, ptr %.unpack232, i64 %53
  store i64 0, ptr %58, align 8, !tbaa !3
  %59 = add nuw i64 %.0193276.us, 1
  %exitcond315.not = icmp eq i64 %.0193276.us, %18
  br i1 %exitcond315.not, label %._crit_edge279, label %.lr.ph278.split.us

_FortranAMaxvalInteger8x1_contract_simplified.exit.loopexit.us: ; preds = %.lr.ph.i.us, %middle.block328
  %.lcssa = phi i64 [ %28, %middle.block328 ], [ %41, %.lr.ph.i.us ]
  %60 = add i64 %.lcssa, %.0195274.us
  br label %51

.lr.ph278.split.split:                            ; preds = %.lr.ph278, %68
  %.0193276 = phi i64 [ %71, %68 ], [ 1, %.lr.ph278 ]
  %.0194275 = phi i64 [ %.1, %68 ], [ 0, %.lr.ph278 ]
  %.0195274 = phi i64 [ %.1196, %68 ], [ 0, %.lr.ph278 ]
  %61 = and i64 %.0193276, 1
  %.not = icmp eq i64 %61, 0
  %62 = xor i64 %.0195274, -9223372036854775808
  %.1196 = select i1 %.not, i64 %.0195274, i64 %62
  br label %63

63:                                               ; preds = %63, %.lr.ph278.split.split
  %.0192 = phi i64 [ 1, %.lr.ph278.split.split ], [ %67, %63 ]
  %64 = add i64 %.0192, -1
  %65 = getelementptr i64, ptr %.unpack232, i64 %64
  %66 = load i64, ptr %65, align 8, !tbaa !3
  %.not231 = icmp eq i64 %66, -9223372036854775808
  %67 = add i64 %.0192, 1
  br i1 %.not231, label %68, label %63

68:                                               ; preds = %63
  %69 = getelementptr i64, ptr %.unpack232, i64 %64
  %70 = xor i64 %.0194275, -9223372036854775808
  %.1 = select i1 %.not, i64 %70, i64 %.0194275
  store i64 0, ptr %69, align 8, !tbaa !3
  %71 = add nuw i64 %.0193276, 1
  %exitcond313.not = icmp eq i64 %.0193276, %18
  br i1 %exitcond313.not, label %._crit_edge279, label %.lr.ph278.split.split

._crit_edge279:                                   ; preds = %68, %57, %._crit_edge
  %.0195.lcssa = phi i64 [ 0, %._crit_edge ], [ %.1196.us, %57 ], [ %.1196, %68 ]
  %.0194.lcssa = phi i64 [ 0, %._crit_edge ], [ %.1.us, %57 ], [ %.1, %68 ]
  %72 = call ptr @_FortranAioBeginExternalListOutput(i32 6, ptr nonnull @_QQcl.de316e6c3a3bfaac099cee4830b117dd, i32 34)
  %73 = sub i64 %.0195.lcssa, %.0194.lcssa
  %74 = call i1 @_FortranAioOutputInteger64(ptr %72, i64 %73)
  %75 = call i32 @_FortranAioEndIoStatement(ptr %72)
  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 @_FortranAioBeginExternalListOutput(i32, ptr, i32) local_unnamed_addr

declare i1 @_FortranAioOutputInteger64(ptr, i64) local_unnamed_addr

; Function Attrs: mustprogress 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 <2 x i64> @llvm.smax.v2i64(<2 x i64>, <2 x i64>) #2

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

attributes #0 = { mustprogress nofree nounwind willreturn allockind("alloc,uninitialized") allocsize(0) memory(inaccessiblemem: readwrite) "alloc-family"="malloc" }
attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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, !10, !11}
!13 = distinct !{!13, !11, !10}
!14 = distinct !{!14, !11, !10}
