; LLVM IR from upupming/algorithm :: CCCC-GPLT/L1-009. N个数求和 (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"

@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 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 uwtable
declare dso_local noundef i64 @_Z3gcdxx(i64 noundef, i64 noundef) #0

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

11:                                               ; preds = %69, %0
  %12 = load i32, ptr %8, align 4, !tbaa !9
  %13 = sext i32 %12 to i64
  %14 = load i64, ptr %2, align 8, !tbaa !5
  %15 = icmp slt i64 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  br label %72

17:                                               ; preds = %11
  %18 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3, ptr noundef %4)
  %19 = load i64, ptr %5, align 8, !tbaa !5
  %20 = icmp eq i64 %19, 0
  br i1 %20, label %24, label %21

21:                                               ; preds = %17
  %22 = load i64, ptr %6, align 8, !tbaa !5
  %23 = icmp eq i64 %22, 0
  br i1 %23, label %24, label %25

24:                                               ; preds = %21, %17
  br label %31

25:                                               ; preds = %21
  %26 = load i64, ptr %5, align 8, !tbaa !5
  %27 = call noundef i64 @_ZSt3absx(i64 noundef %26)
  %28 = load i64, ptr %6, align 8, !tbaa !5
  %29 = call noundef i64 @_ZSt3absx(i64 noundef %28)
  %30 = call noundef i64 @_Z3gcdxx(i64 noundef %27, i64 noundef %29)
  br label %31

31:                                               ; preds = %25, %24
  %32 = phi i64 [ 1, %24 ], [ %30, %25 ]
  store i64 %32, ptr %7, align 8, !tbaa !5
  %33 = load i64, ptr %6, align 8, !tbaa !5
  %34 = load i64, ptr %7, align 8, !tbaa !5
  %35 = sdiv i64 %33, %34
  store i64 %35, ptr %6, align 8, !tbaa !5
  %36 = load i64, ptr %5, align 8, !tbaa !5
  %37 = load i64, ptr %7, align 8, !tbaa !5
  %38 = sdiv i64 %36, %37
  store i64 %38, ptr %5, align 8, !tbaa !5
  %39 = load i64, ptr %3, align 8, !tbaa !5
  %40 = icmp eq i64 %39, 0
  br i1 %40, label %44, label %41

41:                                               ; preds = %31
  %42 = load i64, ptr %4, align 8, !tbaa !5
  %43 = icmp eq i64 %42, 0
  br i1 %43, label %44, label %45

44:                                               ; preds = %41, %31
  br label %51

45:                                               ; preds = %41
  %46 = load i64, ptr %3, align 8, !tbaa !5
  %47 = call noundef i64 @_ZSt3absx(i64 noundef %46)
  %48 = load i64, ptr %4, align 8, !tbaa !5
  %49 = call noundef i64 @_ZSt3absx(i64 noundef %48)
  %50 = call noundef i64 @_Z3gcdxx(i64 noundef %47, i64 noundef %49)
  br label %51

51:                                               ; preds = %45, %44
  %52 = phi i64 [ 1, %44 ], [ %50, %45 ]
  store i64 %52, ptr %7, align 8, !tbaa !5
  %53 = load i64, ptr %3, align 8, !tbaa !5
  %54 = load i64, ptr %7, align 8, !tbaa !5
  %55 = sdiv i64 %53, %54
  store i64 %55, ptr %3, align 8, !tbaa !5
  %56 = load i64, ptr %4, align 8, !tbaa !5
  %57 = load i64, ptr %7, align 8, !tbaa !5
  %58 = sdiv i64 %56, %57
  store i64 %58, ptr %4, align 8, !tbaa !5
  %59 = load i64, ptr %3, align 8, !tbaa !5
  %60 = load i64, ptr %6, align 8, !tbaa !5
  %61 = mul nsw i64 %59, %60
  %62 = load i64, ptr %5, align 8, !tbaa !5
  %63 = load i64, ptr %4, align 8, !tbaa !5
  %64 = mul nsw i64 %62, %63
  %65 = add nsw i64 %61, %64
  store i64 %65, ptr %5, align 8, !tbaa !5
  %66 = load i64, ptr %4, align 8, !tbaa !5
  %67 = load i64, ptr %6, align 8, !tbaa !5
  %68 = mul nsw i64 %66, %67
  store i64 %68, ptr %6, align 8, !tbaa !5
  br label %69

69:                                               ; preds = %51
  %70 = load i32, ptr %8, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %8, align 4, !tbaa !9
  br label %11, !llvm.loop !11

