; LLVM IR from smv1999/CompetitiveProgrammingQuestionBank :: CodeVita Problems (codu loves sum)

; 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"

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca [22 x i32], align 16
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = zext i32 %11 to i64
  %13 = call ptr @llvm.stacksave.p0()
  store ptr %13, ptr %3, align 8
  %14 = alloca i32, i64 %12, align 16
  store i64 %12, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %24, %0
  %16 = load i32, ptr %5, align 4, !tbaa !5
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %19, label %27

19:                                               ; preds = %15
  %20 = load i32, ptr %5, align 4, !tbaa !5
  %21 = sext i32 %20 to i64
  %22 = getelementptr inbounds i32, ptr %14, i64 %21
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %22)
  br label %24

24:                                               ; preds = %19
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  store i32 %26, ptr %5, align 4, !tbaa !5
  br label %15, !llvm.loop !9

27:                                               ; preds = %15
  call void @llvm.lifetime.start.p0(i64 88, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !11
  %28 = getelementptr inbounds [22 x i32], ptr %7, i64 0, i64 0
  store i32 1, ptr %28, align 16, !tbaa !5
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %43, %27
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = icmp slt i32 %30, 22
  br i1 %31, label %32, label %46

32:                                               ; preds = %29
  %33 = load i32, ptr %8, align 4, !tbaa !5
  %34 = sub nsw i32 %33, 1
  %35 = sext i32 %34 to i64
  %36 = getelementptr inbounds [22 x i32], ptr %7, i64 0, i64 %35
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = mul nsw i32 %37, 2
  %39 = srem i32 %38, 100
  %40 = load i32, ptr %8, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [22 x i32], ptr %7, i64 0, i64 %41
  store i32 %39, ptr %42, align 4, !tbaa !5
  br label %43

43:                                               ; preds = %32
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %8, align 4, !tbaa !5
  br label %29, !llvm.loop !13

46:                                               ; preds = %29
  store i32 0, ptr %5, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %78, %46
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = load i32, ptr %2, align 4, !tbaa !5
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %51, label %81

51:                                               ; preds = %47
  %52 = load i32, ptr %5, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i32, ptr %14, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = icmp sgt i32 %55, 21
  br i1 %56, label %57, label %65

57:                                               ; preds = %51
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i32, ptr %14, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  %62 = srem i32 %61, 22
  store i32 %62, ptr %6, align 4, !tbaa !5
  %63 = load i32, ptr %6, align 4, !tbaa !5
  %64 = add nsw i32 %63, 2
  store i32 %64, ptr %6, align 4, !tbaa !5
  br label %70

65:                                               ; preds = %51
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i32, ptr %14, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  store i32 %69, ptr %6, align 4, !tbaa !5
  br label %70

70:                                               ; preds = %65, %57
  %71 = load i64, ptr %9, align 8, !tbaa !11
  %72 = load i32, ptr %6, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = getelementptr inbounds [22 x i32], ptr %7, i64 0, i64 %73
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = add i64 %71, %76
  store i64 %77, ptr %9, align 8, !tbaa !11
  br label %78

78:                                               ; preds = %70
  %79 = load i32, ptr %5, align 4, !tbaa !5
  %80 = add nsw i32 %79, 1
  store i32 %80, ptr %5, align 4, !tbaa !5
  br label %47, !llvm.loop !14

81:                                               ; preds = %47
  %82 = load i64, ptr %9, align 8, !tbaa !11
  %83 = urem i64 %82, 100
  %84 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %83)
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 88, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  %85 = load ptr, ptr %3, align 8
  call void @llvm.stackrestore.p0(ptr %85)
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %86 = load i32, ptr %1, align 4
  ret i32 %86
}

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

attributes #0 = { 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 #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { "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 = { nocallback nofree nosync nounwind willreturn }
attributes #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}


; 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"

@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 x i8], align 1

; Function Attrs: nofree nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca [22 x i32], align 16
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = zext i32 %4 to i64
  %6 = call ptr @llvm.stacksave.p0()
  %7 = alloca i32, i64 %5, align 16
  %8 = load i32, ptr %1, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %10 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %10)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = load i32, ptr %1, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = icmp slt i64 %indvars.iv.next, %13
  br i1 %14, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa = phi i32 [ %8, %0 ], [ %12, %.lr.ph ]
  call void @llvm.lifetime.start.p0(i64 88, ptr nonnull %2) #4
  store <4 x i32> <i32 1, i32 2, i32 4, i32 8>, ptr %2, align 16, !tbaa !5
  %15 = getelementptr inbounds i8, ptr %2, i64 16
  store <4 x i32> <i32 16, i32 32, i32 64, i32 28>, ptr %15, align 16, !tbaa !5
  %16 = getelementptr inbounds i8, ptr %2, i64 32
  store <4 x i32> <i32 56, i32 12, i32 24, i32 48>, ptr %16, align 16, !tbaa !5
  %17 = getelementptr inbounds i8, ptr %2, i64 48
  store <4 x i32> <i32 96, i32 92, i32 84, i32 68>, ptr %17, align 16, !tbaa !5
  %18 = getelementptr inbounds i8, ptr %2, i64 64
  store <4 x i32> <i32 36, i32 72, i32 44, i32 88>, ptr %18, align 16, !tbaa !5
  %19 = getelementptr inbounds i8, ptr %2, i64 80
  store i32 76, ptr %19, align 16, !tbaa !5
  %20 = getelementptr inbounds i8, ptr %2, i64 84
  store i32 52, ptr %20, align 4, !tbaa !5
  %21 = icmp sgt i32 %.lcssa, 0
  br i1 %21, label %.lr.ph26.preheader, label %._crit_edge27

