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

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

13:                                               ; preds = %78, %0
  %14 = load i32, ptr %7, align 4, !tbaa !11
  %15 = add nsw i32 %14, -1
  store i32 %15, ptr %7, align 4, !tbaa !11
  %16 = icmp ne i32 %14, 0
  br i1 %16, label %17, label %79

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

25:                                               ; preds = %35, %17
  %26 = load i64, ptr %9, align 8, !tbaa !5
  %27 = load i64, ptr %2, align 8, !tbaa !5
  %28 = icmp ult i64 %26, %27
  br i1 %28, label %30, label %29

29:                                               ; preds = %25
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  br label %38

30:                                               ; preds = %25
  %31 = load ptr, ptr %8, align 8, !tbaa !13
  %32 = load i64, ptr %9, align 8, !tbaa !5
  %33 = getelementptr inbounds i64, ptr %31, i64 %32
  %34 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef %33)
  br label %35

35:                                               ; preds = %30
  %36 = load i64, ptr %9, align 8, !tbaa !5
  %37 = add i64 %36, 1
  store i64 %37, ptr %9, align 8, !tbaa !5
  br label %25, !llvm.loop !15

38:                                               ; preds = %29
  %39 = load ptr, ptr %8, align 8, !tbaa !13
  %40 = load ptr, ptr %8, align 8, !tbaa !13
  %41 = load i64, ptr %2, align 8, !tbaa !5
  %42 = getelementptr inbounds i64, ptr %40, i64 %41
  call void @_ZSt4sortIPyEvT_S1_(ptr noundef %39, ptr noundef %42)
  store i64 0, ptr %3, align 8, !tbaa !5
  store i64 0, ptr %6, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %43 = load i64, ptr %2, align 8, !tbaa !5
  %44 = sub i64 %43, 1
  %45 = trunc i64 %44 to i32
  store i32 %45, ptr %10, align 4, !tbaa !11
  br label %46

46:                                               ; preds = %65, %38
  %47 = load i32, ptr %10, align 4, !tbaa !11
  %48 = icmp sge i32 %47, 0
  br i1 %48, label %50, label %49

49:                                               ; preds = %46
  store i32 7, ptr %11, align 4
  br label %68

50:                                               ; preds = %46
  %51 = load ptr, ptr %8, align 8, !tbaa !13
  %52 = load i32, ptr %10, align 4, !tbaa !11
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds i64, ptr %51, i64 %53
  %55 = load i64, ptr %54, align 8, !tbaa !9
  %56 = load i64, ptr %6, align 8, !tbaa !9
  %57 = add i64 %56, %55
  store i64 %57, ptr %6, align 8, !tbaa !9
  %58 = load i64, ptr %3, align 8, !tbaa !5
  %59 = add i64 %58, 1
  store i64 %59, ptr %3, align 8, !tbaa !5
  %60 = load i64, ptr %6, align 8, !tbaa !9
  %61 = load i64, ptr %4, align 8, !tbaa !9
  %62 = icmp uge i64 %60, %61
  br i1 %62, label %63, label %64

63:                                               ; preds = %50
  store i32 7, ptr %11, align 4
  br label %68

64:                                               ; preds = %50
  br label %65

65:                                               ; preds = %64
  %66 = load i32, ptr %10, align 4, !tbaa !11
  %67 = add nsw i32 %66, -1
  store i32 %67, ptr %10, align 4, !tbaa !11
  br label %46, !llvm.loop !17

68:                                               ; preds = %63, %49
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %69

69:                                               ; preds = %68
  %70 = load i64, ptr %6, align 8, !tbaa !9
  %71 = load i64, ptr %4, align 8, !tbaa !9
  %72 = icmp uge i64 %70, %71
  br i1 %72, label %73, label %76

73:                                               ; preds = %69
  %74 = load i64, ptr %3, align 8, !tbaa !5
  %75 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, i64 noundef %74)
  br label %78

76:                                               ; preds = %69
  %77 = call i32 (ptr, ...) @printf(ptr noundef @.str.4)
  br label %78

78:                                               ; preds = %76, %73
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br label %13, !llvm.loop !18

79:                                               ; preds = %13
  store i32 0, ptr %1, align 4
  store i32 1, ptr %11, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #6
  %80 = load i32, ptr %1, align 4
  ret i32 %80
}