72:                                               ; preds = %16
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  %73 = load i64, ptr %5, align 8, !tbaa !5
  %74 = load i64, ptr %6, align 8, !tbaa !5
  %75 = sdiv i64 %73, %74
  store i64 %75, ptr %9, align 8, !tbaa !5
  %76 = load i64, ptr %5, align 8, !tbaa !5
  %77 = load i64, ptr %6, align 8, !tbaa !5
  %78 = load i64, ptr %9, align 8, !tbaa !5
  %79 = mul nsw i64 %77, %78
  %80 = sub nsw i64 %76, %79
  store i64 %80, ptr %5, align 8, !tbaa !5
  %81 = load i64, ptr %5, align 8, !tbaa !5
  %82 = icmp eq i64 %81, 0
  br i1 %82, label %86, label %83

83:                                               ; preds = %72
  %84 = load i64, ptr %6, align 8, !tbaa !5
  %85 = icmp eq i64 %84, 0
  br i1 %85, label %86, label %87

86:                                               ; preds = %83, %72
  br label %93

87:                                               ; preds = %83
  %88 = load i64, ptr %5, align 8, !tbaa !5
  %89 = call noundef i64 @_ZSt3absx(i64 noundef %88)
  %90 = load i64, ptr %6, align 8, !tbaa !5
  %91 = call noundef i64 @_ZSt3absx(i64 noundef %90)
  %92 = call noundef i64 @_Z3gcdxx(i64 noundef %89, i64 noundef %91)
  br label %93

93:                                               ; preds = %87, %86
  %94 = phi i64 [ 1, %86 ], [ %92, %87 ]
  store i64 %94, ptr %7, align 8, !tbaa !5
  %95 = load i64, ptr %5, align 8, !tbaa !5
  %96 = load i64, ptr %7, align 8, !tbaa !5
  %97 = sdiv i64 %95, %96
  store i64 %97, ptr %5, align 8, !tbaa !5
  %98 = load i64, ptr %6, align 8, !tbaa !5
  %99 = load i64, ptr %7, align 8, !tbaa !5
  %100 = sdiv i64 %98, %99
  store i64 %100, ptr %6, align 8, !tbaa !5
  %101 = load i64, ptr %9, align 8, !tbaa !5
  %102 = icmp ne i64 %101, 0
  br i1 %102, label %103, label %111

103:                                              ; preds = %93
  %104 = load i64, ptr %9, align 8, !tbaa !5
  %105 = call i32 (ptr, ...) @printf(ptr noundef @.str, i64 noundef %104)
  %106 = load i64, ptr %5, align 8, !tbaa !5
  %107 = icmp ne i64 %106, 0
  br i1 %107, label %108, label %110

108:                                              ; preds = %103
  %109 = call i32 (ptr, ...) @printf(ptr noundef @.str.2)
  br label %110

110:                                              ; preds = %108, %103
  br label %111

111:                                              ; preds = %110, %93
  %112 = load i64, ptr %5, align 8, !tbaa !5
  %113 = icmp ne i64 %112, 0
  br i1 %113, label %114, label %118

114:                                              ; preds = %111
  %115 = load i64, ptr %5, align 8, !tbaa !5
  %116 = load i64, ptr %6, align 8, !tbaa !5
  %117 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i64 noundef %115, i64 noundef %116)
  br label %118

118:                                              ; preds = %114, %111
  %119 = load i64, ptr %9, align 8, !tbaa !5
  %120 = icmp eq i64 %119, 0
  br i1 %120, label %121, label %126

121:                                              ; preds = %118
  %122 = load i64, ptr %5, align 8, !tbaa !5
  %123 = icmp eq i64 %122, 0
  br i1 %123, label %124, label %126

124:                                              ; preds = %121
  %125 = call i32 (ptr, ...) @printf(ptr noundef @.str.3)
  br label %126

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) #4

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

declare i32 @printf(ptr noundef, ...) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { inlinehint mustprogress 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 #5 = { 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 = !{!"long 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"}


; 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 [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [10 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 uwtable
declare dso_local noundef i64 @_Z3gcdxx(i64 noundef, i64 noundef) local_unnamed_addr #0

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

._crit_edge:                                      ; preds = %30, %0
  %.044.lcssa = phi i64 [ 1, %0 ], [ %39, %30 ]
  %.0.lcssa = phi i64 [ 0, %0 ], [ %38, %30 ]
  %7 = sdiv i64 %.0.lcssa, %.044.lcssa
  %8 = mul nsw i64 %7, %.044.lcssa
  %.recomposed = srem i64 %.0.lcssa, %.044.lcssa
  %9 = icmp eq i64 %.0.lcssa, %8
  br i1 %9, label %46, label %42

.lr.ph:                                           ; preds = %0, %30
  %indvars.iv = phi i64 [ %indvars.iv.next, %30 ], [ 0, %0 ]
  %.056 = phi i64 [ %38, %30 ], [ 0, %0 ]
  %.04454 = phi i64 [ %39, %30 ], [ 1, %0 ]
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %2, ptr noundef nonnull %3)
  %11 = icmp eq i64 %.056, 0
  %12 = icmp eq i64 %.04454, 0
  %or.cond = select i1 %11, i1 true, i1 %12
  br i1 %or.cond, label %17, label %13

13:                                               ; preds = %.lr.ph
  %14 = call noundef i64 @_ZSt3absx(i64 noundef %.056)
  %15 = call noundef i64 @_ZSt3absx(i64 noundef %.04454)
  %16 = call noundef i64 @_Z3gcdxx(i64 noundef %14, i64 noundef %15)
  br label %17

17:                                               ; preds = %.lr.ph, %13
  %18 = phi i64 [ %16, %13 ], [ 1, %.lr.ph ]
  %19 = sdiv i64 %.04454, %18
  %20 = sdiv i64 %.056, %18
  %21 = load i64, ptr %2, align 8, !tbaa !5
  %22 = icmp eq i64 %21, 0
  %23 = load i64, ptr %3, align 8
  %24 = icmp eq i64 %23, 0
  %or.cond3 = select i1 %22, i1 true, i1 %24
  br i1 %or.cond3, label %30, label %25

25:                                               ; preds = %17
  %26 = call noundef i64 @_ZSt3absx(i64 noundef %21)
  %27 = load i64, ptr %3, align 8, !tbaa !5
  %28 = call noundef i64 @_ZSt3absx(i64 noundef %27)
  %29 = call noundef i64 @_Z3gcdxx(i64 noundef %26, i64 noundef %28)
  %.pre = load i64, ptr %2, align 8, !tbaa !5
  %.pre60 = load i64, ptr %3, align 8, !tbaa !5
  br label %30

30:                                               ; preds = %17, %25
  %31 = phi i64 [ %.pre60, %25 ], [ %23, %17 ]
  %32 = phi i64 [ %.pre, %25 ], [ %21, %17 ]
  %33 = phi i64 [ %29, %25 ], [ 1, %17 ]
  %34 = sdiv i64 %32, %33
  store i64 %34, ptr %2, align 8, !tbaa !5
  %35 = sdiv i64 %31, %33
  store i64 %35, ptr %3, align 8, !tbaa !5
  %36 = mul nsw i64 %34, %19
  %37 = mul nsw i64 %35, %20
  %38 = add nsw i64 %37, %36
  %39 = mul nsw i64 %35, %19
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %40 = load i64, ptr %1, align 8, !tbaa !5
  %41 = icmp sgt i64 %40, %indvars.iv.next
  br i1 %41, label %.lr.ph, label %._crit_edge, !llvm.loop !9

42:                                               ; preds = %._crit_edge
  %43 = call noundef i64 @_ZSt3absx(i64 noundef %.recomposed)
  %44 = call noundef i64 @_ZSt3absx(i64 noundef %.044.lcssa)
  %45 = call noundef i64 @_Z3gcdxx(i64 noundef %43, i64 noundef %44)
  br label %46

46:                                               ; preds = %._crit_edge, %42
  %47 = phi i64 [ %45, %42 ], [ 1, %._crit_edge ]
  %48 = sdiv i64 %.recomposed, %47
  %49 = sdiv i64 %.044.lcssa, %47
  %.not = icmp eq i64 %7, 0
  br i1 %.not, label %53, label %50

50:                                               ; preds = %46
  %51 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str, i64 noundef %7)
  %cond = icmp eq i64 %48, 0
  br i1 %cond, label %.thread52, label %.thread

.thread:                                          ; preds = %50
  %52 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2)
  br label %54

53:                                               ; preds = %46
  %.not50 = icmp eq i64 %48, 0
  br i1 %.not50, label %56, label %54

54:                                               ; preds = %.thread, %53
  %55 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i64 noundef %48, i64 noundef %49)
  br label %.thread52

56:                                               ; preds = %53
  %57 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3)
  br label %.thread52

.thread52:                                        ; preds = %54, %50, %56
  call void @llvm.lifetime.end.p0(i64 8, 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) #2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZSt3absx(i64 noundef) local_unnamed_addr #4

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { inlinehint mustprogress 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 #5 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}


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