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

; 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: mustprogress norecurse uwtable
define dso_local noundef 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 ptr, align 8
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  br label %13

13:                                               ; preds = %99, %0
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %3)
  %15 = load i32, ptr %3, align 4, !tbaa !5
  %16 = icmp eq i32 %15, 0
  br i1 %16, label %17, label %18

17:                                               ; preds = %13
  br label %100

18:                                               ; preds = %13
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %19 = load i32, ptr %3, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = call { i64, i1 } @llvm.umul.with.overflow.i64(i64 %20, i64 4)
  %22 = extractvalue { i64, i1 } %21, 1
  %23 = extractvalue { i64, i1 } %21, 0
  %24 = select i1 %22, i64 -1, i64 %23
  %25 = call noalias noundef nonnull ptr @_Znam(i64 noundef %24) #7
  store ptr %25, ptr %10, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %26

26:                                               ; preds = %37, %18
  %27 = load i32, ptr %11, align 4, !tbaa !5
  %28 = load i32, ptr %3, align 4, !tbaa !5
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %31, label %30

30:                                               ; preds = %26
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %40

31:                                               ; preds = %26
  %32 = load ptr, ptr %10, align 8, !tbaa !9
  %33 = load i32, ptr %11, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds i32, ptr %32, i64 %34
  %36 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %35)
  br label %37

37:                                               ; preds = %31
  %38 = load i32, ptr %11, align 4, !tbaa !5
  %39 = add nsw i32 %38, 1
  store i32 %39, ptr %11, align 4, !tbaa !5
  br label %26, !llvm.loop !11

40:                                               ; preds = %30
  %41 = load ptr, ptr %10, align 8, !tbaa !9
  %42 = load ptr, ptr %10, align 8, !tbaa !9
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds i32, ptr %42, i64 %44
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef %41, ptr noundef %45)
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = sub nsw i32 %46, 1
  store i32 %47, ptr %12, align 4, !tbaa !5
  br label %48

48:                                               ; preds = %93, %40
  %49 = load i32, ptr %12, align 4, !tbaa !5
  %50 = icmp sge i32 %49, 2
  br i1 %50, label %52, label %51

51:                                               ; preds = %48
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  br label %96

52:                                               ; preds = %48
  %53 = load ptr, ptr %10, align 8, !tbaa !9
  %54 = load i32, ptr %12, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = getelementptr inbounds i32, ptr %53, i64 %55
  %57 = load i32, ptr %56, align 4, !tbaa !5
  store i32 %57, ptr %7, align 4, !tbaa !5
  %58 = load i32, ptr %12, align 4, !tbaa !5
  %59 = sub nsw i32 %58, 1
  store i32 %59, ptr %5, align 4, !tbaa !5
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %60

60:                                               ; preds = %91, %52
  %61 = load i32, ptr %5, align 4, !tbaa !5
  %62 = load i32, ptr %6, align 4, !tbaa !5
  %63 = icmp sgt i32 %61, %62
  br i1 %63, label %64, label %92

64:                                               ; preds = %60
  %65 = load ptr, ptr %10, align 8, !tbaa !9
  %66 = load i32, ptr %5, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds i32, ptr %65, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  store i32 %69, ptr %8, align 4, !tbaa !5
  %70 = load ptr, ptr %10, align 8, !tbaa !9
  %71 = load i32, ptr %6, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds i32, ptr %70, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !5
  store i32 %74, ptr %9, align 4, !tbaa !5
  %75 = load i32, ptr %7, align 4, !tbaa !5
  %76 = load i32, ptr %8, align 4, !tbaa !5
  %77 = load i32, ptr %9, align 4, !tbaa !5
  %78 = add nsw i32 %76, %77
  %79 = icmp sgt i32 %75, %78
  br i1 %79, label %80, label %88

80:                                               ; preds = %64
  %81 = load i32, ptr %5, align 4, !tbaa !5
  %82 = load i32, ptr %6, align 4, !tbaa !5
  %83 = sub nsw i32 %81, %82
  %84 = load i32, ptr %2, align 4, !tbaa !5
  %85 = add nsw i32 %84, %83
  store i32 %85, ptr %2, align 4, !tbaa !5
  %86 = load i32, ptr %6, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %6, align 4, !tbaa !5
  br label %91

88:                                               ; preds = %64
  %89 = load i32, ptr %5, align 4, !tbaa !5
  %90 = add nsw i32 %89, -1
  store i32 %90, ptr %5, align 4, !tbaa !5
  br label %91

91:                                               ; preds = %88, %80
  br label %60, !llvm.loop !13

92:                                               ; preds = %60
  br label %93

93:                                               ; preds = %92
  %94 = load i32, ptr %12, align 4, !tbaa !5
  %95 = add nsw i32 %94, -1
  store i32 %95, ptr %12, align 4, !tbaa !5
  br label %48, !llvm.loop !14

