; LLVM IR from tangjz/acm-icpc :: 51nod (1165)

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

@f = external dso_local global [10000001 x i32], align 16
@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@.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 i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %53, %0
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = icmp sle i32 %12, 10000000
  br i1 %13, label %15, label %14

14:                                               ; preds = %11
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %56

15:                                               ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %16 = load i32, ptr %2, align 4, !tbaa !5
  %17 = sdiv i32 10000000, %16
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sub nsw i32 %17, %18
  store i32 %19, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = sub nsw i32 %20, 1
  store i32 %21, ptr %7, align 4, !tbaa !5
  %22 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %23 = load i32, ptr %22, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  store i32 %23, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = add nsw i32 %25, 1
  %27 = mul nsw i32 %24, %26
  store i32 %27, ptr %8, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %45, %15
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = icmp sle i32 %29, %30
  br i1 %31, label %33, label %32

32:                                               ; preds = %28
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %52

33:                                               ; preds = %28
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = load i32, ptr %4, align 4, !tbaa !5
  %36 = call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %34, i32 noundef %35)
  %37 = icmp eq i32 %36, 1
  br i1 %37, label %38, label %44

38:                                               ; preds = %33
  %39 = load i32, ptr %8, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [10000001 x i32], ptr @f, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = add nsw i32 %42, 1
  store i32 %43, ptr %41, align 4, !tbaa !5
  br label %44

44:                                               ; preds = %38, %33
  br label %45

45:                                               ; preds = %44
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = add nsw i32 %46, 2
  store i32 %47, ptr %4, align 4, !tbaa !5
  %48 = load i32, ptr %2, align 4, !tbaa !5
  %49 = shl i32 %48, 1
  %50 = load i32, ptr %8, align 4, !tbaa !5
  %51 = add nsw i32 %50, %49
  store i32 %51, ptr %8, align 4, !tbaa !5
  br label %28, !llvm.loop !9

52:                                               ; preds = %32
  br label %53

53:                                               ; preds = %52
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = add nsw i32 %54, 2
  store i32 %55, ptr %2, align 4, !tbaa !5
  br label %11, !llvm.loop !11

56:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 10000000, ptr %9, align 4, !tbaa !5
  br label %57

57:                                               ; preds = %91, %56
  %58 = load i32, ptr %9, align 4, !tbaa !5
  %59 = icmp ne i32 %58, 0
  br i1 %59, label %61, label %60

60:                                               ; preds = %57
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  br label %94

61:                                               ; preds = %57
  %62 = load i32, ptr %9, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [10000001 x i32], ptr @f, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = icmp ne i32 %65, 0
  br i1 %66, label %67, label %90

67:                                               ; preds = %61
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %68 = load i32, ptr %9, align 4, !tbaa !5
  %69 = load i32, ptr %9, align 4, !tbaa !5
  %70 = add nsw i32 %68, %69
  store i32 %70, ptr %10, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %85, %67
  %72 = load i32, ptr %10, align 4, !tbaa !5
  %73 = icmp sle i32 %72, 10000000
  br i1 %73, label %75, label %74

74:                                               ; preds = %71
  store i32 11, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %89

75:                                               ; preds = %71
  %76 = load i32, ptr %9, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [10000001 x i32], ptr @f, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = load i32, ptr %10, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [10000001 x i32], ptr @f, i64 0, i64 %81
  %83 = load i32, ptr %82, align 4, !tbaa !5
  %84 = add nsw i32 %83, %79
  store i32 %84, ptr %82, align 4, !tbaa !5
  br label %85

85:                                               ; preds = %75
  %86 = load i32, ptr %9, align 4, !tbaa !5
  %87 = load i32, ptr %10, align 4, !tbaa !5
  %88 = add nsw i32 %87, %86
  store i32 %88, ptr %10, align 4, !tbaa !5
  br label %71, !llvm.loop !12

89:                                               ; preds = %74
  br label %90

90:                                               ; preds = %89, %61
  br label %91

91:                                               ; preds = %90
  %92 = load i32, ptr %9, align 4, !tbaa !5
  %93 = add nsw i32 %92, -1
  store i32 %93, ptr %9, align 4, !tbaa !5
  br label %57, !llvm.loop !13

94:                                               ; preds = %60
  %95 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @t)
  br label %96

96:                                               ; preds = %100, %94
  %97 = load i32, ptr @t, align 4, !tbaa !5
  %98 = add nsw i32 %97, -1
  store i32 %98, ptr @t, align 4, !tbaa !5
  %99 = icmp ne i32 %97, 0
  br i1 %99, label %100, label %107

100:                                              ; preds = %96
  %101 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %102 = load i32, ptr @n, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [10000001 x i32], ptr @f, i64 0, i64 %103
  %105 = load i32, ptr %104, align 4, !tbaa !5
  %106 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %105)
  br label %96, !llvm.loop !14

107:                                              ; preds = %96
  ret i32 0
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef, i32 noundef) #3

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

declare i32 @printf(ptr noundef, ...) #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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { "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 = !{!"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}
!14 = distinct !{!14, !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"

@f = external dso_local local_unnamed_addr global [10000001 x i32], align 16
@t = external dso_local global i32, align 4
@n = external dso_local global i32, align 4
@.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 nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  br label %3

3:                                                ; preds = %0, %._crit_edge
  %indvars.iv53 = phi i64 [ 10, %0 ], [ %indvars.iv.next54, %._crit_edge ]
  %indvars.iv48 = phi i64 [ 2, %0 ], [ %indvars.iv.next49, %._crit_edge ]
  %indvars.iv46 = phi i32 [ 2, %0 ], [ %indvars.iv.next47, %._crit_edge ]
  %.02735 = phi i32 [ 1, %0 ], [ %10, %._crit_edge ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  %4 = udiv i32 10000000, %.02735
  %5 = sub nsw i32 %4, %.02735
  store i32 %5, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  %6 = add nsw i32 %.02735, -1
  store i32 %6, ptr %2, align 4, !tbaa !5
  %7 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %8 = load i32, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  %.not3132 = icmp slt i32 %8, 1
  br i1 %.not3132, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %3
  %9 = zext i32 %indvars.iv46 to i64
  br label %13

._crit_edge:                                      ; preds = %20, %3
  %10 = add nuw nsw i32 %.02735, 2
  %11 = icmp ult i32 %.02735, 9999999
  %indvars.iv.next54 = add nuw nsw i64 %indvars.iv53, 8
  %12 = trunc nuw nsw i64 %indvars.iv53 to i32
  %indvars.iv.next47 = add i32 %indvars.iv46, %12
  %indvars.iv.next49 = add nuw nsw i64 %indvars.iv48, 4
  br i1 %11, label %3, label %.preheader, !llvm.loop !9

13:                                               ; preds = %.lr.ph, %20
  %indvars.iv50 = phi i64 [ %9, %.lr.ph ], [ %indvars.iv.next51, %20 ]
  %.02833 = phi i32 [ 1, %.lr.ph ], [ %21, %20 ]
  %14 = call noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef %.02735, i32 noundef %.02833)
  %15 = icmp eq i32 %14, 1
  br i1 %15, label %16, label %20

16:                                               ; preds = %13
  %17 = getelementptr inbounds [10000001 x i32], ptr @f, i64 0, i64 %indvars.iv50
  %18 = load i32, ptr %17, align 8, !tbaa !5
  %19 = add nsw i32 %18, 1
  store i32 %19, ptr %17, align 8, !tbaa !5
  br label %20

20:                                               ; preds = %13, %16
  %21 = add nuw nsw i32 %.02833, 2
  %indvars.iv.next51 = add nuw nsw i64 %indvars.iv50, %indvars.iv48
  %.not31 = icmp sgt i32 %21, %8
  br i1 %.not31, label %._crit_edge, label %13, !llvm.loop !11

22:                                               ; preds = %.loopexit
  %23 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @t)
  %24 = load i32, ptr @t, align 4, !tbaa !5
  %25 = add nsw i32 %24, -1
  store i32 %25, ptr @t, align 4, !tbaa !5
  %.not2941 = icmp eq i32 %24, 0
  br i1 %.not2941, label %._crit_edge44, label %.lr.ph43

.preheader:                                       ; preds = %._crit_edge, %.loopexit
  %indvars.iv56 = phi i64 [ %indvars.iv.next57, %.loopexit ], [ 10000000, %._crit_edge ]
  %indvars.iv = phi i64 [ %indvars.iv.next, %.loopexit ], [ 20000000, %._crit_edge ]
  %26 = getelementptr inbounds [10000001 x i32], ptr @f, i64 0, i64 %indvars.iv56
  %27 = load i32, ptr %26, align 4, !tbaa !5
  %.not30 = icmp ne i32 %27, 0
  %28 = icmp ult i64 %indvars.iv56, 5000001
  %or.cond = and i1 %.not30, %28
  br i1 %or.cond, label %.lr.ph38, label %.loopexit

.lr.ph38:                                         ; preds = %.preheader, %.lr.ph38
  %indvars.iv58 = phi i64 [ %indvars.iv.next59, %.lr.ph38 ], [ %indvars.iv, %.preheader ]
  %29 = load i32, ptr %26, align 4, !tbaa !5
  %30 = getelementptr inbounds [10000001 x i32], ptr @f, i64 0, i64 %indvars.iv58
  %31 = load i32, ptr %30, align 4, !tbaa !5
  %32 = add nsw i32 %31, %29
  store i32 %32, ptr %30, align 4, !tbaa !5
  %indvars.iv.next59 = add nuw nsw i64 %indvars.iv58, %indvars.iv56
  %33 = icmp ult i64 %indvars.iv.next59, 10000001
  br i1 %33, label %.lr.ph38, label %.loopexit, !llvm.loop !12

.loopexit:                                        ; preds = %.lr.ph38, %.preheader
  %indvars.iv.next57 = add nsw i64 %indvars.iv56, -1
  %.not = icmp eq i64 %indvars.iv.next57, 0
  %indvars.iv.next = add nsw i64 %indvars.iv, -2
  br i1 %.not, label %22, label %.preheader, !llvm.loop !13

.lr.ph43:                                         ; preds = %22, %.lr.ph43
  %34 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %35 = load i32, ptr @n, align 4, !tbaa !5
  %36 = sext i32 %35 to i64
  %37 = getelementptr inbounds [10000001 x i32], ptr @f, i64 0, i64 %36
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %38)
  %40 = load i32, ptr @t, align 4, !tbaa !5
  %41 = add nsw i32 %40, -1
  store i32 %41, ptr @t, align 4, !tbaa !5
  %.not29 = icmp eq i32 %40, 0
  br i1 %.not29, label %._crit_edge44, label %.lr.ph43, !llvm.loop !14

._crit_edge44:                                    ; preds = %.lr.ph43, %22
  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: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i32 @_ZSt5__gcdIiET_S0_S0_(i32 noundef, i32 noundef) local_unnamed_addr #3

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

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

attributes #0 = { mustprogress norecurse 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 #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #2 = { 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 #3 = { 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 #4 = { 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 #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 = !{!"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}
!14 = distinct !{!14, !10}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,PostOrderFunctionAttrsPass,ReassociatePass,SROAPass,SimplifyCFGPass