; LLVM IR from tangjz/acm-icpc :: codeforces/complete (797F)

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

%"struct.std::pair" = type { i32, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global [5001 x i32], align 16
@cur = external dso_local global i32, align 4
@pre = external dso_local global i32, align 4
@b = external dso_local global [5001 x %"struct.std::pair"], align 16
@f = external dso_local global [2 x [5001 x i64]], 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 [7 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 i64, align 8
  %8 = alloca i32, align 4
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %11 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %22, %0
  %13 = load i32, ptr %2, align 4, !tbaa !5
  %14 = load i32, ptr @n, align 4, !tbaa !5
  %15 = icmp sle i32 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %12
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #6
  br label %25

17:                                               ; preds = %12
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds i32, ptr @a, i64 %19
  %21 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %20)
  br label %22

22:                                               ; preds = %17
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = add nsw i32 %23, 1
  store i32 %24, ptr %2, align 4, !tbaa !5
  br label %12, !llvm.loop !9

25:                                               ; preds = %16
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds i32, ptr @a, i64 %27
  %29 = getelementptr inbounds i32, ptr %28, i64 1
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef getelementptr inbounds (i32, ptr @a, i64 1), ptr noundef %29)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 1, ptr %3, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %45, %25
  %31 = load i32, ptr %3, align 4, !tbaa !5
  %32 = load i32, ptr @m, align 4, !tbaa !5
  %33 = icmp sle i32 %31, %32
  br i1 %33, label %35, label %34

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

35:                                               ; preds = %30
  %36 = load i32, ptr %3, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %38 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr @b, i64 0, i64 %37
  %39 = getelementptr inbounds %"struct.std::pair", ptr %38, i32 0, i32 0
  %40 = load i32, ptr %3, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr @b, i64 0, i64 %41
  %43 = getelementptr inbounds %"struct.std::pair", ptr %42, i32 0, i32 1
  %44 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %39, ptr noundef %43)
  br label %45

45:                                               ; preds = %35
  %46 = load i32, ptr %3, align 4, !tbaa !5
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %3, align 4, !tbaa !5
  br label %30, !llvm.loop !11

48:                                               ; preds = %34
  %49 = load i32, ptr @m, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds %"struct.std::pair", ptr @b, i64 %50
  %52 = getelementptr inbounds %"struct.std::pair", ptr %51, i64 1
  call void @_ZSt4sortIPSt4pairIiiEEvT_S3_(ptr noundef getelementptr inbounds (%"struct.std::pair", ptr @b, i64 1), ptr noundef %52)
  %53 = load i32, ptr @cur, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [2 x [5001 x i64]], ptr @f, i64 0, i64 %54
  %56 = getelementptr inbounds [5001 x i64], ptr %55, i64 0, i64 0
  %57 = getelementptr inbounds i64, ptr %56, i64 1
  %58 = load i32, ptr @n, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = mul i64 %59, 8
  call void @llvm.memset.p0.i64(ptr align 8 %57, i8 63, i64 %60, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #6
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %61

61:                                               ; preds = %220, %48
  %62 = load i32, ptr %4, align 4, !tbaa !5
  %63 = load i32, ptr @m, align 4, !tbaa !5
  %64 = icmp sle i32 %62, %63
  br i1 %64, label %66, label %65

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

66:                                               ; preds = %61
  %67 = load i32, ptr @pre, align 4, !tbaa !5
  %68 = xor i32 %67, 1
  store i32 %68, ptr @pre, align 4, !tbaa !5
  %69 = load i32, ptr @cur, align 4, !tbaa !5
  %70 = xor i32 %69, 1
  store i32 %70, ptr @cur, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 0, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  store i64 0, ptr %7, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %216, %66
  %72 = load i32, ptr %8, align 4, !tbaa !5
  %73 = load i32, ptr @n, align 4, !tbaa !5
  %74 = icmp sle i32 %72, %73
  br i1 %74, label %76, label %75

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

76:                                               ; preds = %71
  %77 = load i32, ptr %6, align 4, !tbaa !5
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %6, align 4, !tbaa !5
  %79 = load i32, ptr %8, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %80
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = sext i32 %83 to i64
  %85 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr @b, i64 0, i64 %84
  %86 = getelementptr inbounds %"struct.std::pair", ptr %85, i32 0, i32 0
  %87 = load i32, ptr %86, align 8, !tbaa !14
  %88 = sub nsw i32 %82, %87
  %89 = call i32 @llvm.abs.i32(i32 %88, i1 true)
  %90 = sext i32 %89 to i64
  %91 = load i64, ptr %7, align 8, !tbaa !12
  %92 = add nsw i64 %91, %90
  store i64 %92, ptr %7, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #6
  %93 = load i32, ptr @pre, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [2 x [5001 x i64]], ptr @f, i64 0, i64 %94
  %96 = load i32, ptr %8, align 4, !tbaa !5
  %97 = load i32, ptr %6, align 4, !tbaa !5
  %98 = sub nsw i32 %96, %97
  %99 = sext i32 %98 to i64
  %100 = getelementptr inbounds [5001 x i64], ptr %95, i64 0, i64 %99
  %101 = load i64, ptr %100, align 8, !tbaa !12
  %102 = icmp ne i64 %101, 4557430888798830399
  br i1 %102, label %103, label %123

103:                                              ; preds = %76
  %104 = load i32, ptr %6, align 4, !tbaa !5
  %105 = load i32, ptr %4, align 4, !tbaa !5
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr @b, i64 0, i64 %106
  %108 = getelementptr inbounds %"struct.std::pair", ptr %107, i32 0, i32 1
  %109 = load i32, ptr %108, align 4, !tbaa !16
  %110 = icmp sle i32 %104, %109
  br i1 %110, label %111, label %123

111:                                              ; preds = %103
  %112 = load i32, ptr @pre, align 4, !tbaa !5
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [2 x [5001 x i64]], ptr @f, i64 0, i64 %113
  %115 = load i32, ptr %8, align 4, !tbaa !5
  %116 = load i32, ptr %6, align 4, !tbaa !5
  %117 = sub nsw i32 %115, %116
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds [5001 x i64], ptr %114, i64 0, i64 %118
  %120 = load i64, ptr %119, align 8, !tbaa !12
  %121 = load i64, ptr %7, align 8, !tbaa !12
  %122 = add nsw i64 %120, %121
  br label %124

123:                                              ; preds = %103, %76
  br label %124

124:                                              ; preds = %123, %111
  %125 = phi i64 [ %122, %111 ], [ 4557430888798830399, %123 ]
  store i64 %125, ptr %9, align 8, !tbaa !12
  br label %126

126:                                              ; preds = %207, %124
  %127 = load i32, ptr %6, align 4, !tbaa !5
  %128 = icmp sgt i32 %127, 0
  br i1 %128, label %129, label %208

129:                                              ; preds = %126
  %130 = load i32, ptr %6, align 4, !tbaa !5
  %131 = add nsw i32 %130, -1
  store i32 %131, ptr %6, align 4, !tbaa !5
  %132 = load i32, ptr %8, align 4, !tbaa !5
  %133 = load i32, ptr %6, align 4, !tbaa !5
  %134 = sub nsw i32 %132, %133
  %135 = sext i32 %134 to i64
  %136 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %135
  %137 = load i32, ptr %136, align 4, !tbaa !5
  %138 = load i32, ptr %4, align 4, !tbaa !5
  %139 = sext i32 %138 to i64
  %140 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr @b, i64 0, i64 %139
  %141 = getelementptr inbounds %"struct.std::pair", ptr %140, i32 0, i32 0
  %142 = load i32, ptr %141, align 8, !tbaa !14
  %143 = sub nsw i32 %137, %142
  %144 = call i32 @llvm.abs.i32(i32 %143, i1 true)
  %145 = sext i32 %144 to i64
  %146 = load i64, ptr %7, align 8, !tbaa !12
  %147 = sub nsw i64 %146, %145
  store i64 %147, ptr %7, align 8, !tbaa !12
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #6
  %148 = load i32, ptr @pre, align 4, !tbaa !5
  %149 = sext i32 %148 to i64
  %150 = getelementptr inbounds [2 x [5001 x i64]], ptr @f, i64 0, i64 %149
  %151 = load i32, ptr %8, align 4, !tbaa !5
  %152 = load i32, ptr %6, align 4, !tbaa !5
  %153 = sub nsw i32 %151, %152
  %154 = sext i32 %153 to i64
  %155 = getelementptr inbounds [5001 x i64], ptr %150, i64 0, i64 %154
  %156 = load i64, ptr %155, align 8, !tbaa !12
  %157 = icmp ne i64 %156, 4557430888798830399
  br i1 %157, label %158, label %178

158:                                              ; preds = %129
  %159 = load i32, ptr %6, align 4, !tbaa !5
  %160 = load i32, ptr %4, align 4, !tbaa !5
  %161 = sext i32 %160 to i64
  %162 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr @b, i64 0, i64 %161
  %163 = getelementptr inbounds %"struct.std::pair", ptr %162, i32 0, i32 1
  %164 = load i32, ptr %163, align 4, !tbaa !16
  %165 = icmp sle i32 %159, %164
  br i1 %165, label %166, label %178

166:                                              ; preds = %158
  %167 = load i32, ptr @pre, align 4, !tbaa !5
  %168 = sext i32 %167 to i64
  %169 = getelementptr inbounds [2 x [5001 x i64]], ptr @f, i64 0, i64 %168
  %170 = load i32, ptr %8, align 4, !tbaa !5
  %171 = load i32, ptr %6, align 4, !tbaa !5
  %172 = sub nsw i32 %170, %171
  %173 = sext i32 %172 to i64
  %174 = getelementptr inbounds [5001 x i64], ptr %169, i64 0, i64 %173
  %175 = load i64, ptr %174, align 8, !tbaa !12
  %176 = load i64, ptr %7, align 8, !tbaa !12
  %177 = add nsw i64 %175, %176
  br label %179

178:                                              ; preds = %158, %129
  br label %179

179:                                              ; preds = %178, %166
  %180 = phi i64 [ %177, %166 ], [ 4557430888798830399, %178 ]
  store i64 %180, ptr %10, align 8, !tbaa !12
  %181 = load i64, ptr %9, align 8, !tbaa !12
  %182 = load i64, ptr %10, align 8, !tbaa !12
  %183 = icmp slt i64 %181, %182
  br i1 %183, label %184, label %203

184:                                              ; preds = %179
  %185 = load i32, ptr %8, align 4, !tbaa !5
  %186 = load i32, ptr %6, align 4, !tbaa !5
  %187 = sub nsw i32 %185, %186
  %188 = sext i32 %187 to i64
  %189 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %188
  %190 = load i32, ptr %189, align 4, !tbaa !5
  %191 = load i32, ptr %4, align 4, !tbaa !5
  %192 = sext i32 %191 to i64
  %193 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr @b, i64 0, i64 %192
  %194 = getelementptr inbounds %"struct.std::pair", ptr %193, i32 0, i32 0
  %195 = load i32, ptr %194, align 8, !tbaa !14
  %196 = sub nsw i32 %190, %195
  %197 = call i32 @llvm.abs.i32(i32 %196, i1 true)
  %198 = sext i32 %197 to i64
  %199 = load i64, ptr %7, align 8, !tbaa !12
  %200 = add nsw i64 %199, %198
  store i64 %200, ptr %7, align 8, !tbaa !12
  %201 = load i32, ptr %6, align 4, !tbaa !5
  %202 = add nsw i32 %201, 1
  store i32 %202, ptr %6, align 4, !tbaa !5
  store i32 15, ptr %5, align 4
  br label %205

203:                                              ; preds = %179
  %204 = load i64, ptr %10, align 8, !tbaa !12
  store i64 %204, ptr %9, align 8, !tbaa !12
  store i32 0, ptr %5, align 4
  br label %205

205:                                              ; preds = %203, %184
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #6
  %206 = load i32, ptr %5, align 4
  switch i32 %206, label %244 [
    i32 0, label %207
    i32 15, label %208
  ]

207:                                              ; preds = %205
  br label %126, !llvm.loop !17

208:                                              ; preds = %205, %126
  %209 = load i64, ptr %9, align 8, !tbaa !12
  %210 = load i32, ptr @cur, align 4, !tbaa !5
  %211 = sext i32 %210 to i64
  %212 = getelementptr inbounds [2 x [5001 x i64]], ptr @f, i64 0, i64 %211
  %213 = load i32, ptr %8, align 4, !tbaa !5
  %214 = sext i32 %213 to i64
  %215 = getelementptr inbounds [5001 x i64], ptr %212, i64 0, i64 %214
  store i64 %209, ptr %215, align 8, !tbaa !12
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #6
  br label %216

216:                                              ; preds = %208
  %217 = load i32, ptr %8, align 4, !tbaa !5
  %218 = add nsw i32 %217, 1
  store i32 %218, ptr %8, align 4, !tbaa !5
  br label %71, !llvm.loop !18

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

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

223:                                              ; preds = %65
  %224 = load i32, ptr @cur, align 4, !tbaa !5
  %225 = sext i32 %224 to i64
  %226 = getelementptr inbounds [2 x [5001 x i64]], ptr @f, i64 0, i64 %225
  %227 = load i32, ptr @n, align 4, !tbaa !5
  %228 = sext i32 %227 to i64
  %229 = getelementptr inbounds [5001 x i64], ptr %226, i64 0, i64 %228
  %230 = load i64, ptr %229, align 8, !tbaa !12
  %231 = icmp eq i64 %230, 4557430888798830399
  br i1 %231, label %232, label %233

232:                                              ; preds = %223
  br label %241

233:                                              ; preds = %223
  %234 = load i32, ptr @cur, align 4, !tbaa !5
  %235 = sext i32 %234 to i64
  %236 = getelementptr inbounds [2 x [5001 x i64]], ptr @f, i64 0, i64 %235
  %237 = load i32, ptr @n, align 4, !tbaa !5
  %238 = sext i32 %237 to i64
  %239 = getelementptr inbounds [5001 x i64], ptr %236, i64 0, i64 %238
  %240 = load i64, ptr %239, align 8, !tbaa !12
  br label %241

241:                                              ; preds = %233, %232
  %242 = phi i64 [ -1, %232 ], [ %240, %233 ]
  %243 = call i32 (ptr, ...) @printf(ptr noundef @.str.2, i64 noundef %242)
  ret i32 0

244:                                              ; preds = %205
  unreachable
}

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 @_ZSt4sortIPiEvT_S1_(ptr noundef, ptr noundef) #3

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIPSt4pairIiiEEvT_S3_(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: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #5

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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = !{!13, !13, i64 0}
!13 = !{!"long long", !7, i64 0}
!14 = !{!15, !6, i64 0}
!15 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!16 = !{!15, !6, i64 4}
!17 = distinct !{!17, !10}
!18 = distinct !{!18, !10}
!19 = distinct !{!19, !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"

%"struct.std::pair" = type { i32, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@a = external dso_local global [5001 x i32], align 16
@cur = external dso_local local_unnamed_addr global i32, align 4
@pre = external dso_local local_unnamed_addr global i32, align 4
@b = external dso_local global [5001 x %"struct.std::pair"], align 16
@f = external dso_local local_unnamed_addr global [2 x [5001 x i64]], 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 [7 x i8], align 1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %2 = load i32, ptr @n, align 4, !tbaa !5
  %.not79 = icmp slt i32 %2, 1
  br i1 %.not79, label %.._crit_edge_crit_edge, label %.lr.ph

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = sext i32 %2 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %.pre-phi126 = phi i64 [ %.pre, %.._crit_edge_crit_edge ], [ %9, %.lr.ph ]
  %3 = getelementptr inbounds i32, ptr @a, i64 %.pre-phi126
  %4 = getelementptr inbounds i8, ptr %3, i64 4
  tail call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull getelementptr inbounds (i8, ptr @a, i64 4), ptr noundef nonnull %4)
  %5 = load i32, ptr @m, align 4, !tbaa !5
  %.not6481 = icmp slt i32 %5, 1
  br i1 %.not6481, label %._crit_edge.._crit_edge85_crit_edge, label %.lr.ph84

._crit_edge.._crit_edge85_crit_edge:              ; preds = %._crit_edge
  %.pre127 = sext i32 %5 to i64
  br label %._crit_edge85

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

._crit_edge85:                                    ; preds = %.lr.ph84, %._crit_edge.._crit_edge85_crit_edge
  %.pre-phi128 = phi i64 [ %.pre127, %._crit_edge.._crit_edge85_crit_edge ], [ %39, %.lr.ph84 ]
  %10 = getelementptr inbounds %"struct.std::pair", ptr @b, i64 %.pre-phi128
  %11 = getelementptr inbounds i8, ptr %10, i64 8
  tail call void @_ZSt4sortIPSt4pairIiiEEvT_S3_(ptr noundef nonnull getelementptr inbounds (i8, ptr @b, i64 8), ptr noundef nonnull %11)
  %12 = load i32, ptr @cur, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = getelementptr inbounds [2 x [5001 x i64]], ptr @f, i64 0, i64 %13, i64 1
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = sext i32 %15 to i64
  %17 = shl nsw i64 %16, 3
  tail call void @llvm.memset.p0.i64(ptr nonnull align 8 %14, i8 63, i64 %17, i1 false)
  %18 = load i32, ptr @m, align 4, !tbaa !5
  %.not6594 = icmp slt i32 %18, 1
  br i1 %.not6594, label %40, label %.lr.ph97

.lr.ph97:                                         ; preds = %._crit_edge85
  %pre.promoted = load i32, ptr @pre, align 4, !tbaa !5
  %.not6687 = icmp slt i32 %15, 1
  br i1 %.not6687, label %.lr.ph97.split.us.preheader, label %.lr.ph92.preheader

.lr.ph97.split.us.preheader:                      ; preds = %.lr.ph97
  %min.iters.check = icmp ult i32 %18, 8
  br i1 %min.iters.check, label %.lr.ph97.split.us.preheader157, label %vector.ph

.lr.ph97.split.us.preheader157:                   ; preds = %middle.block, %.lr.ph97.split.us.preheader
  %.05695.us.ph = phi i32 [ 1, %.lr.ph97.split.us.preheader ], [ %ind.end, %middle.block ]
  %.ph = phi i32 [ %pre.promoted, %.lr.ph97.split.us.preheader ], [ %26, %middle.block ]
  %.ph158 = phi i32 [ %12, %.lr.ph97.split.us.preheader ], [ %27, %middle.block ]
  br label %.lr.ph97.split.us

vector.ph:                                        ; preds = %.lr.ph97.split.us.preheader
  %n.vec = and i32 %18, 2147483640
  %ind.end = or disjoint i32 %n.vec, 1
  %19 = insertelement <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, i32 %pre.promoted, i64 0
  %20 = insertelement <4 x i32> <i32 poison, i32 0, i32 0, i32 0>, i32 %12, i64 0
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i32 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %vec.phi = phi <4 x i32> [ %19, %vector.ph ], [ %21, %vector.body ]
  %vec.phi152 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %22, %vector.body ]
  %vec.phi153 = phi <4 x i32> [ %20, %vector.ph ], [ %23, %vector.body ]
  %vec.phi154 = phi <4 x i32> [ zeroinitializer, %vector.ph ], [ %24, %vector.body ]
  %21 = xor <4 x i32> %vec.phi, <i32 1, i32 1, i32 1, i32 1>
  %22 = xor <4 x i32> %vec.phi152, <i32 1, i32 1, i32 1, i32 1>
  %23 = xor <4 x i32> %vec.phi153, <i32 1, i32 1, i32 1, i32 1>
  %24 = xor <4 x i32> %vec.phi154, <i32 1, i32 1, i32 1, i32 1>
  %index.next = add nuw i32 %index, 8
  %25 = icmp eq i32 %index.next, %n.vec
  br i1 %25, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %bin.rdx = xor <4 x i32> %vec.phi152, %vec.phi
  %26 = tail call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %bin.rdx)
  %bin.rdx155 = xor <4 x i32> %vec.phi154, %vec.phi153
  %27 = tail call i32 @llvm.vector.reduce.xor.v4i32(<4 x i32> %bin.rdx155)
  %cmp.n = icmp eq i32 %18, %n.vec
  br i1 %cmp.n, label %._crit_edge98.loopexit, label %.lr.ph97.split.us.preheader157

.lr.ph92.preheader:                               ; preds = %.lr.ph97
  %28 = add nuw i32 %15, 1
  %29 = add nuw i32 %18, 1
  %wide.trip.count122 = zext i32 %29 to i64
  %wide.trip.count = zext i32 %28 to i64
  br label %.lr.ph92

.lr.ph97.split.us:                                ; preds = %.lr.ph97.split.us.preheader157, %.lr.ph97.split.us
  %.05695.us = phi i32 [ %34, %.lr.ph97.split.us ], [ %.05695.us.ph, %.lr.ph97.split.us.preheader157 ]
  %30 = phi i32 [ %32, %.lr.ph97.split.us ], [ %.ph, %.lr.ph97.split.us.preheader157 ]
  %31 = phi i32 [ %33, %.lr.ph97.split.us ], [ %.ph158, %.lr.ph97.split.us.preheader157 ]
  %32 = xor i32 %30, 1
  %33 = xor i32 %31, 1
  %34 = add nuw i32 %.05695.us, 1
  %exitcond124.not = icmp eq i32 %.05695.us, %18
  br i1 %exitcond124.not, label %._crit_edge98.loopexit, label %.lr.ph97.split.us, !llvm.loop !14

.lr.ph84:                                         ; preds = %._crit_edge, %.lr.ph84
  %indvars.iv110 = phi i64 [ %indvars.iv.next111, %.lr.ph84 ], [ 1, %._crit_edge ]
  %35 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr @b, i64 0, i64 %indvars.iv110
  %36 = getelementptr inbounds i8, ptr %35, i64 4
  %37 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %35, ptr noundef nonnull %36)
  %indvars.iv.next111 = add nuw nsw i64 %indvars.iv110, 1
  %38 = load i32, ptr @m, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %.not64.not = icmp slt i64 %indvars.iv110, %39
  br i1 %.not64.not, label %.lr.ph84, label %._crit_edge85, !llvm.loop !15

._crit_edge98.loopexit:                           ; preds = %.lr.ph97.split.us, %middle.block
  %.lcssa141 = phi i32 [ %26, %middle.block ], [ %32, %.lr.ph97.split.us ]
  %.lcssa = phi i32 [ %27, %middle.block ], [ %33, %.lr.ph97.split.us ]
  %.pre125 = sext i32 %.lcssa to i64
  br label %._crit_edge98

._crit_edge98:                                    ; preds = %._crit_edge93, %._crit_edge98.loopexit
  %.pre.pre-phi = phi i64 [ %.pre125, %._crit_edge98.loopexit ], [ %53, %._crit_edge93 ]
  %.us-phi = phi i32 [ %.lcssa, %._crit_edge98.loopexit ], [ %48, %._crit_edge93 ]
  %.us-phi101 = phi i32 [ %.lcssa141, %._crit_edge98.loopexit ], [ %47, %._crit_edge93 ]
  store i32 %.us-phi101, ptr @pre, align 4, !tbaa !5
  store i32 %.us-phi, ptr @cur, align 4, !tbaa !5
  br label %40

40:                                               ; preds = %._crit_edge98, %._crit_edge85
  %.pre-phi = phi i64 [ %.pre.pre-phi, %._crit_edge98 ], [ %13, %._crit_edge85 ]
  %41 = getelementptr inbounds [2 x [5001 x i64]], ptr @f, i64 0, i64 %.pre-phi, i64 %16
  %42 = load i64, ptr %41, align 8, !tbaa !16
  %43 = icmp eq i64 %42, 4557430888798830399
  %spec.select = select i1 %43, i64 -1, i64 %42
  %44 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.2, i64 noundef %spec.select)
  ret i32 0

.lr.ph92:                                         ; preds = %.lr.ph92.preheader, %._crit_edge93
  %indvars.iv119 = phi i64 [ 1, %.lr.ph92.preheader ], [ %indvars.iv.next120, %._crit_edge93 ]
  %45 = phi i32 [ %pre.promoted, %.lr.ph92.preheader ], [ %47, %._crit_edge93 ]
  %46 = phi i32 [ %12, %.lr.ph92.preheader ], [ %48, %._crit_edge93 ]
  %47 = xor i32 %45, 1
  %48 = xor i32 %46, 1
  %49 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr @b, i64 0, i64 %indvars.iv119
  %50 = load i32, ptr %49, align 8, !tbaa !18
  %51 = sext i32 %47 to i64
  %52 = getelementptr inbounds i8, ptr %49, i64 4
  %53 = sext i32 %48 to i64
  br label %54

._crit_edge93:                                    ; preds = %.thread
  %indvars.iv.next120 = add nuw nsw i64 %indvars.iv119, 1
  %exitcond123.not = icmp eq i64 %indvars.iv.next120, %wide.trip.count122
  br i1 %exitcond123.not, label %._crit_edge98, label %.lr.ph92, !llvm.loop !20

54:                                               ; preds = %.lr.ph92, %.thread
  %indvars.iv116 = phi i64 [ 1, %.lr.ph92 ], [ %indvars.iv.next117, %.thread ]
  %.04889 = phi i64 [ 0, %.lr.ph92 ], [ %.149, %.thread ]
  %.05188 = phi i32 [ 0, %.lr.ph92 ], [ %.152.lcssa, %.thread ]
  %55 = add nsw i32 %.05188, 1
  %56 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %indvars.iv116
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = sub nsw i32 %57, %50
  %59 = tail call i32 @llvm.abs.i32(i32 %58, i1 true)
  %60 = zext nneg i32 %59 to i64
  %61 = add nsw i64 %.04889, %60
  %62 = sext i32 %55 to i64
  %63 = sub nsw i64 %indvars.iv116, %62
  %64 = getelementptr inbounds [2 x [5001 x i64]], ptr @f, i64 0, i64 %51, i64 %63
  %65 = load i64, ptr %64, align 8, !tbaa !16
  %.not67 = icmp eq i64 %65, 4557430888798830399
  br i1 %.not67, label %69, label %66

