; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2015-16/Dec 2015/Gold (15 Dec G3)

; 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::basic_ifstream" = type { %"class.std::basic_istream.base", %"class.std::basic_filebuf", %"class.std::basic_ios" }
%"class.std::basic_istream.base" = type { ptr, i64 }
%"class.std::basic_filebuf" = type { %"class.std::basic_streambuf", %union.pthread_mutex_t, %"class.std::__basic_file", i32, %struct.__mbstate_t, %struct.__mbstate_t, %struct.__mbstate_t, ptr, i64, i8, i8, i8, i8, ptr, ptr, i8, ptr, ptr, i64, ptr, ptr }
%"class.std::basic_streambuf" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, %"class.std::locale" }
%"class.std::locale" = type { ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%"class.std::__basic_file" = type <{ ptr, i8, [7 x i8] }>
%struct.__mbstate_t = type { i32, %union.anon }
%union.anon = type { i32 }
%"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::basic_ofstream" = type { %"class.std::basic_ostream.base", %"class.std::basic_filebuf", %"class.std::basic_ios" }
%"class.std::basic_ostream.base" = type { ptr }
%"class.std::queue" = type { %"class.std::deque" }
%"class.std::deque" = type { %"class.std::_Deque_base" }
%"class.std::_Deque_base" = type { %"struct.std::_Deque_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Deque_impl" }
%"struct.std::_Deque_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Deque_impl" = type { %"struct.std::_Deque_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Deque_impl_data" }
%"struct.std::_Deque_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator", %"struct.std::_Deque_iterator" }
%"struct.std::_Deque_iterator" = type { ptr, ptr, ptr, ptr }
%"struct.std::pair" = type { i32, i32 }

@cin = external dso_local global %"class.std::basic_ifstream", align 8
@cout = external dso_local global %"class.std::basic_ofstream", align 8
@grid = external dso_local global [1000 x [1000 x i32]], align 16
@xdir = external dso_local global [4 x i32], align 16
@ydir = external dso_local global [4 x i32], align 16
@N = external dso_local global i32, align 4
@M = external dso_local global i32, align 4
@des = external dso_local global i32, align 4
@visit = external dso_local global [10000000 x i8], align 16
@q = external dso_local global %"class.std::queue", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca i8, align 1
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca %"struct.std::pair", align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca i32, align 4
  %16 = alloca %"struct.std::pair", align 4
  %17 = alloca %"struct.std::pair", align 4
  %18 = alloca %"struct.std::pair", align 4
  %19 = alloca i32, align 4
  %20 = alloca %"struct.std::pair", align 4
  %21 = alloca i32, align 4
  %22 = alloca %"struct.std::pair", align 4
  %23 = alloca i32, align 4
  %24 = alloca i32, align 4
  %25 = alloca i32, align 4
  %26 = alloca i32, align 4
  %27 = alloca i32, align 4
  %28 = alloca %"struct.std::pair", align 4
  %29 = alloca i32, align 4
  %30 = alloca i32, align 4
  %31 = alloca %"struct.std::pair", align 4
  %32 = alloca i32, align 4
  %33 = alloca i32, align 4
  %34 = alloca %"struct.std::pair", align 4
  %35 = alloca i32, align 4
  %36 = alloca i32, align 4
  %37 = alloca %"struct.std::pair", align 4
  %38 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %39 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @cin, ptr noundef nonnull align 4 dereferenceable(4) @N)
  %40 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %39, ptr noundef nonnull align 4 dereferenceable(4) @M)
  call void @llvm.lifetime.start.p0(i64 1, ptr %2) #6
  store i8 0, ptr %2, align 1, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %41

41:                                               ; preds = %64, %0
  %42 = load i32, ptr %3, align 4, !tbaa !9
  %43 = load i32, ptr @N, align 4, !tbaa !9
  %44 = icmp slt i32 %42, %43
  br i1 %44, label %46, label %45

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

46:                                               ; preds = %41
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  store i32 0, ptr %5, align 4, !tbaa !9
  br label %47

47:                                               ; preds = %60, %46
  %48 = load i32, ptr %5, align 4, !tbaa !9
  %49 = load i32, ptr @M, align 4, !tbaa !9
  %50 = icmp slt i32 %48, %49
  br i1 %50, label %52, label %51

51:                                               ; preds = %47
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %63

52:                                               ; preds = %47
  %53 = load i32, ptr %5, align 4, !tbaa !9
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [1000 x [1000 x i32]], ptr @grid, i64 0, i64 %54
  %56 = load i32, ptr %3, align 4, !tbaa !9
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [1000 x i32], ptr %55, i64 0, i64 %57
  %59 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @cin, ptr noundef nonnull align 4 dereferenceable(4) %58)
  br label %60

60:                                               ; preds = %52
  %61 = load i32, ptr %5, align 4, !tbaa !9
  %62 = add nsw i32 %61, 1
  store i32 %62, ptr %5, align 4, !tbaa !9
  br label %47, !llvm.loop !11

63:                                               ; preds = %51
  br label %64

64:                                               ; preds = %63
  %65 = load i32, ptr %3, align 4, !tbaa !9
  %66 = add nsw i32 %65, 1
  store i32 %66, ptr %3, align 4, !tbaa !9
  br label %41, !llvm.loop !13

67:                                               ; preds = %45
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #6
  store i32 0, ptr %7, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #6
  store i32 0, ptr %8, align 4, !tbaa !9
  %68 = call i64 @_ZSt9make_pairIiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS1_INS2_IT0_E4typeEE6__typeEEOS3_OS8_(ptr noundef nonnull align 4 dereferenceable(4) %7, ptr noundef nonnull align 4 dereferenceable(4) %8)
  store i64 %68, ptr %6, align 4
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %6)
  %69 = load i32, ptr @M, align 4, !tbaa !9
  %70 = sub nsw i32 %69, 1
  %71 = mul nsw i32 %70, 1000
  %72 = load i32, ptr @N, align 4, !tbaa !9
  %73 = add nsw i32 %71, %72
  %74 = sub nsw i32 %73, 1
  store i32 %74, ptr @des, align 4, !tbaa !9
  store i8 1, ptr @visit, align 16, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  br label %75

75:                                               ; preds = %443, %67
  %76 = call noundef zeroext i1 @_ZNKSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80) @q)
  %77 = xor i1 %76, true
  br i1 %77, label %78, label %444

78:                                               ; preds = %75
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #6
  store i32 0, ptr %10, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #6
  store i32 0, ptr %11, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #6
  store i32 0, ptr %12, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %15) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr %16) #6
  %79 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80) @q)
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %16, ptr align 4 %79, i64 8, i1 false)
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE3popEv(ptr noundef nonnull align 8 dereferenceable(80) @q)
  %80 = getelementptr inbounds %"struct.std::pair", ptr %16, i32 0, i32 0
  %81 = load i32, ptr %80, align 4, !tbaa !14
  %82 = load i32, ptr @des, align 4, !tbaa !9
  %83 = icmp eq i32 %81, %82
  br i1 %83, label %90, label %84

