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

; 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 [1001 x i32], align 16
@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@top = external dso_local global i32, align 4
@stack = external dso_local global [8 x i32], align 16
@ans = external dso_local global i32, align 4
@now = external dso_local global i64, align 8
@INF = external dso_local global i64, align 8
@vis = external dso_local global [1001 x i8], align 16
@.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 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 ptr, align 8
  %10 = alloca i64, align 8
  %11 = alloca i32, align 4
  %12 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @k)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %14

14:                                               ; preds = %64, %0
  %15 = load i32, ptr %2, align 4, !tbaa !5
  %16 = icmp slt i32 %15, 1001
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %14
  %19 = load i32, ptr %2, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [1001 x i8], ptr @vis, i64 0, i64 %20
  %22 = load i8, ptr %21, align 1, !tbaa !9, !range !11, !noundef !12
  %23 = trunc i8 %22 to i1
  br i1 %23, label %30, label %24

24:                                               ; preds = %18
  %25 = load i32, ptr %2, align 4, !tbaa !5
  %26 = load i32, ptr @tot, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr @tot, align 4, !tbaa !5
  %28 = sext i32 %26 to i64
  %29 = getelementptr inbounds [1001 x i32], ptr @prime, i64 0, i64 %28
  store i32 %25, ptr %29, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %24, %18
  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
  br label %31

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

35:                                               ; preds = %31
  %36 = load i32, ptr %2, align 4, !tbaa !5
  %37 = load i32, ptr %4, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [1001 x i32], ptr @prime, i64 0, i64 %38
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = mul nsw i32 %36, %40
  store i32 %41, ptr %5, align 4, !tbaa !5
  %42 = icmp slt i32 %41, 1001
  br label %43

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

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

46:                                               ; preds = %43
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [1001 x i8], ptr @vis, i64 0, i64 %48
  store i8 1, ptr %49, align 1, !tbaa !9
  %50 = load i32, ptr %2, align 4, !tbaa !5
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [1001 x i32], ptr @prime, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = srem i32 %50, %54
  %56 = icmp eq i32 %55, 0
  br i1 %56, label %57, label %58

57:                                               ; preds = %46
  store i32 5, ptr %3, align 4
  br label %62

58:                                               ; preds = %46
  br label %59

59:                                               ; preds = %58
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = add nsw i32 %60, 1
  store i32 %61, ptr %4, align 4, !tbaa !5
  br label %31, !llvm.loop !13

62:                                               ; preds = %57, %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 %63

63:                                               ; preds = %62
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %2, align 4, !tbaa !5
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %2, align 4, !tbaa !5
  br label %14, !llvm.loop !15

67:                                               ; preds = %17
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 2, ptr %6, align 4, !tbaa !5
  br label %68

68:                                               ; preds = %206, %67
  %69 = load i32, ptr %6, align 4, !tbaa !5
  %70 = load i32, ptr @n, align 4, !tbaa !5
  %71 = icmp sle i32 %69, %70
  br i1 %71, label %73, label %72

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

73:                                               ; preds = %68
  %74 = load i32, ptr %6, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = load i32, ptr @k, align 4, !tbaa !5
  %77 = sext i32 %76 to i64
  %78 = mul nsw i64 %75, %77
  store i64 %78, ptr @INF, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %79 = load i32, ptr %6, align 4, !tbaa !5
  store i32 %79, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %80

80:                                               ; preds = %134, %73
  %81 = load i32, ptr %8, align 4, !tbaa !5
  %82 = load i32, ptr @tot, align 4, !tbaa !5
  %83 = icmp slt i32 %81, %82
  br i1 %83, label %84, label %96

84:                                               ; preds = %80
  %85 = load i32, ptr %8, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [1001 x i32], ptr @prime, i64 0, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  %89 = load i32, ptr %8, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [1001 x i32], ptr @prime, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !5
  %93 = mul nsw i32 %88, %92
  %94 = load i32, ptr %7, align 4, !tbaa !5
  %95 = icmp sle i32 %93, %94
  br label %96

96:                                               ; preds = %84, %80
  %97 = phi i1 [ false, %80 ], [ %95, %84 ]
  br i1 %97, label %99, label %98

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

99:                                               ; preds = %96
  %100 = load i32, ptr %7, align 4, !tbaa !5
  %101 = load i32, ptr %8, align 4, !tbaa !5
  %102 = sext i32 %101 to i64
  %103 = getelementptr inbounds [1001 x i32], ptr @prime, i64 0, i64 %102
  %104 = load i32, ptr %103, align 4, !tbaa !5
  %105 = srem i32 %100, %104
  %106 = icmp eq i32 %105, 0
  br i1 %106, label %107, label %133

107:                                              ; preds = %99
  br label %108

108:                                              ; preds = %117, %107
  %109 = load i32, ptr %7, align 4, !tbaa !5
  %110 = load i32, ptr %8, align 4, !tbaa !5
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds [1001 x i32], ptr @prime, i64 0, i64 %111
  %113 = load i32, ptr %112, align 4, !tbaa !5
  %114 = srem i32 %109, %113
  %115 = icmp eq i32 %114, 0
  br i1 %115, label %116, label %124

116:                                              ; preds = %108
  br label %117

117:                                              ; preds = %116
  %118 = load i32, ptr %8, align 4, !tbaa !5
  %119 = sext i32 %118 to i64
  %120 = getelementptr inbounds [1001 x i32], ptr @prime, i64 0, i64 %119
  %121 = load i32, ptr %120, align 4, !tbaa !5
  %122 = load i32, ptr %7, align 4, !tbaa !5
  %123 = sdiv i32 %122, %121
  store i32 %123, ptr %7, align 4, !tbaa !5
  br label %108, !llvm.loop !18

124:                                              ; preds = %108
  %125 = load i32, ptr %8, align 4, !tbaa !5
  %126 = sext i32 %125 to i64
  %127 = getelementptr inbounds [1001 x i32], ptr @prime, i64 0, i64 %126
  %128 = load i32, ptr %127, align 4, !tbaa !5
  %129 = load i32, ptr @top, align 4, !tbaa !5
  %130 = add nsw i32 %129, 1
  store i32 %130, ptr @top, align 4, !tbaa !5
  %131 = sext i32 %129 to i64
  %132 = getelementptr inbounds [8 x i32], ptr @stack, i64 0, i64 %131
  store i32 %128, ptr %132, align 4, !tbaa !5
  br label %133

133:                                              ; preds = %124, %99
  br label %134

134:                                              ; preds = %133
  %135 = load i32, ptr %8, align 4, !tbaa !5
  %136 = add nsw i32 %135, 1
  store i32 %136, ptr %8, align 4, !tbaa !5
  br label %80, !llvm.loop !19

137:                                              ; preds = %98
  %138 = load i32, ptr %7, align 4, !tbaa !5
  %139 = icmp sgt i32 %138, 1
  br i1 %139, label %140, label %146

140:                                              ; preds = %137
  %141 = load i32, ptr %7, align 4, !tbaa !5
  %142 = load i32, ptr @top, align 4, !tbaa !5
  %143 = add nsw i32 %142, 1
  store i32 %143, ptr @top, align 4, !tbaa !5
  %144 = sext i32 %142 to i64
  %145 = getelementptr inbounds [8 x i32], ptr @stack, i64 0, i64 %144
  store i32 %141, ptr %145, align 4, !tbaa !5
  br label %146

146:                                              ; preds = %140, %137
  %147 = load i32, ptr %6, align 4, !tbaa !5
  %148 = load i32, ptr @k, align 4, !tbaa !5
  %149 = icmp sle i32 %147, %148
  br i1 %149, label %150, label %175

150:                                              ; preds = %146
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #5
  store ptr @top, ptr %9, align 8, !tbaa !20
  br label %151

151:                                              ; preds = %171, %150
  %152 = load i32, ptr @top, align 4, !tbaa !5
  %153 = icmp ne i32 %152, 0
  br i1 %153, label %155, label %154

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

155:                                              ; preds = %151
  %156 = load i64, ptr @now, align 8, !tbaa !16
  %157 = load i32, ptr @top, align 4, !tbaa !5
  %158 = sub nsw i32 %157, 1
  %159 = sext i32 %158 to i64
  %160 = getelementptr inbounds [8 x i32], ptr @stack, i64 0, i64 %159
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #5
  %161 = load i32, ptr %6, align 4, !tbaa !5
  %162 = sext i32 %161 to i64
  %163 = load i32, ptr @top, align 4, !tbaa !5
  %164 = sub nsw i32 %163, 1
  %165 = sext i32 %164 to i64
  %166 = getelementptr inbounds [8 x i32], ptr @stack, i64 0, i64 %165
  %167 = call noundef i64 @_Z4calcxRKi(i64 noundef %162, ptr noundef nonnull align 4 dereferenceable(4) %166)
  %168 = load i32, ptr @k, align 4, !tbaa !5
  %169 = sext i32 %168 to i64
  %170 = mul nsw i64 %167, %169
  store i64 %170, ptr %10, align 8, !tbaa !16
  call void @_Z5checkxRKiRKx(i64 noundef %156, ptr noundef nonnull align 4 dereferenceable(4) %160, ptr noundef nonnull align 8 dereferenceable(8) %10)
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #5
  br label %171

171:                                              ; preds = %155
  %172 = load i32, ptr @top, align 4, !tbaa !5
  %173 = add nsw i32 %172, -1
  store i32 %173, ptr @top, align 4, !tbaa !5
  br label %151, !llvm.loop !22

174:                                              ; preds = %154
  br label %199

175:                                              ; preds = %146
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  store i32 0, ptr %11, align 4, !tbaa !5
  br label %176

176:                                              ; preds = %195, %175
  %177 = load i32, ptr %11, align 4, !tbaa !5
  %178 = load i32, ptr @top, align 4, !tbaa !5
  %179 = icmp slt i32 %177, %178
  br i1 %179, label %181, label %180

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

181:                                              ; preds = %176
  %182 = load i64, ptr @now, align 8, !tbaa !16
  %183 = load i32, ptr %11, align 4, !tbaa !5
  %184 = sext i32 %183 to i64
  %185 = getelementptr inbounds [8 x i32], ptr @stack, i64 0, i64 %184
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #5
  %186 = load i32, ptr %6, align 4, !tbaa !5
  %187 = sext i32 %186 to i64
  %188 = load i32, ptr %11, align 4, !tbaa !5
  %189 = sext i32 %188 to i64
  %190 = getelementptr inbounds [8 x i32], ptr @stack, i64 0, i64 %189
  %191 = call noundef i64 @_Z4calcxRKi(i64 noundef %187, ptr noundef nonnull align 4 dereferenceable(4) %190)
  %192 = load i32, ptr @k, align 4, !tbaa !5
  %193 = sext i32 %192 to i64
  %194 = mul nsw i64 %191, %193
  store i64 %194, ptr %12, align 8, !tbaa !16
  call void @_Z5checkxRKiRKx(i64 noundef %182, ptr noundef nonnull align 4 dereferenceable(4) %185, ptr noundef nonnull align 8 dereferenceable(8) %12)
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #5
  br label %195

195:                                              ; preds = %181
  %196 = load i32, ptr %11, align 4, !tbaa !5
  %197 = add nsw i32 %196, 1
  store i32 %197, ptr %11, align 4, !tbaa !5
  br label %176, !llvm.loop !23

198:                                              ; preds = %180
  store i32 0, ptr @top, align 4, !tbaa !5
  br label %199

199:                                              ; preds = %198, %174
  %200 = load i32, ptr @ans, align 4, !tbaa !5
  %201 = sext i32 %200 to i64
  %202 = load i64, ptr @now, align 8, !tbaa !16
  %203 = add nsw i64 %201, %202
  %204 = srem i64 %203, 1000000007
  %205 = trunc i64 %204 to i32
  store i32 %205, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %206

206:                                              ; preds = %199
  %207 = load i32, ptr %6, align 4, !tbaa !5
  %208 = add nsw i32 %207, 1
  store i32 %208, ptr %6, align 4, !tbaa !5
  br label %68, !llvm.loop !24

209:                                              ; preds = %72
  %210 = load i32, ptr @ans, align 4, !tbaa !5
  %211 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %210)
  ret i32 0
}

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z5checkxRKiRKx(i64 noundef, ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 8 dereferenceable(8)) #3

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

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

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 = { "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 = { inlinehint 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = !{!17, !17, i64 0}
!17 = !{!"long long", !7, i64 0}
!18 = distinct !{!18, !14}
!19 = distinct !{!19, !14}
!20 = !{!21, !21, i64 0}
!21 = !{!"any pointer", !7, i64 0}
!22 = distinct !{!22, !14}
!23 = distinct !{!23, !14}
!24 = distinct !{!24, !14}


; 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 [1001 x i32], align 16
@n = external dso_local global i32, align 4
@k = external dso_local global i32, align 4
@top = external dso_local local_unnamed_addr global i32, align 4
@stack = external dso_local global [8 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@now = external dso_local local_unnamed_addr global i64, align 8
@INF = external dso_local local_unnamed_addr global i64, align 8
@vis = external dso_local local_unnamed_addr global [1001 x i8], align 16
@.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 norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i64, align 8
  %2 = alloca i64, align 8
  %3 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @k)
  %tot.promoted = load i32, ptr @tot, align 4, !tbaa !5
  br label %5

.preheader49:                                     ; preds = %.critedge
  %4 = load i32, ptr @n, align 4, !tbaa !5
  %.not68 = icmp slt i32 %4, 2
  br i1 %.not68, label %.preheader49.._crit_edge71_crit_edge, label %.lr.ph70.preheader

.preheader49.._crit_edge71_crit_edge:             ; preds = %.preheader49
  %.pre = load i32, ptr @ans, align 4, !tbaa !5
  br label %._crit_edge71

.lr.ph70.preheader:                               ; preds = %.preheader49
  %top.promoted.pre = load i32, ptr @top, align 4, !tbaa !5
  br label %.lr.ph70

5:                                                ; preds = %0, %.critedge
  %indvars.iv73 = phi i64 [ 2, %0 ], [ %indvars.iv.next74, %.critedge ]
  %6 = phi i32 [ %tot.promoted, %0 ], [ %16, %.critedge ]
  %7 = getelementptr inbounds [1001 x i8], ptr @vis, i64 0, i64 %indvars.iv73
  %8 = load i8, ptr %7, align 1, !tbaa !9, !range !11, !noundef !12
  %9 = trunc nuw i8 %8 to i1
  br i1 %9, label %15, label %10

10:                                               ; preds = %5
  %11 = add nsw i32 %6, 1
  store i32 %11, ptr @tot, align 4, !tbaa !5
  %12 = sext i32 %6 to i64
  %13 = getelementptr inbounds [1001 x i32], ptr @prime, i64 0, i64 %12
  %14 = trunc nuw nsw i64 %indvars.iv73 to i32
  store i32 %14, ptr %13, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %10, %5
  %16 = phi i32 [ %11, %10 ], [ %6, %5 ]
  %17 = icmp sgt i32 %16, 0
  br i1 %17, label %.lr.ph.preheader, label %.critedge

.lr.ph.preheader:                                 ; preds = %15
  %18 = zext nneg i32 %16 to i64
  %19 = trunc nuw nsw i64 %indvars.iv73 to i32
  br label %.lr.ph

.lr.ph:                                           ; preds = %.lr.ph.preheader, %24
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %24 ]
  %20 = getelementptr inbounds [1001 x i32], ptr @prime, i64 0, i64 %indvars.iv
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = mul nsw i32 %21, %19
  %23 = icmp slt i32 %22, 1001
  br i1 %23, label %24, label %.critedge

24:                                               ; preds = %.lr.ph
  %25 = sext i32 %22 to i64
  %26 = getelementptr inbounds [1001 x i8], ptr @vis, i64 0, i64 %25
  store i8 1, ptr %26, align 1, !tbaa !9
  %27 = srem i32 %19, %21
  %28 = icmp ne i32 %27, 0
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %29 = icmp ult i64 %indvars.iv.next, %18
  %or.cond = select i1 %28, i1 %29, i1 false
  br i1 %or.cond, label %.lr.ph, label %.critedge, !llvm.loop !13

.critedge:                                        ; preds = %.lr.ph, %24, %15
  %indvars.iv.next74 = add nuw nsw i64 %indvars.iv73, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next74, 1001
  br i1 %exitcond.not, label %.preheader49, label %5, !llvm.loop !15

._crit_edge71:                                    ; preds = %.loopexit, %.preheader49.._crit_edge71_crit_edge
  %30 = phi i32 [ %.pre, %.preheader49.._crit_edge71_crit_edge ], [ %92, %.loopexit ]
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %30)
  ret i32 0

.lr.ph70:                                         ; preds = %.lr.ph70.preheader, %.loopexit
  %32 = phi i32 [ %top.promoted.pre, %.lr.ph70.preheader ], [ %86, %.loopexit ]
  %.pr92 = phi i32 [ %top.promoted.pre, %.lr.ph70.preheader ], [ 0, %.loopexit ]
  %indvars.iv83 = phi i64 [ 2, %.lr.ph70.preheader ], [ %indvars.iv.next84, %.loopexit ]
  %33 = load i32, ptr @k, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = mul nsw i64 %indvars.iv83, %34
  store i64 %35, ptr @INF, align 8, !tbaa !16
  %36 = load i32, ptr @tot, align 4, !tbaa !5
  %37 = icmp sgt i32 %36, 0
  %38 = trunc nuw nsw i64 %indvars.iv83 to i32
  br i1 %37, label %.lr.ph59.preheader, label %.critedge2

.lr.ph59.preheader:                               ; preds = %.lr.ph70
  %wide.trip.count = zext nneg i32 %36 to i64
  br label %.lr.ph59

.lr.ph59:                                         ; preds = %.lr.ph59.preheader, %56
  %39 = phi i32 [ %32, %.lr.ph59.preheader ], [ %57, %56 ]
  %.pr91 = phi i32 [ %.pr92, %.lr.ph59.preheader ], [ %.pr89, %56 ]
  %indvars.iv76 = phi i64 [ 0, %.lr.ph59.preheader ], [ %indvars.iv.next77, %56 ]
  %.04056 = phi i32 [ %38, %.lr.ph59.preheader ], [ %.2, %56 ]
  %40 = phi i32 [ %.pr92, %.lr.ph59.preheader ], [ %58, %56 ]
  %41 = getelementptr inbounds [1001 x i32], ptr @prime, i64 0, i64 %indvars.iv76
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = mul nsw i32 %42, %42
  %.not45 = icmp sgt i32 %43, %.04056
  br i1 %.not45, label %.critedge2, label %47

.critedge2:                                       ; preds = %.lr.ph59, %56, %.lr.ph70
  %44 = phi i32 [ %32, %.lr.ph70 ], [ %57, %56 ], [ %39, %.lr.ph59 ]
  %.pr88 = phi i32 [ %.pr92, %.lr.ph70 ], [ %.pr89, %56 ], [ %.pr91, %.lr.ph59 ]
  %45 = phi i32 [ %.pr92, %.lr.ph70 ], [ %58, %56 ], [ %40, %.lr.ph59 ]
  %.040.lcssa = phi i32 [ %38, %.lr.ph70 ], [ %.2, %56 ], [ %.04056, %.lr.ph59 ]
  %46 = icmp sgt i32 %.040.lcssa, 1
  br i1 %46, label %59, label %63

47:                                               ; preds = %.lr.ph59
  %48 = srem i32 %.04056, %42
  %49 = icmp eq i32 %48, 0
  br i1 %49, label %.lr.ph55, label %56

.lr.ph55:                                         ; preds = %47, %.lr.ph55
  %.154 = phi i32 [ %50, %.lr.ph55 ], [ %.04056, %47 ]
  %50 = sdiv i32 %.154, %42
  %51 = srem i32 %50, %42
  %52 = icmp eq i32 %51, 0
  br i1 %52, label %.lr.ph55, label %._crit_edge, !llvm.loop !18

._crit_edge:                                      ; preds = %.lr.ph55
  %53 = add nsw i32 %40, 1
  store i32 %53, ptr @top, align 4, !tbaa !5
  %54 = sext i32 %40 to i64
  %55 = getelementptr inbounds [8 x i32], ptr @stack, i64 0, i64 %54
  store i32 %42, ptr %55, align 4, !tbaa !5
  br label %56

56:                                               ; preds = %47, %._crit_edge
  %57 = phi i32 [ %53, %._crit_edge ], [ %39, %47 ]
  %.pr89 = phi i32 [ %53, %._crit_edge ], [ %.pr91, %47 ]
  %58 = phi i32 [ %53, %._crit_edge ], [ %40, %47 ]
  %.2 = phi i32 [ %50, %._crit_edge ], [ %.04056, %47 ]
  %indvars.iv.next77 = add nuw nsw i64 %indvars.iv76, 1
  %exitcond79.not = icmp eq i64 %indvars.iv.next77, %wide.trip.count
  br i1 %exitcond79.not, label %.critedge2, label %.lr.ph59, !llvm.loop !19

59:                                               ; preds = %.critedge2
  %60 = add nsw i32 %45, 1
  store i32 %60, ptr @top, align 4, !tbaa !5
  %61 = sext i32 %45 to i64
  %62 = getelementptr inbounds [8 x i32], ptr @stack, i64 0, i64 %61
  store i32 %.040.lcssa, ptr %62, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %59, %.critedge2
  %64 = phi i32 [ %60, %59 ], [ %44, %.critedge2 ]
  %.pr = phi i32 [ %60, %59 ], [ %.pr88, %.critedge2 ]
  %.not46 = icmp sgt i64 %indvars.iv83, %34
  br i1 %.not46, label %.preheader48, label %thread-pre-split

.preheader48:                                     ; preds = %63
  %65 = icmp sgt i32 %64, 0
  br i1 %65, label %.lr.ph66, label %._crit_edge67

thread-pre-split:                                 ; preds = %63
  %.not4763 = icmp eq i32 %.pr, 0
  br i1 %.not4763, label %.loopexit, label %.lr.ph64

.lr.ph64:                                         ; preds = %thread-pre-split, %.lr.ph64
  %66 = phi i32 [ %76, %.lr.ph64 ], [ %.pr, %thread-pre-split ]
  %67 = load i64, ptr @now, align 8, !tbaa !16
  %68 = add nsw i32 %66, -1
  %69 = sext i32 %68 to i64
  %70 = getelementptr inbounds [8 x i32], ptr @stack, i64 0, i64 %69
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  %71 = call noundef i64 @_Z4calcxRKi(i64 noundef %indvars.iv83, ptr noundef nonnull align 4 dereferenceable(4) %70)
  %72 = load i32, ptr @k, align 4, !tbaa !5
  %73 = sext i32 %72 to i64
  %74 = mul nsw i64 %71, %73
  store i64 %74, ptr %1, align 8, !tbaa !16
  call void @_Z5checkxRKiRKx(i64 noundef %67, ptr noundef nonnull align 4 dereferenceable(4) %70, ptr noundef nonnull align 8 dereferenceable(8) %1)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  %75 = load i32, ptr @top, align 4, !tbaa !5
  %76 = add nsw i32 %75, -1
  store i32 %76, ptr @top, align 4, !tbaa !5
  %.not47 = icmp eq i32 %76, 0
  br i1 %.not47, label %.loopexit, label %.lr.ph64, !llvm.loop !20

._crit_edge67:                                    ; preds = %.lr.ph66, %.preheader48
  store i32 0, ptr @top, align 4, !tbaa !5
  br label %.loopexit

.lr.ph66:                                         ; preds = %.preheader48, %.lr.ph66
  %indvars.iv80 = phi i64 [ %indvars.iv.next81, %.lr.ph66 ], [ 0, %.preheader48 ]
  %77 = load i64, ptr @now, align 8, !tbaa !16
  %78 = getelementptr inbounds [8 x i32], ptr @stack, i64 0, i64 %indvars.iv80
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #5
  %79 = call noundef i64 @_Z4calcxRKi(i64 noundef %indvars.iv83, ptr noundef nonnull align 4 dereferenceable(4) %78)
  %80 = load i32, ptr @k, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = mul nsw i64 %79, %81
  store i64 %82, ptr %2, align 8, !tbaa !16
  call void @_Z5checkxRKiRKx(i64 noundef %77, ptr noundef nonnull align 4 dereferenceable(4) %78, ptr noundef nonnull align 8 dereferenceable(8) %2)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #5
  %indvars.iv.next81 = add nuw nsw i64 %indvars.iv80, 1
  %83 = load i32, ptr @top, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = icmp slt i64 %indvars.iv.next81, %84
  br i1 %85, label %.lr.ph66, label %._crit_edge67, !llvm.loop !21

.loopexit:                                        ; preds = %.lr.ph64, %thread-pre-split, %._crit_edge67
  %86 = phi i32 [ %64, %thread-pre-split ], [ 0, %._crit_edge67 ], [ 0, %.lr.ph64 ]
  %87 = load i32, ptr @ans, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = load i64, ptr @now, align 8, !tbaa !16
  %90 = add nsw i64 %89, %88
  %91 = srem i64 %90, 1000000007
  %92 = trunc nsw i64 %91 to i32
  store i32 %92, ptr @ans, align 4, !tbaa !5
  %indvars.iv.next84 = add nuw nsw i64 %indvars.iv83, 1
  %93 = load i32, ptr @n, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %.not.not = icmp slt i64 %indvars.iv83, %94
  br i1 %.not.not, label %.lr.ph70, label %._crit_edge71, !llvm.loop !22
}

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_Z5checkxRKiRKx(i64 noundef, ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #3

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

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

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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { inlinehint 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 #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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"bool", !7, i64 0}
!11 = !{i8 0, i8 2}
!12 = !{}
!13 = distinct !{!13, !14}
!14 = !{!"llvm.loop.mustprogress"}
!15 = distinct !{!15, !14}
!16 = !{!17, !17, i64 0}
!17 = !{!"long long", !7, i64 0}
!18 = distinct !{!18, !14}
!19 = distinct !{!19, !14}
!20 = distinct !{!20, !14}
!21 = distinct !{!21, !14}
!22 = distinct !{!22, !14}


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