; 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 @_ZSt4sortIPyEvT_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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long long", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = !{!14, !14, i64 0}
!14 = !{!"any pointer", !7, i64 0}
!15 = distinct !{!15, !16}
!16 = !{!"llvm.loop.mustprogress"}
!17 = distinct !{!17, !16}
!18 = distinct !{!18, !16}


; 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 [10 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [5 x i8], align 1
@.str.4 = 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 i64, align 8
  %2 = alloca i64, align 8
  %3 = alloca i32, align 4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  store i64 0, ptr %1, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  store i64 0, ptr %2, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %3)
  %5 = load i32, ptr %3, align 4, !tbaa !11
  %6 = add nsw i32 %5, -1
  store i32 %6, ptr %3, align 4, !tbaa !11
  %.not25 = icmp eq i32 %5, 0
  br i1 %.not25, label %._crit_edge28, label %.lr.ph27

.lr.ph27:                                         ; preds = %0, %36
  %7 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %8 = load i64, ptr %1, align 8, !tbaa !5
  %9 = icmp ugt i64 %8, 2305843009213693951
  %10 = shl i64 %8, 3
  %11 = select i1 %9, i64 -1, i64 %10
  %12 = call noalias noundef nonnull ptr @_Znam(i64 noundef %11) #6
  %.not29 = icmp eq i64 %8, 0
  br i1 %.not29, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %.lr.ph, %.lr.ph27
  %.lcssa = phi i64 [ 0, %.lr.ph27 ], [ %20, %.lr.ph ]
  %13 = getelementptr inbounds i64, ptr %12, i64 %.lcssa
  call void @_ZSt4sortIPyEvT_S1_(ptr noundef nonnull %12, ptr noundef nonnull %13)
  %14 = load i64, ptr %1, align 8, !tbaa !5
  %15 = load i64, ptr %2, align 8
  %16 = and i64 %14, 4294967295
  br label %22

.lr.ph:                                           ; preds = %.lr.ph27, %.lr.ph
  %.01524 = phi i64 [ %19, %.lr.ph ], [ 0, %.lr.ph27 ]
  %17 = getelementptr inbounds i64, ptr %12, i64 %.01524
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull %17)
  %19 = add nuw i64 %.01524, 1
  %20 = load i64, ptr %1, align 8, !tbaa !5
  %21 = icmp ult i64 %19, %20
  br i1 %21, label %.lr.ph, label %._crit_edge, !llvm.loop !13

22:                                               ; preds = %25, %._crit_edge
  %indvars.iv = phi i64 [ %indvars.iv.next, %25 ], [ %16, %._crit_edge ]
  %.017 = phi i64 [ %30, %25 ], [ 0, %._crit_edge ]
  %.016 = phi i64 [ %29, %25 ], [ 0, %._crit_edge ]
  %indvars.iv.next = add nsw i64 %indvars.iv, -1
  %23 = and i64 %indvars.iv.next, 2147483648
  %24 = icmp eq i64 %23, 0
  br i1 %24, label %25, label %31

25:                                               ; preds = %22
  %26 = and i64 %indvars.iv.next, 2147483647
  %27 = getelementptr inbounds i64, ptr %12, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !9
  %29 = add i64 %28, %.016
  %30 = add nuw nsw i64 %.017, 1
  %.not22 = icmp ult i64 %29, %15
  br i1 %.not22, label %22, label %31, !llvm.loop !15

31:                                               ; preds = %25, %22
  %.118 = phi i64 [ %.017, %22 ], [ %30, %25 ]
  %.1 = phi i64 [ %.016, %22 ], [ %29, %25 ]
  %.not23 = icmp ult i64 %.1, %15
  br i1 %.not23, label %34, label %32

32:                                               ; preds = %31
  %33 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, i64 noundef %.118)
  br label %36

34:                                               ; preds = %31
  %35 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4)
  br label %36

36:                                               ; preds = %34, %32
  %37 = load i32, ptr %3, align 4, !tbaa !11
  %38 = add nsw i32 %37, -1
  store i32 %38, ptr %3, align 4, !tbaa !11
  %.not = icmp eq i32 %37, 0
  br i1 %.not, label %._crit_edge28, label %.lr.ph27, !llvm.loop !16

._crit_edge28:                                    ; preds = %36, %0
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  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: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPyEvT_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 = !{!"long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"long 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}


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