; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/87 Beta Division 2/Problem B (B)

; Unoptimized IR (clang -disable-llvm-passes):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::pair<int, std::pair<int, int>>, std::allocator<std::pair<int, std::pair<int, int>>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::pair<int, std::pair<int, int>>, std::allocator<std::pair<int, std::pair<int, int>>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::pair<int, std::pair<int, int>>, std::allocator<std::pair<int, std::pair<int, int>>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::pair<int, std::pair<int, int>>, std::allocator<std::pair<int, std::pair<int, int>>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.std::pair" = type { i32, %"struct.std::pair.3" }
%"struct.std::pair.3" = type { i32, i32 }
%"class.__gnu_cxx::__normal_iterator" = type { ptr }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@cnt2 = external dso_local global i32, align 4
@res = external dso_local global i32, align 4
@grid = external dso_local global [12 x [12 x i32]], align 16
@cnt = external dso_local global [12 x [12 x i32]], align 16
@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 personality ptr @__gxx_personality_v0 {
  %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 %"class.std::vector", align 8
  %10 = alloca %"struct.std::pair", align 4
  %11 = alloca %"struct.std::pair.3", align 4
  %12 = alloca i32, align 4
  %13 = alloca ptr, align 8
  %14 = alloca i32, align 4
  %15 = alloca { i64, i32 }, align 8
  %16 = alloca %"struct.std::pair", align 4
  %17 = alloca %"struct.std::pair.3", align 4
  %18 = alloca i32, align 4
  %19 = alloca { i64, i32 }, align 8
  %20 = alloca %"struct.std::pair", align 4
  %21 = alloca %"struct.std::pair.3", align 4
  %22 = alloca i32, align 4
  %23 = alloca { i64, i32 }, align 8
  %24 = alloca %"struct.std::pair", align 4
  %25 = alloca %"struct.std::pair.3", align 4
  %26 = alloca i32, align 4
  %27 = alloca { i64, i32 }, align 8
  %28 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %29 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  store i32 0, ptr %1, align 4
  %30 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #7
  store i32 1, ptr %2, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %86, %0
  %32 = load i32, ptr %2, align 4, !tbaa !5
  %33 = load i32, ptr @n, align 4, !tbaa !5
  %34 = icmp sle i32 %32, %33
  br i1 %34, label %36, label %35

35:                                               ; preds = %31
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #7
  br label %89

36:                                               ; preds = %31
  %37 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11)
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  store i32 1, ptr %4, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %82, %36
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = load i32, ptr @m, align 4, !tbaa !5
  %41 = icmp sle i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #7
  br label %85

43:                                               ; preds = %38
  %44 = load i32, ptr %4, align 4, !tbaa !5
  %45 = sub nsw i32 %44, 1
  %46 = sext i32 %45 to i64
  %47 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %46)
  %48 = load i8, ptr %47, align 1, !tbaa !9
  %49 = sext i8 %48 to i32
  %50 = icmp eq i32 %49, 46
  br i1 %50, label %51, label %58

51:                                               ; preds = %43
  %52 = load i32, ptr %2, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %53
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = sext i32 %55 to i64
  %57 = getelementptr inbounds [12 x i32], ptr %54, i64 0, i64 %56
  store i32 0, ptr %57, align 4, !tbaa !5
  br label %81

58:                                               ; preds = %43
  %59 = load i32, ptr %4, align 4, !tbaa !5
  %60 = sub nsw i32 %59, 1
  %61 = sext i32 %60 to i64
  %62 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %61)
  %63 = load i8, ptr %62, align 1, !tbaa !9
  %64 = sext i8 %63 to i32
  %65 = icmp eq i32 %64, 80
  br i1 %65, label %66, label %73

66:                                               ; preds = %58
  %67 = load i32, ptr %2, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %68
  %70 = load i32, ptr %4, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [12 x i32], ptr %69, i64 0, i64 %71
  store i32 1, ptr %72, align 4, !tbaa !5
  br label %80

73:                                               ; preds = %58
  %74 = load i32, ptr %2, align 4, !tbaa !5
  %75 = sext i32 %74 to i64
  %76 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %75
  %77 = load i32, ptr %4, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [12 x i32], ptr %76, i64 0, i64 %78
  store i32 2, ptr %79, align 4, !tbaa !5
  br label %80

80:                                               ; preds = %73, %66
  br label %81

81:                                               ; preds = %80, %51
  br label %82

82:                                               ; preds = %81
  %83 = load i32, ptr %4, align 4, !tbaa !5
  %84 = add nsw i32 %83, 1
  store i32 %84, ptr %4, align 4, !tbaa !5
  br label %38, !llvm.loop !10

85:                                               ; preds = %42
  br label %86

86:                                               ; preds = %85
  %87 = load i32, ptr %2, align 4, !tbaa !5
  %88 = add nsw i32 %87, 1
  store i32 %88, ptr %2, align 4, !tbaa !5
  br label %31, !llvm.loop !12

89:                                               ; preds = %35
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %90

90:                                               ; preds = %165, %89
  %91 = load i32, ptr %5, align 4, !tbaa !5
  %92 = load i32, ptr @n, align 4, !tbaa !5
  %93 = icmp sle i32 %91, %92
  br i1 %93, label %95, label %94

94:                                               ; preds = %90
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  br label %168

95:                                               ; preds = %90
  store i32 0, ptr @cnt2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %96

96:                                               ; preds = %161, %95
  %97 = load i32, ptr %6, align 4, !tbaa !5
  %98 = load i32, ptr @m, align 4, !tbaa !5
  %99 = icmp sle i32 %97, %98
  br i1 %99, label %101, label %100

100:                                              ; preds = %96
  store i32 11, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  br label %164

101:                                              ; preds = %96
  %102 = load i32, ptr %5, align 4, !tbaa !5
  %103 = sub nsw i32 %102, 1
  %104 = sext i32 %103 to i64
  %105 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %104
  %106 = load i32, ptr %6, align 4, !tbaa !5
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds [12 x i32], ptr %105, i64 0, i64 %107
  %109 = load i32, ptr %108, align 4, !tbaa !5
  %110 = icmp eq i32 %109, 1
  br i1 %110, label %111, label %114

111:                                              ; preds = %101
  %112 = load i32, ptr @cnt2, align 4, !tbaa !5
  %113 = add nsw i32 %112, 1
  store i32 %113, ptr @cnt2, align 4, !tbaa !5
  br label %114

114:                                              ; preds = %111, %101
  %115 = load i32, ptr %5, align 4, !tbaa !5
  %116 = add nsw i32 %115, 1
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %117
  %119 = load i32, ptr %6, align 4, !tbaa !5
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds [12 x i32], ptr %118, i64 0, i64 %120
  %122 = load i32, ptr %121, align 4, !tbaa !5
  %123 = icmp eq i32 %122, 1
  br i1 %123, label %124, label %127

