; LLVM IR from tangjz/acm-icpc :: codeforces/complete (755A)

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

@tot = external dso_local global i32, align 4
@pr = external dso_local global [1000003 x i32], align 16
@d = external dso_local global [1000003 x i32], align 16
@.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
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #3
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %9

9:                                                ; preds = %62, %0
  %10 = load i32, ptr %2, align 4, !tbaa !5
  %11 = icmp slt i32 %10, 1000003
  br i1 %11, label %13, label %12

12:                                               ; preds = %9
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #3
  br label %65

13:                                               ; preds = %9
  %14 = load i32, ptr %2, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [1000003 x i32], ptr @d, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = icmp ne i32 %17, 0
  br i1 %18, label %28, label %19

19:                                               ; preds = %13
  %20 = load i32, ptr %2, align 4, !tbaa !5
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds [1000003 x i32], ptr @d, i64 0, i64 %22
  store i32 %20, ptr %23, align 4, !tbaa !5
  %24 = load i32, ptr @tot, align 4, !tbaa !5
  %25 = add nsw i32 %24, 1
  store i32 %25, ptr @tot, align 4, !tbaa !5
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds [1000003 x i32], ptr @pr, i64 0, i64 %26
  store i32 %20, ptr %27, align 4, !tbaa !5
  br label %28

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

29:                                               ; preds = %57, %28
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = load i32, ptr %4, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %33 = getelementptr inbounds [1000003 x i32], ptr @pr, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = mul nsw i32 %30, %34
  store i32 %35, ptr %5, align 4, !tbaa !5
  %36 = icmp slt i32 %35, 1000003
  br i1 %36, label %38, label %37

37:                                               ; preds = %29
  store i32 5, ptr %3, align 4
  br label %60

38:                                               ; preds = %29
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [1000003 x i32], ptr @pr, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = load i32, ptr %5, align 4, !tbaa !5
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [1000003 x i32], ptr @d, i64 0, i64 %44
  store i32 %42, ptr %45, align 4, !tbaa !5
  %46 = load i32, ptr %2, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [1000003 x i32], ptr @d, i64 0, i64 %47
  %49 = load i32, ptr %48, align 4, !tbaa !5
  %50 = load i32, ptr %4, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds [1000003 x i32], ptr @pr, i64 0, i64 %51
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = icmp eq i32 %49, %53
  br i1 %54, label %55, label %56

55:                                               ; preds = %38
  store i32 5, ptr %3, align 4
  br label %60

56:                                               ; preds = %38
  br label %57

57:                                               ; preds = %56
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = add nsw i32 %58, 1
  store i32 %59, ptr %4, align 4, !tbaa !5
  br label %29, !llvm.loop !9

60:                                               ; preds = %55, %37
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #3
  br label %61

61:                                               ; preds = %60
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %2, align 4, !tbaa !5
  br label %9, !llvm.loop !11

65:                                               ; preds = %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #3
  %66 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %6)
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %67

67:                                               ; preds = %89, %65
  %68 = load i32, ptr %7, align 4, !tbaa !5
  %69 = icmp sle i32 %68, 1000
  br i1 %69, label %71, label %70

70:                                               ; preds = %67
  store i32 8, ptr %3, align 4
  br label %92

71:                                               ; preds = %67
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %72 = load i32, ptr %7, align 4, !tbaa !5
  %73 = load i32, ptr %6, align 4, !tbaa !5
  %74 = mul nsw i32 %72, %73
  %75 = add nsw i32 %74, 1
  store i32 %75, ptr %8, align 4, !tbaa !5
  %76 = load i32, ptr %8, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [1000003 x i32], ptr @d, i64 0, i64 %77
  %79 = load i32, ptr %78, align 4, !tbaa !5
  %80 = load i32, ptr %8, align 4, !tbaa !5
  %81 = icmp ne i32 %79, %80
  br i1 %81, label %82, label %85

82:                                               ; preds = %71
  %83 = load i32, ptr %7, align 4, !tbaa !5
  %84 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %83)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %86

85:                                               ; preds = %71
  store i32 0, ptr %3, align 4
  br label %86

86:                                               ; preds = %85, %82
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  %87 = load i32, ptr %3, align 4
  switch i32 %87, label %92 [
    i32 0, label %88
  ]

88:                                               ; preds = %86
  br label %89

89:                                               ; preds = %88
  %90 = load i32, ptr %7, align 4, !tbaa !5
  %91 = add nsw i32 %90, 1
  store i32 %91, ptr %7, align 4, !tbaa !5
  br label %67, !llvm.loop !12

92:                                               ; preds = %86, %70
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  %93 = load i32, ptr %3, align 4
  switch i32 %93, label %95 [
    i32 8, label %94
  ]

94:                                               ; preds = %92
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  br label %95

95:                                               ; preds = %94, %92
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #3
  %96 = load i32, ptr %1, align 4
  ret i32 %96
}

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

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

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

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 = { 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}


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

@tot = external dso_local local_unnamed_addr global i32, align 4
@pr = external dso_local local_unnamed_addr global [1000003 x i32], align 16
@d = external dso_local local_unnamed_addr global [1000003 x i32], align 16
@.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 nofree norecurse nounwind uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !5
  br label %6

2:                                                ; preds = %._crit_edge
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #3
  %3 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1)
  %4 = load i32, ptr %1, align 4, !tbaa !5
  %5 = sext i32 %4 to i64
  br label %30

