; LLVM IR from UtkarshPathrabe/Competitive-Coding :: SPOJ Solutions (C1LJUTNJ)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@n = external dso_local global i32, align 4
@i = external dso_local global i32, align 4
@anger = external dso_local global i32, align 4
@array = external dso_local global [100000 x i32], align 16
@total = external dso_local global i64, align 8
@ans = external dso_local global i64, align 8
@m = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @m, ptr noundef @n)
  store i64 0, ptr @ans, align 8, !tbaa !5
  store i64 0, ptr @total, align 8, !tbaa !5
  store i32 0, ptr @i, align 4, !tbaa !9
  br label %5

5:                                                ; preds = %21, %0
  %6 = load i32, ptr @i, align 4, !tbaa !9
  %7 = load i32, ptr @n, align 4, !tbaa !9
  %8 = icmp slt i32 %6, %7
  br i1 %8, label %9, label %24

9:                                                ; preds = %5
  %10 = load i32, ptr @i, align 4, !tbaa !9
  %11 = sext i32 %10 to i64
  %12 = getelementptr inbounds [100000 x i32], ptr @array, i64 0, i64 %11
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %12)
  %14 = load i32, ptr @i, align 4, !tbaa !9
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [100000 x i32], ptr @array, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !9
  %18 = sext i32 %17 to i64
  %19 = load i64, ptr @total, align 8, !tbaa !5
  %20 = add nsw i64 %19, %18
  store i64 %20, ptr @total, align 8, !tbaa !5
  br label %21

21:                                               ; preds = %9
  %22 = load i32, ptr @i, align 4, !tbaa !9
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr @i, align 4, !tbaa !9
  br label %5, !llvm.loop !11

24:                                               ; preds = %5
  %25 = load i64, ptr @m, align 8, !tbaa !5
  %26 = load i64, ptr @total, align 8, !tbaa !5
  %27 = sub nsw i64 %26, %25
  store i64 %27, ptr @total, align 8, !tbaa !5
  %28 = load i32, ptr @n, align 4, !tbaa !9
  %29 = sext i32 %28 to i64
  %30 = getelementptr inbounds i32, ptr @array, i64 %29
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @array, ptr noundef %30)
  store i32 0, ptr @i, align 4, !tbaa !9
  br label %31

31:                                               ; preds = %60, %24
  %32 = load i32, ptr @i, align 4, !tbaa !9
  %33 = load i32, ptr @n, align 4, !tbaa !9
  %34 = icmp slt i32 %32, %33
  br i1 %34, label %35, label %63

35:                                               ; preds = %31
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #5
  %36 = load i32, ptr @i, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [100000 x i32], ptr @array, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !9
  %40 = sext i32 %39 to i64
  store i64 %40, ptr %2, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #5
  %41 = load i64, ptr @total, align 8, !tbaa !5
  %42 = load i32, ptr @n, align 4, !tbaa !9
  %43 = load i32, ptr @i, align 4, !tbaa !9
  %44 = sub nsw i32 %42, %43
  %45 = sext i32 %44 to i64
  %46 = sdiv i64 %41, %45
  store i64 %46, ptr %3, align 8, !tbaa !5
  %47 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %2, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %48 = load i64, ptr %47, align 8, !tbaa !5
  %49 = trunc i64 %48 to i32
  store i32 %49, ptr @anger, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #5
  %50 = load i32, ptr @anger, align 4, !tbaa !9
  %51 = load i32, ptr @anger, align 4, !tbaa !9
  %52 = mul nsw i32 %50, %51
  %53 = sext i32 %52 to i64
  %54 = load i64, ptr @ans, align 8, !tbaa !5
  %55 = add nsw i64 %54, %53
  store i64 %55, ptr @ans, align 8, !tbaa !5
  %56 = load i32, ptr @anger, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = load i64, ptr @total, align 8, !tbaa !5
  %59 = sub nsw i64 %58, %57
  store i64 %59, ptr @total, align 8, !tbaa !5
  br label %60

60:                                               ; preds = %35
  %61 = load i32, ptr @i, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr @i, align 4, !tbaa !9
  br label %31, !llvm.loop !13

63:                                               ; preds = %31
  %64 = load i64, ptr @ans, align 8, !tbaa !5
  %65 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %64)
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #3

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #4

; Function Attrs: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #4

declare i32 @printf(ptr noundef, ...) #1

attributes #0 = { mustprogress norecurse uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { inlinehint mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