124:                                              ; preds = %114
  %125 = load i32, ptr @cnt2, align 4, !tbaa !5
  %126 = add nsw i32 %125, 1
  store i32 %126, ptr @cnt2, align 4, !tbaa !5
  br label %127

127:                                              ; preds = %124, %114
  %128 = load i32, ptr %5, align 4, !tbaa !5
  %129 = sext i32 %128 to i64
  %130 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %129
  %131 = load i32, ptr %6, align 4, !tbaa !5
  %132 = sub nsw i32 %131, 1
  %133 = sext i32 %132 to i64
  %134 = getelementptr inbounds [12 x i32], ptr %130, i64 0, i64 %133
  %135 = load i32, ptr %134, align 4, !tbaa !5
  %136 = icmp eq i32 %135, 1
  br i1 %136, label %137, label %140

137:                                              ; preds = %127
  %138 = load i32, ptr @cnt2, align 4, !tbaa !5
  %139 = add nsw i32 %138, 1
  store i32 %139, ptr @cnt2, align 4, !tbaa !5
  br label %140

140:                                              ; preds = %137, %127
  %141 = load i32, ptr %5, align 4, !tbaa !5
  %142 = sext i32 %141 to i64
  %143 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %142
  %144 = load i32, ptr %6, align 4, !tbaa !5
  %145 = add nsw i32 %144, 1
  %146 = sext i32 %145 to i64
  %147 = getelementptr inbounds [12 x i32], ptr %143, i64 0, i64 %146
  %148 = load i32, ptr %147, align 4, !tbaa !5
  %149 = icmp eq i32 %148, 1
  br i1 %149, label %150, label %153

150:                                              ; preds = %140
  %151 = load i32, ptr @cnt2, align 4, !tbaa !5
  %152 = add nsw i32 %151, 1
  store i32 %152, ptr @cnt2, align 4, !tbaa !5
  br label %153

153:                                              ; preds = %150, %140
  %154 = load i32, ptr @cnt2, align 4, !tbaa !5
  %155 = load i32, ptr %5, align 4, !tbaa !5
  %156 = sext i32 %155 to i64
  %157 = getelementptr inbounds [12 x [12 x i32]], ptr @cnt, i64 0, i64 %156
  %158 = load i32, ptr %6, align 4, !tbaa !5
  %159 = sext i32 %158 to i64
  %160 = getelementptr inbounds [12 x i32], ptr %157, i64 0, i64 %159
  store i32 %154, ptr %160, align 4, !tbaa !5
  br label %161

161:                                              ; preds = %153
  %162 = load i32, ptr %6, align 4, !tbaa !5
  %163 = add nsw i32 %162, 1
  store i32 %163, ptr %6, align 4, !tbaa !5
  br label %96, !llvm.loop !13

164:                                              ; preds = %100
  br label %165

165:                                              ; preds = %164
  %166 = load i32, ptr %5, align 4, !tbaa !5
  %167 = add nsw i32 %166, 1
  store i32 %167, ptr %5, align 4, !tbaa !5
  br label %90, !llvm.loop !14

168:                                              ; preds = %94
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  store i32 1, ptr %7, align 4, !tbaa !5
  br label %169

169:                                              ; preds = %349, %168
  %170 = load i32, ptr %7, align 4, !tbaa !5
  %171 = load i32, ptr @n, align 4, !tbaa !5
  %172 = icmp sle i32 %170, %171
  br i1 %172, label %174, label %173

173:                                              ; preds = %169
  store i32 14, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  br label %352

174:                                              ; preds = %169
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  store i32 1, ptr %8, align 4, !tbaa !5
  br label %175

175:                                              ; preds = %345, %174
  %176 = load i32, ptr %8, align 4, !tbaa !5
  %177 = load i32, ptr @m, align 4, !tbaa !5
  %178 = icmp sle i32 %176, %177
  br i1 %178, label %180, label %179

179:                                              ; preds = %175
  store i32 17, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  br label %348

180:                                              ; preds = %175
  %181 = load i32, ptr %7, align 4, !tbaa !5
  %182 = sext i32 %181 to i64
  %183 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %182
  %184 = load i32, ptr %8, align 4, !tbaa !5
  %185 = sext i32 %184 to i64
  %186 = getelementptr inbounds [12 x i32], ptr %183, i64 0, i64 %185
  %187 = load i32, ptr %186, align 4, !tbaa !5
  %188 = icmp eq i32 %187, 1
  br i1 %188, label %189, label %344

189:                                              ; preds = %180
  call void @llvm.lifetime.start.p0(i64 24, ptr %9) #7
  call void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %9) #7
  %190 = load i32, ptr %7, align 4, !tbaa !5
  %191 = sub nsw i32 %190, 1
  %192 = sext i32 %191 to i64
  %193 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %192
  %194 = load i32, ptr %8, align 4, !tbaa !5
  %195 = sext i32 %194 to i64
  %196 = getelementptr inbounds [12 x i32], ptr %193, i64 0, i64 %195
  %197 = load i32, ptr %196, align 4, !tbaa !5
  %198 = icmp eq i32 %197, 2
  br i1 %198, label %199, label %218

199:                                              ; preds = %189
  call void @llvm.lifetime.start.p0(i64 12, ptr %10) #7
  %200 = load i32, ptr %7, align 4, !tbaa !5
  %201 = sub nsw i32 %200, 1
  %202 = sext i32 %201 to i64
  %203 = getelementptr inbounds [12 x [12 x i32]], ptr @cnt, i64 0, i64 %202
  %204 = load i32, ptr %8, align 4, !tbaa !5
  %205 = sext i32 %204 to i64
  %206 = getelementptr inbounds [12 x i32], ptr %203, i64 0, i64 %205
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  %207 = load i32, ptr %7, align 4, !tbaa !5
  %208 = sub nsw i32 %207, 1
  store i32 %208, ptr %12, align 4, !tbaa !5
  %209 = invoke i64 @_ZSt9make_pairIiRiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %12, ptr noundef nonnull align 4 dereferenceable(4) %8)
          to label %210 unwind label %214

210:                                              ; preds = %199
  store i64 %209, ptr %11, align 4
  %211 = invoke { i64, i32 } @_ZSt9make_pairIRiSt4pairIiiEES1_INSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS3_INS4_IT0_E4typeEE6__typeEEOS5_OSA_(ptr noundef nonnull align 4 dereferenceable(4) %206, ptr noundef nonnull align 4 dereferenceable(8) %11)
          to label %212 unwind label %214

212:                                              ; preds = %210
  store { i64, i32 } %211, ptr %15, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %10, ptr align 8 %15, i64 12, i1 false)
  invoke void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE9push_backEOS2_(ptr noundef nonnull align 8 dereferenceable(24) %9, ptr noundef nonnull align 4 dereferenceable(12) %10)
          to label %213 unwind label %214

213:                                              ; preds = %212
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr %10) #7
  br label %218

214:                                              ; preds = %212, %210, %199
  %215 = landingpad { ptr, i32 }
          cleanup
  %216 = extractvalue { ptr, i32 } %215, 0
  store ptr %216, ptr %13, align 8
  %217 = extractvalue { ptr, i32 } %215, 1
  store i32 %217, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr %10) #7
  br label %343

218:                                              ; preds = %213, %189
  %219 = load i32, ptr %7, align 4, !tbaa !5
  %220 = add nsw i32 %219, 1
  %221 = sext i32 %220 to i64
  %222 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %221
  %223 = load i32, ptr %8, align 4, !tbaa !5
  %224 = sext i32 %223 to i64
  %225 = getelementptr inbounds [12 x i32], ptr %222, i64 0, i64 %224
  %226 = load i32, ptr %225, align 4, !tbaa !5
  %227 = icmp eq i32 %226, 2
  br i1 %227, label %228, label %247

228:                                              ; preds = %218
  call void @llvm.lifetime.start.p0(i64 12, ptr %16) #7
  %229 = load i32, ptr %7, align 4, !tbaa !5
  %230 = add nsw i32 %229, 1
  %231 = sext i32 %230 to i64
  %232 = getelementptr inbounds [12 x [12 x i32]], ptr @cnt, i64 0, i64 %231
  %233 = load i32, ptr %8, align 4, !tbaa !5
  %234 = sext i32 %233 to i64
  %235 = getelementptr inbounds [12 x i32], ptr %232, i64 0, i64 %234
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #7
  %236 = load i32, ptr %7, align 4, !tbaa !5
  %237 = add nsw i32 %236, 1
  store i32 %237, ptr %18, align 4, !tbaa !5
  %238 = invoke i64 @_ZSt9make_pairIiRiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %18, ptr noundef nonnull align 4 dereferenceable(4) %8)
          to label %239 unwind label %243

239:                                              ; preds = %228
  store i64 %238, ptr %17, align 4
  %240 = invoke { i64, i32 } @_ZSt9make_pairIRiSt4pairIiiEES1_INSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS3_INS4_IT0_E4typeEE6__typeEEOS5_OSA_(ptr noundef nonnull align 4 dereferenceable(4) %235, ptr noundef nonnull align 4 dereferenceable(8) %17)
          to label %241 unwind label %243

241:                                              ; preds = %239
  store { i64, i32 } %240, ptr %19, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 8 %19, i64 12, i1 false)
  invoke void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE9push_backEOS2_(ptr noundef nonnull align 8 dereferenceable(24) %9, ptr noundef nonnull align 4 dereferenceable(12) %16)
          to label %242 unwind label %243

242:                                              ; preds = %241
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr %16) #7
  br label %247

243:                                              ; preds = %241, %239, %228
  %244 = landingpad { ptr, i32 }
          cleanup
  %245 = extractvalue { ptr, i32 } %244, 0
  store ptr %245, ptr %13, align 8
  %246 = extractvalue { ptr, i32 } %244, 1
  store i32 %246, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr %16) #7
  br label %343

247:                                              ; preds = %242, %218
  %248 = load i32, ptr %7, align 4, !tbaa !5
  %249 = sext i32 %248 to i64
  %250 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %249
  %251 = load i32, ptr %8, align 4, !tbaa !5
  %252 = sub nsw i32 %251, 1
  %253 = sext i32 %252 to i64
  %254 = getelementptr inbounds [12 x i32], ptr %250, i64 0, i64 %253
  %255 = load i32, ptr %254, align 4, !tbaa !5
  %256 = icmp eq i32 %255, 2
  br i1 %256, label %257, label %276

257:                                              ; preds = %247
  call void @llvm.lifetime.start.p0(i64 12, ptr %20) #7
  %258 = load i32, ptr %7, align 4, !tbaa !5
  %259 = sext i32 %258 to i64
  %260 = getelementptr inbounds [12 x [12 x i32]], ptr @cnt, i64 0, i64 %259
  %261 = load i32, ptr %8, align 4, !tbaa !5
  %262 = sub nsw i32 %261, 1
  %263 = sext i32 %262 to i64
  %264 = getelementptr inbounds [12 x i32], ptr %260, i64 0, i64 %263
  call void @llvm.lifetime.start.p0(i64 8, ptr %21) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %22) #7
  %265 = load i32, ptr %8, align 4, !tbaa !5
  %266 = sub nsw i32 %265, 1
  store i32 %266, ptr %22, align 4, !tbaa !5
  %267 = invoke i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %7, ptr noundef nonnull align 4 dereferenceable(4) %22)
          to label %268 unwind label %272

268:                                              ; preds = %257
  store i64 %267, ptr %21, align 4
  %269 = invoke { i64, i32 } @_ZSt9make_pairIRiSt4pairIiiEES1_INSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS3_INS4_IT0_E4typeEE6__typeEEOS5_OSA_(ptr noundef nonnull align 4 dereferenceable(4) %264, ptr noundef nonnull align 4 dereferenceable(8) %21)
          to label %270 unwind label %272

270:                                              ; preds = %268
  store { i64, i32 } %269, ptr %23, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %20, ptr align 8 %23, i64 12, i1 false)
  invoke void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE9push_backEOS2_(ptr noundef nonnull align 8 dereferenceable(24) %9, ptr noundef nonnull align 4 dereferenceable(12) %20)
          to label %271 unwind label %272

271:                                              ; preds = %270
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr %20) #7
  br label %276

272:                                              ; preds = %270, %268, %257
  %273 = landingpad { ptr, i32 }
          cleanup
  %274 = extractvalue { ptr, i32 } %273, 0
  store ptr %274, ptr %13, align 8
  %275 = extractvalue { ptr, i32 } %273, 1
  store i32 %275, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %22) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %21) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr %20) #7
  br label %343

276:                                              ; preds = %271, %247
  %277 = load i32, ptr %7, align 4, !tbaa !5
  %278 = sext i32 %277 to i64
  %279 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %278
  %280 = load i32, ptr %8, align 4, !tbaa !5
  %281 = add nsw i32 %280, 1
  %282 = sext i32 %281 to i64
  %283 = getelementptr inbounds [12 x i32], ptr %279, i64 0, i64 %282
  %284 = load i32, ptr %283, align 4, !tbaa !5
  %285 = icmp eq i32 %284, 2
  br i1 %285, label %286, label %305

286:                                              ; preds = %276
  call void @llvm.lifetime.start.p0(i64 12, ptr %24) #7
  %287 = load i32, ptr %7, align 4, !tbaa !5
  %288 = sext i32 %287 to i64
  %289 = getelementptr inbounds [12 x [12 x i32]], ptr @cnt, i64 0, i64 %288
  %290 = load i32, ptr %8, align 4, !tbaa !5
  %291 = add nsw i32 %290, 1
  %292 = sext i32 %291 to i64
  %293 = getelementptr inbounds [12 x i32], ptr %289, i64 0, i64 %292
  call void @llvm.lifetime.start.p0(i64 8, ptr %25) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #7
  %294 = load i32, ptr %8, align 4, !tbaa !5
  %295 = add nsw i32 %294, 1
  store i32 %295, ptr %26, align 4, !tbaa !5
  %296 = invoke i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %7, ptr noundef nonnull align 4 dereferenceable(4) %26)
          to label %297 unwind label %301

297:                                              ; preds = %286
  store i64 %296, ptr %25, align 4
  %298 = invoke { i64, i32 } @_ZSt9make_pairIRiSt4pairIiiEES1_INSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS3_INS4_IT0_E4typeEE6__typeEEOS5_OSA_(ptr noundef nonnull align 4 dereferenceable(4) %293, ptr noundef nonnull align 4 dereferenceable(8) %25)
          to label %299 unwind label %301

299:                                              ; preds = %297
  store { i64, i32 } %298, ptr %27, align 8
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %24, ptr align 8 %27, i64 12, i1 false)
  invoke void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE9push_backEOS2_(ptr noundef nonnull align 8 dereferenceable(24) %9, ptr noundef nonnull align 4 dereferenceable(12) %24)
          to label %300 unwind label %301

300:                                              ; preds = %299
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %25) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr %24) #7
  br label %305

301:                                              ; preds = %299, %297, %286
  %302 = landingpad { ptr, i32 }
          cleanup
  %303 = extractvalue { ptr, i32 } %302, 0
  store ptr %303, ptr %13, align 8
  %304 = extractvalue { ptr, i32 } %302, 1
  store i32 %304, ptr %14, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr %25) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr %24) #7
  br label %343

305:                                              ; preds = %300, %276
  %306 = call noundef i64 @_ZNKSt6vectorISt4pairIiS0_IiiEESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %9) #7
  %307 = icmp ne i64 %306, 0
  br i1 %307, label %308, label %342

308:                                              ; preds = %305
  %309 = call ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %9) #7
  %310 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %28, i32 0, i32 0
  store ptr %309, ptr %310, align 8
  %311 = call ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %9) #7
  %312 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %29, i32 0, i32 0
  store ptr %311, ptr %312, align 8
  %313 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %28, i32 0, i32 0
  %314 = load ptr, ptr %313, align 8
  %315 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %29, i32 0, i32 0
  %316 = load ptr, ptr %315, align 8
  invoke void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIPSt4pairIiS2_IiiEESt6vectorIS4_SaIS4_EEEEEvT_SA_(ptr %314, ptr %316)
          to label %317 unwind label %338

317:                                              ; preds = %308
  %318 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %9, i64 noundef 0) #7
  %319 = getelementptr inbounds %"struct.std::pair", ptr %318, i32 0, i32 1
  %320 = getelementptr inbounds %"struct.std::pair.3", ptr %319, i32 0, i32 0
  %321 = load i32, ptr %320, align 4, !tbaa !15
  %322 = sext i32 %321 to i64
  %323 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %322
  %324 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %9, i64 noundef 0) #7
  %325 = getelementptr inbounds %"struct.std::pair", ptr %324, i32 0, i32 1
  %326 = getelementptr inbounds %"struct.std::pair.3", ptr %325, i32 0, i32 1
  %327 = load i32, ptr %326, align 4, !tbaa !18
  %328 = sext i32 %327 to i64
  %329 = getelementptr inbounds [12 x i32], ptr %323, i64 0, i64 %328
  store i32 0, ptr %329, align 4, !tbaa !5
  %330 = load i32, ptr @res, align 4, !tbaa !5
  %331 = add nsw i32 %330, 1
  store i32 %331, ptr @res, align 4, !tbaa !5
  %332 = load i32, ptr %7, align 4, !tbaa !5
  %333 = sext i32 %332 to i64
  %334 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %333
  %335 = load i32, ptr %8, align 4, !tbaa !5
  %336 = sext i32 %335 to i64
  %337 = getelementptr inbounds [12 x i32], ptr %334, i64 0, i64 %336
  store i32 0, ptr %337, align 4, !tbaa !5
  br label %342

338:                                              ; preds = %308
  %339 = landingpad { ptr, i32 }
          cleanup
  %340 = extractvalue { ptr, i32 } %339, 0
  store ptr %340, ptr %13, align 8
  %341 = extractvalue { ptr, i32 } %339, 1
  store i32 %341, ptr %14, align 4
  br label %343

342:                                              ; preds = %317, %305
  call void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %9) #7
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #7
  br label %344

343:                                              ; preds = %338, %301, %272, %243, %214
  call void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %9) #7
  call void @llvm.lifetime.end.p0(i64 24, ptr %9) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  br label %356

344:                                              ; preds = %342, %180
  br label %345

345:                                              ; preds = %344
  %346 = load i32, ptr %8, align 4, !tbaa !5
  %347 = add nsw i32 %346, 1
  store i32 %347, ptr %8, align 4, !tbaa !5
  br label %175, !llvm.loop !19

348:                                              ; preds = %179
  br label %349

349:                                              ; preds = %348
  %350 = load i32, ptr %7, align 4, !tbaa !5
  %351 = add nsw i32 %350, 1
  store i32 %351, ptr %7, align 4, !tbaa !5
  br label %169, !llvm.loop !20

352:                                              ; preds = %173
  %353 = load i32, ptr @res, align 4, !tbaa !5
  %354 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %353)
  %355 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %354, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0

356:                                              ; preds = %343
  %357 = load ptr, ptr %13, align 8
  %358 = load i32, ptr %14, align 4
  %359 = insertvalue { ptr, i32 } poison, ptr %357, 0
  %360 = insertvalue { ptr, i32 } %359, i32 %358, 1
  resume { ptr, i32 } %360
}

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(32)) #1

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #3 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EEC2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #3 align 2

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE9push_backEOS2_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(12)) #4 align 2

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i32 } @_ZSt9make_pairIRiSt4pairIiiEES1_INSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS3_INS4_IT0_E4typeEE6__typeEEOS5_OSA_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(8)) #4

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

declare i32 @__gxx_personality_v0(...)

; 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) #5

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorISt4pairIiS0_IiiEESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIPSt4pairIiS2_IiiEESt6vectorIS4_SaIS4_EEEEEvT_SA_(ptr, ptr) #6

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24)) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) #3 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24)) unnamed_addr #3 align 2

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #1

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

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #6

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 = { 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 #4 = { 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 #5 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) }
attributes #6 = { 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 #7 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!7, !7, i64 0}
!10 = distinct !{!10, !11}
!11 = !{!"llvm.loop.mustprogress"}
!12 = distinct !{!12, !11}
!13 = distinct !{!13, !11}
!14 = distinct !{!14, !11}
!15 = !{!16, !6, i64 4}
!16 = !{!"_ZTSSt4pairIiS_IiiEE", !6, i64 0, !17, i64 4}
!17 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!18 = !{!16, !6, i64 8}
!19 = distinct !{!19, !11}
!20 = distinct !{!20, !11}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }
%"class.std::basic_ios" = type { %"class.std::ios_base", ptr, i8, i8, ptr, ptr, ptr, ptr }
%"class.std::ios_base" = type { ptr, i64, i64, i32, i32, i32, ptr, %"struct.std::ios_base::_Words", [8 x %"struct.std::ios_base::_Words"], i32, ptr, %"class.std::locale" }
%"struct.std::ios_base::_Words" = type { ptr, i64 }
%"class.std::locale" = type { ptr }
%"class.std::basic_ostream" = type { ptr, %"class.std::basic_ios" }
%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::pair<int, std::pair<int, int>>, std::allocator<std::pair<int, std::pair<int, int>>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::pair<int, std::pair<int, int>>, std::allocator<std::pair<int, std::pair<int, int>>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::pair<int, std::pair<int, int>>, std::allocator<std::pair<int, std::pair<int, int>>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::pair<int, std::pair<int, int>>, std::allocator<std::pair<int, std::pair<int, int>>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.std::pair" = type { i32, %"struct.std::pair.3" }
%"struct.std::pair.3" = type { i32, i32 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@cnt2 = external dso_local local_unnamed_addr global i32, align 4
@res = external dso_local local_unnamed_addr global i32, align 4
@grid = external dso_local local_unnamed_addr global [12 x [12 x i32]], align 16
@cnt = external dso_local global [12 x [12 x i32]], align 16
@_Z1sB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca %"class.std::vector", align 8
  %4 = alloca %"struct.std::pair", align 8
  %5 = alloca %"struct.std::pair.3", align 8
  %6 = alloca i32, align 4
  %7 = alloca %"struct.std::pair", align 8
  %8 = alloca %"struct.std::pair.3", align 8
  %9 = alloca i32, align 4
  %10 = alloca %"struct.std::pair", align 8
  %11 = alloca %"struct.std::pair.3", align 8
  %12 = alloca i32, align 4
  %13 = alloca %"struct.std::pair", align 8
  %14 = alloca %"struct.std::pair.3", align 8
  %15 = alloca i32, align 4
  %16 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %17 = load i32, ptr @n, align 4, !tbaa !5
  %.not57 = icmp slt i32 %17, 1
  br i1 %.not57, label %.thread, label %.lr.ph60

.preheader:                                       ; preds = %._crit_edge
  %.not4767 = icmp slt i32 %23, 1
  br i1 %.not4767, label %.thread, label %.lr.ph69

.lr.ph69:                                         ; preds = %.preheader
  %18 = load i32, ptr @m, align 4, !tbaa !5
  %.not5361 = icmp slt i32 %18, 1
  br i1 %.not5361, label %.thread115, label %.lr.ph64.preheader

.thread115:                                       ; preds = %.lr.ph69
  store i32 0, ptr @cnt2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #7
  store i32 1, ptr %1, align 4, !tbaa !5
  br label %.lr.ph80

.lr.ph64.preheader:                               ; preds = %.lr.ph69
  %19 = add nuw i32 %18, 1
  %20 = add nuw i32 %23, 1
  %wide.trip.count97 = zext i32 %20 to i64
  %wide.trip.count = zext i32 %19 to i64
  br label %.lr.ph64

.lr.ph60:                                         ; preds = %0, %._crit_edge
  %indvars.iv88 = phi i64 [ %indvars.iv.next89, %._crit_edge ], [ 1, %0 ]
  %21 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11)
  %22 = load i32, ptr @m, align 4, !tbaa !5
  %.not5455 = icmp slt i32 %22, 1
  br i1 %.not5455, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %38, %.lr.ph60
  %indvars.iv.next89 = add nuw nsw i64 %indvars.iv88, 1
  %23 = load i32, ptr @n, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %.not.not = icmp slt i64 %indvars.iv88, %24
  br i1 %.not.not, label %.lr.ph60, label %.preheader, !llvm.loop !9

.lr.ph:                                           ; preds = %.lr.ph60, %38
  %indvars.iv = phi i64 [ %indvars.iv.next, %38 ], [ 1, %.lr.ph60 ]
  %25 = add nsw i64 %indvars.iv, -1
  %26 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %25)
  %27 = load i8, ptr %26, align 1, !tbaa !11
  %28 = icmp eq i8 %27, 46
  br i1 %28, label %29, label %31

29:                                               ; preds = %.lr.ph
  %30 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %indvars.iv88, i64 %indvars.iv
  store i32 0, ptr %30, align 4, !tbaa !5
  br label %38

31:                                               ; preds = %.lr.ph
  %32 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %25)
  %33 = load i8, ptr %32, align 1, !tbaa !11
  %34 = icmp eq i8 %33, 80
  %35 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %indvars.iv88, i64 %indvars.iv
  br i1 %34, label %36, label %37

36:                                               ; preds = %31
  store i32 1, ptr %35, align 4, !tbaa !5
  br label %38

37:                                               ; preds = %31
  store i32 2, ptr %35, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %29, %37, %36
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %39 = load i32, ptr @m, align 4, !tbaa !5
  %40 = sext i32 %39 to i64
  %.not54.not = icmp slt i64 %indvars.iv, %40
  br i1 %.not54.not, label %.lr.ph, label %._crit_edge, !llvm.loop !12

.thread:                                          ; preds = %.preheader, %0
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #7
  br label %._crit_edge81

41:                                               ; preds = %._crit_edge65
  store i32 %66, ptr @cnt2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #7
  store i32 1, ptr %1, align 4, !tbaa !5
  br i1 %.not4767, label %._crit_edge81, label %.lr.ph80

.lr.ph80:                                         ; preds = %.thread115, %41
  %.sroa.214.0..sroa_idx = getelementptr inbounds i8, ptr %4, i64 8
  %.sroa.210.0..sroa_idx = getelementptr inbounds i8, ptr %7, i64 8
  %.sroa.26.0..sroa_idx = getelementptr inbounds i8, ptr %10, i64 8
  %.sroa.2.0..sroa_idx = getelementptr inbounds i8, ptr %13, i64 8
  %42 = load i32, ptr @m, align 4, !tbaa !5
  %43 = icmp slt i32 %42, 1
  br i1 %43, label %._crit_edge81, label %.lr.ph80.split

.lr.ph64:                                         ; preds = %.lr.ph64.preheader, %._crit_edge65
  %indvars.iv94 = phi i64 [ 1, %.lr.ph64.preheader ], [ %indvars.iv.next95, %._crit_edge65 ]
  %44 = add nsw i64 %indvars.iv94, -1
  %indvars.iv.next95 = add nuw nsw i64 %indvars.iv94, 1
  br label %45

._crit_edge65:                                    ; preds = %45
  %exitcond98.not = icmp eq i64 %indvars.iv.next95, %wide.trip.count97
  br i1 %exitcond98.not, label %41, label %.lr.ph64, !llvm.loop !13

45:                                               ; preds = %.lr.ph64, %45
  %indvars.iv91 = phi i64 [ 1, %.lr.ph64 ], [ %indvars.iv.next92, %45 ]
  %46 = phi i32 [ 0, %.lr.ph64 ], [ %66, %45 ]
  %47 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %44, i64 %indvars.iv91
  %48 = load i32, ptr %47, align 4, !tbaa !5
  %49 = icmp eq i32 %48, 1
  %50 = zext i1 %49 to i32
  %spec.select = add nsw i32 %46, %50
  %51 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %indvars.iv.next95, i64 %indvars.iv91
  %52 = load i32, ptr %51, align 4, !tbaa !5
  %53 = icmp eq i32 %52, 1
  %54 = zext i1 %53 to i32
  %55 = add nsw i32 %spec.select, %54
  %56 = add nsw i64 %indvars.iv91, -1
  %57 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %indvars.iv94, i64 %56
  %58 = load i32, ptr %57, align 4, !tbaa !5
  %59 = icmp eq i32 %58, 1
  %60 = zext i1 %59 to i32
  %61 = add nsw i32 %55, %60
  %indvars.iv.next92 = add nuw nsw i64 %indvars.iv91, 1
  %62 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %indvars.iv94, i64 %indvars.iv.next92
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = icmp eq i32 %63, 1
  %65 = zext i1 %64 to i32
  %66 = add nsw i32 %61, %65
  %67 = getelementptr inbounds [12 x [12 x i32]], ptr @cnt, i64 0, i64 %indvars.iv94, i64 %indvars.iv91
  store i32 %66, ptr %67, align 4, !tbaa !5
  %exitcond.not = icmp eq i64 %indvars.iv.next92, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge65, label %45, !llvm.loop !14

._crit_edge81:                                    ; preds = %._crit_edge77, %.lr.ph80, %.thread, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #7
  %68 = load i32, ptr @res, align 4, !tbaa !5
  %69 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %68)
  %70 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %69, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0

.lr.ph80.split:                                   ; preds = %.lr.ph80, %._crit_edge77
  %71 = phi i32 [ %75, %._crit_edge77 ], [ %23, %.lr.ph80 ]
  %72 = phi i32 [ %79, %._crit_edge77 ], [ 1, %.lr.ph80 ]
  %73 = phi i32 [ %77, %._crit_edge77 ], [ %42, %.lr.ph80 ]
  %74 = phi i32 [ %78, %._crit_edge77 ], [ %42, %.lr.ph80 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #7
  store i32 1, ptr %2, align 4, !tbaa !5
  %.not5073 = icmp slt i32 %74, 1
  br i1 %.not5073, label %._crit_edge77, label %.lr.ph76

._crit_edge77.loopexit:                           ; preds = %182
  %.pre107 = load i32, ptr %1, align 4, !tbaa !5
  %.pre108 = load i32, ptr @n, align 4, !tbaa !5
  br label %._crit_edge77

._crit_edge77:                                    ; preds = %._crit_edge77.loopexit, %.lr.ph80.split
  %75 = phi i32 [ %.pre108, %._crit_edge77.loopexit ], [ %71, %.lr.ph80.split ]
  %76 = phi i32 [ %.pre107, %._crit_edge77.loopexit ], [ %72, %.lr.ph80.split ]
  %77 = phi i32 [ %183, %._crit_edge77.loopexit ], [ %73, %.lr.ph80.split ]
  %78 = phi i32 [ %183, %._crit_edge77.loopexit ], [ %74, %.lr.ph80.split ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #7
  %79 = add nsw i32 %76, 1
  store i32 %79, ptr %1, align 4, !tbaa !5
  %.not48.not = icmp slt i32 %76, %75
  br i1 %.not48.not, label %.lr.ph80.split, label %._crit_edge81, !llvm.loop !15

.lr.ph76:                                         ; preds = %.lr.ph80.split, %182
  %80 = phi i32 [ %183, %182 ], [ %73, %.lr.ph80.split ]
  %storemerge4974 = phi i32 [ %185, %182 ], [ 1, %.lr.ph80.split ]
  %81 = load i32, ptr %1, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = sext i32 %storemerge4974 to i64
  %84 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %82, i64 %83
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = icmp eq i32 %85, 1
  br i1 %86, label %87, label %182

87:                                               ; preds = %.lr.ph76
  call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %3) #7
  call void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EEC2Ev(ptr noundef nonnull align 8 dereferenceable(24) %3) #7
  %88 = load i32, ptr %1, align 4, !tbaa !5
  %89 = add nsw i32 %88, -1
  %90 = sext i32 %89 to i64
  %91 = load i32, ptr %2, align 4, !tbaa !5
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %90, i64 %92
  %94 = load i32, ptr %93, align 4, !tbaa !5
  %95 = icmp eq i32 %94, 2
  br i1 %95, label %96, label %105

96:                                               ; preds = %87
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %4) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #7
  store i32 %89, ptr %6, align 4, !tbaa !5
  %97 = invoke i64 @_ZSt9make_pairIiRiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %6, ptr noundef nonnull align 4 dereferenceable(4) %2)
          to label %98 unwind label %103

98:                                               ; preds = %96
  %99 = getelementptr inbounds [12 x [12 x i32]], ptr @cnt, i64 0, i64 %90, i64 %92
  store i64 %97, ptr %5, align 8
  %100 = invoke { i64, i32 } @_ZSt9make_pairIRiSt4pairIiiEES1_INSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS3_INS4_IT0_E4typeEE6__typeEEOS5_OSA_(ptr noundef nonnull align 4 dereferenceable(4) %99, ptr noundef nonnull align 4 dereferenceable(8) %5)
          to label %101 unwind label %103

101:                                              ; preds = %98
  %.fca.0.extract11 = extractvalue { i64, i32 } %100, 0
  %.fca.1.extract12 = extractvalue { i64, i32 } %100, 1
  store i64 %.fca.0.extract11, ptr %4, align 8
  store i32 %.fca.1.extract12, ptr %.sroa.214.0..sroa_idx, align 8
  invoke void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE9push_backEOS2_(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 4 dereferenceable(12) %4)
          to label %102 unwind label %103

102:                                              ; preds = %101
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #7
  %.pre = load i32, ptr %1, align 4, !tbaa !5
  %.pre100 = load i32, ptr %2, align 4, !tbaa !5
  %.pre109 = sext i32 %.pre100 to i64
  br label %105

103:                                              ; preds = %101, %98, %96
  %104 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %4) #7
  br label %181

105:                                              ; preds = %102, %87
  %.pre-phi = phi i64 [ %.pre109, %102 ], [ %92, %87 ]
  %106 = phi i32 [ %.pre100, %102 ], [ %91, %87 ]
  %107 = phi i32 [ %.pre, %102 ], [ %88, %87 ]
  %108 = add nsw i32 %107, 1
  %109 = sext i32 %108 to i64
  %110 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %109, i64 %.pre-phi
  %111 = load i32, ptr %110, align 4, !tbaa !5
  %112 = icmp eq i32 %111, 2
  br i1 %112, label %113, label %122

113:                                              ; preds = %105
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %7) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %8) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %9) #7
  store i32 %108, ptr %9, align 4, !tbaa !5
  %114 = invoke i64 @_ZSt9make_pairIiRiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %9, ptr noundef nonnull align 4 dereferenceable(4) %2)
          to label %115 unwind label %120

115:                                              ; preds = %113
  %116 = getelementptr inbounds [12 x [12 x i32]], ptr @cnt, i64 0, i64 %109, i64 %.pre-phi
  store i64 %114, ptr %8, align 8
  %117 = invoke { i64, i32 } @_ZSt9make_pairIRiSt4pairIiiEES1_INSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS3_INS4_IT0_E4typeEE6__typeEEOS5_OSA_(ptr noundef nonnull align 4 dereferenceable(4) %116, ptr noundef nonnull align 4 dereferenceable(8) %8)
          to label %118 unwind label %120

118:                                              ; preds = %115
  %.fca.0.extract7 = extractvalue { i64, i32 } %117, 0
  %.fca.1.extract8 = extractvalue { i64, i32 } %117, 1
  store i64 %.fca.0.extract7, ptr %7, align 8
  store i32 %.fca.1.extract8, ptr %.sroa.210.0..sroa_idx, align 8
  invoke void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE9push_backEOS2_(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 4 dereferenceable(12) %7)
          to label %119 unwind label %120

119:                                              ; preds = %118
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %9) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %7) #7
  %.pre101 = load i32, ptr %1, align 4, !tbaa !5
  %.pre102 = load i32, ptr %2, align 4, !tbaa !5
  br label %122

120:                                              ; preds = %118, %115, %113
  %121 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %9) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %8) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %7) #7
  br label %181

122:                                              ; preds = %119, %105
  %123 = phi i32 [ %.pre102, %119 ], [ %106, %105 ]
  %124 = phi i32 [ %.pre101, %119 ], [ %107, %105 ]
  %125 = sext i32 %124 to i64
  %126 = add nsw i32 %123, -1
  %127 = sext i32 %126 to i64
  %128 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %125, i64 %127
  %129 = load i32, ptr %128, align 4, !tbaa !5
  %130 = icmp eq i32 %129, 2
  br i1 %130, label %131, label %140

131:                                              ; preds = %122
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %10) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %11) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %12) #7
  store i32 %126, ptr %12, align 4, !tbaa !5
  %132 = invoke i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %12)
          to label %133 unwind label %138

133:                                              ; preds = %131
  %134 = getelementptr inbounds [12 x [12 x i32]], ptr @cnt, i64 0, i64 %125, i64 %127
  store i64 %132, ptr %11, align 8
  %135 = invoke { i64, i32 } @_ZSt9make_pairIRiSt4pairIiiEES1_INSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS3_INS4_IT0_E4typeEE6__typeEEOS5_OSA_(ptr noundef nonnull align 4 dereferenceable(4) %134, ptr noundef nonnull align 4 dereferenceable(8) %11)
          to label %136 unwind label %138

136:                                              ; preds = %133
  %.fca.0.extract3 = extractvalue { i64, i32 } %135, 0
  %.fca.1.extract4 = extractvalue { i64, i32 } %135, 1
  store i64 %.fca.0.extract3, ptr %10, align 8
  store i32 %.fca.1.extract4, ptr %.sroa.26.0..sroa_idx, align 8
  invoke void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE9push_backEOS2_(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 4 dereferenceable(12) %10)
          to label %137 unwind label %138

137:                                              ; preds = %136
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %12) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %10) #7
  %.pre103 = load i32, ptr %1, align 4, !tbaa !5
  %.pre104 = load i32, ptr %2, align 4, !tbaa !5
  %.pre110 = sext i32 %.pre103 to i64
  br label %140

138:                                              ; preds = %136, %133, %131
  %139 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %12) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %10) #7
  br label %181

140:                                              ; preds = %137, %122
  %.pre-phi111 = phi i64 [ %.pre110, %137 ], [ %125, %122 ]
  %141 = phi i32 [ %.pre104, %137 ], [ %123, %122 ]
  %142 = add nsw i32 %141, 1
  %143 = sext i32 %142 to i64
  %144 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %.pre-phi111, i64 %143
  %145 = load i32, ptr %144, align 4, !tbaa !5
  %146 = icmp eq i32 %145, 2
  br i1 %146, label %147, label %156

147:                                              ; preds = %140
  call void @llvm.lifetime.start.p0(i64 12, ptr nonnull %13) #7
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %14) #7
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %15) #7
  store i32 %142, ptr %15, align 4, !tbaa !5
  %148 = invoke i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %15)
          to label %149 unwind label %154

149:                                              ; preds = %147
  %150 = getelementptr inbounds [12 x [12 x i32]], ptr @cnt, i64 0, i64 %.pre-phi111, i64 %143
  store i64 %148, ptr %14, align 8
  %151 = invoke { i64, i32 } @_ZSt9make_pairIRiSt4pairIiiEES1_INSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS3_INS4_IT0_E4typeEE6__typeEEOS5_OSA_(ptr noundef nonnull align 4 dereferenceable(4) %150, ptr noundef nonnull align 4 dereferenceable(8) %14)
          to label %152 unwind label %154

152:                                              ; preds = %149
  %.fca.0.extract = extractvalue { i64, i32 } %151, 0
  %.fca.1.extract = extractvalue { i64, i32 } %151, 1
  store i64 %.fca.0.extract, ptr %13, align 8
  store i32 %.fca.1.extract, ptr %.sroa.2.0..sroa_idx, align 8
  invoke void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE9push_backEOS2_(ptr noundef nonnull align 8 dereferenceable(24) %3, ptr noundef nonnull align 4 dereferenceable(12) %13)
          to label %153 unwind label %154

153:                                              ; preds = %152
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %15) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %14) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %13) #7
  br label %156

154:                                              ; preds = %152, %149, %147
  %155 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %15) #7
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %14) #7
  call void @llvm.lifetime.end.p0(i64 12, ptr nonnull %13) #7
  br label %181

156:                                              ; preds = %153, %140
  %157 = call noundef i64 @_ZNKSt6vectorISt4pairIiS0_IiiEESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #7
  %.not51 = icmp eq i64 %157, 0
  br i1 %.not51, label %180, label %158

158:                                              ; preds = %156
  %159 = call ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #7
  %160 = call ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24) %3) #7
  invoke void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIPSt4pairIiS2_IiiEESt6vectorIS4_SaIS4_EEEEEvT_SA_(ptr %159, ptr %160)
          to label %161 unwind label %178

161:                                              ; preds = %158
  %162 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef 0) #7
  %163 = getelementptr inbounds i8, ptr %162, i64 4
  %164 = load i32, ptr %163, align 4, !tbaa !17
  %165 = sext i32 %164 to i64
  %166 = call noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef 0) #7
  %167 = getelementptr inbounds i8, ptr %166, i64 8
  %168 = load i32, ptr %167, align 4, !tbaa !20
  %169 = sext i32 %168 to i64
  %170 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %165, i64 %169
  store i32 0, ptr %170, align 4, !tbaa !5
  %171 = load i32, ptr @res, align 4, !tbaa !5
  %172 = add nsw i32 %171, 1
  store i32 %172, ptr @res, align 4, !tbaa !5
  %173 = load i32, ptr %1, align 4, !tbaa !5
  %174 = sext i32 %173 to i64
  %175 = load i32, ptr %2, align 4, !tbaa !5
  %176 = sext i32 %175 to i64
  %177 = getelementptr inbounds [12 x [12 x i32]], ptr @grid, i64 0, i64 %174, i64 %176
  store i32 0, ptr %177, align 4, !tbaa !5
  br label %180

178:                                              ; preds = %158
  %179 = landingpad { ptr, i32 }
          cleanup
  br label %181

180:                                              ; preds = %161, %156
  call void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %3) #7
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #7
  %.pre105 = load i32, ptr %2, align 4, !tbaa !5
  %.pre106 = load i32, ptr @m, align 4, !tbaa !5
  br label %182

181:                                              ; preds = %178, %154, %138, %120, %103
  %.pn = phi { ptr, i32 } [ %179, %178 ], [ %155, %154 ], [ %139, %138 ], [ %121, %120 ], [ %104, %103 ]
  call void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EED2Ev(ptr noundef nonnull align 8 dereferenceable(24) %3) #7
  call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %3) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #7
  resume { ptr, i32 } %.pn

182:                                              ; preds = %.lr.ph76, %180
  %183 = phi i32 [ %80, %.lr.ph76 ], [ %.pre106, %180 ]
  %184 = phi i32 [ %storemerge4974, %.lr.ph76 ], [ %.pre105, %180 ]
  %185 = add nsw i32 %184, 1
  store i32 %185, ptr %2, align 4, !tbaa !5
  %.not50.not = icmp slt i32 %184, %183
  br i1 %.not50.not, label %.lr.ph76, label %._crit_edge77.loopexit, !llvm.loop !21
}

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

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

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #3

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EE9push_backEOS2_(ptr noundef nonnull align 8 dereferenceable(24), ptr noundef nonnull align 4 dereferenceable(12)) local_unnamed_addr #5 align 2

; Function Attrs: mustprogress uwtable
declare dso_local { i64, i32 } @_ZSt9make_pairIRiSt4pairIiiEES1_INSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS3_INS4_IT0_E4typeEE6__typeEEOS5_OSA_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #5

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

declare i32 @__gxx_personality_v0(...)

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_ZNKSt6vectorISt4pairIiS0_IiiEESaIS2_EE4sizeEv(ptr noundef nonnull align 8 dereferenceable(24)) local_unnamed_addr #4 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIPSt4pairIiS2_IiiEESt6vectorIS4_SaIS4_EEEEEvT_SA_(ptr, ptr) local_unnamed_addr #6

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(12) ptr @_ZNSt6vectorISt4pairIiS0_IiiEESaIS2_EEixEm(ptr noundef nonnull align 8 dereferenceable(24), i64 noundef) local_unnamed_addr #4 align 2

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

declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #3

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #5 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_(ptr noundef nonnull align 8 dereferenceable(8)) #6

attributes #0 = { mustprogress norecurse uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { "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 nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { 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 = { 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 #7 = { nounwind }

!llvm.module.flags = !{!0, !1, !2, !3}
!llvm.ident = !{!4}

!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 8, !"PIC Level", i32 2}
!2 = !{i32 7, !"PIE Level", i32 2}
!3 = !{i32 7, !"uwtable", i32 2}
!4 = !{!"clang version 19.1.0 (git@github.com:llvm/llvm-project.git a4bf6cd7cfb1a1421ba92bca9d017b49936c55e4)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !10}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10, !16}
!16 = !{!"llvm.loop.unswitch.partial.disable"}
!17 = !{!18, !6, i64 4}
!18 = !{!"_ZTSSt4pairIiS_IiiEE", !6, i64 0, !19, i64 4}
!19 = !{!"_ZTSSt4pairIiiE", !6, i64 0, !6, i64 4}
!20 = !{!18, !6, i64 8}
!21 = distinct !{!21, !10}


; Effective O3 passes: BDCEPass,CorrelatedValuePropagationPass,DSEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferAlignmentPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LICMPass,LoopInstSimplifyPass,LoopRotatePass,LoopSimplifyCFGPass,LoopSimplifyPass,LoopUnrollPass,SCCPPass,SROAPass,SimpleLoopUnswitchPass,SimplifyCFGPass,TailCallElimPass