; LLVM IR from chirag-singhal/Coding-Interview-101 :: Miscellaneous/Codechef/junecook (2)

; 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 [4 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 i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca [2 x i32], align 4
  %11 = alloca [2 x i32], align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %104, %0
  %17 = load i32, ptr %3, align 4, !tbaa !5
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 2, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %107

21:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.memset.p0.i64(ptr align 4 %10, i8 0, i64 8, i1 false)
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  call void @llvm.memset.p0.i64(ptr align 4 %11, i8 0, i64 8, i1 false)
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %5)
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %6)
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store i32 0, ptr %12, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %94, %21
  %25 = load i32, ptr %12, align 4, !tbaa !5
  %26 = load i32, ptr %5, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  br label %97

29:                                               ; preds = %24
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store i32 0, ptr %13, align 4, !tbaa !5
  %30 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %7)
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %8)
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #4
  store i32 0, ptr %14, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %61, %29
  %33 = load i32, ptr %14, align 4, !tbaa !5
  %34 = icmp slt i32 %33, 2
  br i1 %34, label %36, label %35

35:                                               ; preds = %32
  store i32 8, ptr %4, align 4
  br label %64

36:                                               ; preds = %32
  %37 = load i32, ptr %7, align 4, !tbaa !5
  %38 = load i32, ptr %14, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [2 x i32], ptr %10, i64 0, i64 %39
  %41 = load i32, ptr %40, align 4, !tbaa !5
  %42 = icmp eq i32 %37, %41
  br i1 %42, label %43, label %60

43:                                               ; preds = %36
  store i32 1, ptr %13, align 4, !tbaa !5
  %44 = load i32, ptr %8, align 4, !tbaa !5
  %45 = load i32, ptr %14, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds [2 x i32], ptr %11, i64 0, i64 %46
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = icmp sgt i32 %44, %48
  br i1 %49, label %50, label %59

50:                                               ; preds = %43
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = load i32, ptr %14, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [2 x i32], ptr %10, i64 0, i64 %53
  store i32 %51, ptr %54, align 4, !tbaa !5
  %55 = load i32, ptr %8, align 4, !tbaa !5
  %56 = load i32, ptr %14, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [2 x i32], ptr %11, i64 0, i64 %57
  store i32 %55, ptr %58, align 4, !tbaa !5
  store i32 8, ptr %4, align 4
  br label %64

59:                                               ; preds = %43
  br label %60

60:                                               ; preds = %59, %36
  br label %61

61:                                               ; preds = %60
  %62 = load i32, ptr %14, align 4, !tbaa !5
  %63 = add nsw i32 %62, 1
  store i32 %63, ptr %14, align 4, !tbaa !5
  br label %32, !llvm.loop !9

64:                                               ; preds = %50, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #4
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %13, align 4, !tbaa !5
  %67 = icmp ne i32 %66, 0
  br i1 %67, label %93, label %68

68:                                               ; preds = %65
  %69 = getelementptr inbounds [2 x i32], ptr %11, i64 0, i64 0
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = getelementptr inbounds [2 x i32], ptr %11, i64 0, i64 1
  %72 = load i32, ptr %71, align 4, !tbaa !5
  %73 = icmp slt i32 %70, %72
  br i1 %73, label %74, label %75

74:                                               ; preds = %68
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %76

75:                                               ; preds = %68
  store i32 1, ptr %9, align 4, !tbaa !5
  br label %76

76:                                               ; preds = %75, %74
  %77 = load i32, ptr %8, align 4, !tbaa !5
  %78 = load i32, ptr %9, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [2 x i32], ptr %11, i64 0, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !5
  %82 = icmp sgt i32 %77, %81
  br i1 %82, label %83, label %92

83:                                               ; preds = %76
  %84 = load i32, ptr %8, align 4, !tbaa !5
  %85 = load i32, ptr %9, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [2 x i32], ptr %11, i64 0, i64 %86
  store i32 %84, ptr %87, align 4, !tbaa !5
  %88 = load i32, ptr %7, align 4, !tbaa !5
  %89 = load i32, ptr %9, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [2 x i32], ptr %10, i64 0, i64 %90
  store i32 %88, ptr %91, align 4, !tbaa !5
  br label %92

92:                                               ; preds = %83, %76
  br label %93

93:                                               ; preds = %92, %65
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %94

94:                                               ; preds = %93
  %95 = load i32, ptr %12, align 4, !tbaa !5
  %96 = add nsw i32 %95, 1
  store i32 %96, ptr %12, align 4, !tbaa !5
  br label %24, !llvm.loop !11

97:                                               ; preds = %28
  %98 = getelementptr inbounds [2 x i32], ptr %11, i64 0, i64 0
  %99 = load i32, ptr %98, align 4, !tbaa !5
  %100 = getelementptr inbounds [2 x i32], ptr %11, i64 0, i64 1
  %101 = load i32, ptr %100, align 4, !tbaa !5
  %102 = add nsw i32 %99, %101
  %103 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %102)
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 4, 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
  br label %104

104:                                              ; preds = %97
  %105 = load i32, ptr %3, align 4, !tbaa !5
  %106 = add nsw i32 %105, 1
  store i32 %106, ptr %3, align 4, !tbaa !5
  br label %16, !llvm.loop !12

107:                                              ; preds = %20
  store i32 0, ptr %1, align 4
  store i32 1, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #4
  %108 = load i32, ptr %1, align 4
  ret i32 %108
}