84:                                               ; preds = %78
  %85 = getelementptr inbounds %"struct.std::pair", ptr %16, i32 0, i32 0
  %86 = load i32, ptr %85, align 4, !tbaa !14
  %87 = load i32, ptr @des, align 4, !tbaa !9
  %88 = add nsw i32 %87, 5000000
  %89 = icmp eq i32 %86, %88
  br i1 %89, label %90, label %94

90:                                               ; preds = %84, %78
  %91 = getelementptr inbounds %"struct.std::pair", ptr %16, i32 0, i32 1
  %92 = load i32, ptr %91, align 4, !tbaa !16
  %93 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @cout, i32 noundef %92)
  store i8 1, ptr %2, align 1, !tbaa !5
  store i32 9, ptr %4, align 4
  br label %441

94:                                               ; preds = %84
  %95 = getelementptr inbounds %"struct.std::pair", ptr %16, i32 0, i32 0
  %96 = load i32, ptr %95, align 4, !tbaa !14
  %97 = sdiv i32 %96, 5000000
  store i32 %97, ptr %9, align 4, !tbaa !9
  %98 = load i32, ptr %9, align 4, !tbaa !9
  %99 = mul nsw i32 %98, 5000000
  %100 = getelementptr inbounds %"struct.std::pair", ptr %16, i32 0, i32 0
  %101 = load i32, ptr %100, align 4, !tbaa !14
  %102 = sub nsw i32 %101, %99
  store i32 %102, ptr %100, align 4, !tbaa !14
  %103 = getelementptr inbounds %"struct.std::pair", ptr %16, i32 0, i32 0
  %104 = load i32, ptr %103, align 4, !tbaa !14
  %105 = sdiv i32 %104, 1000000
  store i32 %105, ptr %10, align 4, !tbaa !9
  %106 = load i32, ptr %10, align 4, !tbaa !9
  %107 = mul nsw i32 %106, 1000000
  %108 = getelementptr inbounds %"struct.std::pair", ptr %16, i32 0, i32 0
  %109 = load i32, ptr %108, align 4, !tbaa !14
  %110 = sub nsw i32 %109, %107
  store i32 %110, ptr %108, align 4, !tbaa !14
  %111 = getelementptr inbounds %"struct.std::pair", ptr %16, i32 0, i32 0
  %112 = load i32, ptr %111, align 4, !tbaa !14
  %113 = sdiv i32 %112, 1000
  store i32 %113, ptr %11, align 4, !tbaa !9
  %114 = getelementptr inbounds %"struct.std::pair", ptr %16, i32 0, i32 0
  %115 = load i32, ptr %114, align 4, !tbaa !14
  %116 = srem i32 %115, 1000
  store i32 %116, ptr %12, align 4, !tbaa !9
  %117 = load i32, ptr %10, align 4, !tbaa !9
  %118 = icmp ne i32 %117, 0
  br i1 %118, label %119, label %272

119:                                              ; preds = %94
  %120 = load i32, ptr %11, align 4, !tbaa !9
  %121 = load i32, ptr %10, align 4, !tbaa !9
  %122 = sub nsw i32 %121, 1
  %123 = sext i32 %122 to i64
  %124 = getelementptr inbounds [4 x i32], ptr @xdir, i64 0, i64 %123
  %125 = load i32, ptr %124, align 4, !tbaa !9
  %126 = add nsw i32 %120, %125
  store i32 %126, ptr %13, align 4, !tbaa !9
  %127 = load i32, ptr %12, align 4, !tbaa !9
  %128 = load i32, ptr %10, align 4, !tbaa !9
  %129 = sub nsw i32 %128, 1
  %130 = sext i32 %129 to i64
  %131 = getelementptr inbounds [4 x i32], ptr @ydir, i64 0, i64 %130
  %132 = load i32, ptr %131, align 4, !tbaa !9
  %133 = add nsw i32 %127, %132
  store i32 %133, ptr %14, align 4, !tbaa !9
  %134 = load i32, ptr %13, align 4, !tbaa !9
  %135 = icmp slt i32 %134, 0
  br i1 %135, label %165, label %136

136:                                              ; preds = %119
  %137 = load i32, ptr %13, align 4, !tbaa !9
  %138 = load i32, ptr @M, align 4, !tbaa !9
  %139 = icmp sge i32 %137, %138
  br i1 %139, label %165, label %140

140:                                              ; preds = %136
  %141 = load i32, ptr %14, align 4, !tbaa !9
  %142 = icmp slt i32 %141, 0
  br i1 %142, label %165, label %143

143:                                              ; preds = %140
  %144 = load i32, ptr %14, align 4, !tbaa !9
  %145 = load i32, ptr @N, align 4, !tbaa !9
  %146 = icmp sge i32 %144, %145
  br i1 %146, label %165, label %147

147:                                              ; preds = %143
  %148 = load i32, ptr %13, align 4, !tbaa !9
  %149 = sext i32 %148 to i64
  %150 = getelementptr inbounds [1000 x [1000 x i32]], ptr @grid, i64 0, i64 %149
  %151 = load i32, ptr %14, align 4, !tbaa !9
  %152 = sext i32 %151 to i64
  %153 = getelementptr inbounds [1000 x i32], ptr %150, i64 0, i64 %152
  %154 = load i32, ptr %153, align 4, !tbaa !9
  %155 = icmp eq i32 %154, 0
  br i1 %155, label %165, label %156

156:                                              ; preds = %147
  %157 = load i32, ptr %13, align 4, !tbaa !9
  %158 = sext i32 %157 to i64
  %159 = getelementptr inbounds [1000 x [1000 x i32]], ptr @grid, i64 0, i64 %158
  %160 = load i32, ptr %14, align 4, !tbaa !9
  %161 = sext i32 %160 to i64
  %162 = getelementptr inbounds [1000 x i32], ptr %159, i64 0, i64 %161
  %163 = load i32, ptr %162, align 4, !tbaa !9
  %164 = icmp eq i32 %163, 3
  br i1 %164, label %165, label %184

165:                                              ; preds = %156, %147, %143, %140, %136, %119
  %166 = load i32, ptr %11, align 4, !tbaa !9
  %167 = mul nsw i32 1000, %166
  %168 = load i32, ptr %12, align 4, !tbaa !9
  %169 = add nsw i32 %167, %168
  store i32 %169, ptr %15, align 4, !tbaa !9
  %170 = load i32, ptr %15, align 4, !tbaa !9
  %171 = sext i32 %170 to i64
  %172 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %171
  %173 = load i8, ptr %172, align 1, !tbaa !5, !range !17, !noundef !18
  %174 = trunc i8 %173 to i1
  %175 = zext i1 %174 to i32
  %176 = icmp eq i32 %175, 0
  br i1 %176, label %177, label %183

177:                                              ; preds = %165
  call void @llvm.lifetime.start.p0(i64 8, ptr %17) #6
  %178 = getelementptr inbounds %"struct.std::pair", ptr %16, i32 0, i32 1
  %179 = call i64 @_ZSt9make_pairIRiS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %15, ptr noundef nonnull align 4 dereferenceable(4) %178)
  store i64 %179, ptr %17, align 4
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %17)
  %180 = load i32, ptr %15, align 4, !tbaa !9
  %181 = sext i32 %180 to i64
  %182 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %181
  store i8 1, ptr %182, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 8, ptr %17) #6
  br label %183

183:                                              ; preds = %177, %165
  br label %271

184:                                              ; preds = %156
  %185 = load i32, ptr %13, align 4, !tbaa !9
  %186 = sext i32 %185 to i64
  %187 = getelementptr inbounds [1000 x [1000 x i32]], ptr @grid, i64 0, i64 %186
  %188 = load i32, ptr %14, align 4, !tbaa !9
  %189 = sext i32 %188 to i64
  %190 = getelementptr inbounds [1000 x i32], ptr %187, i64 0, i64 %189
  %191 = load i32, ptr %190, align 4, !tbaa !9
  %192 = icmp eq i32 %191, 1
  br i1 %192, label %193, label %214

193:                                              ; preds = %184
  %194 = load i32, ptr %13, align 4, !tbaa !9
  %195 = mul nsw i32 1000, %194
  %196 = load i32, ptr %14, align 4, !tbaa !9
  %197 = add nsw i32 %195, %196
  store i32 %197, ptr %15, align 4, !tbaa !9
  %198 = load i32, ptr %15, align 4, !tbaa !9
  %199 = sext i32 %198 to i64
  %200 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %199
  %201 = load i8, ptr %200, align 1, !tbaa !5, !range !17, !noundef !18
  %202 = trunc i8 %201 to i1
  %203 = zext i1 %202 to i32
  %204 = icmp eq i32 %203, 0
  br i1 %204, label %205, label %213

205:                                              ; preds = %193
  call void @llvm.lifetime.start.p0(i64 8, ptr %18) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %19) #6
  %206 = getelementptr inbounds %"struct.std::pair", ptr %16, i32 0, i32 1
  %207 = load i32, ptr %206, align 4, !tbaa !16
  %208 = add nsw i32 %207, 1
  store i32 %208, ptr %19, align 4, !tbaa !9
  %209 = call i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %15, ptr noundef nonnull align 4 dereferenceable(4) %19)
  store i64 %209, ptr %18, align 4
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %18)
  %210 = load i32, ptr %15, align 4, !tbaa !9
  %211 = sext i32 %210 to i64
  %212 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %211
  store i8 1, ptr %212, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %19) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %18) #6
  br label %213

213:                                              ; preds = %205, %193
  br label %270

214:                                              ; preds = %184
  %215 = load i32, ptr %13, align 4, !tbaa !9
  %216 = sext i32 %215 to i64
  %217 = getelementptr inbounds [1000 x [1000 x i32]], ptr @grid, i64 0, i64 %216
  %218 = load i32, ptr %14, align 4, !tbaa !9
  %219 = sext i32 %218 to i64
  %220 = getelementptr inbounds [1000 x i32], ptr %217, i64 0, i64 %219
  %221 = load i32, ptr %220, align 4, !tbaa !9
  %222 = icmp eq i32 %221, 2
  br i1 %222, label %223, label %245

223:                                              ; preds = %214
  %224 = load i32, ptr %13, align 4, !tbaa !9
  %225 = mul nsw i32 1000, %224
  %226 = add nsw i32 5000000, %225
  %227 = load i32, ptr %14, align 4, !tbaa !9
  %228 = add nsw i32 %226, %227
  store i32 %228, ptr %15, align 4, !tbaa !9
  %229 = load i32, ptr %15, align 4, !tbaa !9
  %230 = sext i32 %229 to i64
  %231 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %230
  %232 = load i8, ptr %231, align 1, !tbaa !5, !range !17, !noundef !18
  %233 = trunc i8 %232 to i1
  %234 = zext i1 %233 to i32
  %235 = icmp eq i32 %234, 0
  br i1 %235, label %236, label %244

236:                                              ; preds = %223
  call void @llvm.lifetime.start.p0(i64 8, ptr %20) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %21) #6
  %237 = getelementptr inbounds %"struct.std::pair", ptr %16, i32 0, i32 1
  %238 = load i32, ptr %237, align 4, !tbaa !16
  %239 = add nsw i32 %238, 1
  store i32 %239, ptr %21, align 4, !tbaa !9
  %240 = call i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %15, ptr noundef nonnull align 4 dereferenceable(4) %21)
  store i64 %240, ptr %20, align 4
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %20)
  %241 = load i32, ptr %15, align 4, !tbaa !9
  %242 = sext i32 %241 to i64
  %243 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %242
  store i8 1, ptr %243, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %21) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %20) #6
  br label %244

244:                                              ; preds = %236, %223
  br label %269

245:                                              ; preds = %214
  %246 = load i32, ptr %10, align 4, !tbaa !9
  %247 = mul nsw i32 %246, 1000000
  %248 = load i32, ptr %13, align 4, !tbaa !9
  %249 = mul nsw i32 1000, %248
  %250 = add nsw i32 %247, %249
  %251 = load i32, ptr %14, align 4, !tbaa !9
  %252 = add nsw i32 %250, %251
  store i32 %252, ptr %15, align 4, !tbaa !9
  %253 = load i32, ptr %15, align 4, !tbaa !9
  %254 = sext i32 %253 to i64
  %255 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %254
  %256 = load i8, ptr %255, align 1, !tbaa !5, !range !17, !noundef !18
  %257 = trunc i8 %256 to i1
  %258 = zext i1 %257 to i32
  %259 = icmp eq i32 %258, 0
  br i1 %259, label %260, label %268

260:                                              ; preds = %245
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %23) #6
  %261 = getelementptr inbounds %"struct.std::pair", ptr %16, i32 0, i32 1
  %262 = load i32, ptr %261, align 4, !tbaa !16
  %263 = add nsw i32 %262, 1
  store i32 %263, ptr %23, align 4, !tbaa !9
  %264 = call i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %15, ptr noundef nonnull align 4 dereferenceable(4) %23)
  store i64 %264, ptr %22, align 4
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %22)
  %265 = load i32, ptr %15, align 4, !tbaa !9
  %266 = sext i32 %265 to i64
  %267 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %266
  store i8 1, ptr %267, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %23) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #6
  br label %268

268:                                              ; preds = %260, %245
  br label %269

269:                                              ; preds = %268, %244
  br label %270

270:                                              ; preds = %269, %213
  br label %271

271:                                              ; preds = %270, %183
  br label %440

272:                                              ; preds = %94
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #6
  store i32 0, ptr %24, align 4, !tbaa !9
  br label %273

273:                                              ; preds = %436, %272
  %274 = load i32, ptr %24, align 4, !tbaa !9
  %275 = icmp slt i32 %274, 4
  br i1 %275, label %277, label %276

276:                                              ; preds = %273
  store i32 10, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #6
  br label %439

277:                                              ; preds = %273
  call void @llvm.lifetime.start.p0(i64 4, ptr %25) #6
  %278 = load i32, ptr %11, align 4, !tbaa !9
  %279 = load i32, ptr %24, align 4, !tbaa !9
  %280 = sext i32 %279 to i64
  %281 = getelementptr inbounds [4 x i32], ptr @xdir, i64 0, i64 %280
  %282 = load i32, ptr %281, align 4, !tbaa !9
  %283 = add nsw i32 %278, %282
  store i32 %283, ptr %25, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %26) #6
  %284 = load i32, ptr %12, align 4, !tbaa !9
  %285 = load i32, ptr %24, align 4, !tbaa !9
  %286 = sext i32 %285 to i64
  %287 = getelementptr inbounds [4 x i32], ptr @ydir, i64 0, i64 %286
  %288 = load i32, ptr %287, align 4, !tbaa !9
  %289 = add nsw i32 %284, %288
  store i32 %289, ptr %26, align 4, !tbaa !9
  %290 = load i32, ptr %25, align 4, !tbaa !9
  %291 = icmp slt i32 %290, 0
  br i1 %291, label %312, label %292

292:                                              ; preds = %277
  %293 = load i32, ptr %25, align 4, !tbaa !9
  %294 = load i32, ptr @M, align 4, !tbaa !9
  %295 = icmp sge i32 %293, %294
  br i1 %295, label %312, label %296

296:                                              ; preds = %292
  %297 = load i32, ptr %26, align 4, !tbaa !9
  %298 = icmp slt i32 %297, 0
  br i1 %298, label %312, label %299

299:                                              ; preds = %296
  %300 = load i32, ptr %26, align 4, !tbaa !9
  %301 = load i32, ptr @N, align 4, !tbaa !9
  %302 = icmp sge i32 %300, %301
  br i1 %302, label %312, label %303

303:                                              ; preds = %299
  %304 = load i32, ptr %25, align 4, !tbaa !9
  %305 = sext i32 %304 to i64
  %306 = getelementptr inbounds [1000 x [1000 x i32]], ptr @grid, i64 0, i64 %305
  %307 = load i32, ptr %26, align 4, !tbaa !9
  %308 = sext i32 %307 to i64
  %309 = getelementptr inbounds [1000 x i32], ptr %306, i64 0, i64 %308
  %310 = load i32, ptr %309, align 4, !tbaa !9
  %311 = icmp eq i32 %310, 0
  br i1 %311, label %312, label %313

312:                                              ; preds = %303, %299, %296, %292, %277
  store i32 12, ptr %4, align 4
  br label %433

313:                                              ; preds = %303
  %314 = load i32, ptr %25, align 4, !tbaa !9
  %315 = sext i32 %314 to i64
  %316 = getelementptr inbounds [1000 x [1000 x i32]], ptr @grid, i64 0, i64 %315
  %317 = load i32, ptr %26, align 4, !tbaa !9
  %318 = sext i32 %317 to i64
  %319 = getelementptr inbounds [1000 x i32], ptr %316, i64 0, i64 %318
  %320 = load i32, ptr %319, align 4, !tbaa !9
  %321 = icmp eq i32 %320, 1
  br i1 %321, label %322, label %344

322:                                              ; preds = %313
  call void @llvm.lifetime.start.p0(i64 4, ptr %27) #6
  %323 = load i32, ptr %9, align 4, !tbaa !9
  %324 = mul nsw i32 5000000, %323
  %325 = load i32, ptr %25, align 4, !tbaa !9
  %326 = mul nsw i32 1000, %325
  %327 = add nsw i32 %324, %326
  %328 = load i32, ptr %26, align 4, !tbaa !9
  %329 = add nsw i32 %327, %328
  store i32 %329, ptr %27, align 4, !tbaa !9
  %330 = load i32, ptr %27, align 4, !tbaa !9
  %331 = sext i32 %330 to i64
  %332 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %331
  %333 = load i8, ptr %332, align 1, !tbaa !5, !range !17, !noundef !18
  %334 = trunc i8 %333 to i1
  br i1 %334, label %343, label %335

335:                                              ; preds = %322
  call void @llvm.lifetime.start.p0(i64 8, ptr %28) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %29) #6
  %336 = getelementptr inbounds %"struct.std::pair", ptr %16, i32 0, i32 1
  %337 = load i32, ptr %336, align 4, !tbaa !16
  %338 = add nsw i32 %337, 1
  store i32 %338, ptr %29, align 4, !tbaa !9
  %339 = call i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %27, ptr noundef nonnull align 4 dereferenceable(4) %29)
  store i64 %339, ptr %28, align 4
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %28)
  %340 = load i32, ptr %27, align 4, !tbaa !9
  %341 = sext i32 %340 to i64
  %342 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %341
  store i8 1, ptr %342, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %29) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %28) #6
  br label %343

343:                                              ; preds = %335, %322
  call void @llvm.lifetime.end.p0(i64 4, ptr %27) #6
  br label %431

344:                                              ; preds = %313
  %345 = load i32, ptr %25, align 4, !tbaa !9
  %346 = sext i32 %345 to i64
  %347 = getelementptr inbounds [1000 x [1000 x i32]], ptr @grid, i64 0, i64 %346
  %348 = load i32, ptr %26, align 4, !tbaa !9
  %349 = sext i32 %348 to i64
  %350 = getelementptr inbounds [1000 x i32], ptr %347, i64 0, i64 %349
  %351 = load i32, ptr %350, align 4, !tbaa !9
  %352 = icmp eq i32 %351, 2
  br i1 %352, label %353, label %373

353:                                              ; preds = %344
  call void @llvm.lifetime.start.p0(i64 4, ptr %30) #6
  %354 = load i32, ptr %25, align 4, !tbaa !9
  %355 = mul nsw i32 1000, %354
  %356 = add nsw i32 5000000, %355
  %357 = load i32, ptr %26, align 4, !tbaa !9
  %358 = add nsw i32 %356, %357
  store i32 %358, ptr %30, align 4, !tbaa !9
  %359 = load i32, ptr %30, align 4, !tbaa !9
  %360 = sext i32 %359 to i64
  %361 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %360
  %362 = load i8, ptr %361, align 1, !tbaa !5, !range !17, !noundef !18
  %363 = trunc i8 %362 to i1
  br i1 %363, label %372, label %364

364:                                              ; preds = %353
  call void @llvm.lifetime.start.p0(i64 8, ptr %31) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %32) #6
  %365 = getelementptr inbounds %"struct.std::pair", ptr %16, i32 0, i32 1
  %366 = load i32, ptr %365, align 4, !tbaa !16
  %367 = add nsw i32 %366, 1
  store i32 %367, ptr %32, align 4, !tbaa !9
  %368 = call i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %30, ptr noundef nonnull align 4 dereferenceable(4) %32)
  store i64 %368, ptr %31, align 4
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %31)
  %369 = load i32, ptr %30, align 4, !tbaa !9
  %370 = sext i32 %369 to i64
  %371 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %370
  store i8 1, ptr %371, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %32) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %31) #6
  br label %372

372:                                              ; preds = %364, %353
  call void @llvm.lifetime.end.p0(i64 4, ptr %30) #6
  br label %430

373:                                              ; preds = %344
  %374 = load i32, ptr %25, align 4, !tbaa !9
  %375 = sext i32 %374 to i64
  %376 = getelementptr inbounds [1000 x [1000 x i32]], ptr @grid, i64 0, i64 %375
  %377 = load i32, ptr %26, align 4, !tbaa !9
  %378 = sext i32 %377 to i64
  %379 = getelementptr inbounds [1000 x i32], ptr %376, i64 0, i64 %378
  %380 = load i32, ptr %379, align 4, !tbaa !9
  %381 = icmp eq i32 %380, 3
  br i1 %381, label %382, label %406

382:                                              ; preds = %373
  %383 = load i32, ptr %9, align 4, !tbaa !9
  %384 = icmp eq i32 %383, 1
  br i1 %384, label %385, label %405

385:                                              ; preds = %382
  call void @llvm.lifetime.start.p0(i64 4, ptr %33) #6
  %386 = load i32, ptr %25, align 4, !tbaa !9
  %387 = mul nsw i32 1000, %386
  %388 = add nsw i32 5000000, %387
  %389 = load i32, ptr %26, align 4, !tbaa !9
  %390 = add nsw i32 %388, %389
  store i32 %390, ptr %33, align 4, !tbaa !9
  %391 = load i32, ptr %33, align 4, !tbaa !9
  %392 = sext i32 %391 to i64
  %393 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %392
  %394 = load i8, ptr %393, align 1, !tbaa !5, !range !17, !noundef !18
  %395 = trunc i8 %394 to i1
  br i1 %395, label %404, label %396

396:                                              ; preds = %385
  call void @llvm.lifetime.start.p0(i64 8, ptr %34) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %35) #6
  %397 = getelementptr inbounds %"struct.std::pair", ptr %16, i32 0, i32 1
  %398 = load i32, ptr %397, align 4, !tbaa !16
  %399 = add nsw i32 %398, 1
  store i32 %399, ptr %35, align 4, !tbaa !9
  %400 = call i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %33, ptr noundef nonnull align 4 dereferenceable(4) %35)
  store i64 %400, ptr %34, align 4
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %34)
  %401 = load i32, ptr %33, align 4, !tbaa !9
  %402 = sext i32 %401 to i64
  %403 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %402
  store i8 1, ptr %403, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %35) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %34) #6
  br label %404

404:                                              ; preds = %396, %385
  call void @llvm.lifetime.end.p0(i64 4, ptr %33) #6
  br label %405

405:                                              ; preds = %404, %382
  br label %429

406:                                              ; preds = %373
  call void @llvm.lifetime.start.p0(i64 4, ptr %36) #6
  %407 = load i32, ptr %24, align 4, !tbaa !9
  %408 = add nsw i32 %407, 1
  %409 = mul nsw i32 %408, 1000000
  %410 = load i32, ptr %25, align 4, !tbaa !9
  %411 = mul nsw i32 1000, %410
  %412 = add nsw i32 %409, %411
  %413 = load i32, ptr %26, align 4, !tbaa !9
  %414 = add nsw i32 %412, %413
  store i32 %414, ptr %36, align 4, !tbaa !9
  %415 = load i32, ptr %36, align 4, !tbaa !9
  %416 = sext i32 %415 to i64
  %417 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %416
  %418 = load i8, ptr %417, align 1, !tbaa !5, !range !17, !noundef !18
  %419 = trunc i8 %418 to i1
  br i1 %419, label %428, label %420

420:                                              ; preds = %406
  call void @llvm.lifetime.start.p0(i64 8, ptr %37) #6
  call void @llvm.lifetime.start.p0(i64 4, ptr %38) #6
  %421 = getelementptr inbounds %"struct.std::pair", ptr %16, i32 0, i32 1
  %422 = load i32, ptr %421, align 4, !tbaa !16
  %423 = add nsw i32 %422, 1
  store i32 %423, ptr %38, align 4, !tbaa !9
  %424 = call i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %36, ptr noundef nonnull align 4 dereferenceable(4) %38)
  store i64 %424, ptr %37, align 4
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %37)
  %425 = load i32, ptr %36, align 4, !tbaa !9
  %426 = sext i32 %425 to i64
  %427 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %426
  store i8 1, ptr %427, align 1, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %38) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %37) #6
  br label %428

428:                                              ; preds = %420, %406
  call void @llvm.lifetime.end.p0(i64 4, ptr %36) #6
  br label %429

429:                                              ; preds = %428, %405
  br label %430

430:                                              ; preds = %429, %372
  br label %431

431:                                              ; preds = %430, %343
  br label %432

432:                                              ; preds = %431
  store i32 0, ptr %4, align 4
  br label %433

433:                                              ; preds = %432, %312
  call void @llvm.lifetime.end.p0(i64 4, ptr %26) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %25) #6
  %434 = load i32, ptr %4, align 4
  switch i32 %434, label %451 [
    i32 0, label %435
    i32 12, label %436
  ]

435:                                              ; preds = %433
  br label %436

436:                                              ; preds = %435, %433
  %437 = load i32, ptr %24, align 4, !tbaa !9
  %438 = add nsw i32 %437, 1
  store i32 %438, ptr %24, align 4, !tbaa !9
  br label %273, !llvm.loop !19

439:                                              ; preds = %276
  br label %440

440:                                              ; preds = %439, %271
  store i32 0, ptr %4, align 4
  br label %441

441:                                              ; preds = %440, %90
  call void @llvm.lifetime.end.p0(i64 8, ptr %16) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %15) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %14) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #6
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  %442 = load i32, ptr %4, align 4
  switch i32 %442, label %451 [
    i32 0, label %443
    i32 9, label %444
  ]

443:                                              ; preds = %441
  br label %75, !llvm.loop !20

444:                                              ; preds = %441, %75
  %445 = load i8, ptr %2, align 1, !tbaa !5, !range !17, !noundef !18
  %446 = trunc i8 %445 to i1
  br i1 %446, label %449, label %447

447:                                              ; preds = %444
  %448 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @cout, i32 noundef -1)
  br label %449

449:                                              ; preds = %447, %444
  call void @llvm.lifetime.end.p0(i64 1, ptr %2) #6
  %450 = load i32, ptr %1, align 4
  ret i32 %450

451:                                              ; preds = %441, %433
  unreachable
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) #1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 4 dereferenceable(8)) #3 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80)) #4 align 2

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

; 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 nounwind uwtable
declare dso_local void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE3popEv(ptr noundef nonnull align 8 dereferenceable(80)) #4 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 dso_local i64 @_ZSt9make_pairIRiS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #3

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

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

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

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


; 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::basic_ifstream" = type { %"class.std::basic_istream.base", %"class.std::basic_filebuf", %"class.std::basic_ios" }
%"class.std::basic_istream.base" = type { ptr, i64 }
%"class.std::basic_filebuf" = type { %"class.std::basic_streambuf", %union.pthread_mutex_t, %"class.std::__basic_file", i32, %struct.__mbstate_t, %struct.__mbstate_t, %struct.__mbstate_t, ptr, i64, i8, i8, i8, i8, ptr, ptr, i8, ptr, ptr, i64, ptr, ptr }
%"class.std::basic_streambuf" = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, %"class.std::locale" }
%"class.std::locale" = type { ptr }
%union.pthread_mutex_t = type { %struct.__pthread_mutex_s }
%struct.__pthread_mutex_s = type { i32, i32, i32, i32, i32, i16, i16, %struct.__pthread_internal_list }
%struct.__pthread_internal_list = type { ptr, ptr }
%"class.std::__basic_file" = type <{ ptr, i8, [7 x i8] }>
%struct.__mbstate_t = type { i32, %union.anon }
%union.anon = type { i32 }
%"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::basic_ofstream" = type { %"class.std::basic_ostream.base", %"class.std::basic_filebuf", %"class.std::basic_ios" }
%"class.std::basic_ostream.base" = type { ptr }
%"class.std::queue" = type { %"class.std::deque" }
%"class.std::deque" = type { %"class.std::_Deque_base" }
%"class.std::_Deque_base" = type { %"struct.std::_Deque_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Deque_impl" }
%"struct.std::_Deque_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Deque_impl" = type { %"struct.std::_Deque_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Deque_impl_data" }
%"struct.std::_Deque_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Deque_impl_data" = type { ptr, i64, %"struct.std::_Deque_iterator", %"struct.std::_Deque_iterator" }
%"struct.std::_Deque_iterator" = type { ptr, ptr, ptr, ptr }
%"struct.std::pair" = type { i32, i32 }

@cin = external dso_local global %"class.std::basic_ifstream", align 8
@cout = external dso_local global %"class.std::basic_ofstream", align 8
@grid = external dso_local global [1000 x [1000 x i32]], align 16
@xdir = external dso_local local_unnamed_addr global [4 x i32], align 16
@ydir = external dso_local local_unnamed_addr global [4 x i32], align 16
@N = external dso_local global i32, align 4
@M = external dso_local global i32, align 4
@des = external dso_local local_unnamed_addr global i32, align 4
@visit = external dso_local local_unnamed_addr global [10000000 x i8], align 16
@q = external dso_local global %"class.std::queue", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca %"struct.std::pair", align 8
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca %"struct.std::pair", align 8
  %6 = alloca %"struct.std::pair", align 8
  %7 = alloca %"struct.std::pair", align 8
  %8 = alloca i32, align 4
  %9 = alloca %"struct.std::pair", align 8
  %10 = alloca i32, align 4
  %11 = alloca %"struct.std::pair", align 8
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca %"struct.std::pair", align 8
  %15 = alloca i32, align 4
  %16 = alloca i32, align 4
  %17 = alloca %"struct.std::pair", align 8
  %18 = alloca i32, align 4
  %19 = alloca i32, align 4
  %20 = alloca %"struct.std::pair", align 8
  %21 = alloca i32, align 4
  %22 = alloca i32, align 4
  %23 = alloca %"struct.std::pair", align 8
  %24 = alloca i32, align 4
  %25 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @cin, ptr noundef nonnull align 4 dereferenceable(4) @N)
  %26 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %25, ptr noundef nonnull align 4 dereferenceable(4) @M)
  %27 = load i32, ptr @N, align 4, !tbaa !5
  %28 = icmp sgt i32 %27, 0
  %29 = load i32, ptr @M, align 4
  %30 = icmp sgt i32 %29, 0
  %or.cond = select i1 %28, i1 %30, i1 false
  br i1 %or.cond, label %.preheader100, label %._crit_edge103

.preheader100:                                    ; preds = %0, %._crit_edge
  %31 = phi i32 [ %42, %._crit_edge ], [ %27, %0 ]
  %32 = phi i32 [ %43, %._crit_edge ], [ %29, %0 ]
  %indvars.iv110 = phi i64 [ %indvars.iv.next111, %._crit_edge ], [ 0, %0 ]
  %33 = icmp sgt i32 %32, 0
  br i1 %33, label %.lr.ph, label %._crit_edge

._crit_edge103:                                   ; preds = %._crit_edge, %0
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %1) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  %34 = call i64 @_ZSt9make_pairIiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS1_INS2_IT0_E4typeEE6__typeEEOS3_OS8_(ptr noundef nonnull align 4 dereferenceable(4) %2, ptr noundef nonnull align 4 dereferenceable(4) %3)
  store i64 %34, ptr %1, align 8
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %1)
  %35 = load i32, ptr @M, align 4, !tbaa !5
  %36 = mul i32 %35, 1000
  %37 = load i32, ptr @N, align 4, !tbaa !5
  %38 = add i32 %36, -1001
  %39 = add i32 %38, %37
  store i32 %39, ptr @des, align 4, !tbaa !5
  store i8 1, ptr @visit, align 16, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %1) #5
  %40 = call noundef zeroext i1 @_ZNKSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80) @q)
  br i1 %40, label %._crit_edge107, label %.lr.ph106

.lr.ph106:                                        ; preds = %._crit_edge103
  %41 = getelementptr inbounds i8, ptr %5, i64 4
  br label %51

._crit_edge.loopexit:                             ; preds = %.lr.ph
  %.pre = load i32, ptr @N, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader100
  %42 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %31, %.preheader100 ]
  %43 = phi i32 [ %48, %._crit_edge.loopexit ], [ %32, %.preheader100 ]
  %indvars.iv.next111 = add nuw nsw i64 %indvars.iv110, 1
  %44 = sext i32 %42 to i64
  %45 = icmp slt i64 %indvars.iv.next111, %44
  br i1 %45, label %.preheader100, label %._crit_edge103, !llvm.loop !11

.lr.ph:                                           ; preds = %.preheader100, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader100 ]
  %46 = getelementptr inbounds [1000 x [1000 x i32]], ptr @grid, i64 0, i64 %indvars.iv, i64 %indvars.iv110
  %47 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @cin, ptr noundef nonnull align 4 dereferenceable(4) %46)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %48 = load i32, ptr @M, align 4, !tbaa !5
  %49 = sext i32 %48 to i64
  %50 = icmp slt i64 %indvars.iv.next, %49
  br i1 %50, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !14

51:                                               ; preds = %.lr.ph106, %.loopexit
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #5
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %5) #5
  %52 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE5frontEv(ptr noundef nonnull align 8 dereferenceable(80) @q)
  %53 = load i64, ptr %52, align 4
  store i64 %53, ptr %5, align 8
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE3popEv(ptr noundef nonnull align 8 dereferenceable(80) @q)
  %54 = load i32, ptr %5, align 8, !tbaa !15
  %.fr = freeze i32 %54
  %55 = load i32, ptr @des, align 4, !tbaa !5
  %56 = icmp eq i32 %.fr, %55
  %57 = add nsw i32 %55, 5000000
  %58 = icmp eq i32 %.fr, %57
  %or.cond86 = select i1 %56, i1 true, i1 %58
  br i1 %or.cond86, label %.thread92, label %61

.thread92:                                        ; preds = %51
  %59 = load i32, ptr %41, align 4, !tbaa !17
  %60 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @cout, i32 noundef %59)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #5
  br label %232

61:                                               ; preds = %51
  %62 = srem i32 %.fr, 5000000
  %63 = sub nsw i32 %.fr, %62
  %64 = sdiv i32 %62, 1000000
  %65 = mul nsw i32 %64, 1000000
  %.recomposed = srem i32 %62, 1000000
  store i32 %.recomposed, ptr %5, align 8, !tbaa !15
  %66 = sdiv i32 %.recomposed, 1000
  %67 = srem i32 %.recomposed, 1000
  %.off = add nsw i32 %62, 999999
  %.not = icmp ult i32 %.off, 1999999
  br i1 %.not, label %.preheader, label %69

.preheader:                                       ; preds = %61
  %.off83 = add i32 %.fr, -5000000
  %68 = icmp ult i32 %.off83, 5000000
  br label %143

69:                                               ; preds = %61
  %70 = add nsw i32 %64, -1
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [4 x i32], ptr @xdir, i64 0, i64 %71
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = add nsw i32 %73, %66
  %75 = getelementptr inbounds [4 x i32], ptr @ydir, i64 0, i64 %71
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = add nsw i32 %76, %67
  %78 = icmp slt i32 %74, 0
  br i1 %78, label %89, label %79

79:                                               ; preds = %69
  %80 = load i32, ptr @M, align 4, !tbaa !5
  %81 = icmp slt i32 %74, %80
  %82 = icmp sgt i32 %77, -1
  %or.cond.not96 = select i1 %81, i1 %82, i1 false
  %83 = load i32, ptr @N, align 4
  %.not84 = icmp slt i32 %77, %83
  %or.cond87 = select i1 %or.cond.not96, i1 %.not84, i1 false
  br i1 %or.cond87, label %84, label %89

84:                                               ; preds = %79
  %85 = zext nneg i32 %74 to i64
  %86 = zext nneg i32 %77 to i64
  %87 = getelementptr inbounds [1000 x [1000 x i32]], ptr @grid, i64 0, i64 %85, i64 %86
  %88 = load i32, ptr %87, align 4, !tbaa !5
  switch i32 %88, label %128 [
    i32 0, label %89
    i32 3, label %89
    i32 1, label %99
    i32 2, label %113
  ]

89:                                               ; preds = %84, %84, %79, %69
  store i32 %.recomposed, ptr %4, align 4, !tbaa !5
  %90 = sext i32 %.recomposed to i64
  %91 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %90
  %92 = load i8, ptr %91, align 1, !tbaa !9, !range !18, !noundef !19
  %93 = icmp eq i8 %92, 0
  br i1 %93, label %94, label %.loopexit

94:                                               ; preds = %89
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %6) #5
  %95 = call i64 @_ZSt9make_pairIRiS0_ESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %41)
  store i64 %95, ptr %6, align 8
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %6)
  %96 = load i32, ptr %4, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %97
  store i8 1, ptr %98, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %6) #5
  br label %.loopexit

99:                                               ; preds = %84
  %100 = mul nuw nsw i32 %74, 1000
  %101 = add nuw nsw i32 %100, %77
  store i32 %101, ptr %4, align 4, !tbaa !5
  %102 = zext nneg i32 %101 to i64
  %103 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %102
  %104 = load i8, ptr %103, align 1, !tbaa !9, !range !18, !noundef !19
  %105 = icmp eq i8 %104, 0
  br i1 %105, label %106, label %.loopexit

106:                                              ; preds = %99
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %7) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #5
  %107 = load i32, ptr %41, align 4, !tbaa !17
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr %8, align 4, !tbaa !5
  %109 = call i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %8)
  store i64 %109, ptr %7, align 8
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %7)
  %110 = load i32, ptr %4, align 4, !tbaa !5
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %111
  store i8 1, ptr %112, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %7) #5
  br label %.loopexit

113:                                              ; preds = %84
  %114 = mul nuw nsw i32 %74, 1000
  %115 = add nuw nsw i32 %114, 5000000
  %116 = add nuw nsw i32 %115, %77
  store i32 %116, ptr %4, align 4, !tbaa !5
  %117 = zext nneg i32 %116 to i64
  %118 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %117
  %119 = load i8, ptr %118, align 1, !tbaa !9, !range !18, !noundef !19
  %120 = icmp eq i8 %119, 0
  br i1 %120, label %121, label %.loopexit

121:                                              ; preds = %113
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %9) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %10) #5
  %122 = load i32, ptr %41, align 4, !tbaa !17
  %123 = add nsw i32 %122, 1
  store i32 %123, ptr %10, align 4, !tbaa !5
  %124 = call i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %10)
  store i64 %124, ptr %9, align 8
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %9)
  %125 = load i32, ptr %4, align 4, !tbaa !5
  %126 = sext i32 %125 to i64
  %127 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %126
  store i8 1, ptr %127, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %10) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %9) #5
  br label %.loopexit

128:                                              ; preds = %84
  %129 = mul nuw nsw i32 %74, 1000
  %130 = add nsw i32 %129, %65
  %131 = add nsw i32 %130, %77
  store i32 %131, ptr %4, align 4, !tbaa !5
  %132 = sext i32 %131 to i64
  %133 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %132
  %134 = load i8, ptr %133, align 1, !tbaa !9, !range !18, !noundef !19
  %135 = icmp eq i8 %134, 0
  br i1 %135, label %136, label %.loopexit

136:                                              ; preds = %128
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %11) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %12) #5
  %137 = load i32, ptr %41, align 4, !tbaa !17
  %138 = add nsw i32 %137, 1
  store i32 %138, ptr %12, align 4, !tbaa !5
  %139 = call i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %4, ptr noundef nonnull align 4 dereferenceable(4) %12)
  store i64 %139, ptr %11, align 8
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %11)
  %140 = load i32, ptr %4, align 4, !tbaa !5
  %141 = sext i32 %140 to i64
  %142 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %141
  store i8 1, ptr %142, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %12) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #5
  br label %.loopexit

143:                                              ; preds = %.preheader, %229
  %indvars.iv113 = phi i64 [ 0, %.preheader ], [ %indvars.iv.next114, %229 ]
  %144 = getelementptr inbounds [4 x i32], ptr @xdir, i64 0, i64 %indvars.iv113
  %145 = load i32, ptr %144, align 4, !tbaa !5
  %146 = add nsw i32 %145, %66
  %147 = getelementptr inbounds [4 x i32], ptr @ydir, i64 0, i64 %indvars.iv113
  %148 = load i32, ptr %147, align 4, !tbaa !5
  %149 = add nsw i32 %148, %67
  %150 = icmp slt i32 %146, 0
  br i1 %150, label %229, label %151

151:                                              ; preds = %143
  %152 = load i32, ptr @M, align 4, !tbaa !5
  %153 = icmp slt i32 %146, %152
  %154 = icmp sgt i32 %149, -1
  %or.cond3.not99 = select i1 %153, i1 %154, i1 false
  %155 = load i32, ptr @N, align 4
  %.not82 = icmp slt i32 %149, %155
  %or.cond88 = select i1 %or.cond3.not99, i1 %.not82, i1 false
  br i1 %or.cond88, label %156, label %229

156:                                              ; preds = %151
  %157 = zext nneg i32 %146 to i64
  %158 = zext nneg i32 %149 to i64
  %159 = getelementptr inbounds [1000 x [1000 x i32]], ptr @grid, i64 0, i64 %157, i64 %158
  %160 = load i32, ptr %159, align 4, !tbaa !5
  switch i32 %160, label %210 [
    i32 0, label %229
    i32 1, label %161
    i32 2, label %177
    i32 3, label %193
  ]

161:                                              ; preds = %156
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %13) #5
  %162 = mul nuw nsw i32 %146, 1000
  %163 = add nsw i32 %63, %162
  %164 = add nsw i32 %163, %149
  store i32 %164, ptr %13, align 4, !tbaa !5
  %165 = sext i32 %164 to i64
  %166 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %165
  %167 = load i8, ptr %166, align 1, !tbaa !9, !range !18, !noundef !19
  %168 = trunc nuw i8 %167 to i1
  br i1 %168, label %176, label %169

169:                                              ; preds = %161
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %14) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %15) #5
  %170 = load i32, ptr %41, align 4, !tbaa !17
  %171 = add nsw i32 %170, 1
  store i32 %171, ptr %15, align 4, !tbaa !5
  %172 = call i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %13, ptr noundef nonnull align 4 dereferenceable(4) %15)
  store i64 %172, ptr %14, align 8
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %14)
  %173 = load i32, ptr %13, align 4, !tbaa !5
  %174 = sext i32 %173 to i64
  %175 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %174
  store i8 1, ptr %175, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %15) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %14) #5
  br label %176

176:                                              ; preds = %169, %161
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %13) #5
  br label %229

177:                                              ; preds = %156
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %16) #5
  %178 = mul nuw nsw i32 %146, 1000
  %179 = add nuw nsw i32 %178, 5000000
  %180 = add nuw nsw i32 %179, %149
  store i32 %180, ptr %16, align 4, !tbaa !5
  %181 = zext nneg i32 %180 to i64
  %182 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %181
  %183 = load i8, ptr %182, align 1, !tbaa !9, !range !18, !noundef !19
  %184 = trunc nuw i8 %183 to i1
  br i1 %184, label %192, label %185

185:                                              ; preds = %177
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %17) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %18) #5
  %186 = load i32, ptr %41, align 4, !tbaa !17
  %187 = add nsw i32 %186, 1
  store i32 %187, ptr %18, align 4, !tbaa !5
  %188 = call i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %16, ptr noundef nonnull align 4 dereferenceable(4) %18)
  store i64 %188, ptr %17, align 8
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %17)
  %189 = load i32, ptr %16, align 4, !tbaa !5
  %190 = sext i32 %189 to i64
  %191 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %190
  store i8 1, ptr %191, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %18) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %17) #5
  br label %192

192:                                              ; preds = %185, %177
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %16) #5
  br label %229

193:                                              ; preds = %156
  br i1 %68, label %194, label %229

194:                                              ; preds = %193
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %19) #5
  %195 = mul nuw nsw i32 %146, 1000
  %196 = add nuw nsw i32 %195, 5000000
  %197 = add nuw nsw i32 %196, %149
  store i32 %197, ptr %19, align 4, !tbaa !5
  %198 = zext nneg i32 %197 to i64
  %199 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %198
  %200 = load i8, ptr %199, align 1, !tbaa !9, !range !18, !noundef !19
  %201 = trunc nuw i8 %200 to i1
  br i1 %201, label %209, label %202

202:                                              ; preds = %194
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %20) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %21) #5
  %203 = load i32, ptr %41, align 4, !tbaa !17
  %204 = add nsw i32 %203, 1
  store i32 %204, ptr %21, align 4, !tbaa !5
  %205 = call i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %19, ptr noundef nonnull align 4 dereferenceable(4) %21)
  store i64 %205, ptr %20, align 8
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %20)
  %206 = load i32, ptr %19, align 4, !tbaa !5
  %207 = sext i32 %206 to i64
  %208 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %207
  store i8 1, ptr %208, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %21) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %20) #5
  br label %209

209:                                              ; preds = %202, %194
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %19) #5
  br label %229

210:                                              ; preds = %156
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %22) #5
  %211 = mul nuw nsw i32 %146, 1000
  %212 = trunc i64 %indvars.iv113 to i32
  %213 = mul i32 %212, 1000000
  %214 = add i32 %213, 1000000
  %215 = add nuw nsw i32 %214, %211
  %216 = add nuw nsw i32 %215, %149
  store i32 %216, ptr %22, align 4, !tbaa !5
  %217 = zext nneg i32 %216 to i64
  %218 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %217
  %219 = load i8, ptr %218, align 1, !tbaa !9, !range !18, !noundef !19
  %220 = trunc nuw i8 %219 to i1
  br i1 %220, label %228, label %221

221:                                              ; preds = %210
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %23) #5
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %24) #5
  %222 = load i32, ptr %41, align 4, !tbaa !17
  %223 = add nsw i32 %222, 1
  store i32 %223, ptr %24, align 4, !tbaa !5
  %224 = call i64 @_ZSt9make_pairIRiiESt4pairINSt25__strip_reference_wrapperINSt5decayIT_E4typeEE6__typeENS2_INS3_IT0_E4typeEE6__typeEEOS4_OS9_(ptr noundef nonnull align 4 dereferenceable(4) %22, ptr noundef nonnull align 4 dereferenceable(4) %24)
  store i64 %224, ptr %23, align 8
  call void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80) @q, ptr noundef nonnull align 4 dereferenceable(8) %23)
  %225 = load i32, ptr %22, align 4, !tbaa !5
  %226 = sext i32 %225 to i64
  %227 = getelementptr inbounds [10000000 x i8], ptr @visit, i64 0, i64 %226
  store i8 1, ptr %227, align 1, !tbaa !9
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %24) #5
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %23) #5
  br label %228

228:                                              ; preds = %221, %210
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %22) #5
  br label %229

229:                                              ; preds = %192, %193, %209, %228, %176, %156, %143, %151
  %indvars.iv.next114 = add nuw nsw i64 %indvars.iv113, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next114, 4
  br i1 %exitcond.not, label %.loopexit, label %143, !llvm.loop !20

.loopexit:                                        ; preds = %229, %106, %99, %128, %136, %113, %121, %89, %94
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %5) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #5
  %230 = call noundef zeroext i1 @_ZNKSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80) @q)
  br i1 %230, label %._crit_edge107, label %51

._crit_edge107:                                   ; preds = %.loopexit, %._crit_edge103
  %231 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @cout, i32 noundef -1)
  br label %232

232:                                              ; preds = %.thread92, %._crit_edge107
  ret i32 0
}

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #1

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE4pushEOS1_(ptr noundef nonnull align 8 dereferenceable(80), ptr noundef nonnull align 4 dereferenceable(8)) local_unnamed_addr #3 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZNKSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE5emptyEv(ptr noundef nonnull align 8 dereferenceable(80)) local_unnamed_addr #4 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt5queueISt4pairIiiESt5dequeIS1_SaIS1_EEE3popEv(ptr noundef nonnull align 8 dereferenceable(80)) local_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 #1

; Function Attrs: mustprogress uwtable
declare dso_local i64 @_ZSt9make_pairIRiS0_ESt4pairINSt25__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 #3

; 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 #3

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


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