; LLVM IR from tangjz/acm-icpc :: codeforces/complete (1340C)

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@c0 = external dso_local global i32, align 4
@c1 = external dso_local global i32, align 4
@a = external dso_local global [10001 x i32], align 16
@dis = external dso_local global [10001 x i32], align 16
@que0 = external dso_local global [10001 x i32], align 16
@que1 = external dso_local global [2004003 x i32], align 16
@vis = external dso_local global [10000001 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %17

17:                                               ; preds = %263, %0
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = add nsw i32 %18, -1
  store i32 %19, ptr %2, align 4, !tbaa !5
  %20 = icmp ne i32 %18, 0
  br i1 %20, label %21, label %266

21:                                               ; preds = %17
  %22 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %23

23:                                               ; preds = %33, %21
  %24 = load i32, ptr %3, align 4, !tbaa !5
  %25 = load i32, ptr @m, align 4, !tbaa !5
  %26 = icmp slt i32 %24, %25
  br i1 %26, label %28, label %27

27:                                               ; preds = %23
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  br label %36

28:                                               ; preds = %23
  %29 = load i32, ptr %3, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds i32, ptr @a, i64 %30
  %32 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %31)
  br label %33

33:                                               ; preds = %28
  %34 = load i32, ptr %3, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %3, align 4, !tbaa !5
  br label %23, !llvm.loop !9

36:                                               ; preds = %27
  %37 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @c0, ptr noundef @c1)
  %38 = load i32, ptr @m, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds i32, ptr @a, i64 %39
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @a, ptr noundef %40)
  %41 = load i32, ptr @m, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds i32, ptr @a, i64 %42
  %44 = call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef @a, ptr noundef %43)
  %45 = ptrtoint ptr %44 to i64
  %46 = sub i64 %45, ptrtoint (ptr @a to i64)
  %47 = sdiv exact i64 %46, 4
  %48 = trunc i64 %47 to i32
  store i32 %48, ptr @m, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 1061109567, ptr %4, align 4, !tbaa !5
  %49 = load i32, ptr @m, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = mul i64 %50, 4
  call void @llvm.memset.p0.i64(ptr align 16 @dis, i8 63, i64 %51, i1 false)
  store i32 0, ptr @que0, align 16, !tbaa !5
  store i32 0, ptr @dis, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %254, %36
  %53 = load i32, ptr %5, align 4, !tbaa !5
  %54 = load i32, ptr %6, align 4, !tbaa !5
  %55 = icmp slt i32 %53, %54
  br i1 %55, label %57, label %56

56:                                               ; preds = %52
  store i32 7, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %257

57:                                               ; preds = %52
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  %58 = load i32, ptr %5, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [10001 x i32], ptr @que0, i64 0, i64 %59
  %61 = load i32, ptr %60, align 4, !tbaa !5
  store i32 %61, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %62 = load i32, ptr @m, align 4, !tbaa !5
  %63 = sub nsw i32 %62, 1
  %64 = sext i32 %63 to i64
  %65 = getelementptr inbounds [10001 x i32], ptr @a, i64 0, i64 %64
  %66 = load i32, ptr %65, align 4, !tbaa !5
  %67 = load i32, ptr %8, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [10001 x i32], ptr @a, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = sub nsw i32 %66, %70
  %72 = load i32, ptr @c0, align 4, !tbaa !5
  %73 = icmp sle i32 %71, %72
  br i1 %73, label %74, label %96

74:                                               ; preds = %57
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  %75 = load i32, ptr %8, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [10001 x i32], ptr @dis, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = load i32, ptr @c0, align 4, !tbaa !5
  %80 = load i32, ptr @c1, align 4, !tbaa !5
  %81 = add nsw i32 %79, %80
  %82 = mul nsw i32 %78, %81
  %83 = load i32, ptr @m, align 4, !tbaa !5
  %84 = sub nsw i32 %83, 1
  %85 = sext i32 %84 to i64
  %86 = getelementptr inbounds [10001 x i32], ptr @a, i64 0, i64 %85
  %87 = load i32, ptr %86, align 4, !tbaa !5
  %88 = add nsw i32 %82, %87
  %89 = load i32, ptr %8, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [10001 x i32], ptr @a, i64 0, i64 %90
  %92 = load i32, ptr %91, align 4, !tbaa !5
  %93 = sub nsw i32 %88, %92
  store i32 %93, ptr %10, align 4, !tbaa !5
  %94 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %10)
  %95 = load i32, ptr %94, align 4, !tbaa !5
  store i32 %95, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  br label %96

96:                                               ; preds = %74, %57
  %97 = load i32, ptr %4, align 4, !tbaa !5
  %98 = icmp slt i32 %97, 1061109567
  br i1 %98, label %99, label %100

99:                                               ; preds = %96
  store i32 9, ptr %7, align 4
  br label %251

100:                                              ; preds = %96
  %101 = load i32, ptr %8, align 4, !tbaa !5
  %102 = call noundef i32 @_Z3idxii(i32 noundef %101, i32 noundef 0)
  store i32 %102, ptr %9, align 4, !tbaa !5
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [10000001 x i8], ptr @vis, i64 0, i64 %103
  store i8 1, ptr %104, align 1, !tbaa !11
  %105 = load i32, ptr %9, align 4, !tbaa !5
  store i32 %105, ptr @que1, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  store i32 0, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  store i32 1, ptr %12, align 4, !tbaa !5
  br label %106

106:                                              ; preds = %247, %100
  %107 = load i32, ptr %11, align 4, !tbaa !5
  %108 = load i32, ptr %12, align 4, !tbaa !5
  %109 = icmp slt i32 %107, %108
  br i1 %109, label %111, label %110

110:                                              ; preds = %106
  store i32 10, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  br label %250

111:                                              ; preds = %106
  %112 = load i32, ptr %11, align 4, !tbaa !5
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [2004003 x i32], ptr @que1, i64 0, i64 %113
  %115 = load i32, ptr %114, align 4, !tbaa !5
  store i32 %115, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #6
  %116 = load i32, ptr %9, align 4, !tbaa !5
  call void @_Z3rdxiRiS_(i32 noundef %116, ptr noundef nonnull align 4 dereferenceable(4) %13, ptr noundef nonnull align 4 dereferenceable(4) %14)
  %117 = load i32, ptr %13, align 4, !tbaa !5
  %118 = icmp sgt i32 %117, 0
  br i1 %118, label %119, label %180

119:                                              ; preds = %111
  %120 = load i32, ptr %14, align 4, !tbaa !5
  %121 = load i32, ptr %13, align 4, !tbaa !5
  %122 = sext i32 %121 to i64
  %123 = getelementptr inbounds [10001 x i32], ptr @a, i64 0, i64 %122
  %124 = load i32, ptr %123, align 4, !tbaa !5
  %125 = add nsw i32 %120, %124
  %126 = load i32, ptr %13, align 4, !tbaa !5
  %127 = sub nsw i32 %126, 1
  %128 = sext i32 %127 to i64
  %129 = getelementptr inbounds [10001 x i32], ptr @a, i64 0, i64 %128
  %130 = load i32, ptr %129, align 4, !tbaa !5
  %131 = sub nsw i32 %125, %130
  store i32 %131, ptr %16, align 4, !tbaa !5
  %132 = load i32, ptr @c0, align 4, !tbaa !5
  %133 = icmp sle i32 %131, %132
  br i1 %133, label %134, label %180

134:                                              ; preds = %119
  %135 = load i32, ptr %13, align 4, !tbaa !5
  %136 = sub nsw i32 %135, 1
  store i32 %136, ptr %15, align 4, !tbaa !5
  %137 = load i32, ptr %16, align 4, !tbaa !5
  %138 = load i32, ptr @c0, align 4, !tbaa !5
  %139 = icmp eq i32 %137, %138
  br i1 %139, label %140, label %161

140:                                              ; preds = %134
  %141 = load i32, ptr %15, align 4, !tbaa !5
  %142 = sext i32 %141 to i64
  %143 = getelementptr inbounds [10001 x i32], ptr @dis, i64 0, i64 %142
  %144 = load i32, ptr %143, align 4, !tbaa !5
  %145 = icmp eq i32 %144, 1061109567
  br i1 %145, label %146, label %160

146:                                              ; preds = %140
  %147 = load i32, ptr %8, align 4, !tbaa !5
  %148 = sext i32 %147 to i64
  %149 = getelementptr inbounds [10001 x i32], ptr @dis, i64 0, i64 %148
  %150 = load i32, ptr %149, align 4, !tbaa !5
  %151 = add nsw i32 %150, 1
  %152 = load i32, ptr %15, align 4, !tbaa !5
  %153 = sext i32 %152 to i64
  %154 = getelementptr inbounds [10001 x i32], ptr @dis, i64 0, i64 %153
  store i32 %151, ptr %154, align 4, !tbaa !5
  %155 = load i32, ptr %15, align 4, !tbaa !5
  %156 = load i32, ptr %6, align 4, !tbaa !5
  %157 = add nsw i32 %156, 1
  store i32 %157, ptr %6, align 4, !tbaa !5
  %158 = sext i32 %156 to i64
  %159 = getelementptr inbounds [10001 x i32], ptr @que0, i64 0, i64 %158
  store i32 %155, ptr %159, align 4, !tbaa !5
  br label %160

160:                                              ; preds = %146, %140
  br label %179

161:                                              ; preds = %134
  %162 = load i32, ptr %15, align 4, !tbaa !5
  %163 = load i32, ptr %16, align 4, !tbaa !5
  %164 = call noundef i32 @_Z3idxii(i32 noundef %162, i32 noundef %163)
  store i32 %164, ptr %9, align 4, !tbaa !5
  %165 = sext i32 %164 to i64
  %166 = getelementptr inbounds [10000001 x i8], ptr @vis, i64 0, i64 %165
  %167 = load i8, ptr %166, align 1, !tbaa !11, !range !13, !noundef !14
  %168 = trunc i8 %167 to i1
  br i1 %168, label %178, label %169

169:                                              ; preds = %161
  %170 = load i32, ptr %9, align 4, !tbaa !5
  %171 = sext i32 %170 to i64
  %172 = getelementptr inbounds [10000001 x i8], ptr @vis, i64 0, i64 %171
  store i8 1, ptr %172, align 1, !tbaa !11
  %173 = load i32, ptr %9, align 4, !tbaa !5
  %174 = load i32, ptr %12, align 4, !tbaa !5
  %175 = add nsw i32 %174, 1
  store i32 %175, ptr %12, align 4, !tbaa !5
  %176 = sext i32 %174 to i64
  %177 = getelementptr inbounds [2004003 x i32], ptr @que1, i64 0, i64 %176
  store i32 %173, ptr %177, align 4, !tbaa !5
  br label %178

178:                                              ; preds = %169, %161
  br label %179

179:                                              ; preds = %178, %160
  br label %180

180:                                              ; preds = %179, %119, %111
  %181 = load i32, ptr %13, align 4, !tbaa !5
  %182 = load i32, ptr @m, align 4, !tbaa !5
  %183 = sub nsw i32 %182, 1
  %184 = icmp slt i32 %181, %183
  br i1 %184, label %185, label %246

185:                                              ; preds = %180
  %186 = load i32, ptr %14, align 4, !tbaa !5
  %187 = load i32, ptr %13, align 4, !tbaa !5
  %188 = add nsw i32 %187, 1
  %189 = sext i32 %188 to i64
  %190 = getelementptr inbounds [10001 x i32], ptr @a, i64 0, i64 %189
  %191 = load i32, ptr %190, align 4, !tbaa !5
  %192 = add nsw i32 %186, %191
  %193 = load i32, ptr %13, align 4, !tbaa !5
  %194 = sext i32 %193 to i64
  %195 = getelementptr inbounds [10001 x i32], ptr @a, i64 0, i64 %194
  %196 = load i32, ptr %195, align 4, !tbaa !5
  %197 = sub nsw i32 %192, %196
  store i32 %197, ptr %16, align 4, !tbaa !5
  %198 = load i32, ptr @c0, align 4, !tbaa !5
  %199 = icmp sle i32 %197, %198
  br i1 %199, label %200, label %246

200:                                              ; preds = %185
  %201 = load i32, ptr %13, align 4, !tbaa !5
  %202 = add nsw i32 %201, 1
  store i32 %202, ptr %15, align 4, !tbaa !5
  %203 = load i32, ptr %16, align 4, !tbaa !5
  %204 = load i32, ptr @c0, align 4, !tbaa !5
  %205 = icmp eq i32 %203, %204
  br i1 %205, label %206, label %227

206:                                              ; preds = %200
  %207 = load i32, ptr %15, align 4, !tbaa !5
  %208 = sext i32 %207 to i64
  %209 = getelementptr inbounds [10001 x i32], ptr @dis, i64 0, i64 %208
  %210 = load i32, ptr %209, align 4, !tbaa !5
  %211 = icmp eq i32 %210, 1061109567
  br i1 %211, label %212, label %226

212:                                              ; preds = %206
  %213 = load i32, ptr %8, align 4, !tbaa !5
  %214 = sext i32 %213 to i64
  %215 = getelementptr inbounds [10001 x i32], ptr @dis, i64 0, i64 %214
  %216 = load i32, ptr %215, align 4, !tbaa !5
  %217 = add nsw i32 %216, 1
  %218 = load i32, ptr %15, align 4, !tbaa !5
  %219 = sext i32 %218 to i64
  %220 = getelementptr inbounds [10001 x i32], ptr @dis, i64 0, i64 %219
  store i32 %217, ptr %220, align 4, !tbaa !5
  %221 = load i32, ptr %15, align 4, !tbaa !5
  %222 = load i32, ptr %6, align 4, !tbaa !5
  %223 = add nsw i32 %222, 1
  store i32 %223, ptr %6, align 4, !tbaa !5
  %224 = sext i32 %222 to i64
  %225 = getelementptr inbounds [10001 x i32], ptr @que0, i64 0, i64 %224
  store i32 %221, ptr %225, align 4, !tbaa !5
  br label %226

226:                                              ; preds = %212, %206
  br label %245

227:                                              ; preds = %200
  %228 = load i32, ptr %15, align 4, !tbaa !5
  %229 = load i32, ptr %16, align 4, !tbaa !5
  %230 = call noundef i32 @_Z3idxii(i32 noundef %228, i32 noundef %229)
  store i32 %230, ptr %9, align 4, !tbaa !5
  %231 = sext i32 %230 to i64
  %232 = getelementptr inbounds [10000001 x i8], ptr @vis, i64 0, i64 %231
  %233 = load i8, ptr %232, align 1, !tbaa !11, !range !13, !noundef !14
  %234 = trunc i8 %233 to i1
  br i1 %234, label %244, label %235

235:                                              ; preds = %227
  %236 = load i32, ptr %9, align 4, !tbaa !5
  %237 = sext i32 %236 to i64
  %238 = getelementptr inbounds [10000001 x i8], ptr @vis, i64 0, i64 %237
  store i8 1, ptr %238, align 1, !tbaa !11
  %239 = load i32, ptr %9, align 4, !tbaa !5
  %240 = load i32, ptr %12, align 4, !tbaa !5
  %241 = add nsw i32 %240, 1
  store i32 %241, ptr %12, align 4, !tbaa !5
  %242 = sext i32 %240 to i64
  %243 = getelementptr inbounds [2004003 x i32], ptr @que1, i64 0, i64 %242
  store i32 %239, ptr %243, align 4, !tbaa !5
  br label %244

244:                                              ; preds = %235, %227
  br label %245

245:                                              ; preds = %244, %226
  br label %246

246:                                              ; preds = %245, %185, %180
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  br label %247

247:                                              ; preds = %246
  %248 = load i32, ptr %11, align 4, !tbaa !5
  %249 = add nsw i32 %248, 1
  store i32 %249, ptr %11, align 4, !tbaa !5
  br label %106, !llvm.loop !15

250:                                              ; preds = %110
  store i32 0, ptr %7, align 4
  br label %251

251:                                              ; preds = %250, %99
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  %252 = load i32, ptr %7, align 4
  switch i32 %252, label %268 [
    i32 0, label %253
    i32 9, label %254
  ]

253:                                              ; preds = %251
  br label %254

254:                                              ; preds = %253, %251
  %255 = load i32, ptr %5, align 4, !tbaa !5
  %256 = add nsw i32 %255, 1
  store i32 %256, ptr %5, align 4, !tbaa !5
  br label %52, !llvm.loop !16

257:                                              ; preds = %56
  %258 = load i32, ptr %4, align 4, !tbaa !5
  %259 = icmp slt i32 %258, 1061109567
  br i1 %259, label %260, label %262

260:                                              ; preds = %257
  %261 = load i32, ptr %4, align 4, !tbaa !5
  br label %263

262:                                              ; preds = %257
  br label %263

263:                                              ; preds = %262, %260
  %264 = phi i32 [ %261, %260 ], [ -1, %262 ]
  %265 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i32 noundef %264)
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #6
  br label %17, !llvm.loop !17

266:                                              ; preds = %17
  store i32 0, ptr %1, align 4
  store i32 1, ptr %7, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  %267 = load i32, ptr %1, align 4
  ret i32 %267

268:                                              ; preds = %251
  unreachable
}

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef, ptr noundef) #3

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3idxii(i32 noundef, i32 noundef) #5

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

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 = { 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 #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 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !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"

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@c0 = external dso_local global i32, align 4
@c1 = external dso_local global i32, align 4
@a = external dso_local global [10001 x i32], align 16
@dis = external dso_local local_unnamed_addr global [10001 x i32], align 16
@que0 = external dso_local local_unnamed_addr global [10001 x i32], align 16
@que1 = external dso_local local_unnamed_addr global [2004003 x i32], align 16
@vis = external dso_local local_unnamed_addr global [10000001 x i8], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = 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 i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %6 = load i32, ptr @m, align 4, !tbaa !5
  %7 = icmp sgt i32 %6, 0
  br i1 %7, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %8 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @c0, ptr noundef nonnull @c1)
  %9 = load i32, ptr @m, align 4, !tbaa !5
  %10 = sext i32 %9 to i64
  %11 = getelementptr inbounds i32, ptr @a, i64 %10
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @a, ptr noundef nonnull %11)
  %12 = load i32, ptr @m, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds i32, ptr @a, i64 %13
  %15 = tail call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef nonnull @a, ptr noundef nonnull %14)
  %16 = ptrtoint ptr %15 to i64
  %17 = sub i64 %16, ptrtoint (ptr @a to i64)
  %18 = lshr exact i64 %17, 2
  %19 = trunc i64 %18 to i32
  store i32 %19, ptr @m, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  store i32 1061109567, ptr %1, align 4, !tbaa !5
  %sext = shl i64 %17, 30
  %20 = ashr exact i64 %sext, 30
  %21 = and i64 %20, -4
  tail call void @llvm.memset.p0.i64(ptr nonnull align 16 @dis, i8 63, i64 %21, i1 false)
  store i32 0, ptr @que0, align 16, !tbaa !5
  store i32 0, ptr @dis, align 16, !tbaa !5
  br label %32

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %22 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %23 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %22)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %24 = load i32, ptr @m, align 4, !tbaa !5
  %25 = sext i32 %24 to i64
  %26 = icmp slt i64 %indvars.iv.next, %25
  br i1 %26, label %.lr.ph, label %._crit_edge, !llvm.loop !9

27:                                               ; preds = %.loopexit
  %28 = load i32, ptr %1, align 4
  %29 = icmp slt i32 %28, 1061109567
  %30 = select i1 %29, i32 %28, i32 -1
  %31 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i32 noundef %30)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  ret i32 0

32:                                               ; preds = %._crit_edge, %.loopexit
  %indvars.iv69 = phi i64 [ 0, %._crit_edge ], [ %indvars.iv.next70, %.loopexit ]
  %.04264 = phi i32 [ 1, %._crit_edge ], [ %.4, %.loopexit ]
  %33 = getelementptr inbounds [10001 x i32], ptr @que0, i64 0, i64 %indvars.iv69
  %34 = load i32, ptr %33, align 4, !tbaa !5
  %35 = load i32, ptr @m, align 4, !tbaa !5
  %36 = add nsw i32 %35, -1
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [10001 x i32], ptr @a, i64 0, i64 %37
  %39 = load i32, ptr %38, align 4, !tbaa !5
  %40 = sext i32 %34 to i64
  %41 = getelementptr inbounds [10001 x i32], ptr @a, i64 0, i64 %40
  %42 = load i32, ptr %41, align 4, !tbaa !5
  %43 = sub i32 %39, %42
  %44 = load i32, ptr @c0, align 4, !tbaa !5
  %.not54 = icmp sgt i32 %43, %44
  br i1 %.not54, label %thread-pre-split, label %45

45:                                               ; preds = %32
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  %46 = getelementptr inbounds [10001 x i32], ptr @dis, i64 0, i64 %40
  %47 = load i32, ptr %46, align 4, !tbaa !5
  %48 = load i32, ptr @c1, align 4, !tbaa !5
  %49 = add nsw i32 %48, %44
  %50 = mul nsw i32 %49, %47
  %51 = add i32 %43, %50
  store i32 %51, ptr %2, align 4, !tbaa !5
  %52 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %53 = load i32, ptr %52, align 4, !tbaa !5
  store i32 %53, ptr %1, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  br label %54

thread-pre-split:                                 ; preds = %32
  %.pr = load i32, ptr %1, align 4, !tbaa !5
  br label %54

54:                                               ; preds = %thread-pre-split, %45
  %55 = phi i32 [ %.pr, %thread-pre-split ], [ %53, %45 ]
  %56 = icmp slt i32 %55, 1061109567
  br i1 %56, label %.loopexit, label %57

57:                                               ; preds = %54
  %58 = call noundef i32 @_Z3idxii(i32 noundef %34, i32 noundef 0)
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [10000001 x i8], ptr @vis, i64 0, i64 %59
  store i8 1, ptr %60, align 1, !tbaa !11
  store i32 %58, ptr @que1, align 16, !tbaa !5
  %61 = getelementptr inbounds [10001 x i32], ptr @dis, i64 0, i64 %40
  br label %62

62:                                               ; preds = %57, %140
  %indvars.iv66 = phi i64 [ 0, %57 ], [ %indvars.iv.next67, %140 ]
  %.062 = phi i32 [ 1, %57 ], [ %.2, %140 ]
  %.14360 = phi i32 [ %.04264, %57 ], [ %.3, %140 ]
  %63 = getelementptr inbounds [2004003 x i32], ptr @que1, i64 0, i64 %indvars.iv66
  %64 = load i32, ptr %63, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #6
  call void @_Z3rdxiRiS_(i32 noundef %64, ptr noundef nonnull align 4 dereferenceable(4) %3, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %65 = load i32, ptr %3, align 4, !tbaa !5
  %66 = icmp sgt i32 %65, 0
  br i1 %66, label %67, label %101

67:                                               ; preds = %62
  %68 = load i32, ptr %4, align 4, !tbaa !5
  %69 = zext nneg i32 %65 to i64
  %70 = getelementptr inbounds [10001 x i32], ptr @a, i64 0, i64 %69
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = add nsw i32 %71, %68
  %73 = add nsw i32 %65, -1
  %74 = zext nneg i32 %73 to i64
  %75 = getelementptr inbounds [10001 x i32], ptr @a, i64 0, i64 %74
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = sub i32 %72, %76
  %78 = load i32, ptr @c0, align 4, !tbaa !5
  %.not55 = icmp sgt i32 %77, %78
  br i1 %.not55, label %101, label %79

79:                                               ; preds = %67
  %80 = icmp eq i32 %77, %78
  br i1 %80, label %81, label %91

81:                                               ; preds = %79
  %82 = getelementptr inbounds [10001 x i32], ptr @dis, i64 0, i64 %74
  %83 = load i32, ptr %82, align 4, !tbaa !5
  %84 = icmp eq i32 %83, 1061109567
  br i1 %84, label %85, label %101

85:                                               ; preds = %81
  %86 = load i32, ptr %61, align 4, !tbaa !5
  %87 = add nsw i32 %86, 1
  store i32 %87, ptr %82, align 4, !tbaa !5
  %88 = add nsw i32 %.14360, 1
  %89 = sext i32 %.14360 to i64
  %90 = getelementptr inbounds [10001 x i32], ptr @que0, i64 0, i64 %89
  store i32 %73, ptr %90, align 4, !tbaa !5
  br label %101

91:                                               ; preds = %79
  %92 = call noundef i32 @_Z3idxii(i32 noundef %73, i32 noundef %77)
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [10000001 x i8], ptr @vis, i64 0, i64 %93
  %95 = load i8, ptr %94, align 1, !tbaa !11, !range !13, !noundef !14
  %96 = trunc nuw i8 %95 to i1
  br i1 %96, label %101, label %97

97:                                               ; preds = %91
  store i8 1, ptr %94, align 1, !tbaa !11
  %98 = add nsw i32 %.062, 1
  %99 = sext i32 %.062 to i64
  %100 = getelementptr inbounds [2004003 x i32], ptr @que1, i64 0, i64 %99
  store i32 %92, ptr %100, align 4, !tbaa !5
  br label %101

101:                                              ; preds = %85, %81, %97, %91, %67, %62
  %.244 = phi i32 [ %88, %85 ], [ %.14360, %81 ], [ %.14360, %91 ], [ %.14360, %97 ], [ %.14360, %67 ], [ %.14360, %62 ]
  %.1 = phi i32 [ %.062, %85 ], [ %.062, %81 ], [ %.062, %91 ], [ %98, %97 ], [ %.062, %67 ], [ %.062, %62 ]
  %102 = load i32, ptr %3, align 4, !tbaa !5
  %103 = load i32, ptr @m, align 4, !tbaa !5
  %104 = add nsw i32 %103, -1
  %105 = icmp slt i32 %102, %104
  br i1 %105, label %106, label %140

106:                                              ; preds = %101
  %107 = load i32, ptr %4, align 4, !tbaa !5
  %108 = add nsw i32 %102, 1
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [10001 x i32], ptr @a, i64 0, i64 %109
  %111 = load i32, ptr %110, align 4, !tbaa !5
  %112 = add nsw i32 %111, %107
  %113 = sext i32 %102 to i64
  %114 = getelementptr inbounds [10001 x i32], ptr @a, i64 0, i64 %113
  %115 = load i32, ptr %114, align 4, !tbaa !5
  %116 = sub i32 %112, %115
  %117 = load i32, ptr @c0, align 4, !tbaa !5
  %.not56 = icmp sgt i32 %116, %117
  br i1 %.not56, label %140, label %118

118:                                              ; preds = %106
  %119 = icmp eq i32 %116, %117
  br i1 %119, label %120, label %130

120:                                              ; preds = %118
  %121 = getelementptr inbounds [10001 x i32], ptr @dis, i64 0, i64 %109
  %122 = load i32, ptr %121, align 4, !tbaa !5
  %123 = icmp eq i32 %122, 1061109567
  br i1 %123, label %124, label %140

124:                                              ; preds = %120
  %125 = load i32, ptr %61, align 4, !tbaa !5
  %126 = add nsw i32 %125, 1
  store i32 %126, ptr %121, align 4, !tbaa !5
  %127 = add nsw i32 %.244, 1
  %128 = sext i32 %.244 to i64
  %129 = getelementptr inbounds [10001 x i32], ptr @que0, i64 0, i64 %128
  store i32 %108, ptr %129, align 4, !tbaa !5
  br label %140

130:                                              ; preds = %118
  %131 = call noundef i32 @_Z3idxii(i32 noundef %108, i32 noundef %116)
  %132 = sext i32 %131 to i64
  %133 = getelementptr inbounds [10000001 x i8], ptr @vis, i64 0, i64 %132
  %134 = load i8, ptr %133, align 1, !tbaa !11, !range !13, !noundef !14
  %135 = trunc nuw i8 %134 to i1
  br i1 %135, label %140, label %136

136:                                              ; preds = %130
  store i8 1, ptr %133, align 1, !tbaa !11
  %137 = add nsw i32 %.1, 1
  %138 = sext i32 %.1 to i64
  %139 = getelementptr inbounds [2004003 x i32], ptr @que1, i64 0, i64 %138
  store i32 %131, ptr %139, align 4, !tbaa !5
  br label %140

140:                                              ; preds = %124, %120, %136, %130, %106, %101
  %.3 = phi i32 [ %127, %124 ], [ %.244, %120 ], [ %.244, %130 ], [ %.244, %136 ], [ %.244, %106 ], [ %.244, %101 ]
  %.2 = phi i32 [ %.1, %124 ], [ %.1, %120 ], [ %.1, %130 ], [ %137, %136 ], [ %.1, %106 ], [ %.1, %101 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #6
  %indvars.iv.next67 = add nuw nsw i64 %indvars.iv66, 1
  %141 = sext i32 %.2 to i64
  %142 = icmp slt i64 %indvars.iv.next67, %141
  br i1 %142, label %62, label %.loopexit, !llvm.loop !15

.loopexit:                                        ; preds = %140, %54
  %.4 = phi i32 [ %.04264, %54 ], [ %.3, %140 ]
  %indvars.iv.next70 = add nuw nsw i64 %indvars.iv69, 1
  %143 = sext i32 %.4 to i64
  %144 = icmp slt i64 %indvars.iv.next70, %143
  br i1 %144, label %32, label %27, !llvm.loop !16
}

; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.start.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: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef, ptr noundef) local_unnamed_addr #3

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef i32 @_Z3idxii(i32 noundef, i32 noundef) local_unnamed_addr #5

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

; Function Attrs: nofree nounwind
declare noundef i32 @printf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { 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 = { 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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { 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 #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 = !{!12, !12, i64 0}
!12 = !{!"bool", !7, i64 0}
!13 = !{i8 0, i8 2}
!14 = !{}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}


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