6:                                                ; preds = %0, %._crit_edge
  %indvars.iv38 = phi i64 [ 2, %0 ], [ %indvars.iv.next39, %._crit_edge ]
  %7 = phi i32 [ %tot.promoted, %0 ], [ %15, %._crit_edge ]
  %8 = getelementptr inbounds [1000003 x i32], ptr @d, i64 0, i64 %indvars.iv38
  %9 = load i32, ptr %8, align 4, !tbaa !5
  %.not28 = icmp eq i32 %9, 0
  %10 = trunc nuw nsw i64 %indvars.iv38 to i32
  br i1 %.not28, label %11, label %._crit_edge45

11:                                               ; preds = %6
  store i32 %10, ptr %8, align 4, !tbaa !5
  %12 = add nsw i32 %7, 1
  store i32 %12, ptr @tot, align 4, !tbaa !5
  %13 = sext i32 %7 to i64
  %14 = getelementptr inbounds [1000003 x i32], ptr @pr, i64 0, i64 %13
  store i32 %10, ptr %14, align 4, !tbaa !5
  br label %._crit_edge45

._crit_edge45:                                    ; preds = %6, %11
  %15 = phi i32 [ %12, %11 ], [ %7, %6 ]
  %16 = load i32, ptr @pr, align 16, !tbaa !5
  %17 = mul nsw i32 %16, %10
  %18 = icmp slt i32 %17, 1000003
  br i1 %18, label %.lr.ph, label %._crit_edge

19:                                               ; preds = %.lr.ph
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %20 = getelementptr inbounds [1000003 x i32], ptr @pr, i64 0, i64 %indvars.iv.next
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = mul nsw i32 %21, %10
  %23 = icmp slt i32 %22, 1000003
  br i1 %23, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.lr.ph:                                           ; preds = %._crit_edge45, %19
  %indvars.iv = phi i64 [ %indvars.iv.next, %19 ], [ 0, %._crit_edge45 ]
  %24 = phi i32 [ %22, %19 ], [ %17, %._crit_edge45 ]
  %25 = phi i32 [ %21, %19 ], [ %16, %._crit_edge45 ]
  %26 = sext i32 %24 to i64
  %27 = getelementptr inbounds [1000003 x i32], ptr @d, i64 0, i64 %26
  store i32 %25, ptr %27, align 4, !tbaa !5
  %28 = load i32, ptr %8, align 4, !tbaa !5
  %29 = icmp eq i32 %28, %25
  br i1 %29, label %._crit_edge, label %19

._crit_edge:                                      ; preds = %19, %.lr.ph, %._crit_edge45
  %indvars.iv.next39 = add nuw nsw i64 %indvars.iv38, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next39, 1000003
  br i1 %exitcond.not, label %2, label %6, !llvm.loop !11

30:                                               ; preds = %.critedge.3, %2
  %indvars.iv41 = phi i64 [ 1, %2 ], [ %indvars.iv.next42.3, %.critedge.3 ]
  %31 = mul nsw i64 %indvars.iv41, %5
  %32 = add nsw i64 %31, 1
  %33 = getelementptr inbounds [1000003 x i32], ptr @d, i64 0, i64 %32
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = trunc nsw i64 %32 to i32
  %.not = icmp eq i32 %34, %35
  br i1 %.not, label %.critedge, label %36

36:                                               ; preds = %.critedge.2, %.critedge.1, %.critedge, %30
  %indvars.iv41.lcssa = phi i64 [ %indvars.iv41, %30 ], [ %indvars.iv.next42, %.critedge ], [ %indvars.iv.next42.1, %.critedge.1 ], [ %indvars.iv.next42.2, %.critedge.2 ]
  %37 = trunc nuw nsw i64 %indvars.iv41.lcssa to i32
  %38 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %37)
  br label %.critedge30

.critedge:                                        ; preds = %30
  %indvars.iv.next42 = add nuw nsw i64 %indvars.iv41, 1
  %39 = mul nsw i64 %indvars.iv.next42, %5
  %40 = add nuw nsw i64 %39, 1
  %41 = getelementptr inbounds [1000003 x i32], ptr @d, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = trunc nsw i64 %40 to i32
  %.not.1 = icmp eq i32 %42, %43
  br i1 %.not.1, label %.critedge.1, label %36

.critedge.1:                                      ; preds = %.critedge
  %indvars.iv.next42.1 = add nuw nsw i64 %indvars.iv41, 2
  %44 = mul nsw i64 %indvars.iv.next42.1, %5
  %45 = add nsw i64 %44, 1
  %46 = getelementptr inbounds [1000003 x i32], ptr @d, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = trunc nsw i64 %45 to i32
  %.not.2 = icmp eq i32 %47, %48
  br i1 %.not.2, label %.critedge.2, label %36

.critedge.2:                                      ; preds = %.critedge.1
  %indvars.iv.next42.2 = add nuw nsw i64 %indvars.iv41, 3
  %49 = mul nsw i64 %indvars.iv.next42.2, %5
  %50 = add nuw nsw i64 %49, 1
  %51 = getelementptr inbounds [1000003 x i32], ptr @d, i64 0, i64 %50
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = trunc nsw i64 %50 to i32
  %.not.3 = icmp eq i32 %52, %53
  br i1 %.not.3, label %.critedge.3, label %36

.critedge.3:                                      ; preds = %.critedge.2
  %indvars.iv.next42.3 = add nuw nsw i64 %indvars.iv41, 4
  %exitcond44.3 = icmp eq i64 %indvars.iv.next42.3, 1001
  br i1 %exitcond44.3, label %.critedge30, label %30, !llvm.loop !12

.critedge30:                                      ; preds = %.critedge.3, %36
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #3
  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: 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 @__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

attributes #0 = { mustprogress nofree 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 = { 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 = { 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}


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