; LLVM IR from ravireddy07/cpp-book :: src/Code-Chef (IPCCERT)

; 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 [15 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [5 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
  %4 = alloca i64, align 8
  %5 = alloca ptr, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2, ptr noundef %3, ptr noundef %4)
  %15 = load i64, ptr %2, align 8, !tbaa !5
  %16 = load i64, ptr %2, align 8, !tbaa !5
  %17 = call ptr @llvm.stacksave.p0()
  store ptr %17, ptr %5, align 8
  %18 = mul nuw i64 %15, %16
  %19 = alloca i64, i64 %18, align 16
  store i64 %15, ptr %6, align 8
  store i64 %16, ptr %7, align 8
  %20 = load i64, ptr %2, align 8, !tbaa !5
  %21 = alloca i64, i64 %20, align 16
  store i64 %20, ptr %8, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 0, ptr %10, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store i32 0, ptr %11, align 4, !tbaa !9
  br label %22

22:                                               ; preds = %75, %0
  %23 = load i32, ptr %11, align 4, !tbaa !9
  %24 = sext i32 %23 to i64
  %25 = load i64, ptr %2, align 8, !tbaa !5
  %26 = icmp slt i64 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %22
  store i32 2, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  br label %78

28:                                               ; preds = %22
  store i64 0, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !9
  br label %29

29:                                               ; preds = %54, %28
  %30 = load i32, ptr %13, align 4, !tbaa !9
  %31 = sext i32 %30 to i64
  %32 = load i64, ptr %2, align 8, !tbaa !5
  %33 = icmp slt i64 %31, %32
  br i1 %33, label %35, label %34

34:                                               ; preds = %29
  store i32 5, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %57

35:                                               ; preds = %29
  %36 = load i32, ptr %11, align 4, !tbaa !9
  %37 = sext i32 %36 to i64
  %38 = mul nsw i64 %37, %16
  %39 = getelementptr inbounds i64, ptr %19, i64 %38
  %40 = load i32, ptr %13, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i64, ptr %39, i64 %41
  %43 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %42)
  %44 = load i32, ptr %11, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = mul nsw i64 %45, %16
  %47 = getelementptr inbounds i64, ptr %19, i64 %46
  %48 = load i32, ptr %13, align 4, !tbaa !9
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds i64, ptr %47, i64 %49
  %51 = load i64, ptr %50, align 8, !tbaa !5
  %52 = load i64, ptr %9, align 8, !tbaa !5
  %53 = add nsw i64 %52, %51
  store i64 %53, ptr %9, align 8, !tbaa !5
  br label %54

54:                                               ; preds = %35
  %55 = load i32, ptr %13, align 4, !tbaa !9
  %56 = add nsw i32 %55, 1
  store i32 %56, ptr %13, align 4, !tbaa !9
  br label %29, !llvm.loop !11

57:                                               ; preds = %34
  %58 = load i32, ptr %11, align 4, !tbaa !9
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds i64, ptr %21, i64 %59
  %61 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %60)
  %62 = load i64, ptr %9, align 8, !tbaa !5
  %63 = load i64, ptr %3, align 8, !tbaa !5
  %64 = icmp sge i64 %62, %63
  br i1 %64, label %65, label %74

65:                                               ; preds = %57
  %66 = load i32, ptr %11, align 4, !tbaa !9
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i64, ptr %21, i64 %67
  %69 = load i64, ptr %68, align 8, !tbaa !5
  %70 = icmp sle i64 %69, 10
  br i1 %70, label %71, label %74

71:                                               ; preds = %65
  %72 = load i64, ptr %10, align 8, !tbaa !5
  %73 = add nsw i64 %72, 1
  store i64 %73, ptr %10, align 8, !tbaa !5
  br label %74

74:                                               ; preds = %71, %65, %57
  br label %75

75:                                               ; preds = %74
  %76 = load i32, ptr %11, align 4, !tbaa !9
  %77 = add nsw i32 %76, 1
  store i32 %77, ptr %11, align 4, !tbaa !9
  br label %22, !llvm.loop !13

78:                                               ; preds = %27
  %79 = load i64, ptr %10, align 8, !tbaa !5
  %80 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %79)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %12, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %81 = load ptr, ptr %5, align 8
  call void @llvm.stackrestore.p0(ptr %81)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  %82 = load i32, ptr %1, align 4
  ret i32 %82
}

; 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

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

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

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

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 = { 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 = !{!"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"

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

; Function Attrs: mustprogress nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %5 = load i64, ptr %1, align 8, !tbaa !5
  %6 = call ptr @llvm.stacksave.p0()
  %7 = mul nuw i64 %5, %5
  %8 = alloca i64, i64 %7, align 16
  %9 = load i64, ptr %1, align 8, !tbaa !5
  %10 = alloca i64, i64 %9, align 16
  %11 = icmp sgt i64 %9, 0
  br i1 %11, label %.preheader, label %._crit_edge24

.preheader:                                       ; preds = %0, %31
  %12 = phi i64 [ %32, %31 ], [ %9, %0 ]
  %indvars.iv27 = phi i64 [ %indvars.iv.next28, %31 ], [ 0, %0 ]
  %.01622 = phi i64 [ %.1, %31 ], [ 0, %0 ]
  %13 = icmp sgt i64 %12, 0
  br i1 %13, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader
  %14 = mul nsw i64 %indvars.iv27, %5
  %15 = getelementptr inbounds i64, ptr %8, i64 %14
  br label %20

._crit_edge24:                                    ; preds = %31, %0
  %.016.lcssa = phi i64 [ 0, %0 ], [ %.1, %31 ]
  %16 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %.016.lcssa)
  call void @llvm.stackrestore.p0(ptr %6)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #4
  ret i32 0

._crit_edge:                                      ; preds = %20, %.preheader
  %.017.lcssa = phi i64 [ 0, %.preheader ], [ %24, %20 ]
  %17 = getelementptr inbounds i64, ptr %10, i64 %indvars.iv27
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %17)
  %19 = load i64, ptr %2, align 8, !tbaa !5
  %.not = icmp slt i64 %.017.lcssa, %19
  br i1 %.not, label %31, label %27

20:                                               ; preds = %.lr.ph, %20
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %20 ]
  %.01720 = phi i64 [ 0, %.lr.ph ], [ %24, %20 ]
  %21 = getelementptr inbounds i64, ptr %15, i64 %indvars.iv
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %21)
  %23 = load i64, ptr %21, align 8, !tbaa !5
  %24 = add nsw i64 %23, %.01720
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %25 = load i64, ptr %1, align 8, !tbaa !5
  %26 = icmp sgt i64 %25, %indvars.iv.next
  br i1 %26, label %20, label %._crit_edge, !llvm.loop !9

27:                                               ; preds = %._crit_edge
  %28 = load i64, ptr %17, align 8, !tbaa !5
  %29 = icmp slt i64 %28, 11
  %30 = zext i1 %29 to i64
  %spec.select = add nsw i64 %.01622, %30
  br label %31

31:                                               ; preds = %27, %._crit_edge
  %.1 = phi i64 [ %.01622, %._crit_edge ], [ %spec.select, %27 ]
  %indvars.iv.next28 = add nuw nsw i64 %indvars.iv27, 1
  %32 = load i64, ptr %1, align 8, !tbaa !5
  %33 = icmp sgt i64 %32, %indvars.iv.next28
  br i1 %33, label %.preheader, label %._crit_edge24, !llvm.loop !11
}

; 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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

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

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

attributes #0 = { mustprogress nofree norecurse 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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