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

; 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
@prime = external dso_local global [1000010 x i32], align 16
@f = external dso_local global [1000010 x i32], align 16
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = 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: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z3decRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z4calci(i32 noundef) #2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #3 {
  %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
  store i32 0, ptr %1, align 4
  store i32 1, ptr getelementptr inbounds ([1000010 x i32], ptr @f, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %8

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

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

12:                                               ; preds = %8
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = sext i32 %13 to i64
  %15 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %14
  %16 = load i32, ptr %15, align 4, !tbaa !5
  %17 = icmp ne i32 %16, 0
  br i1 %17, label %29, label %18

18:                                               ; preds = %12
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = load i32, ptr @tot, align 4, !tbaa !5
  %21 = add nsw i32 %20, 1
  store i32 %21, ptr @tot, align 4, !tbaa !5
  %22 = sext i32 %20 to i64
  %23 = getelementptr inbounds [1000010 x i32], ptr @prime, i64 0, i64 %22
  store i32 %19, ptr %23, align 4, !tbaa !5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sub nsw i32 %24, 1
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %27
  store i32 %25, ptr %28, align 4, !tbaa !5
  br label %29

29:                                               ; preds = %18, %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = sdiv i32 1000009, %30
  store i32 %31, ptr %5, align 4, !tbaa !5
  br label %32

32:                                               ; preds = %92, %29
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = load i32, ptr @tot, align 4, !tbaa !5
  %35 = icmp slt i32 %33, %34
  br i1 %35, label %36, label %43

36:                                               ; preds = %32
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [1000010 x i32], ptr @prime, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = load i32, ptr %5, align 4, !tbaa !5
  %42 = icmp sle i32 %40, %41
  br label %43

43:                                               ; preds = %36, %32
  %44 = phi i1 [ false, %32 ], [ %42, %36 ]
  br i1 %44, label %46, label %45

45:                                               ; preds = %43
  store i32 5, ptr %3, align 4
  br label %95

46:                                               ; preds = %43
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = load i32, ptr %4, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = getelementptr inbounds [1000010 x i32], ptr @prime, i64 0, i64 %49
  %51 = load i32, ptr %50, align 4, !tbaa !5
  %52 = srem i32 %47, %51
  %53 = icmp eq i32 %52, 0
  br i1 %53, label %54, label %72

54:                                               ; preds = %46
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = sext i32 %59 to i64
  %61 = getelementptr inbounds [1000010 x i32], ptr @prime, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  %63 = mul nsw i32 %58, %62
  %64 = load i32, ptr %2, align 4, !tbaa !5
  %65 = load i32, ptr %4, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [1000010 x i32], ptr @prime, i64 0, i64 %66
  %68 = load i32, ptr %67, align 4, !tbaa !5
  %69 = mul nsw i32 %64, %68
  %70 = sext i32 %69 to i64
  %71 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %70
  store i32 %63, ptr %71, align 4, !tbaa !5
  store i32 5, ptr %3, align 4
  br label %95

72:                                               ; preds = %46
  %73 = load i32, ptr %2, align 4, !tbaa !5
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [1000010 x i32], ptr @prime, i64 0, i64 %78
  %80 = load i32, ptr %79, align 4, !tbaa !5
  %81 = sub nsw i32 %80, 1
  %82 = mul nsw i32 %76, %81
  %83 = load i32, ptr %2, align 4, !tbaa !5
  %84 = load i32, ptr %4, align 4, !tbaa !5
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [1000010 x i32], ptr @prime, i64 0, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !5
  %88 = mul nsw i32 %83, %87
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %89
  store i32 %82, ptr %90, align 4, !tbaa !5
  br label %91

91:                                               ; preds = %72
  br label %92

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

95:                                               ; preds = %54, %45
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %96

96:                                               ; preds = %95
  %97 = load i32, ptr %2, align 4, !tbaa !5
  %98 = sub nsw i32 %97, 1
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %99
  %101 = load i32, ptr %100, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = load i32, ptr %2, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = load i32, ptr %2, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %106
  %108 = load i32, ptr %107, align 4, !tbaa !5
  %109 = sext i32 %108 to i64
  %110 = mul nsw i64 %104, %109
  %111 = add nsw i64 %102, %110
  %112 = srem i64 %111, 1000000007
  %113 = trunc i64 %112 to i32
  %114 = load i32, ptr %2, align 4, !tbaa !5
  %115 = sext i32 %114 to i64
  %116 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %115
  store i32 %113, ptr %116, align 4, !tbaa !5
  br label %117

117:                                              ; preds = %96
  %118 = load i32, ptr %2, align 4, !tbaa !5
  %119 = add nsw i32 %118, 1
  store i32 %119, ptr %2, align 4, !tbaa !5
  br label %8, !llvm.loop !11

120:                                              ; preds = %11
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %121 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %6, ptr noundef %7)
  %122 = load i32, ptr %7, align 4, !tbaa !5
  %123 = call noundef i32 @_Z4calci(i32 noundef %122)
  store i32 %123, ptr @ans, align 4, !tbaa !5
  %124 = load i32, ptr %6, align 4, !tbaa !5
  %125 = sub nsw i32 %124, 1
  %126 = call noundef i32 @_Z4calci(i32 noundef %125)
  call void @_Z3decRii(ptr noundef nonnull align 4 dereferenceable(4) @ans, i32 noundef %126)
  %127 = load i32, ptr @ans, align 4, !tbaa !5
  %128 = sext i32 %127 to i64
  %129 = mul nsw i64 %128, 500000004
  %130 = srem i64 %129, 1000000007
  %131 = trunc i64 %130 to i32
  store i32 %131, ptr @ans, align 4, !tbaa !5
  %132 = load i32, ptr @ans, align 4, !tbaa !5
  %133 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %132)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  %134 = load i32, ptr %1, align 4
  ret i32 %134
}

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

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

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