66:                                               ; preds = %54
  %67 = load i32, ptr %52, align 4, !tbaa !21
  %.not68.not = icmp slt i32 %.05188, %67
  %68 = add nsw i64 %61, %65
  %spec.select71 = select i1 %.not68.not, i64 %68, i64 4557430888798830399
  br label %69

69:                                               ; preds = %66, %54
  %70 = phi i64 [ 4557430888798830399, %54 ], [ %spec.select71, %66 ]
  %71 = sext i32 %.05188 to i64
  %72 = add nsw i64 %71, 1
  %smin = tail call i32 @llvm.smin.i32(i32 %55, i32 0)
  br label %73

73:                                               ; preds = %89, %69
  %indvars.iv113 = phi i64 [ %indvars.iv.next114, %89 ], [ %72, %69 ]
  %.149 = phi i64 [ %82, %89 ], [ %61, %69 ]
  %.046 = phi i64 [ %90, %89 ], [ %70, %69 ]
  %74 = icmp sgt i64 %indvars.iv113, 0
  br i1 %74, label %75, label %.thread

75:                                               ; preds = %73
  %indvars.iv.next114 = add nsw i64 %indvars.iv113, -1
  %76 = sub nsw i64 %indvars.iv116, %indvars.iv.next114
  %77 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %76
  %78 = load i32, ptr %77, align 4, !tbaa !5
  %79 = sub nsw i32 %78, %50
  %80 = tail call i32 @llvm.abs.i32(i32 %79, i1 true)
  %81 = zext nneg i32 %80 to i64
  %82 = sub nsw i64 %.149, %81
  %83 = getelementptr inbounds [2 x [5001 x i64]], ptr @f, i64 0, i64 %51, i64 %76
  %84 = load i64, ptr %83, align 8, !tbaa !16
  %.not69 = icmp eq i64 %84, 4557430888798830399
  br i1 %.not69, label %89, label %85

85:                                               ; preds = %75
  %86 = load i32, ptr %52, align 4, !tbaa !21
  %87 = sext i32 %86 to i64
  %.not70 = icmp sgt i64 %indvars.iv.next114, %87
  %88 = add nsw i64 %82, %84
  %spec.select72 = select i1 %.not70, i64 4557430888798830399, i64 %88
  br label %89

89:                                               ; preds = %85, %75
  %90 = phi i64 [ 4557430888798830399, %75 ], [ %spec.select72, %85 ]
  %91 = icmp slt i64 %.046, %90
  br i1 %91, label %.thread.split.loop.exit, label %73

.thread.split.loop.exit:                          ; preds = %89
  %92 = trunc nsw i64 %indvars.iv113 to i32
  br label %.thread

.thread:                                          ; preds = %73, %.thread.split.loop.exit
  %.152.lcssa = phi i32 [ %92, %.thread.split.loop.exit ], [ %smin, %73 ]
  %93 = getelementptr inbounds [2 x [5001 x i64]], ptr @f, i64 0, i64 %53, i64 %indvars.iv116
  store i64 %.046, ptr %93, align 8, !tbaa !16
  %indvars.iv.next117 = add nuw nsw i64 %indvars.iv116, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next117, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge93, label %54, !llvm.loop !22
}

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

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

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

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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.abs.i32(i32, i1 immarg) #4

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

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

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare i32 @llvm.vector.reduce.xor.v4i32(<4 x i32>) #5

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 = { 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 #3 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #4 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!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, !13}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !10, !13, !12}
!15 = distinct !{!15, !10}
!16 = !{!17, !17, i64 0}
!17 = !{!"long long", !7, i64 0}
!18 = !{!19, !6, i64 0}
!19 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!20 = distinct !{!20, !10}
!21 = !{!19, !6, i64 4}
!22 = distinct !{!22, !10}


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