@n = external dso_local global i32, align 4
@i = external dso_local local_unnamed_addr global i32, align 4
@anger = external dso_local local_unnamed_addr global i32, align 4
@array = external dso_local global [100000 x i32], align 16
@total = external dso_local local_unnamed_addr global i64, align 8
@ans = external dso_local local_unnamed_addr global i64, align 8
@m = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [8 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [6 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @m, ptr noundef nonnull @n)
  store i64 0, ptr @ans, align 8, !tbaa !5
  store i64 0, ptr @total, align 8, !tbaa !5
  store i32 0, ptr @i, align 4, !tbaa !9
  %4 = load i32, ptr @n, align 4, !tbaa !9
  %5 = icmp sgt i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %storemerge2 = phi i32 [ %16, %.lr.ph ], [ 0, %0 ]
  %6 = sext i32 %storemerge2 to i64
  %7 = getelementptr inbounds [100000 x i32], ptr @array, i64 0, i64 %6
  %8 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %7)
  %9 = load i32, ptr @i, align 4, !tbaa !9
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds [100000 x i32], ptr @array, i64 0, i64 %10
  %12 = load i32, ptr %11, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = load i64, ptr @total, align 8, !tbaa !5
  %15 = add nsw i64 %14, %13
  store i64 %15, ptr @total, align 8, !tbaa !5
  %16 = add nsw i32 %9, 1
  store i32 %16, ptr @i, align 4, !tbaa !9
  %17 = load i32, ptr @n, align 4, !tbaa !9
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %.lr.ph, label %._crit_edge, !llvm.loop !11

._crit_edge:                                      ; preds = %.lr.ph, %0
  %19 = phi i64 [ 0, %0 ], [ %15, %.lr.ph ]
  %.lcssa = phi i32 [ %4, %0 ], [ %17, %.lr.ph ]
  %20 = load i64, ptr @m, align 8, !tbaa !5
  %21 = sub nsw i64 %19, %20
  store i64 %21, ptr @total, align 8, !tbaa !5
  %22 = sext i32 %.lcssa to i64
  %23 = getelementptr inbounds i32, ptr @array, i64 %22
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @array, ptr noundef nonnull %23)
  store i32 0, ptr @i, align 4, !tbaa !9
  %24 = load i32, ptr @n, align 4, !tbaa !9
  %25 = icmp sgt i32 %24, 0
  br i1 %25, label %.lr.ph5.preheader, label %._crit_edge.._crit_edge6_crit_edge

._crit_edge.._crit_edge6_crit_edge:               ; preds = %._crit_edge
  %.pre8 = load i64, ptr @ans, align 8, !tbaa !5
  br label %._crit_edge6

.lr.ph5.preheader:                                ; preds = %._crit_edge
  %.pre = load i64, ptr @total, align 8, !tbaa !5
  br label %.lr.ph5

.lr.ph5:                                          ; preds = %.lr.ph5.preheader, %.lr.ph5
  %26 = phi i64 [ %44, %.lr.ph5 ], [ %.pre, %.lr.ph5.preheader ]
  %27 = phi i32 [ %47, %.lr.ph5 ], [ %24, %.lr.ph5.preheader ]
  %storemerge13 = phi i32 [ %46, %.lr.ph5 ], [ 0, %.lr.ph5.preheader ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %28 = sext i32 %storemerge13 to i64
  %29 = getelementptr inbounds [100000 x i32], ptr @array, i64 0, i64 %28
  %30 = load i32, ptr %29, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  store i64 %31, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %32 = sub nsw i32 %27, %storemerge13
  %33 = sext i32 %32 to i64
  %34 = sdiv i64 %26, %33
  store i64 %34, ptr %2, align 8, !tbaa !5
  %35 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8) %1, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %36 = load i64, ptr %35, align 8, !tbaa !5
  %37 = trunc i64 %36 to i32
  store i32 %37, ptr @anger, align 4, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  %38 = mul i64 %36, %36
  %39 = and i64 %38, 4294967295
  %40 = load i64, ptr @ans, align 8, !tbaa !5
  %41 = add nsw i64 %40, %39
  store i64 %41, ptr @ans, align 8, !tbaa !5
  %sext = shl i64 %36, 32
  %42 = ashr exact i64 %sext, 32
  %43 = load i64, ptr @total, align 8, !tbaa !5
  %44 = sub nsw i64 %43, %42
  store i64 %44, ptr @total, align 8, !tbaa !5
  %45 = load i32, ptr @i, align 4, !tbaa !9
  %46 = add nsw i32 %45, 1
  store i32 %46, ptr @i, align 4, !tbaa !9
  %47 = load i32, ptr @n, align 4, !tbaa !9
  %48 = icmp slt i32 %46, %47
  br i1 %48, label %.lr.ph5, label %._crit_edge6, !llvm.loop !13

._crit_edge6:                                     ; preds = %.lr.ph5, %._crit_edge.._crit_edge6_crit_edge
  %49 = phi i64 [ %.pre8, %._crit_edge.._crit_edge6_crit_edge ], [ %41, %.lr.ph5 ]
  %50 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %49)
  ret i32 0
}

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #2

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 8 dereferenceable(8) ptr @_ZSt3minIxERKT_S2_S2_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #4

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #4

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #1

attributes #0 = { mustprogress norecurse uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { inlinehint mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { inlinehint mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #4 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"int", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass