; LLVM IR from upupming/algorithm :: acwing/算法竞赛进阶指南/0x06-倍增/109. 天才ACM (main)

; 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"

@k = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global [500010 x i32], align 16
@b = external dso_local global [500010 x i32], align 16
@c = external dso_local global [500010 x i32], align 16
@t = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5calcTiii(i32 noundef, i32 noundef, i32 noundef) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %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
  store i32 0, ptr %1, align 4
  %9 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @k)
  br label %10

10:                                               ; preds = %101, %0
  %11 = load i32, ptr @k, align 4, !tbaa !5
  %12 = add nsw i32 %11, -1
  store i32 %12, ptr @k, align 4, !tbaa !5
  %13 = icmp ne i32 %11, 0
  br i1 %13, label %14, label %104

14:                                               ; preds = %10
  %15 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @n, ptr noundef @m, ptr noundef @t)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #4
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %36, %14
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

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

21:                                               ; preds = %16
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [500010 x i32], ptr @a, i64 0, i64 %23
  %25 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %24)
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [500010 x i32], ptr @a, i64 0, i64 %27
  %29 = load i32, ptr %28, align 4, !tbaa !5
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [500010 x i32], ptr @b, i64 0, i64 %31
  store i32 %29, ptr %32, align 4, !tbaa !5
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [500010 x i32], ptr @c, i64 0, i64 %34
  store i32 %29, ptr %35, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %21
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %2, align 4, !tbaa !5
  br label %16, !llvm.loop !9

39:                                               ; preds = %20
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  store i32 0, ptr %4, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %98, %39
  %41 = load i32, ptr %4, align 4, !tbaa !5
  %42 = load i32, ptr @n, align 4, !tbaa !5
  %43 = icmp slt i32 %41, %42
  br i1 %43, label %45, label %44

44:                                               ; preds = %40
  store i32 7, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %101

45:                                               ; preds = %40
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 1, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %46 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %46, ptr %7, align 4, !tbaa !5
  br label %47

47:                                               ; preds = %94, %45
  %48 = load i32, ptr %6, align 4, !tbaa !5
  %49 = icmp ne i32 %48, 0
  br i1 %49, label %50, label %95

50:                                               ; preds = %47
  %51 = load i32, ptr %7, align 4, !tbaa !5
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = add nsw i32 %51, %52
  %54 = load i32, ptr @n, align 4, !tbaa !5
  %55 = icmp slt i32 %53, %54
  br i1 %55, label %56, label %91

56:                                               ; preds = %50
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = load i32, ptr %7, align 4, !tbaa !5
  %59 = load i32, ptr %7, align 4, !tbaa !5
  %60 = load i32, ptr %6, align 4, !tbaa !5
  %61 = add nsw i32 %59, %60
  %62 = call noundef i64 @_Z5calcTiii(i32 noundef %57, i32 noundef %58, i32 noundef %61)
  %63 = load i64, ptr @t, align 8, !tbaa !11
  %64 = icmp sle i64 %62, %63
  br i1 %64, label %65, label %91

65:                                               ; preds = %56
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %66 = load i32, ptr %4, align 4, !tbaa !5
  store i32 %66, ptr %8, align 4, !tbaa !5
  br label %67

67:                                               ; preds = %82, %65
  %68 = load i32, ptr %8, align 4, !tbaa !5
  %69 = load i32, ptr %7, align 4, !tbaa !5
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = add nsw i32 %69, %70
  %72 = icmp sle i32 %68, %71
  br i1 %72, label %74, label %73

73:                                               ; preds = %67
  store i32 12, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %85

74:                                               ; preds = %67
  %75 = load i32, ptr %8, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [500010 x i32], ptr @c, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = load i32, ptr %8, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [500010 x i32], ptr @a, i64 0, i64 %80
  store i32 %78, ptr %81, align 4, !tbaa !5
  br label %82

82:                                               ; preds = %74
  %83 = load i32, ptr %8, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %8, align 4, !tbaa !5
  br label %67, !llvm.loop !13

85:                                               ; preds = %73
  %86 = load i32, ptr %6, align 4, !tbaa !5
  %87 = load i32, ptr %7, align 4, !tbaa !5
  %88 = add nsw i32 %87, %86
  store i32 %88, ptr %7, align 4, !tbaa !5
  %89 = load i32, ptr %6, align 4, !tbaa !5
  %90 = mul nsw i32 %89, 2
  store i32 %90, ptr %6, align 4, !tbaa !5
  br label %94

91:                                               ; preds = %56, %50
  %92 = load i32, ptr %6, align 4, !tbaa !5
  %93 = sdiv i32 %92, 2
  store i32 %93, ptr %6, align 4, !tbaa !5
  br label %94

94:                                               ; preds = %91, %85
  br label %47, !llvm.loop !14

95:                                               ; preds = %47
  %96 = load i32, ptr %7, align 4, !tbaa !5
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  br label %98

98:                                               ; preds = %95
  %99 = load i32, ptr %3, align 4, !tbaa !5
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %3, align 4, !tbaa !5
  br label %40, !llvm.loop !15

101:                                              ; preds = %44
  %102 = load i32, ptr %3, align 4, !tbaa !5
  %103 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %102)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  br label %10, !llvm.loop !16

104:                                              ; preds = %10
  ret i32 0
}

declare i32 @__isoc99_scanf(ptr noundef, ...) #3

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #3 = { "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 }