; 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
@prime = external dso_local local_unnamed_addr global [1000010 x i32], align 16
@f = external dso_local local_unnamed_addr global [1000010 x i32], align 16
@ans = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local void @_Z3decRii(ptr noundef nonnull align 4 dereferenceable(4), i32 noundef) local_unnamed_addr #1

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z4calci(i32 noundef) local_unnamed_addr #2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  store i32 1, ptr getelementptr inbounds (i8, ptr @f, i64 4), align 4, !tbaa !5
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !5
  br label %16

3:                                                ; preds = %.critedge
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  %4 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %1, ptr noundef nonnull %2)
  %5 = load i32, ptr %2, align 4, !tbaa !5
  %6 = call noundef i32 @_Z4calci(i32 noundef %5)
  store i32 %6, ptr @ans, align 4, !tbaa !5
  %7 = load i32, ptr %1, align 4, !tbaa !5
  %8 = add nsw i32 %7, -1
  %9 = call noundef i32 @_Z4calci(i32 noundef %8)
  call void @_Z3decRii(ptr noundef nonnull align 4 dereferenceable(4) @ans, i32 noundef %9)
  %10 = load i32, ptr @ans, align 4, !tbaa !5
  %11 = sext i32 %10 to i64
  %12 = mul nsw i64 %11, 500000004
  %13 = srem i64 %12, 1000000007
  %14 = trunc nsw i64 %13 to i32
  store i32 %14, ptr @ans, align 4, !tbaa !5
  %15 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %14)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #5
  ret i32 0

16:                                               ; preds = %0, %.critedge
  %indvars.iv34 = phi i64 [ 2, %0 ], [ %indvars.iv.next35, %.critedge ]
  %17 = phi i32 [ %tot.promoted, %0 ], [ %28, %.critedge ]
  %18 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %indvars.iv34
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %.not = icmp eq i32 %19, 0
  br i1 %.not, label %20, label %._crit_edge

._crit_edge:                                      ; preds = %16
  %.pre = trunc nuw nsw i64 %indvars.iv34 to i32
  br label %27

20:                                               ; preds = %16
  %21 = add nsw i32 %17, 1
  store i32 %21, ptr @tot, align 4, !tbaa !5
  %22 = sext i32 %17 to i64
  %23 = getelementptr inbounds [1000010 x i32], ptr @prime, i64 0, i64 %22
  %24 = trunc nuw nsw i64 %indvars.iv34 to i32
  store i32 %24, ptr %23, align 4, !tbaa !5
  %25 = trunc i64 %indvars.iv34 to i32
  %26 = add i32 %25, -1
  store i32 %26, ptr %18, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %._crit_edge, %20
  %.pre-phi = phi i32 [ %.pre, %._crit_edge ], [ %24, %20 ]
  %28 = phi i32 [ %17, %._crit_edge ], [ %21, %20 ]
  %29 = udiv i32 1000009, %.pre-phi
  %30 = icmp sgt i32 %28, 0
  br i1 %30, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %27
  %wide.trip.count = zext nneg i32 %28 to i64
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %42
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %42 ]
  %31 = getelementptr inbounds [1000010 x i32], ptr @prime, i64 0, i64 %indvars.iv
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %.not28 = icmp sgt i32 %32, %29
  br i1 %.not28, label %.critedge, label %33

33:                                               ; preds = %.lr.ph
  %34 = srem i32 %.pre-phi, %32
  %35 = icmp eq i32 %34, 0
  %36 = load i32, ptr %18, align 4, !tbaa !5
  br i1 %35, label %37, label %42

37:                                               ; preds = %33
  %38 = mul nsw i32 %36, %32
  %39 = sext i32 %32 to i64
  %40 = mul nsw i64 %indvars.iv34, %39
  %41 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %40
  store i32 %38, ptr %41, align 4, !tbaa !5
  br label %.critedge

42:                                               ; preds = %33
  %43 = add nsw i32 %32, -1
  %44 = mul nsw i32 %36, %43
  %45 = sext i32 %32 to i64
  %46 = mul nsw i64 %indvars.iv34, %45
  %47 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %46
  store i32 %44, ptr %47, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond.not, label %.critedge, label %.lr.ph, !llvm.loop !9

.critedge:                                        ; preds = %42, %.lr.ph, %27, %37
  %48 = add nsw i64 %indvars.iv34, -1
  %49 = getelementptr inbounds [1000010 x i32], ptr @f, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = load i32, ptr %18, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = mul nsw i64 %indvars.iv34, %53
  %55 = add nsw i64 %54, %51
  %56 = srem i64 %55, 1000000007
  %57 = trunc nsw i64 %56 to i32
  store i32 %57, ptr %18, align 4, !tbaa !5
  %indvars.iv.next35 = add nuw nsw i64 %indvars.iv34, 1
  %exitcond37.not = icmp eq i64 %indvars.iv.next35, 1000010
  br i1 %exitcond37.not, label %3, label %16, !llvm.loop !11
}

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


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