; LLVM IR from tangjz/acm-icpc :: hdu (5760)

; 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
@a = external dso_local global [5001 x i32], align 16
@m = external dso_local global i32, align 4
@seq = external dso_local global [5001 x i32], align 16
@pos = external dso_local global [5001 x i32], align 16
@f = external dso_local global [5001 x [5001 x %"struct.std::pair"]], align 16
@dif = external dso_local global [5001 x %"struct.std::pair"], align 16
@ans = external dso_local global %"struct.std::pair", align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [62 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [11 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSERKS0_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #1 align 2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca %"struct.std::pair", 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 %"struct.std::pair", align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca %"struct.std::pair", align 4
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca i32, align 4
  %18 = alloca %"struct.std::pair", align 4
  %19 = alloca i32, align 4
  %20 = alloca i32, align 4
  %21 = alloca i32, align 4
  %22 = alloca %"struct.std::pair", align 4
  %23 = alloca %"struct.std::pair", align 4
  %24 = alloca %"struct.std::pair", align 4
  %25 = alloca i32, align 4
  %26 = alloca i32, align 4
  %27 = alloca i32, align 4
  %28 = alloca i32, align 4
  %29 = alloca %"struct.std::pair", align 4
  store i32 0, ptr %1, align 4
  br label %30

30:                                               ; preds = %292, %0
  %31 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n)
  %32 = icmp eq i32 %31, 1
  br i1 %32, label %33, label %296

33:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #8
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %34

34:                                               ; preds = %58, %33
  %35 = load i32, ptr %2, align 4, !tbaa !5
  %36 = load i32, ptr @n, align 4, !tbaa !5
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #8
  br label %61

39:                                               ; preds = %34
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds i32, ptr @a, i64 %41
  %43 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef %42)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #8
  store i32 1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #8
  store i32 1, ptr %5, align 4, !tbaa !5
  call void @_ZNSt4pairIiiEC2IiiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS3_OS4_(ptr noundef nonnull align 4 dereferenceable(8) %3, ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [5001 x [5001 x %"struct.std::pair"]], ptr @f, i64 0, i64 %45
  %47 = load i32, ptr %2, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr %46, i64 0, i64 %48
  %50 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8) %49, ptr noundef nonnull align 4 dereferenceable(8) %3) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #8
  %51 = load i32, ptr %2, align 4, !tbaa !5
  %52 = sext i32 %51 to i64
  %53 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %52
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = load i32, ptr %2, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [5001 x i32], ptr @seq, i64 0, i64 %56
  store i32 %54, ptr %57, align 4, !tbaa !5
  br label %58

58:                                               ; preds = %39
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = add nsw i32 %59, 1
  store i32 %60, ptr %2, align 4, !tbaa !5
  br label %34, !llvm.loop !9

61:                                               ; preds = %38
  %62 = load i32, ptr @n, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds i32, ptr @seq, i64 %63
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef @seq, ptr noundef %64)
  %65 = load i32, ptr @n, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds i32, ptr @seq, i64 %66
  %68 = call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef @seq, ptr noundef %67)
  %69 = ptrtoint ptr %68 to i64
  %70 = sub i64 %69, ptrtoint (ptr @seq to i64)
  %71 = sdiv exact i64 %70, 4
  %72 = trunc i64 %71 to i32
  store i32 %72, ptr @m, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #8
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %73

73:                                               ; preds = %93, %61
  %74 = load i32, ptr %6, align 4, !tbaa !5
  %75 = load i32, ptr @n, align 4, !tbaa !5
  %76 = icmp slt i32 %74, %75
  br i1 %76, label %78, label %77

77:                                               ; preds = %73
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #8
  br label %96

78:                                               ; preds = %73
  %79 = load i32, ptr @m, align 4, !tbaa !5
  %80 = sext i32 %79 to i64
  %81 = getelementptr inbounds i32, ptr @seq, i64 %80
  %82 = load i32, ptr %6, align 4, !tbaa !5
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %83
  %85 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef @seq, ptr noundef %81, ptr noundef nonnull align 4 dereferenceable(4) %84)
  %86 = ptrtoint ptr %85 to i64
  %87 = sub i64 %86, ptrtoint (ptr @seq to i64)
  %88 = sdiv exact i64 %87, 4
  %89 = trunc i64 %88 to i32
  %90 = load i32, ptr %6, align 4, !tbaa !5
  %91 = sext i32 %90 to i64
  %92 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %91
  store i32 %89, ptr %92, align 4, !tbaa !5
  br label %93

93:                                               ; preds = %78
  %94 = load i32, ptr %6, align 4, !tbaa !5
  %95 = add nsw i32 %94, 1
  store i32 %95, ptr %6, align 4, !tbaa !5
  br label %73, !llvm.loop !11

96:                                               ; preds = %77
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #8
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %97

97:                                               ; preds = %107, %96
  %98 = load i32, ptr %7, align 4, !tbaa !5
  %99 = load i32, ptr @m, align 4, !tbaa !5
  %100 = icmp slt i32 %98, %99
  br i1 %100, label %102, label %101

101:                                              ; preds = %97
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #8
  br label %110

102:                                              ; preds = %97
  %103 = load i32, ptr @n, align 4, !tbaa !5
  %104 = load i32, ptr %7, align 4, !tbaa !5
  %105 = sext i32 %104 to i64
  %106 = getelementptr inbounds [5001 x i32], ptr @pos, i64 0, i64 %105
  store i32 %103, ptr %106, align 4, !tbaa !5
  br label %107

107:                                              ; preds = %102
  %108 = load i32, ptr %7, align 4, !tbaa !5
  %109 = add nsw i32 %108, 1
  store i32 %109, ptr %7, align 4, !tbaa !5
  br label %97, !llvm.loop !12

110:                                              ; preds = %101
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #8
  %111 = load i32, ptr @n, align 4, !tbaa !5
  %112 = sub nsw i32 %111, 1
  store i32 %112, ptr %8, align 4, !tbaa !5
  br label %113

113:                                              ; preds = %249, %110
  %114 = load i32, ptr %8, align 4, !tbaa !5
  %115 = icmp sge i32 %114, 0
  br i1 %115, label %117, label %116

116:                                              ; preds = %113
  store i32 13, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #8
  br label %252

117:                                              ; preds = %113
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #8
  store i32 0, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #8
  store i32 1, ptr %12, align 4, !tbaa !5
  call void @_ZNSt4pairIiiEC2IiiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS3_OS4_(ptr noundef nonnull align 4 dereferenceable(8) %10, ptr noundef nonnull align 4 dereferenceable(4) %11, ptr noundef nonnull align 4 dereferenceable(4) %12)
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #8
  store i32 0, ptr %13, align 4, !tbaa !5
  br label %118

118:                                              ; preds = %128, %117
  %119 = load i32, ptr %13, align 4, !tbaa !5
  %120 = load i32, ptr @m, align 4, !tbaa !5
  %121 = icmp slt i32 %119, %120
  br i1 %121, label %123, label %122

122:                                              ; preds = %118
  store i32 16, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #8
  br label %131

123:                                              ; preds = %118
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #8
  store i32 0, ptr %15, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #8
  store i32 0, ptr %16, align 4, !tbaa !5
  call void @_ZNSt4pairIiiEC2IiiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS3_OS4_(ptr noundef nonnull align 4 dereferenceable(8) %14, ptr noundef nonnull align 4 dereferenceable(4) %15, ptr noundef nonnull align 4 dereferenceable(4) %16)
  %124 = load i32, ptr %13, align 4, !tbaa !5
  %125 = sext i32 %124 to i64
  %126 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr @dif, i64 0, i64 %125
  %127 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8) %126, ptr noundef nonnull align 4 dereferenceable(8) %14) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #8
  br label %128

128:                                              ; preds = %123
  %129 = load i32, ptr %13, align 4, !tbaa !5
  %130 = add nsw i32 %129, 1
  store i32 %130, ptr %13, align 4, !tbaa !5
  br label %118, !llvm.loop !13

131:                                              ; preds = %122
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #8
  %132 = load i32, ptr %8, align 4, !tbaa !5
  %133 = add nsw i32 %132, 1
  store i32 %133, ptr %17, align 4, !tbaa !5
  br label %134

134:                                              ; preds = %238, %131
  %135 = load i32, ptr %17, align 4, !tbaa !5
  %136 = load i32, ptr @n, align 4, !tbaa !5
  %137 = icmp slt i32 %135, %136
  br i1 %137, label %139, label %138

138:                                              ; preds = %134
  store i32 19, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #8
  br label %241

139:                                              ; preds = %134
  %140 = load i32, ptr %17, align 4, !tbaa !5
  %141 = sext i32 %140 to i64
  %142 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %141
  %143 = load i32, ptr %142, align 4, !tbaa !5
  %144 = load i32, ptr %8, align 4, !tbaa !5
  %145 = sext i32 %144 to i64
  %146 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %145
  %147 = load i32, ptr %146, align 4, !tbaa !5
  %148 = icmp sle i32 %143, %147
  br i1 %148, label %149, label %237

149:                                              ; preds = %139
  %150 = load i32, ptr %17, align 4, !tbaa !5
  %151 = sext i32 %150 to i64
  %152 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %151
  %153 = load i32, ptr %152, align 4, !tbaa !5
  %154 = load i32, ptr %8, align 4, !tbaa !5
  %155 = sext i32 %154 to i64
  %156 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %155
  %157 = load i32, ptr %156, align 4, !tbaa !5
  %158 = icmp eq i32 %153, %157
  br i1 %158, label %159, label %171

159:                                              ; preds = %149
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #8
  %160 = getelementptr inbounds %"struct.std::pair", ptr %10, i32 0, i32 0
  %161 = load i32, ptr %160, align 4, !tbaa !14
  %162 = add nsw i32 %161, 2
  store i32 %162, ptr %19, align 4, !tbaa !5
  %163 = getelementptr inbounds %"struct.std::pair", ptr %10, i32 0, i32 1
  call void @_ZNSt4pairIiiEC2IiRiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %18, ptr noundef nonnull align 4 dereferenceable(4) %19, ptr noundef nonnull align 4 dereferenceable(4) %163)
  %164 = load i32, ptr %8, align 4, !tbaa !5
  %165 = sext i32 %164 to i64
  %166 = getelementptr inbounds [5001 x [5001 x %"struct.std::pair"]], ptr @f, i64 0, i64 %165
  %167 = load i32, ptr %17, align 4, !tbaa !5
  %168 = sext i32 %167 to i64
  %169 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr %166, i64 0, i64 %168
  %170 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8) %169, ptr noundef nonnull align 4 dereferenceable(8) %18) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #8
  br label %171

171:                                              ; preds = %159, %149
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #8
  %172 = load i32, ptr %17, align 4, !tbaa !5
  %173 = sext i32 %172 to i64
  %174 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %173
  %175 = load i32, ptr %174, align 4, !tbaa !5
  store i32 %175, ptr %20, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #8
  %176 = load i32, ptr %20, align 4, !tbaa !5
  %177 = sext i32 %176 to i64
  %178 = getelementptr inbounds [5001 x i32], ptr @pos, i64 0, i64 %177
  %179 = load i32, ptr %178, align 4, !tbaa !5
  store i32 %179, ptr %21, align 4, !tbaa !5
  %180 = load i32, ptr %21, align 4, !tbaa !5
  %181 = load i32, ptr %17, align 4, !tbaa !5
  %182 = icmp sle i32 %180, %181
  br i1 %182, label %183, label %236

183:                                              ; preds = %171
  %184 = load i32, ptr %21, align 4, !tbaa !5
  %185 = sext i32 %184 to i64
  %186 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %185
  %187 = load i32, ptr %186, align 4, !tbaa !5
  %188 = load i32, ptr %17, align 4, !tbaa !5
  %189 = sext i32 %188 to i64
  %190 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %189
  %191 = load i32, ptr %190, align 4, !tbaa !5
  %192 = icmp eq i32 %187, %191
  br i1 %192, label %193, label %194

193:                                              ; preds = %183
  br label %196

194:                                              ; preds = %183
  call void @__assert_fail(ptr noundef @.str.2, ptr noundef @.str.3, i32 noundef 37, ptr noundef @__PRETTY_FUNCTION__.main) #9
  unreachable

195:                                              ; No predecessors!
  br label %196

196:                                              ; preds = %195, %193
  %197 = load i32, ptr %20, align 4, !tbaa !5
  %198 = sext i32 %197 to i64
  %199 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr @dif, i64 0, i64 %198
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %22, ptr align 8 %199, i64 8, i1 false)
  %200 = load i64, ptr %22, align 4
  call void @_Z5mergeRSt4pairIiiES0_(ptr noundef nonnull align 4 dereferenceable(8) %10, i64 %200)
  %201 = load i32, ptr %21, align 4, !tbaa !5
  %202 = sext i32 %201 to i64
  %203 = getelementptr inbounds [5001 x [5001 x %"struct.std::pair"]], ptr @f, i64 0, i64 %202
  %204 = load i32, ptr %17, align 4, !tbaa !5
  %205 = sext i32 %204 to i64
  %206 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr %203, i64 0, i64 %205
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %23, ptr align 8 %206, i64 8, i1 false)
  %207 = load i64, ptr %23, align 4
  call void @_Z5mergeRSt4pairIiiES0_(ptr noundef nonnull align 4 dereferenceable(8) %10, i64 %207)
  %208 = load i32, ptr %21, align 4, !tbaa !5
  %209 = sext i32 %208 to i64
  %210 = getelementptr inbounds [5001 x [5001 x %"struct.std::pair"]], ptr @f, i64 0, i64 %209
  %211 = load i32, ptr %17, align 4, !tbaa !5
  %212 = sext i32 %211 to i64
  %213 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr %210, i64 0, i64 %212
  %214 = load i32, ptr %20, align 4, !tbaa !5
  %215 = sext i32 %214 to i64
  %216 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr @dif, i64 0, i64 %215
  %217 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSERKS0_(ptr noundef nonnull align 4 dereferenceable(8) %216, ptr noundef nonnull align 4 dereferenceable(8) %213)
  %218 = load i32, ptr %20, align 4, !tbaa !5
  %219 = sext i32 %218 to i64
  %220 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr @dif, i64 0, i64 %219
  %221 = getelementptr inbounds %"struct.std::pair", ptr %220, i32 0, i32 1
  %222 = load i32, ptr %221, align 4, !tbaa !16
  %223 = icmp ne i32 %222, 0
  br i1 %223, label %224, label %235

224:                                              ; preds = %196
  %225 = load i32, ptr %20, align 4, !tbaa !5
  %226 = sext i32 %225 to i64
  %227 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr @dif, i64 0, i64 %226
  %228 = getelementptr inbounds %"struct.std::pair", ptr %227, i32 0, i32 1
  %229 = load i32, ptr %228, align 4, !tbaa !16
  %230 = sub nsw i32 1000000007, %229
  %231 = load i32, ptr %20, align 4, !tbaa !5
  %232 = sext i32 %231 to i64
  %233 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr @dif, i64 0, i64 %232
  %234 = getelementptr inbounds %"struct.std::pair", ptr %233, i32 0, i32 1
  store i32 %230, ptr %234, align 4, !tbaa !16
  br label %235

235:                                              ; preds = %224, %196
  br label %236

236:                                              ; preds = %235, %171
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #8
  br label %237

237:                                              ; preds = %236, %139
  br label %238

238:                                              ; preds = %237
  %239 = load i32, ptr %17, align 4, !tbaa !5
  %240 = add nsw i32 %239, 1
  store i32 %240, ptr %17, align 4, !tbaa !5
  br label %134, !llvm.loop !17

241:                                              ; preds = %138
  %242 = load i32, ptr %8, align 4, !tbaa !5
  %243 = load i32, ptr %8, align 4, !tbaa !5
  %244 = sext i32 %243 to i64
  %245 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %244
  %246 = load i32, ptr %245, align 4, !tbaa !5
  %247 = sext i32 %246 to i64
  %248 = getelementptr inbounds [5001 x i32], ptr @pos, i64 0, i64 %247
  store i32 %242, ptr %248, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #8
  br label %249

249:                                              ; preds = %241
  %250 = load i32, ptr %8, align 4, !tbaa !5
  %251 = add nsw i32 %250, -1
  store i32 %251, ptr %8, align 4, !tbaa !5
  br label %113, !llvm.loop !18

252:                                              ; preds = %116
  call void @llvm.lifetime.start.p0(i64 8, ptr %24) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #8
  store i32 0, ptr %25, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #8
  store i32 0, ptr %26, align 4, !tbaa !5
  call void @_ZNSt4pairIiiEC2IiiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS3_OS4_(ptr noundef nonnull align 4 dereferenceable(8) %24, ptr noundef nonnull align 4 dereferenceable(4) %25, ptr noundef nonnull align 4 dereferenceable(4) %26)
  %253 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8) @ans, ptr noundef nonnull align 4 dereferenceable(8) %24) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr %24) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr %27) #8
  store i32 0, ptr %27, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %28) #8
  br label %254

254:                                              ; preds = %289, %252
  %255 = load i32, ptr %27, align 4, !tbaa !5
  %256 = load i32, ptr @m, align 4, !tbaa !5
  %257 = icmp slt i32 %255, %256
  br i1 %257, label %259, label %258

258:                                              ; preds = %254
  store i32 22, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %28) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr %27) #8
  br label %292

259:                                              ; preds = %254
  %260 = load i32, ptr @n, align 4, !tbaa !5
  %261 = sub nsw i32 %260, 1
  store i32 %261, ptr %28, align 4, !tbaa !5
  br label %262

262:                                              ; preds = %275, %259
  %263 = load i32, ptr %28, align 4, !tbaa !5
  %264 = icmp sge i32 %263, 0
  br i1 %264, label %265, label %272

265:                                              ; preds = %262
  %266 = load i32, ptr %28, align 4, !tbaa !5
  %267 = sext i32 %266 to i64
  %268 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %267
  %269 = load i32, ptr %268, align 4, !tbaa !5
  %270 = load i32, ptr %27, align 4, !tbaa !5
  %271 = icmp ne i32 %269, %270
  br label %272

272:                                              ; preds = %265, %262
  %273 = phi i1 [ false, %262 ], [ %271, %265 ]
  br i1 %273, label %274, label %278

274:                                              ; preds = %272
  br label %275

275:                                              ; preds = %274
  %276 = load i32, ptr %28, align 4, !tbaa !5
  %277 = add nsw i32 %276, -1
  store i32 %277, ptr %28, align 4, !tbaa !5
  br label %262, !llvm.loop !19

278:                                              ; preds = %272
  %279 = load i32, ptr %27, align 4, !tbaa !5
  %280 = sext i32 %279 to i64
  %281 = getelementptr inbounds [5001 x i32], ptr @pos, i64 0, i64 %280
  %282 = load i32, ptr %281, align 4, !tbaa !5
  %283 = sext i32 %282 to i64
  %284 = getelementptr inbounds [5001 x [5001 x %"struct.std::pair"]], ptr @f, i64 0, i64 %283
  %285 = load i32, ptr %28, align 4, !tbaa !5
  %286 = sext i32 %285 to i64
  %287 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr %284, i64 0, i64 %286
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %29, ptr align 8 %287, i64 8, i1 false)
  %288 = load i64, ptr %29, align 4
  call void @_Z5mergeRSt4pairIiiES0_(ptr noundef nonnull align 4 dereferenceable(8) @ans, i64 %288)
  br label %289

289:                                              ; preds = %278
  %290 = load i32, ptr %27, align 4, !tbaa !5
  %291 = add nsw i32 %290, 1
  store i32 %291, ptr %27, align 4, !tbaa !5
  br label %254, !llvm.loop !20

292:                                              ; preds = %258
  %293 = load i32, ptr @ans, align 4, !tbaa !14
  %294 = load i32, ptr getelementptr inbounds (%"struct.std::pair", ptr @ans, i32 0, i32 1), align 4, !tbaa !16
  %295 = call i32 (ptr, ...) @printf(ptr noundef @.str.4, i32 noundef %293, i32 noundef %294)
  br label %30, !llvm.loop !21

296:                                              ; preds = %30
  ret i32 0
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIiiEC2IiiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS3_OS4_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) #1 align 2

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIiiEC2IiRiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #1 align 2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) #6

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite)
declare void @llvm.memcpy.p0.p0.i64(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i64, i1 immarg) #7

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

attributes #0 = { 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 #1 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress 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 #3 = { "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 nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #6 = { noreturn 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 #7 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #8 = { nounwind }
attributes #9 = { noreturn 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 = !{!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}
!20 = distinct !{!20, !10}
!21 = distinct !{!21, !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
@a = external dso_local global [5001 x i32], align 16
@m = external dso_local local_unnamed_addr global i32, align 4
@seq = external dso_local global [5001 x i32], align 16
@pos = external dso_local local_unnamed_addr global [5001 x i32], align 16
@f = external dso_local global [5001 x [5001 x %"struct.std::pair"]], align 16
@dif = external dso_local global [5001 x %"struct.std::pair"], align 16
@ans = external dso_local global %"struct.std::pair", align 4
@.str = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [15 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [62 x i8], align 1
@__PRETTY_FUNCTION__.main = external hidden unnamed_addr constant [11 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [7 x i8], align 1

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSERKS0_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #1 align 2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca %"struct.std::pair", align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca %"struct.std::pair", align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %"struct.std::pair", align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca %"struct.std::pair", align 4
  %11 = alloca i32, align 4
  %12 = alloca %"struct.std::pair", align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %16 = icmp eq i32 %15, 1
  br i1 %16, label %.preheader72.lr.ph, label %._crit_edge96

.preheader72.lr.ph:                               ; preds = %0
  %17 = getelementptr inbounds i8, ptr %4, i64 4
  br label %.preheader72

.preheader72:                                     ; preds = %.preheader72.lr.ph, %._crit_edge95
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = icmp sgt i32 %18, 0
  br i1 %19, label %.lr.ph, label %.preheader72.._crit_edge_crit_edge

.preheader72.._crit_edge_crit_edge:               ; preds = %.preheader72
  %.pre123 = sext i32 %18 to i64
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.preheader72.._crit_edge_crit_edge
  %.pre-phi = phi i64 [ %.pre123, %.preheader72.._crit_edge_crit_edge ], [ %38, %.lr.ph ]
  %20 = getelementptr inbounds i32, ptr @seq, i64 %.pre-phi
  call void @_ZSt4sortIPiEvT_S1_(ptr noundef nonnull @seq, ptr noundef nonnull %20)
  %21 = load i32, ptr @n, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr @seq, i64 %22
  %24 = call noundef ptr @_ZSt6uniqueIPiET_S1_S1_(ptr noundef nonnull @seq, ptr noundef nonnull %23)
  %25 = ptrtoint ptr %24 to i64
  %26 = sub i64 %25, ptrtoint (ptr @seq to i64)
  %27 = lshr exact i64 %26, 2
  %28 = trunc i64 %27 to i32
  store i32 %28, ptr @m, align 4, !tbaa !5
  %29 = load i32, ptr @n, align 4, !tbaa !5
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %.lr.ph77, label %.preheader71

.lr.ph:                                           ; preds = %.preheader72, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader72 ]
  %31 = getelementptr inbounds i32, ptr @a, i64 %indvars.iv
  %32 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull %31)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #8
  store i32 1, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #8
  store i32 1, ptr %3, align 4, !tbaa !5
  call void @_ZNSt4pairIiiEC2IiiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS3_OS4_(ptr noundef nonnull align 4 dereferenceable(8) %1, ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %33 = getelementptr inbounds [5001 x [5001 x %"struct.std::pair"]], ptr @f, i64 0, i64 %indvars.iv, i64 %indvars.iv
  %34 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8) %33, ptr noundef nonnull align 4 dereferenceable(8) %1) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #8
  %35 = load i32, ptr %31, align 4, !tbaa !5
  %36 = getelementptr inbounds [5001 x i32], ptr @seq, i64 0, i64 %indvars.iv
  store i32 %35, ptr %36, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %37 = load i32, ptr @n, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = icmp slt i64 %indvars.iv.next, %38
  br i1 %39, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.preheader71.loopexit:                            ; preds = %.lr.ph77
  %.pre = load i32, ptr @m, align 4, !tbaa !5
  br label %.preheader71

.preheader71:                                     ; preds = %.preheader71.loopexit, %._crit_edge
  %40 = phi i32 [ %28, %._crit_edge ], [ %.pre, %.preheader71.loopexit ]
  %.lcssa73 = phi i32 [ %29, %._crit_edge ], [ %54, %.preheader71.loopexit ]
  %41 = icmp sgt i32 %40, 0
  br i1 %41, label %.lr.ph80.preheader, label %.preheader70

.lr.ph80.preheader:                               ; preds = %.preheader71
  %wide.trip.count = zext nneg i32 %40 to i64
  %min.iters.check = icmp ult i32 %40, 8
  br i1 %min.iters.check, label %.lr.ph80.preheader128, label %vector.ph

.lr.ph80.preheader128:                            ; preds = %middle.block, %.lr.ph80.preheader
  %indvars.iv103.ph = phi i64 [ 0, %.lr.ph80.preheader ], [ %n.vec, %middle.block ]
  br label %.lr.ph80

vector.ph:                                        ; preds = %.lr.ph80.preheader
  %n.vec = and i64 %wide.trip.count, 2147483640
  %broadcast.splatinsert = insertelement <4 x i32> poison, i32 %.lcssa73, i64 0
  %broadcast.splat = shufflevector <4 x i32> %broadcast.splatinsert, <4 x i32> poison, <4 x i32> zeroinitializer
  br label %vector.body

vector.body:                                      ; preds = %vector.body, %vector.ph
  %index = phi i64 [ 0, %vector.ph ], [ %index.next, %vector.body ]
  %42 = getelementptr inbounds [5001 x i32], ptr @pos, i64 0, i64 %index
  %43 = getelementptr inbounds i8, ptr %42, i64 16
  store <4 x i32> %broadcast.splat, ptr %42, align 16, !tbaa !5
  store <4 x i32> %broadcast.splat, ptr %43, align 16, !tbaa !5
  %index.next = add nuw i64 %index, 8
  %44 = icmp eq i64 %index.next, %n.vec
  br i1 %44, label %middle.block, label %vector.body, !llvm.loop !11

middle.block:                                     ; preds = %vector.body
  %cmp.n = icmp eq i64 %n.vec, %wide.trip.count
  br i1 %cmp.n, label %.preheader70, label %.lr.ph80.preheader128

.lr.ph77:                                         ; preds = %._crit_edge, %.lr.ph77
  %indvars.iv100 = phi i64 [ %indvars.iv.next101, %.lr.ph77 ], [ 0, %._crit_edge ]
  %45 = load i32, ptr @m, align 4, !tbaa !5
  %46 = sext i32 %45 to i64
  %47 = getelementptr inbounds i32, ptr @seq, i64 %46
  %48 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %indvars.iv100
  %49 = call noundef ptr @_ZSt11lower_boundIPiiET_S1_S1_RKT0_(ptr noundef nonnull @seq, ptr noundef nonnull %47, ptr noundef nonnull align 4 dereferenceable(4) %48)
  %50 = ptrtoint ptr %49 to i64
  %51 = sub i64 %50, ptrtoint (ptr @seq to i64)
  %52 = lshr exact i64 %51, 2
  %53 = trunc i64 %52 to i32
  store i32 %53, ptr %48, align 4, !tbaa !5
  %indvars.iv.next101 = add nuw nsw i64 %indvars.iv100, 1
  %54 = load i32, ptr @n, align 4, !tbaa !5
  %55 = sext i32 %54 to i64
  %56 = icmp slt i64 %indvars.iv.next101, %55
  br i1 %56, label %.lr.ph77, label %.preheader71.loopexit, !llvm.loop !14

.preheader70:                                     ; preds = %.lr.ph80, %middle.block, %.preheader71
  %57 = icmp sgt i32 %.lcssa73, 0
  br i1 %57, label %.lr.ph90.preheader, label %._crit_edge91

.lr.ph90.preheader:                               ; preds = %.preheader70
  %58 = zext nneg i32 %.lcssa73 to i64
  br label %.lr.ph90

.lr.ph80:                                         ; preds = %.lr.ph80.preheader128, %.lr.ph80
  %indvars.iv103 = phi i64 [ %indvars.iv.next104, %.lr.ph80 ], [ %indvars.iv103.ph, %.lr.ph80.preheader128 ]
  %59 = getelementptr inbounds [5001 x i32], ptr @pos, i64 0, i64 %indvars.iv103
  store i32 %.lcssa73, ptr %59, align 4, !tbaa !5
  %indvars.iv.next104 = add nuw nsw i64 %indvars.iv103, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next104, %wide.trip.count
  br i1 %exitcond.not, label %.preheader70, label %.lr.ph80, !llvm.loop !15

._crit_edge91:                                    ; preds = %._crit_edge86, %.preheader70
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %12) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %13) #8
  store i32 0, ptr %13, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %14) #8
  store i32 0, ptr %14, align 4, !tbaa !5
  call void @_ZNSt4pairIiiEC2IiiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS3_OS4_(ptr noundef nonnull align 4 dereferenceable(8) %12, ptr noundef nonnull align 4 dereferenceable(4) %13, ptr noundef nonnull align 4 dereferenceable(4) %14)
  %60 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8) @ans, ptr noundef nonnull align 4 dereferenceable(8) %12) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %14) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %13) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %12) #8
  %61 = load i32, ptr @m, align 4, !tbaa !5
  %62 = icmp sgt i32 %61, 0
  br i1 %62, label %.lr.ph94, label %._crit_edge95

.lr.ph90:                                         ; preds = %.lr.ph90.preheader, %._crit_edge86
  %indvars.iv109 = phi i64 [ %58, %.lr.ph90.preheader ], [ %indvars.iv.next110, %._crit_edge86 ]
  %indvars.iv.next110 = add nsw i64 %indvars.iv109, -1
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #8
  store i32 0, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #8
  store i32 1, ptr %6, align 4, !tbaa !5
  call void @_ZNSt4pairIiiEC2IiiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS3_OS4_(ptr noundef nonnull align 4 dereferenceable(8) %4, ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #8
  %63 = load i32, ptr @m, align 4, !tbaa !5
  %64 = icmp sgt i32 %63, 0
  br i1 %64, label %.lr.ph83, label %.preheader

.preheader:                                       ; preds = %.lr.ph83, %.lr.ph90
  %65 = load i32, ptr @n, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = icmp slt i64 %indvars.iv109, %66
  br i1 %67, label %.lr.ph85, label %._crit_edge86

.lr.ph85:                                         ; preds = %.preheader
  %68 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %indvars.iv.next110
  br label %80

.lr.ph83:                                         ; preds = %.lr.ph90, %.lr.ph83
  %indvars.iv106 = phi i64 [ %indvars.iv.next107, %.lr.ph83 ], [ 0, %.lr.ph90 ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #8
  store i32 0, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %9) #8
  store i32 0, ptr %9, align 4, !tbaa !5
  call void @_ZNSt4pairIiiEC2IiiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS3_OS4_(ptr noundef nonnull align 4 dereferenceable(8) %7, ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %69 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr @dif, i64 0, i64 %indvars.iv106
  %70 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8) %69, ptr noundef nonnull align 4 dereferenceable(8) %7) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %9) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #8
  %indvars.iv.next107 = add nuw nsw i64 %indvars.iv106, 1
  %71 = load i32, ptr @m, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = icmp slt i64 %indvars.iv.next107, %72
  br i1 %73, label %.lr.ph83, label %.preheader, !llvm.loop !16

._crit_edge86:                                    ; preds = %111, %.preheader
  %74 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %indvars.iv.next110
  %75 = load i32, ptr %74, align 4, !tbaa !5
  %76 = sext i32 %75 to i64
  %77 = getelementptr inbounds [5001 x i32], ptr @pos, i64 0, i64 %76
  %78 = trunc nuw nsw i64 %indvars.iv.next110 to i32
  store i32 %78, ptr %77, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #8
  %79 = icmp sgt i64 %indvars.iv109, 1
  br i1 %79, label %.lr.ph90, label %._crit_edge91, !llvm.loop !17

80:                                               ; preds = %.lr.ph85, %111
  %indvars.iv111 = phi i64 [ %indvars.iv109, %.lr.ph85 ], [ %indvars.iv.next112, %111 ]
  %81 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %indvars.iv111
  %82 = load i32, ptr %81, align 4, !tbaa !5
  %83 = load i32, ptr %68, align 4, !tbaa !5
  %.not67 = icmp sgt i32 %82, %83
  br i1 %.not67, label %111, label %84

84:                                               ; preds = %80
  %85 = icmp eq i32 %82, %83
  br i1 %85, label %86, label %91

86:                                               ; preds = %84
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %11) #8
  %87 = load i32, ptr %4, align 4, !tbaa !18
  %88 = add nsw i32 %87, 2
  store i32 %88, ptr %11, align 4, !tbaa !5
  call void @_ZNSt4pairIiiEC2IiRiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %10, ptr noundef nonnull align 4 dereferenceable(4) %11, ptr noundef nonnull align 4 dereferenceable(4) %17)
  %89 = getelementptr inbounds [5001 x [5001 x %"struct.std::pair"]], ptr @f, i64 0, i64 %indvars.iv.next110, i64 %indvars.iv111
  %90 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8) %89, ptr noundef nonnull align 4 dereferenceable(8) %10) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %11) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #8
  %.pre122 = load i32, ptr %81, align 4, !tbaa !5
  br label %91

91:                                               ; preds = %86, %84
  %92 = phi i32 [ %.pre122, %86 ], [ %82, %84 ]
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [5001 x i32], ptr @pos, i64 0, i64 %93
  %95 = load i32, ptr %94, align 4, !tbaa !5
  %96 = trunc nuw i64 %indvars.iv111 to i32
  %.not68 = icmp sgt i32 %95, %96
  br i1 %.not68, label %111, label %97

97:                                               ; preds = %91
  %98 = sext i32 %95 to i64
  %99 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %98
  %100 = load i32, ptr %99, align 4, !tbaa !5
  %101 = icmp eq i32 %100, %92
  br i1 %101, label %103, label %102

102:                                              ; preds = %97
  call void @__assert_fail(ptr noundef nonnull @.str.2, ptr noundef nonnull @.str.3, i32 noundef 37, ptr noundef nonnull @__PRETTY_FUNCTION__.main) #9
  unreachable

103:                                              ; preds = %97
  %104 = getelementptr inbounds [5001 x %"struct.std::pair"], ptr @dif, i64 0, i64 %93
  %.sroa.09.0.copyload = load i64, ptr %104, align 8
  call void @_Z5mergeRSt4pairIiiES0_(ptr noundef nonnull align 4 dereferenceable(8) %4, i64 %.sroa.09.0.copyload)
  %105 = getelementptr inbounds [5001 x [5001 x %"struct.std::pair"]], ptr @f, i64 0, i64 %98, i64 %indvars.iv111
  %.sroa.08.0.copyload = load i64, ptr %105, align 8
  call void @_Z5mergeRSt4pairIiiES0_(ptr noundef nonnull align 4 dereferenceable(8) %4, i64 %.sroa.08.0.copyload)
  %106 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSERKS0_(ptr noundef nonnull align 4 dereferenceable(8) %104, ptr noundef nonnull align 4 dereferenceable(8) %105)
  %107 = getelementptr inbounds i8, ptr %104, i64 4
  %108 = load i32, ptr %107, align 4, !tbaa !20
  %.not69 = icmp eq i32 %108, 0
  br i1 %.not69, label %111, label %109

109:                                              ; preds = %103
  %110 = sub nsw i32 1000000007, %108
  store i32 %110, ptr %107, align 4, !tbaa !20
  br label %111

111:                                              ; preds = %91, %109, %103, %80
  %indvars.iv.next112 = add nuw nsw i64 %indvars.iv111, 1
  %112 = load i32, ptr @n, align 4, !tbaa !5
  %113 = trunc nuw i64 %indvars.iv.next112 to i32
  %114 = icmp sgt i32 %112, %113
  br i1 %114, label %80, label %._crit_edge86, !llvm.loop !21

._crit_edge95:                                    ; preds = %.critedge, %._crit_edge91
  %115 = load i32, ptr @ans, align 4, !tbaa !18
  %116 = load i32, ptr getelementptr inbounds (i8, ptr @ans, i64 4), align 4, !tbaa !20
  %117 = call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.4, i32 noundef %115, i32 noundef %116)
  %118 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n)
  %119 = icmp eq i32 %118, 1
  br i1 %119, label %.preheader72, label %._crit_edge96, !llvm.loop !22

.lr.ph94:                                         ; preds = %._crit_edge91, %.critedge
  %indvars.iv118 = phi i64 [ %indvars.iv.next119, %.critedge ], [ 0, %._crit_edge91 ]
  %120 = load i32, ptr @n, align 4, !tbaa !5
  %121 = zext i32 %120 to i64
  %smin = call i32 @llvm.smin.i32(i32 %120, i32 0)
  %122 = add i32 %smin, -1
  br label %123

123:                                              ; preds = %126, %.lr.ph94
  %indvars.iv115 = phi i64 [ %indvars.iv.next116, %126 ], [ %121, %.lr.ph94 ]
  %124 = trunc nuw i64 %indvars.iv115 to i32
  %125 = icmp sgt i32 %124, 0
  br i1 %125, label %126, label %.critedge

126:                                              ; preds = %123
  %indvars.iv.next116 = add nsw i64 %indvars.iv115, -1
  %127 = and i64 %indvars.iv.next116, 4294967295
  %128 = getelementptr inbounds [5001 x i32], ptr @a, i64 0, i64 %127
  %129 = load i32, ptr %128, align 4, !tbaa !5
  %130 = zext i32 %129 to i64
  %.not = icmp eq i64 %indvars.iv118, %130
  br i1 %.not, label %.critedge.split.loop.exit125, label %123, !llvm.loop !23

.critedge.split.loop.exit125:                     ; preds = %126
  %indvars.le = trunc i64 %indvars.iv.next116 to i32
  br label %.critedge

.critedge:                                        ; preds = %123, %.critedge.split.loop.exit125
  %.055.lcssa = phi i32 [ %indvars.le, %.critedge.split.loop.exit125 ], [ %122, %123 ]
  %131 = getelementptr inbounds [5001 x i32], ptr @pos, i64 0, i64 %indvars.iv118
  %132 = load i32, ptr %131, align 4, !tbaa !5
  %133 = sext i32 %132 to i64
  %134 = sext i32 %.055.lcssa to i64
  %135 = getelementptr inbounds [5001 x [5001 x %"struct.std::pair"]], ptr @f, i64 0, i64 %133, i64 %134
  %.sroa.0.0.copyload = load i64, ptr %135, align 8
  call void @_Z5mergeRSt4pairIiiES0_(ptr noundef nonnull align 4 dereferenceable(8) @ans, i64 %.sroa.0.0.copyload)
  %indvars.iv.next119 = add nuw nsw i64 %indvars.iv118, 1
  %136 = load i32, ptr @m, align 4, !tbaa !5
  %137 = sext i32 %136 to i64
  %138 = icmp slt i64 %indvars.iv.next119, %137
  br i1 %138, label %.lr.ph94, label %._crit_edge95, !llvm.loop !24

._crit_edge96:                                    ; preds = %._crit_edge95, %0
  ret i32 0
}

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIiiEC2IiiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS3_S4_EEEbE4typeELb1EEEOS3_OS4_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #1 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #1 align 2

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIiiEC2IiRiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) unnamed_addr #1 align 2

; Function Attrs: noreturn nounwind
declare void @__assert_fail(ptr noundef, ptr noundef, i32 noundef, ptr noundef) local_unnamed_addr #6

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

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

attributes #0 = { 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 #1 = { mustprogress nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress 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 #3 = { 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 #4 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #5 = { 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 #6 = { noreturn 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 #7 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #8 = { nounwind }
attributes #9 = { noreturn 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}
!12 = !{!"llvm.loop.isvectorized", i32 1}
!13 = !{!"llvm.loop.unroll.runtime.disable"}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10, !13, !12}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !10}
!18 = !{!19, !6, i64 0}
!19 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!20 = !{!19, !6, i64 4}
!21 = distinct !{!21, !10}
!22 = distinct !{!22, !10}
!23 = distinct !{!23, !10}
!24 = distinct !{!24, !10}


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