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

; 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 [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 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 ptr, align 8
  %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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %2)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #4
  %10 = call noalias noundef nonnull ptr @_Znam(i64 noundef 40) #5
  store ptr %10, ptr %3, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  br label %11

11:                                               ; preds = %70, %0
  %12 = load i64, ptr %2, align 8, !tbaa !9
  %13 = add i64 %12, -1
  store i64 %13, ptr %2, align 8, !tbaa !9
  %14 = icmp ne i64 %12, 0
  br i1 %14, label %15, label %72

15:                                               ; preds = %11
  store i32 9, ptr %4, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !11
  br label %16

16:                                               ; preds = %26, %15
  %17 = load i32, ptr %6, align 4, !tbaa !11
  %18 = icmp sle i32 %17, 9
  br i1 %18, label %20, label %19

19:                                               ; preds = %16
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %29

20:                                               ; preds = %16
  %21 = load ptr, ptr %3, align 8, !tbaa !5
  %22 = load i32, ptr %6, align 4, !tbaa !11
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds i32, ptr %21, i64 %23
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %24)
  br label %26

26:                                               ; preds = %20
  %27 = load i32, ptr %6, align 4, !tbaa !11
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %6, align 4, !tbaa !11
  br label %16, !llvm.loop !13

29:                                               ; preds = %19
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store i32 0, ptr %7, align 4, !tbaa !11
  br label %30

30:                                               ; preds = %50, %29
  %31 = load i32, ptr %7, align 4, !tbaa !11
  %32 = icmp sle i32 %31, 9
  br i1 %32, label %34, label %33

33:                                               ; preds = %30
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  br label %53

34:                                               ; preds = %30
  %35 = load ptr, ptr %3, align 8, !tbaa !5
  %36 = load i32, ptr %7, align 4, !tbaa !11
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds i32, ptr %35, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !11
  %40 = load i32, ptr %4, align 4, !tbaa !11
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %42, label %49

42:                                               ; preds = %34
  %43 = load ptr, ptr %3, align 8, !tbaa !5
  %44 = load i32, ptr %7, align 4, !tbaa !11
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds i32, ptr %43, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !11
  store i32 %47, ptr %4, align 4, !tbaa !11
  %48 = load i32, ptr %7, align 4, !tbaa !11
  store i32 %48, ptr %5, align 4, !tbaa !11
  br label %49

49:                                               ; preds = %42, %34
  br label %50

50:                                               ; preds = %49
  %51 = load i32, ptr %7, align 4, !tbaa !11
  %52 = add nsw i32 %51, 1
  store i32 %52, ptr %7, align 4, !tbaa !11
  br label %30, !llvm.loop !15

53:                                               ; preds = %33
  %54 = load i32, ptr %5, align 4, !tbaa !11
  %55 = icmp eq i32 %54, 0
  br i1 %55, label %56, label %58

56:                                               ; preds = %53
  %57 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %58

58:                                               ; preds = %56, %53
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store i32 0, ptr %8, align 4, !tbaa !11
  br label %59

59:                                               ; preds = %67, %58
  %60 = load i32, ptr %8, align 4, !tbaa !11
  %61 = load i32, ptr %4, align 4, !tbaa !11
  %62 = icmp sle i32 %60, %61
  br i1 %62, label %64, label %63

63:                                               ; preds = %59
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %70

64:                                               ; preds = %59
  %65 = load i32, ptr %5, align 4, !tbaa !11
  %66 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %65)
  br label %67

67:                                               ; preds = %64
  %68 = load i32, ptr %8, align 4, !tbaa !11
  %69 = add nsw i32 %68, 1
  store i32 %69, ptr %8, align 4, !tbaa !11
  br label %59, !llvm.loop !16

70:                                               ; preds = %63
  %71 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %11, !llvm.loop !17

72:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  call void @llvm.lifetime.end.p0(i64 4, 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
  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: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znam(i64 noundef) #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 = { 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 = { 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 = { nounwind }
attributes #5 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = distinct !{!16, !14}
!17 = distinct !{!17, !14}


; 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 [4 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [2 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [2 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %2 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %3 = call noalias noundef nonnull dereferenceable(40) ptr @_Znam(i64 noundef 40) #6
  %4 = load i64, ptr %1, align 8, !tbaa !5
  %5 = add i64 %4, -1
  store i64 %5, ptr %1, align 8, !tbaa !5
  %.not31 = icmp eq i64 %4, 0
  br i1 %.not31, label %._crit_edge33, label %.preheader24.preheader

.preheader24.preheader:                           ; preds = %0
  %6 = getelementptr inbounds i8, ptr %3, i64 4
  %7 = getelementptr inbounds i8, ptr %3, i64 8
  %8 = getelementptr inbounds i8, ptr %3, i64 12
  %9 = getelementptr inbounds i8, ptr %3, i64 16
  %10 = getelementptr inbounds i8, ptr %3, i64 20
  %11 = getelementptr inbounds i8, ptr %3, i64 24
  %12 = getelementptr inbounds i8, ptr %3, i64 28
  %13 = getelementptr inbounds i8, ptr %3, i64 32
  %14 = getelementptr inbounds i8, ptr %3, i64 36
  br label %.preheader24

.preheader24:                                     ; preds = %.preheader24.preheader, %._crit_edge
  %.01832 = phi i32 [ %spec.select23.9, %._crit_edge ], [ undef, %.preheader24.preheader ]
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %3)
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %6)
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %7)
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %8)
  %19 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %9)
  %20 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %10)
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %11)
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %12)
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %13)
  %24 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %14)
  %25 = load i32, ptr %3, align 4, !tbaa !9
  %26 = icmp slt i32 %25, 9
  %spec.select = call i32 @llvm.smin.i32(i32 %25, i32 9)
  %spec.select23 = select i1 %26, i32 0, i32 %.01832
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = icmp slt i32 %27, %spec.select
  %spec.select.1 = call i32 @llvm.smin.i32(i32 %27, i32 %spec.select)
  %spec.select23.1 = select i1 %28, i32 1, i32 %spec.select23
  %29 = load i32, ptr %7, align 4, !tbaa !9
  %30 = icmp slt i32 %29, %spec.select.1
  %spec.select.2 = call i32 @llvm.smin.i32(i32 %29, i32 %spec.select.1)
  %spec.select23.2 = select i1 %30, i32 2, i32 %spec.select23.1
  %31 = load i32, ptr %8, align 4, !tbaa !9
  %32 = icmp slt i32 %31, %spec.select.2
  %spec.select.3 = call i32 @llvm.smin.i32(i32 %31, i32 %spec.select.2)
  %spec.select23.3 = select i1 %32, i32 3, i32 %spec.select23.2
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = icmp slt i32 %33, %spec.select.3
  %spec.select.4 = call i32 @llvm.smin.i32(i32 %33, i32 %spec.select.3)
  %spec.select23.4 = select i1 %34, i32 4, i32 %spec.select23.3
  %35 = load i32, ptr %10, align 4, !tbaa !9
  %36 = icmp slt i32 %35, %spec.select.4
  %spec.select.5 = call i32 @llvm.smin.i32(i32 %35, i32 %spec.select.4)
  %spec.select23.5 = select i1 %36, i32 5, i32 %spec.select23.4
  %37 = load i32, ptr %11, align 4, !tbaa !9
  %38 = icmp slt i32 %37, %spec.select.5
  %spec.select.6 = call i32 @llvm.smin.i32(i32 %37, i32 %spec.select.5)
  %spec.select23.6 = select i1 %38, i32 6, i32 %spec.select23.5
  %39 = load i32, ptr %12, align 4, !tbaa !9
  %40 = icmp slt i32 %39, %spec.select.6
  %spec.select.7 = call i32 @llvm.smin.i32(i32 %39, i32 %spec.select.6)
  %spec.select23.7 = select i1 %40, i32 7, i32 %spec.select23.6
  %41 = load i32, ptr %13, align 4, !tbaa !9
  %42 = icmp slt i32 %41, %spec.select.7
  %spec.select.8 = call i32 @llvm.smin.i32(i32 %41, i32 %spec.select.7)
  %spec.select23.8 = select i1 %42, i32 8, i32 %spec.select23.7
  %43 = load i32, ptr %14, align 4, !tbaa !9
  %44 = icmp slt i32 %43, %spec.select.8
  %spec.select.9 = call i32 @llvm.smin.i32(i32 %43, i32 %spec.select.8)
  %spec.select23.9 = select i1 %44, i32 9, i32 %spec.select23.8
  %45 = icmp eq i32 %spec.select23.9, 0
  br i1 %45, label %46, label %48

46:                                               ; preds = %.preheader24
  %47 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %48

48:                                               ; preds = %46, %.preheader24
  %.not2229 = icmp slt i32 %spec.select.9, 0
  br i1 %.not2229, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %48
  %49 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  %50 = load i64, ptr %1, align 8, !tbaa !5
  %51 = add i64 %50, -1
  store i64 %51, ptr %1, align 8, !tbaa !5
  %.not = icmp eq i64 %50, 0
  br i1 %.not, label %._crit_edge33, label %.preheader24, !llvm.loop !11

.lr.ph:                                           ; preds = %48, %.lr.ph
  %.030 = phi i32 [ %53, %.lr.ph ], [ 0, %48 ]
  %52 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %spec.select23.9)
  %53 = add nuw nsw i32 %.030, 1
  %exitcond.not = icmp eq i32 %.030, %spec.select.9
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !13

._crit_edge33:                                    ; preds = %._crit_edge, %0
  call void @llvm.lifetime.end.p0(i64 8, 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: 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) #4

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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!"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,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LCSSAPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,SROAPass,SimplifyCFGPass