!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 = !{!12, !12, i64 0}
!12 = !{!"long long", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !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"

@k = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global [500010 x i32], align 16
@b = external dso_local local_unnamed_addr global [500010 x i32], align 16
@c = external dso_local local_unnamed_addr global [500010 x i32], align 16
@t = external dso_local global i64, align 8
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [9 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i64 @_Z5calcTiii(i32 noundef, i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @k)
  %2 = load i32, ptr @k, align 4, !tbaa !5
  %3 = add nsw i32 %2, -1
  store i32 %3, ptr @k, align 4, !tbaa !5
  %.not50 = icmp eq i32 %2, 0
  br i1 %.not50, label %._crit_edge53, label %.lr.ph52

.lr.ph52:                                         ; preds = %0, %._crit_edge49
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @t)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge49

.preheader40:                                     ; preds = %.lr.ph
  %7 = icmp sgt i32 %13, 0
  br i1 %7, label %.preheader39, label %._crit_edge49

.lr.ph:                                           ; preds = %.lr.ph52, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.lr.ph52 ]
  %8 = getelementptr inbounds [500010 x i32], ptr @a, i64 0, i64 %indvars.iv
  %9 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %8)
  %10 = load i32, ptr %8, align 4, !tbaa !5
  %11 = getelementptr inbounds [500010 x i32], ptr @b, i64 0, i64 %indvars.iv
  store i32 %10, ptr %11, align 4, !tbaa !5
  %12 = getelementptr inbounds [500010 x i32], ptr @c, i64 0, i64 %indvars.iv
  store i32 %10, ptr %12, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = icmp slt i64 %indvars.iv.next, %14
  br i1 %15, label %.lr.ph, label %.preheader40, !llvm.loop !9

.preheader39:                                     ; preds = %.preheader40, %39
  %.pre59 = phi i32 [ %.pre5960, %39 ], [ %13, %.preheader40 ]
  %.03248 = phi i32 [ %40, %39 ], [ 0, %.preheader40 ]
  %.03347 = phi i32 [ %41, %39 ], [ 0, %.preheader40 ]
  %16 = sext i32 %.03248 to i64
  %17 = shl nsw i64 %16, 2
  %scevgep = getelementptr i8, ptr @a, i64 %17
  %scevgep55 = getelementptr i8, ptr @c, i64 %17
  br label %21

._crit_edge49:                                    ; preds = %39, %.lr.ph52, %.preheader40
  %.033.lcssa = phi i32 [ 0, %.preheader40 ], [ 0, %.lr.ph52 ], [ %41, %39 ]
  %18 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %.033.lcssa)
  %19 = load i32, ptr @k, align 4, !tbaa !5
  %20 = add nsw i32 %19, -1
  store i32 %20, ptr @k, align 4, !tbaa !5
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %._crit_edge53, label %.lr.ph52, !llvm.loop !11

21:                                               ; preds = %.preheader39, %37
  %.pre5962 = phi i32 [ %.pre59, %.preheader39 ], [ %.pre5960, %37 ]
  %22 = phi i32 [ %.pre59, %.preheader39 ], [ %38, %37 ]
  %.02946 = phi i32 [ %.03248, %.preheader39 ], [ %.1, %37 ]
  %.03045 = phi i32 [ 1, %.preheader39 ], [ %.131, %37 ]
  %23 = add nsw i32 %.02946, %.03045
  %24 = icmp slt i32 %23, %22
  br i1 %24, label %25, label %34

25:                                               ; preds = %21
  %26 = tail call noundef i64 @_Z5calcTiii(i32 noundef %.03248, i32 noundef %.02946, i32 noundef %23)
  %27 = load i64, ptr @t, align 8, !tbaa !12
  %.not37 = icmp sgt i64 %26, %27
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br i1 %.not37, label %34, label %.preheader

.preheader:                                       ; preds = %25
  %.not3842 = icmp sgt i32 %.03248, %23
  br i1 %.not3842, label %._crit_edge, label %.lr.ph44.preheader

.lr.ph44.preheader:                               ; preds = %.preheader
  %28 = sub i32 %.02946, %.03248
  %29 = add i32 %28, %.03045
  %30 = zext i32 %29 to i64
  %31 = shl nuw nsw i64 %30, 2
  %32 = add nuw nsw i64 %31, 4
  tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(1) %scevgep, ptr noundef nonnull align 4 dereferenceable(1) %scevgep55, i64 %32, i1 false), !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph44.preheader, %.preheader
  %33 = shl nsw i32 %.03045, 1
  br label %37

34:                                               ; preds = %25, %21
  %.pre5961 = phi i32 [ %.pre, %25 ], [ %.pre5962, %21 ]
  %35 = phi i32 [ %.pre, %25 ], [ %22, %21 ]
  %36 = sdiv i32 %.03045, 2
  br label %37

37:                                               ; preds = %34, %._crit_edge
  %.pre5960 = phi i32 [ %.pre, %._crit_edge ], [ %.pre5961, %34 ]
  %38 = phi i32 [ %.pre, %._crit_edge ], [ %35, %34 ]
  %.131 = phi i32 [ %33, %._crit_edge ], [ %36, %34 ]
  %.1 = phi i32 [ %23, %._crit_edge ], [ %.02946, %34 ]
  %.not36 = icmp eq i32 %.131, 0
  br i1 %.not36, label %39, label %21, !llvm.loop !14

39:                                               ; preds = %37
  %40 = add nsw i32 %.1, 1
  %41 = add nuw nsw i32 %.03347, 1
  %42 = icmp slt i32 %40, %38
  br i1 %42, label %.preheader39, label %._crit_edge49, !llvm.loop !15

._crit_edge53:                                    ; preds = %._crit_edge49, %0
  ret i32 0
}

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

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #3

attributes #0 = { 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 #1 = { 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 #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 nounwind willreturn memory(argmem: readwrite) }

!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 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}


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