; 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 nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #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

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 nounwind willreturn memory(argmem: write) }
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}
!12 = distinct !{!12, !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 [4 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 i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %.sroa.050 = alloca i32, align 4
  %.sroa.6 = alloca i32, align 4
  %.sroa.0 = alloca i32, align 4
  %.sroa.8 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  %6 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = icmp sgt i32 %7, 0
  br i1 %8, label %.lr.ph38, label %._crit_edge39

._crit_edge39:                                    ; preds = %._crit_edge, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  ret i32 0

.lr.ph38:                                         ; preds = %0, %._crit_edge
  %.01836 = phi i32 [ %16, %._crit_edge ], [ 0, %0 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %.sroa.050)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %.sroa.6)
  store i32 0, ptr %.sroa.050, align 4
  store i32 0, ptr %.sroa.6, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %.sroa.0)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %.sroa.8)
  store i32 0, ptr %.sroa.0, align 4
  store i32 0, ptr %.sroa.8, align 4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %2)
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %3)
  %11 = load i32, ptr %2, align 4, !tbaa !5
  %12 = icmp sgt i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge

._crit_edge.loopexit:                             ; preds = %.thread53
  %.sroa.0.0..sroa.0.0..sroa.0.0.43.pre = load i32, ptr %.sroa.0, align 4, !tbaa !5
  %.sroa.8.0..sroa.8.0..sroa.8.4..pre = load i32, ptr %.sroa.8, align 4, !tbaa !5
  %13 = add nsw i32 %.sroa.8.0..sroa.8.0..sroa.8.4..pre, %.sroa.0.0..sroa.0.0..sroa.0.0.43.pre
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.lr.ph38
  %14 = phi i32 [ %13, %._crit_edge.loopexit ], [ 0, %.lr.ph38 ]
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %14)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %.sroa.0)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %.sroa.8)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %.sroa.050)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %.sroa.6)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #4
  %16 = add nuw nsw i32 %.01836, 1
  %17 = load i32, ptr %1, align 4, !tbaa !5
  %18 = icmp slt i32 %16, %17
  br i1 %18, label %.lr.ph38, label %._crit_edge39, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph38, %.thread53
  %.01635 = phi i32 [ %34, %.thread53 ], [ 0, %.lr.ph38 ]
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %4)
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %5)
  %21 = load i32, ptr %4, align 4, !tbaa !5
  %22 = load i32, ptr %5, align 4
  %.sroa.050.0..sroa.050.0..sroa.050.0. = load i32, ptr %.sroa.050, align 4, !tbaa !5
  %.not = icmp eq i32 %21, %.sroa.050.0..sroa.050.0..sroa.050.0.
  %.sroa.0.0..sroa.0.0..sroa.0.0.44 = load i32, ptr %.sroa.0, align 4
  %23 = icmp sgt i32 %22, %.sroa.0.0..sroa.0.0..sroa.0.0.44
  %or.cond = select i1 %.not, i1 %23, i1 false
  br i1 %or.cond, label %.thread, label %24

.thread:                                          ; preds = %.lr.ph, %26
  %.lcssa.sroa.phi = phi ptr [ %.sroa.8, %26 ], [ %.sroa.0, %.lr.ph ]
  %.lcssa.sroa.phi48 = phi ptr [ %.sroa.6, %26 ], [ %.sroa.050, %.lr.ph ]
  store i32 %21, ptr %.lcssa.sroa.phi48, align 4, !tbaa !5
  store i32 %22, ptr %.lcssa.sroa.phi, align 4, !tbaa !5
  br label %.thread53

24:                                               ; preds = %.lr.ph
  %.sroa.6.0..sroa.6.0..sroa.6.4. = load i32, ptr %.sroa.6, align 4, !tbaa !5
  %25 = icmp eq i32 %21, %.sroa.6.0..sroa.6.0..sroa.6.4.
  br i1 %25, label %26, label %28

26:                                               ; preds = %24
  %.sroa.8.0..sroa.8.0..sroa.8.4.46 = load i32, ptr %.sroa.8, align 4, !tbaa !5
  %27 = icmp sgt i32 %22, %.sroa.8.0..sroa.8.0..sroa.8.4.46
  br i1 %27, label %.thread, label %.thread53

28:                                               ; preds = %24
  br i1 %.not, label %.thread53, label %29

29:                                               ; preds = %28
  %.sroa.0.0..sroa.0.0..sroa.0.0. = load i32, ptr %.sroa.0, align 4, !tbaa !5
  %.sroa.8.0..sroa.8.0..sroa.8.4.45 = load i32, ptr %.sroa.8, align 4, !tbaa !5
  %30 = call i32 @llvm.smin.i32(i32 %.sroa.0.0..sroa.0.0..sroa.0.0., i32 %.sroa.8.0..sroa.8.0..sroa.8.4.45)
  %31 = icmp sgt i32 %22, %30
  br i1 %31, label %32, label %.thread53

32:                                               ; preds = %29
  %33 = icmp slt i32 %.sroa.0.0..sroa.0.0..sroa.0.0., %.sroa.8.0..sroa.8.0..sroa.8.4.45
  %..sroa.sel = select i1 %33, ptr %.sroa.0, ptr %.sroa.8
  store i32 %22, ptr %..sroa.sel, align 4, !tbaa !5
  %..sroa.sel24.idx.sroa.sel = select i1 %33, ptr %.sroa.050, ptr %.sroa.6
  store i32 %21, ptr %..sroa.sel24.idx.sroa.sel, align 4, !tbaa !5
  br label %.thread53

.thread53:                                        ; preds = %26, %.thread, %29, %32, %28
  %34 = add nuw nsw i32 %.01635, 1
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = icmp slt i32 %34, %35
  br i1 %36, label %.lr.ph, label %._crit_edge.loopexit, !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 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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.smin.i32(i32, i32) #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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: BDCEPass,CorrelatedValuePropagationPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass