; LLVM IR from tangjz/acm-icpc :: Summer_Training/2016-07-19 (F - PowMod - tjz)

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

%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }

@tot = external dso_local global i32, align 4
@prime = external dso_local global [1250000 x i32], align 16
@d = external dso_local global [10000001 x i32], align 16
@phi = external dso_local global [10000001 x i32], align 16
@s = external dso_local global [10000001 x i32], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@sz = external dso_local global i32, align 4
@fact = external dso_local global [8 x i32], align 16
@all = external dso_local global i32, align 4
@f = external dso_local global [256 x i32], align 16
@ans = external dso_local global i32, align 4
@g = external dso_local global [256 x %"class.std::map"], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEC2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEED2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z1Gii(i32 noundef, i32 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: mustprogress uwtable
declare dso_local noundef i32 @_Z4calcii(i32 noundef, i32 noundef) #1

; 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
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca %"class.std::map", align 8
  store i32 0, ptr %1, align 4
  store i32 1, ptr getelementptr inbounds ([10000001 x i32], ptr @s, i64 0, i64 1), align 4, !tbaa !5
  store i32 1, ptr getelementptr inbounds ([10000001 x i32], ptr @phi, i64 0, i64 1), align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 2, ptr %2, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %149, %0
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = icmp slt i32 %13, 10000001
  br i1 %14, label %16, label %15

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

16:                                               ; preds = %12
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %18
  %20 = load i32, ptr %19, align 4, !tbaa !5
  %21 = icmp ne i32 %20, 0
  br i1 %21, label %36, label %22

22:                                               ; preds = %16
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = load i32, ptr %2, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %25
  store i32 %23, ptr %26, align 4, !tbaa !5
  %27 = load i32, ptr @tot, align 4, !tbaa !5
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr @tot, align 4, !tbaa !5
  %29 = sext i32 %27 to i64
  %30 = getelementptr inbounds [1250000 x i32], ptr @prime, i64 0, i64 %29
  store i32 %23, ptr %30, align 4, !tbaa !5
  %31 = load i32, ptr %2, align 4, !tbaa !5
  %32 = sub nsw i32 %31, 1
  %33 = load i32, ptr %2, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %34
  store i32 %32, ptr %35, align 4, !tbaa !5
  br label %36

36:                                               ; preds = %22, %16
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 0, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = sdiv i32 10000000, %37
  store i32 %38, ptr %5, align 4, !tbaa !5
  br label %39

39:                                               ; preds = %123, %36
  %40 = load i32, ptr %4, align 4, !tbaa !5
  %41 = load i32, ptr @tot, align 4, !tbaa !5
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %43, label %50

43:                                               ; preds = %39
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1250000 x i32], ptr @prime, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = load i32, ptr %5, align 4, !tbaa !5
  %49 = icmp sle i32 %47, %48
  br label %50

50:                                               ; preds = %43, %39
  %51 = phi i1 [ false, %39 ], [ %49, %43 ]
  br i1 %51, label %53, label %52

52:                                               ; preds = %50
  store i32 5, ptr %3, align 4
  br label %126

53:                                               ; preds = %50
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [1250000 x i32], ptr @prime, i64 0, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = srem i32 %54, %58
  %60 = icmp ne i32 %59, 0
  br i1 %60, label %61, label %92

61:                                               ; preds = %53
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [1250000 x i32], ptr @prime, i64 0, i64 %63
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = load i32, ptr %2, align 4, !tbaa !5
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [1250000 x i32], ptr @prime, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = mul nsw i32 %66, %70
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %72
  store i32 %65, ptr %73, align 4, !tbaa !5
  %74 = load i32, ptr %2, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %75
  %77 = load i32, ptr %76, align 4, !tbaa !5
  %78 = load i32, ptr %4, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [1250000 x i32], ptr @prime, i64 0, i64 %79
  %81 = load i32, ptr %80, align 4, !tbaa !5
  %82 = sub nsw i32 %81, 1
  %83 = mul nsw i32 %77, %82
  %84 = load i32, ptr %2, align 4, !tbaa !5
  %85 = load i32, ptr %4, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [1250000 x i32], ptr @prime, i64 0, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  %89 = mul nsw i32 %84, %88
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %90
  store i32 %83, ptr %91, align 4, !tbaa !5
  br label %122

92:                                               ; preds = %53
  %93 = load i32, ptr %4, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [1250000 x i32], ptr @prime, i64 0, i64 %94
  %96 = load i32, ptr %95, align 4, !tbaa !5
  %97 = load i32, ptr %2, align 4, !tbaa !5
  %98 = load i32, ptr %4, align 4, !tbaa !5
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [1250000 x i32], ptr @prime, i64 0, i64 %99
  %101 = load i32, ptr %100, align 4, !tbaa !5
  %102 = mul nsw i32 %97, %101
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %103
  store i32 %96, ptr %104, align 4, !tbaa !5
  %105 = load i32, ptr %2, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %106
  %108 = load i32, ptr %107, align 4, !tbaa !5
  %109 = load i32, ptr %4, align 4, !tbaa !5
  %110 = sext i32 %109 to i64
  %111 = getelementptr inbounds [1250000 x i32], ptr @prime, i64 0, i64 %110
  %112 = load i32, ptr %111, align 4, !tbaa !5
  %113 = mul nsw i32 %108, %112
  %114 = load i32, ptr %2, align 4, !tbaa !5
  %115 = load i32, ptr %4, align 4, !tbaa !5
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds [1250000 x i32], ptr @prime, i64 0, i64 %116
  %118 = load i32, ptr %117, align 4, !tbaa !5
  %119 = mul nsw i32 %114, %118
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %120
  store i32 %113, ptr %121, align 4, !tbaa !5
  store i32 5, ptr %3, align 4
  br label %126

122:                                              ; preds = %61
  br label %123

123:                                              ; preds = %122
  %124 = load i32, ptr %4, align 4, !tbaa !5
  %125 = add nsw i32 %124, 1
  store i32 %125, ptr %4, align 4, !tbaa !5
  br label %39, !llvm.loop !9

126:                                              ; preds = %92, %52
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %127

127:                                              ; preds = %126
  %128 = load i32, ptr %2, align 4, !tbaa !5
  %129 = sub nsw i32 %128, 1
  %130 = sext i32 %129 to i64
  %131 = getelementptr inbounds [10000001 x i32], ptr @s, i64 0, i64 %130
  %132 = load i32, ptr %131, align 4, !tbaa !5
  %133 = load i32, ptr %2, align 4, !tbaa !5
  %134 = sext i32 %133 to i64
  %135 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %134
  %136 = load i32, ptr %135, align 4, !tbaa !5
  %137 = add nsw i32 %132, %136
  %138 = load i32, ptr %2, align 4, !tbaa !5
  %139 = sext i32 %138 to i64
  %140 = getelementptr inbounds [10000001 x i32], ptr @s, i64 0, i64 %139
  store i32 %137, ptr %140, align 4, !tbaa !5
  %141 = icmp sge i32 %137, 1000000007
  br i1 %141, label %142, label %148

142:                                              ; preds = %127
  %143 = load i32, ptr %2, align 4, !tbaa !5
  %144 = sext i32 %143 to i64
  %145 = getelementptr inbounds [10000001 x i32], ptr @s, i64 0, i64 %144
  %146 = load i32, ptr %145, align 4, !tbaa !5
  %147 = sub nsw i32 %146, 1000000007
  store i32 %147, ptr %145, align 4, !tbaa !5
  br label %148

148:                                              ; preds = %142, %127
  br label %149

149:                                              ; preds = %148
  %150 = load i32, ptr %2, align 4, !tbaa !5
  %151 = add nsw i32 %150, 1
  store i32 %151, ptr %2, align 4, !tbaa !5
  br label %12, !llvm.loop !11

152:                                              ; preds = %15
  br label %153

153:                                              ; preds = %236, %152
  %154 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m, ptr noundef @p)
  %155 = icmp eq i32 %154, 3
  br i1 %155, label %156, label %244

156:                                              ; preds = %153
  store i32 0, ptr @sz, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  %157 = load i32, ptr @n, align 4, !tbaa !5
  store i32 %157, ptr %6, align 4, !tbaa !5
  br label %158

158:                                              ; preds = %163, %156
  %159 = load i32, ptr %6, align 4, !tbaa !5
  %160 = icmp sgt i32 %159, 1
  br i1 %160, label %162, label %161

161:                                              ; preds = %158
  store i32 10, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %178

162:                                              ; preds = %158
  br label %163

163:                                              ; preds = %162
  %164 = load i32, ptr %6, align 4, !tbaa !5
  %165 = sext i32 %164 to i64
  %166 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %165
  %167 = load i32, ptr %166, align 4, !tbaa !5
  %168 = load i32, ptr @sz, align 4, !tbaa !5
  %169 = add nsw i32 %168, 1
  store i32 %169, ptr @sz, align 4, !tbaa !5
  %170 = sext i32 %168 to i64
  %171 = getelementptr inbounds [8 x i32], ptr @fact, i64 0, i64 %170
  store i32 %167, ptr %171, align 4, !tbaa !5
  %172 = load i32, ptr %6, align 4, !tbaa !5
  %173 = sext i32 %172 to i64
  %174 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %173
  %175 = load i32, ptr %174, align 4, !tbaa !5
  %176 = load i32, ptr %6, align 4, !tbaa !5
  %177 = sdiv i32 %176, %175
  store i32 %177, ptr %6, align 4, !tbaa !5
  br label %158, !llvm.loop !12

178:                                              ; preds = %161
  %179 = load i32, ptr @sz, align 4, !tbaa !5
  %180 = shl i32 1, %179
  %181 = sub nsw i32 %180, 1
  store i32 %181, ptr @all, align 4, !tbaa !5
  store i32 1, ptr @f, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  store i32 1, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 0, ptr %8, align 4, !tbaa !5
  br label %182

182:                                              ; preds = %220, %178
  %183 = load i32, ptr %7, align 4, !tbaa !5
  %184 = load i32, ptr @all, align 4, !tbaa !5
  %185 = icmp sle i32 %183, %184
  br i1 %185, label %187, label %186

186:                                              ; preds = %182
  store i32 13, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  br label %223

187:                                              ; preds = %182
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %188 = load i32, ptr %7, align 4, !tbaa !5
  %189 = load i32, ptr %7, align 4, !tbaa !5
  %190 = sub nsw i32 0, %189
  %191 = and i32 %188, %190
  store i32 %191, ptr %9, align 4, !tbaa !5
  %192 = load i32, ptr %9, align 4, !tbaa !5
  %193 = load i32, ptr %7, align 4, !tbaa !5
  %194 = icmp eq i32 %192, %193
  br i1 %194, label %195, label %204

195:                                              ; preds = %187
  %196 = load i32, ptr %8, align 4, !tbaa !5
  %197 = add nsw i32 %196, 1
  store i32 %197, ptr %8, align 4, !tbaa !5
  %198 = sext i32 %196 to i64
  %199 = getelementptr inbounds [8 x i32], ptr @fact, i64 0, i64 %198
  %200 = load i32, ptr %199, align 4, !tbaa !5
  %201 = load i32, ptr %7, align 4, !tbaa !5
  %202 = sext i32 %201 to i64
  %203 = getelementptr inbounds [256 x i32], ptr @f, i64 0, i64 %202
  store i32 %200, ptr %203, align 4, !tbaa !5
  br label %219

204:                                              ; preds = %187
  %205 = load i32, ptr %9, align 4, !tbaa !5
  %206 = sext i32 %205 to i64
  %207 = getelementptr inbounds [256 x i32], ptr @f, i64 0, i64 %206
  %208 = load i32, ptr %207, align 4, !tbaa !5
  %209 = load i32, ptr %7, align 4, !tbaa !5
  %210 = load i32, ptr %9, align 4, !tbaa !5
  %211 = xor i32 %209, %210
  %212 = sext i32 %211 to i64
  %213 = getelementptr inbounds [256 x i32], ptr @f, i64 0, i64 %212
  %214 = load i32, ptr %213, align 4, !tbaa !5
  %215 = mul nsw i32 %208, %214
  %216 = load i32, ptr %7, align 4, !tbaa !5
  %217 = sext i32 %216 to i64
  %218 = getelementptr inbounds [256 x i32], ptr @f, i64 0, i64 %217
  store i32 %215, ptr %218, align 4, !tbaa !5
  br label %219

219:                                              ; preds = %204, %195
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %220

220:                                              ; preds = %219
  %221 = load i32, ptr %7, align 4, !tbaa !5
  %222 = add nsw i32 %221, 1
  store i32 %222, ptr %7, align 4, !tbaa !5
  br label %182, !llvm.loop !13

223:                                              ; preds = %186
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 1, ptr %10, align 4, !tbaa !5
  br label %224

224:                                              ; preds = %233, %223
  %225 = load i32, ptr %10, align 4, !tbaa !5
  %226 = load i32, ptr @all, align 4, !tbaa !5
  %227 = icmp sle i32 %225, %226
  br i1 %227, label %229, label %228

228:                                              ; preds = %224
  store i32 16, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %236

229:                                              ; preds = %224
  call void @llvm.lifetime.start.p0(i64 48, ptr %11) #6
  call void @llvm.memset.p0.i64(ptr align 8 %11, i8 0, i64 48, i1 false)
  call void @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEC2Ev(ptr noundef nonnull align 8 dereferenceable(48) %11) #6
  %230 = load i32, ptr %10, align 4, !tbaa !5
  %231 = sext i32 %230 to i64
  %232 = getelementptr inbounds [256 x %"class.std::map"], ptr @g, i64 0, i64 %231
  call void @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEE4swapERS6_(ptr noundef nonnull align 8 dereferenceable(48) %11, ptr noundef nonnull align 8 dereferenceable(48) %232) #6
  call void @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %11) #6
  call void @llvm.lifetime.end.p0(i64 48, ptr %11) #6
  br label %233

233:                                              ; preds = %229
  %234 = load i32, ptr %10, align 4, !tbaa !5
  %235 = add nsw i32 %234, 1
  store i32 %235, ptr %10, align 4, !tbaa !5
  br label %224, !llvm.loop !14

236:                                              ; preds = %228
  %237 = load i32, ptr @all, align 4, !tbaa !5
  %238 = load i32, ptr @m, align 4, !tbaa !5
  %239 = call noundef i32 @_Z1Gii(i32 noundef %237, i32 noundef %238)
  store i32 %239, ptr @ans, align 4, !tbaa !5
  %240 = load i32, ptr @ans, align 4, !tbaa !5
  %241 = load i32, ptr @p, align 4, !tbaa !5
  %242 = call noundef i32 @_Z4calcii(i32 noundef %240, i32 noundef %241)
  %243 = call i32 (ptr, ...) @printf(ptr noundef @.str.1, i32 noundef %242)
  br label %153, !llvm.loop !15

244:                                              ; preds = %153
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEE4swapERS6_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(48)) #0 align 2

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

attributes #0 = { 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 #1 = { 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 #2 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { 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}
!15 = distinct !{!15, !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"

%"class.std::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }

@tot = external dso_local local_unnamed_addr global i32, align 4
@prime = external dso_local local_unnamed_addr global [1250000 x i32], align 16
@d = external dso_local local_unnamed_addr global [10000001 x i32], align 16
@phi = external dso_local local_unnamed_addr global [10000001 x i32], align 16
@s = external dso_local local_unnamed_addr global [10000001 x i32], align 16
@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@p = external dso_local global i32, align 4
@sz = external dso_local local_unnamed_addr global i32, align 4
@fact = external dso_local local_unnamed_addr global [8 x i32], align 16
@all = external dso_local local_unnamed_addr global i32, align 4
@f = external dso_local local_unnamed_addr global [256 x i32], align 16
@ans = external dso_local local_unnamed_addr global i32, align 4
@g = external dso_local global [256 x %"class.std::map"], align 16
@.str = external hidden unnamed_addr constant [7 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEC2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEED2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #0 align 2

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z1Gii(i32 noundef, i32 noundef) 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: mustprogress uwtable
declare dso_local noundef i32 @_Z4calcii(i32 noundef, i32 noundef) local_unnamed_addr #1

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

.preheader64:                                     ; preds = %.critedge
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @p)
  %3 = icmp eq i32 %2, 3
  br i1 %3, label %.lr.ph81, label %._crit_edge82

4:                                                ; preds = %0, %.critedge
  %5 = phi i32 [ 1, %0 ], [ %spec.select, %.critedge ]
  %indvars.iv88 = phi i64 [ 2, %0 ], [ %indvars.iv.next89, %.critedge ]
  %6 = phi i32 [ %tot.promoted, %0 ], [ %17, %.critedge ]
  %7 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %indvars.iv88
  %8 = load i32, ptr %7, align 4, !tbaa !5
  %.not61 = icmp eq i32 %8, 0
  %9 = trunc nuw nsw i64 %indvars.iv88 to i32
  br i1 %.not61, label %10, label %._crit_edge103

10:                                               ; preds = %4
  store i32 %9, ptr %7, align 4, !tbaa !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 [1250000 x i32], ptr @prime, i64 0, i64 %12
  store i32 %9, ptr %13, align 4, !tbaa !5
  %14 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %indvars.iv88
  %15 = trunc i64 %indvars.iv88 to i32
  %16 = add i32 %15, -1
  store i32 %16, ptr %14, align 4, !tbaa !5
  br label %._crit_edge103

._crit_edge103:                                   ; preds = %4, %10
  %17 = phi i32 [ %11, %10 ], [ %6, %4 ]
  %18 = udiv i32 10000000, %9
  %19 = icmp sgt i32 %17, 0
  br i1 %19, label %.lr.ph, label %.critedge

.lr.ph:                                           ; preds = %._crit_edge103
  %20 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %indvars.iv88
  %wide.trip.count = zext nneg i32 %17 to i64
  br label %21

21:                                               ; preds = %.lr.ph, %30
  %indvars.iv = phi i64 [ 0, %.lr.ph ], [ %indvars.iv.next, %30 ]
  %22 = getelementptr inbounds [1250000 x i32], ptr @prime, i64 0, i64 %indvars.iv
  %23 = load i32, ptr %22, align 4, !tbaa !5
  %.not62 = icmp sgt i32 %23, %18
  br i1 %.not62, label %.critedge, label %24

24:                                               ; preds = %21
  %25 = srem i32 %9, %23
  %.not63 = icmp eq i32 %25, 0
  %26 = sext i32 %23 to i64
  %27 = mul nsw i64 %indvars.iv88, %26
  %28 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %27
  store i32 %23, ptr %28, align 4, !tbaa !5
  %29 = load i32, ptr %20, align 4, !tbaa !5
  br i1 %.not63, label %34, label %30

30:                                               ; preds = %24
  %31 = add nsw i32 %23, -1
  %32 = mul nsw i32 %29, %31
  %33 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %27
  store i32 %32, ptr %33, 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 %21, !llvm.loop !9

34:                                               ; preds = %24
  %35 = mul nsw i32 %29, %23
  %36 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %27
  store i32 %35, ptr %36, align 4, !tbaa !5
  br label %.critedge

.critedge:                                        ; preds = %30, %21, %._crit_edge103, %34
  %37 = getelementptr inbounds [10000001 x i32], ptr @phi, i64 0, i64 %indvars.iv88
  %38 = load i32, ptr %37, align 4, !tbaa !5
  %39 = add nsw i32 %38, %5
  %40 = getelementptr inbounds [10000001 x i32], ptr @s, i64 0, i64 %indvars.iv88
  %41 = icmp sgt i32 %39, 1000000006
  %42 = add nsw i32 %39, -1000000007
  %spec.select = select i1 %41, i32 %42, i32 %39
  store i32 %spec.select, ptr %40, align 4, !tbaa !5
  %indvars.iv.next89 = add nuw nsw i64 %indvars.iv88, 1
  %exitcond91.not = icmp eq i64 %indvars.iv.next89, 10000001
  br i1 %exitcond91.not, label %.preheader64, label %4, !llvm.loop !11

.lr.ph81:                                         ; preds = %.preheader64, %._crit_edge80
  store i32 0, ptr @sz, align 4, !tbaa !5
  %43 = load i32, ptr @n, align 4, !tbaa !5
  %44 = icmp sgt i32 %43, 1
  br i1 %44, label %.lr.ph70, label %.preheader

.lr.ph76.preheader:                               ; preds = %.lr.ph70
  %45 = trunc nuw i64 %indvars.iv.next93 to i32
  store i32 %45, ptr @sz, align 4, !tbaa !5
  %notmask = shl nsw i32 -1, %45
  %46 = xor i32 %notmask, -1
  store i32 %46, ptr @all, align 4, !tbaa !5
  store i32 1, ptr @f, align 16, !tbaa !5
  %umax = call i32 @llvm.umax.i32(i32 %46, i32 1)
  %47 = add nuw i32 %umax, 1
  %wide.trip.count98 = zext i32 %47 to i64
  br label %.lr.ph76

.lr.ph70:                                         ; preds = %.lr.ph81, %.lr.ph70
  %indvars.iv92 = phi i64 [ %indvars.iv.next93, %.lr.ph70 ], [ 0, %.lr.ph81 ]
  %.05469 = phi i32 [ %52, %.lr.ph70 ], [ %43, %.lr.ph81 ]
  %48 = zext nneg i32 %.05469 to i64
  %49 = getelementptr inbounds [10000001 x i32], ptr @d, i64 0, i64 %48
  %50 = load i32, ptr %49, align 4, !tbaa !5
  %indvars.iv.next93 = add nuw nsw i64 %indvars.iv92, 1
  %51 = getelementptr inbounds [8 x i32], ptr @fact, i64 0, i64 %indvars.iv92
  store i32 %50, ptr %51, align 4, !tbaa !5
  %52 = sdiv i32 %.05469, %50
  %53 = icmp sgt i32 %52, 1
  br i1 %53, label %.lr.ph70, label %.lr.ph76.preheader, !llvm.loop !12

.preheader:                                       ; preds = %.lr.ph81
  store i32 0, ptr @all, align 4, !tbaa !5
  store i32 1, ptr @f, align 16, !tbaa !5
  br label %._crit_edge80

.lr.ph76:                                         ; preds = %.lr.ph76.preheader, %71
  %indvars.iv95 = phi i64 [ 1, %.lr.ph76.preheader ], [ %indvars.iv.next96, %71 ]
  %.05274 = phi i32 [ 0, %.lr.ph76.preheader ], [ %.1, %71 ]
  %indvars97 = trunc i64 %indvars.iv95 to i32
  %54 = sub nsw i32 0, %indvars97
  %55 = and i32 %indvars97, %54
  %56 = zext i32 %55 to i64
  %57 = icmp eq i64 %indvars.iv95, %56
  br i1 %57, label %58, label %63

58:                                               ; preds = %.lr.ph76
  %59 = add nsw i32 %.05274, 1
  %60 = sext i32 %.05274 to i64
  %61 = getelementptr inbounds [8 x i32], ptr @fact, i64 0, i64 %60
  %62 = load i32, ptr %61, align 4, !tbaa !5
  br label %71

63:                                               ; preds = %.lr.ph76
  %64 = getelementptr inbounds [256 x i32], ptr @f, i64 0, i64 %56
  %65 = load i32, ptr %64, align 4, !tbaa !5
  %66 = xor i32 %55, %indvars97
  %67 = zext nneg i32 %66 to i64
  %68 = getelementptr inbounds [256 x i32], ptr @f, i64 0, i64 %67
  %69 = load i32, ptr %68, align 4, !tbaa !5
  %70 = mul nsw i32 %69, %65
  br label %71

71:                                               ; preds = %63, %58
  %.sink = phi i32 [ %62, %58 ], [ %70, %63 ]
  %.1 = phi i32 [ %59, %58 ], [ %.05274, %63 ]
  %72 = getelementptr inbounds [256 x i32], ptr @f, i64 0, i64 %indvars.iv95
  store i32 %.sink, ptr %72, align 4
  %indvars.iv.next96 = add nuw nsw i64 %indvars.iv95, 1
  %exitcond99.not = icmp eq i64 %indvars.iv.next96, %wide.trip.count98
  br i1 %exitcond99.not, label %.lr.ph79, label %.lr.ph76, !llvm.loop !13

._crit_edge80:                                    ; preds = %.lr.ph79, %.preheader
  %.lcssa = phi i32 [ 0, %.preheader ], [ %81, %.lr.ph79 ]
  %73 = load i32, ptr @m, align 4, !tbaa !5
  %74 = call noundef i32 @_Z1Gii(i32 noundef %.lcssa, i32 noundef %73)
  store i32 %74, ptr @ans, align 4, !tbaa !5
  %75 = load i32, ptr @p, align 4, !tbaa !5
  %76 = call noundef i32 @_Z4calcii(i32 noundef %74, i32 noundef %75)
  %77 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.1, i32 noundef %76)
  %78 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m, ptr noundef nonnull @p)
  %79 = icmp eq i32 %78, 3
  br i1 %79, label %.lr.ph81, label %._crit_edge82, !llvm.loop !14

.lr.ph79:                                         ; preds = %71, %.lr.ph79
  %indvars.iv100 = phi i64 [ %indvars.iv.next101, %.lr.ph79 ], [ 1, %71 ]
  call void @llvm.lifetime.start.p0(i64 48, ptr nonnull %1) #7
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 8 dereferenceable(48) %1, i8 0, i64 48, i1 false)
  call void @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEC2Ev(ptr noundef nonnull align 8 dereferenceable(48) %1) #7
  %80 = getelementptr inbounds [256 x %"class.std::map"], ptr @g, i64 0, i64 %indvars.iv100
  call void @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEE4swapERS6_(ptr noundef nonnull align 8 dereferenceable(48) %1, ptr noundef nonnull align 8 dereferenceable(48) %80) #7
  call void @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %1) #7
  call void @llvm.lifetime.end.p0(i64 48, ptr nonnull %1) #7
  %indvars.iv.next101 = add nuw nsw i64 %indvars.iv100, 1
  %81 = load i32, ptr @all, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %.not60.not = icmp slt i64 %indvars.iv100, %82
  br i1 %.not60.not, label %.lr.ph79, label %._crit_edge80, !llvm.loop !15

._crit_edge82:                                    ; preds = %._crit_edge80, %.preheader64
  ret i32 0
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #5

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEE4swapERS6_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #0 align 2

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.umax.i32(i32, i32) #6

attributes #0 = { 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 #1 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #6 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #7 = { 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}
!15 = distinct !{!15, !10}


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