96:                                               ; preds = %51
  %97 = load i32, ptr %2, align 4, !tbaa !5
  %98 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %97)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  br label %99

99:                                               ; preds = %96
  br i1 true, label %13, label %100, !llvm.loop !15

100:                                              ; preds = %99, %17
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  ret i32 0
}

; 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 speculatable willreturn memory(none)
declare { i64, i1 } @llvm.umul.with.overflow.i64(i64, i64) #3

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #4

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

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

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

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 speculatable willreturn memory(none) }
attributes #4 = { nobuiltin allocsize(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 #5 = { 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 #6 = { nounwind }
attributes #7 = { builtin allocsize(0) }

!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++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !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 [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = load i32, ptr %1, align 4, !tbaa !5
  %4 = icmp eq i32 %3, 0
  br i1 %4, label %._crit_edge50, label %.lr.ph49

.lr.ph49:                                         ; preds = %0, %._crit_edge46
  %5 = phi i32 [ %24, %._crit_edge46 ], [ %3, %0 ]
  %6 = sext i32 %5 to i64
  %7 = icmp slt i32 %5, 0
  %8 = shl nsw i64 %6, 2
  %9 = select i1 %7, i64 -1, i64 %8
  %10 = call noalias noundef nonnull ptr @_Znam(i64 noundef %9) #6
  %11 = icmp sgt i32 %5, 0
  br i1 %11, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph49
  %.pre-phi = phi i64 [ %6, %.lr.ph49 ], [ %19, %.lr.ph ]
  %12 = getelementptr inbounds i32, ptr %10, i64 %.pre-phi
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull %10, ptr noundef nonnull %12)
  %13 = load i32, ptr %1, align 4, !tbaa !5
  %14 = icmp sgt i32 %13, 2
  br i1 %14, label %.lr.ph45.preheader, label %._crit_edge46

.lr.ph45.preheader:                               ; preds = %._crit_edge
  %15 = zext nneg i32 %13 to i64
  br label %.lr.ph38.preheader

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

.loopexit:                                        ; preds = %.lr.ph38
  %21 = icmp sgt i64 %indvars.iv53, 3
  br i1 %21, label %.lr.ph38.preheader, label %._crit_edge46, !llvm.loop !11

._crit_edge46:                                    ; preds = %.loopexit, %._crit_edge
  %.026.lcssa = phi i32 [ 0, %._crit_edge ], [ %.2, %.loopexit ]
  %22 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %.026.lcssa)
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %24 = load i32, ptr %1, align 4, !tbaa !5
  %25 = icmp eq i32 %24, 0
  br i1 %25, label %._crit_edge50, label %.lr.ph49, !llvm.loop !12

.lr.ph38.preheader:                               ; preds = %.loopexit, %.lr.ph45.preheader
  %indvars.iv53 = phi i64 [ %15, %.lr.ph45.preheader ], [ %indvars.iv.next54, %.loopexit ]
  %.02641 = phi i32 [ 0, %.lr.ph45.preheader ], [ %.2, %.loopexit ]
  %indvars.iv.next54 = add nsw i64 %indvars.iv53, -1
  %26 = getelementptr inbounds i32, ptr %10, i64 %indvars.iv.next54
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %28 = trunc i64 %indvars.iv53 to i32
  %29 = add i32 %28, -2
  br label %.lr.ph38

.lr.ph38:                                         ; preds = %.lr.ph38.preheader, %.lr.ph38
  %.136 = phi i32 [ %.2, %.lr.ph38 ], [ %.02641, %.lr.ph38.preheader ]
  %.02735 = phi i32 [ %.128, %.lr.ph38 ], [ %29, %.lr.ph38.preheader ]
  %.02934 = phi i32 [ %.130, %.lr.ph38 ], [ 0, %.lr.ph38.preheader ]
  %30 = sext i32 %.02735 to i64
  %31 = getelementptr inbounds i32, ptr %10, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = zext nneg i32 %.02934 to i64
  %34 = getelementptr inbounds i32, ptr %10, i64 %33
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = add nsw i32 %35, %32
  %37 = icmp sgt i32 %27, %36
  %38 = sub nsw i32 %.02735, %.02934
  %39 = zext i1 %37 to i32
  %.130 = add nuw nsw i32 %.02934, %39
  %not. = xor i1 %37, true
  %40 = sext i1 %not. to i32
  %.128 = add nsw i32 %.02735, %40
  %41 = select i1 %37, i32 %38, i32 0
  %.2 = add nsw i32 %41, %.136
  %42 = icmp sgt i32 %.128, %.130
  br i1 %42, label %.lr.ph38, label %.loopexit, !llvm.loop !13

._crit_edge50:                                    ; preds = %._crit_edge46, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) local_unnamed_addr #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: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #4

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

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 = { 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 = { nobuiltin allocsize(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 = { 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 #5 = { nounwind }
attributes #6 = { builtin allocsize(0) }

!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++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}


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