.lr.ph26.preheader:                               ; preds = %._crit_edge
  %wide.trip.count = zext nneg i32 %.lcssa to i64
  %xtraiter = and i64 %wide.trip.count, 1
  %22 = icmp eq i32 %.lcssa, 1
  br i1 %22, label %._crit_edge27.loopexit.unr-lcssa, label %.lr.ph26.preheader.new

.lr.ph26.preheader.new:                           ; preds = %.lr.ph26.preheader
  %unroll_iter = and i64 %wide.trip.count, 2147483646
  br label %.lr.ph26

.lr.ph26:                                         ; preds = %40, %.lr.ph26.preheader.new
  %indvars.iv35 = phi i64 [ 0, %.lr.ph26.preheader.new ], [ %indvars.iv.next36.1, %40 ]
  %.025 = phi i64 [ 0, %.lr.ph26.preheader.new ], [ %45, %40 ]
  %niter = phi i64 [ 0, %.lr.ph26.preheader.new ], [ %niter.next.1, %40 ]
  %23 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv35
  %24 = load i32, ptr %23, align 8, !tbaa !5
  %25 = icmp sgt i32 %24, 21
  br i1 %25, label %26, label %.lr.ph26.1

26:                                               ; preds = %.lr.ph26
  %27 = urem i32 %24, 22
  %28 = add nuw nsw i32 %27, 2
  br label %.lr.ph26.1

.lr.ph26.1:                                       ; preds = %.lr.ph26, %26
  %.018 = phi i32 [ %28, %26 ], [ %24, %.lr.ph26 ]
  %29 = sext i32 %.018 to i64
  %30 = getelementptr inbounds [22 x i32], ptr %2, i64 0, i64 %29
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = add i64 %.025, %32
  %indvars.iv.next36 = or disjoint i64 %indvars.iv35, 1
  %34 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv.next36
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp sgt i32 %35, 21
  br i1 %36, label %37, label %40

37:                                               ; preds = %.lr.ph26.1
  %38 = urem i32 %35, 22
  %39 = add nuw nsw i32 %38, 2
  br label %40

40:                                               ; preds = %37, %.lr.ph26.1
  %.018.1 = phi i32 [ %39, %37 ], [ %35, %.lr.ph26.1 ]
  %41 = sext i32 %.018.1 to i64
  %42 = getelementptr inbounds [22 x i32], ptr %2, i64 0, i64 %41
  %43 = load i32, ptr %42, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = add i64 %33, %44
  %indvars.iv.next36.1 = add nuw nsw i64 %indvars.iv35, 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_edge27.loopexit.unr-lcssa, label %.lr.ph26, !llvm.loop !11

._crit_edge27.loopexit.unr-lcssa:                 ; preds = %40, %.lr.ph26.preheader
  %.lcssa42.ph = phi i64 [ poison, %.lr.ph26.preheader ], [ %45, %40 ]
  %indvars.iv35.unr = phi i64 [ 0, %.lr.ph26.preheader ], [ %indvars.iv.next36.1, %40 ]
  %.025.unr = phi i64 [ 0, %.lr.ph26.preheader ], [ %45, %40 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge27.loopexit, label %.lr.ph26.epil

.lr.ph26.epil:                                    ; preds = %._crit_edge27.loopexit.unr-lcssa
  %46 = getelementptr inbounds i32, ptr %7, i64 %indvars.iv35.unr
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = icmp sgt i32 %47, 21
  br i1 %48, label %49, label %._crit_edge27.loopexit.epilog-lcssa

49:                                               ; preds = %.lr.ph26.epil
  %50 = urem i32 %47, 22
  %51 = add nuw nsw i32 %50, 2
  br label %._crit_edge27.loopexit.epilog-lcssa

._crit_edge27.loopexit.epilog-lcssa:              ; preds = %49, %.lr.ph26.epil
  %.018.epil = phi i32 [ %51, %49 ], [ %47, %.lr.ph26.epil ]
  %52 = sext i32 %.018.epil to i64
  %53 = getelementptr inbounds [22 x i32], ptr %2, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = add i64 %.025.unr, %55
  br label %._crit_edge27.loopexit

._crit_edge27.loopexit:                           ; preds = %._crit_edge27.loopexit.unr-lcssa, %._crit_edge27.loopexit.epilog-lcssa
  %.lcssa42 = phi i64 [ %.lcssa42.ph, %._crit_edge27.loopexit.unr-lcssa ], [ %56, %._crit_edge27.loopexit.epilog-lcssa ]
  %57 = urem i64 %.lcssa42, 100
  br label %._crit_edge27

._crit_edge27:                                    ; preds = %._crit_edge27.loopexit, %._crit_edge
  %.0.lcssa = phi i64 [ 0, %._crit_edge ], [ %57, %._crit_edge27.loopexit ]
  %58 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %.0.lcssa)
  call void @llvm.lifetime.end.p0(i64 88, ptr nonnull %2) #4
  call void @llvm.stackrestore.p0(ptr %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0
}

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #3

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #3

attributes #0 = { nofree 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { mustprogress nocallback nofree nosync nounwind willreturn }
attributes #4 = { 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


; Effective O3 passes: EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass