; LLVM IR from bqi343/cp-notebook :: Contests/USACO Solutions/2013-14/Jan 2014 (14 Jan 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::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::pair<int, std::pair<std::pair<int, int>, std::pair<int, int>>>, std::allocator<std::pair<int, std::pair<std::pair<int, int>, std::pair<int, int>>>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::pair<int, std::pair<std::pair<int, int>, std::pair<int, int>>>, std::allocator<std::pair<int, std::pair<std::pair<int, int>, std::pair<int, int>>>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::pair<int, std::pair<std::pair<int, int>, std::pair<int, int>>>, std::allocator<std::pair<int, std::pair<std::pair<int, int>, std::pair<int, int>>>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::pair<int, std::pair<std::pair<int, int>, std::pair<int, int>>>, std::allocator<std::pair<int, std::pair<std::pair<int, int>, std::pair<int, int>>>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.std::pair" = type { i32, i32 }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"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 }
%"struct.std::pair.5" = type { i32, %"struct.std::pair.7" }
%"struct.std::pair.7" = type { %"struct.std::pair", %"struct.std::pair" }
%"class.__gnu_cxx::__normal_iterator.9" = type { ptr }

@M = external dso_local global i32, align 4
@N = external dso_local global i32, align 4
@T = external dso_local global i32, align 4
@grid = external dso_local global [500 x [500 x i32]], align 16
@query = external dso_local global [500 x [500 x i32]], align 16
@ans = external dso_local global i64, align 8
@edge = external dso_local global %"class.std::vector", align 8
@comp = external dso_local global [500 x [500 x %"struct.std::pair"]], align 16
@mem = external dso_local global [500 x [500 x %"class.std::vector.0"]], align 16
@cin = external dso_local global %"class.std::basic_ifstream", align 8
@cout = external dso_local global %"class.std::basic_ofstream", align 8

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

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5uniteiSt4pairIiiES0_(i32 noundef, i64, i64) #2

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

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

39:                                               ; preds = %62, %0
  %40 = load i32, ptr %2, align 4, !tbaa !5
  %41 = load i32, ptr @M, align 4, !tbaa !5
  %42 = icmp slt i32 %40, %41
  br i1 %42, label %44, label %43

43:                                               ; preds = %39
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #9
  br label %65

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

45:                                               ; preds = %58, %44
  %46 = load i32, ptr %4, align 4, !tbaa !5
  %47 = load i32, ptr @N, align 4, !tbaa !5
  %48 = icmp slt i32 %46, %47
  br i1 %48, label %50, label %49

49:                                               ; preds = %45
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #9
  br label %61

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

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

61:                                               ; preds = %49
  br label %62

62:                                               ; preds = %61
  %63 = load i32, ptr %2, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %2, align 4, !tbaa !5
  br label %39, !llvm.loop !11

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

66:                                               ; preds = %95, %65
  %67 = load i32, ptr %5, align 4, !tbaa !5
  %68 = load i32, ptr @M, align 4, !tbaa !5
  %69 = icmp slt i32 %67, %68
  br i1 %69, label %71, label %70

70:                                               ; preds = %66
  store i32 8, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #9
  br label %98

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

72:                                               ; preds = %91, %71
  %73 = load i32, ptr %6, align 4, !tbaa !5
  %74 = load i32, ptr @N, align 4, !tbaa !5
  %75 = icmp slt i32 %73, %74
  br i1 %75, label %77, label %76

76:                                               ; preds = %72
  store i32 11, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #9
  br label %94

77:                                               ; preds = %72
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #9
  call void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %7, ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %78 = load i32, ptr %5, align 4, !tbaa !5
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [500 x [500 x %"struct.std::pair"]], ptr @comp, i64 0, i64 %79
  %81 = load i32, ptr %6, align 4, !tbaa !5
  %82 = sext i32 %81 to i64
  %83 = getelementptr inbounds [500 x %"struct.std::pair"], ptr %80, i64 0, i64 %82
  %84 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8) %83, ptr noundef nonnull align 4 dereferenceable(8) %7) #9
  %85 = load i32, ptr %5, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = getelementptr inbounds [500 x [500 x %"class.std::vector.0"]], ptr @mem, i64 0, i64 %86
  %88 = load i32, ptr %6, align 4, !tbaa !5
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [500 x %"class.std::vector.0"], ptr %87, i64 0, i64 %89
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #9
  call void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %8, ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  call void @_ZNSt6vectorISt4pairIiiESaIS1_EE9push_backEOS1_(ptr noundef nonnull align 8 dereferenceable(24) %90, ptr noundef nonnull align 4 dereferenceable(8) %8)
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #9
  br label %91

91:                                               ; preds = %77
  %92 = load i32, ptr %6, align 4, !tbaa !5
  %93 = add nsw i32 %92, 1
  store i32 %93, ptr %6, align 4, !tbaa !5
  br label %72, !llvm.loop !12

94:                                               ; preds = %76
  br label %95

95:                                               ; preds = %94
  %96 = load i32, ptr %5, align 4, !tbaa !5
  %97 = add nsw i32 %96, 1
  store i32 %97, ptr %5, align 4, !tbaa !5
  br label %66, !llvm.loop !13

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

99:                                               ; preds = %135, %98
  %100 = load i32, ptr %9, align 4, !tbaa !5
  %101 = load i32, ptr @M, align 4, !tbaa !5
  %102 = sub nsw i32 %101, 1
  %103 = icmp slt i32 %100, %102
  br i1 %103, label %105, label %104

104:                                              ; preds = %99
  store i32 14, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #9
  br label %138

105:                                              ; preds = %99
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #9
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %106

106:                                              ; preds = %131, %105
  %107 = load i32, ptr %10, align 4, !tbaa !5
  %108 = load i32, ptr @N, align 4, !tbaa !5
  %109 = icmp slt i32 %107, %108
  br i1 %109, label %111, label %110

110:                                              ; preds = %106
  store i32 17, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #9
  br label %134

111:                                              ; preds = %106
  call void @llvm.lifetime.start.p0(i64 20, ptr %11) #9
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #9
  %112 = load i32, ptr %9, align 4, !tbaa !5
  %113 = sext i32 %112 to i64
  %114 = getelementptr inbounds [500 x [500 x i32]], ptr @grid, i64 0, i64 %113
  %115 = load i32, ptr %10, align 4, !tbaa !5
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds [500 x i32], ptr %114, i64 0, i64 %116
  %118 = load i32, ptr %117, align 4, !tbaa !5
  %119 = load i32, ptr %9, align 4, !tbaa !5
  %120 = add nsw i32 %119, 1
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds [500 x [500 x i32]], ptr @grid, i64 0, i64 %121
  %123 = load i32, ptr %10, align 4, !tbaa !5
  %124 = sext i32 %123 to i64
  %125 = getelementptr inbounds [500 x i32], ptr %122, i64 0, i64 %124
  %126 = load i32, ptr %125, align 4, !tbaa !5
  %127 = sub nsw i32 %118, %126
  %128 = call i32 @llvm.abs.i32(i32 %127, i1 true)
  store i32 %128, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %13) #9
  call void @llvm.lifetime.start.p0(i64 8, ptr %14) #9
  call void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %14, ptr noundef nonnull align 4 dereferenceable(4) %9, ptr noundef nonnull align 4 dereferenceable(4) %10)
  call void @llvm.lifetime.start.p0(i64 8, ptr %15) #9
  call void @llvm.lifetime.start.p0(i64 4, ptr %16) #9
  %129 = load i32, ptr %9, align 4, !tbaa !5
  %130 = add nsw i32 %129, 1
  store i32 %130, ptr %16, align 4, !tbaa !5
  call void @_ZNSt4pairIiiEC2IiRiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %15, ptr noundef nonnull align 4 dereferenceable(4) %16, ptr noundef nonnull align 4 dereferenceable(4) %10)
  call void @_ZNSt4pairIS_IiiES0_EC2IS0_S0_TnNSt9enable_ifIXaaclsr5_PCCPE18_ConstructiblePairIT_T0_EEclsr5_PCCPE26_ImplicitlyConvertiblePairIS4_S5_EEEbE4typeELb1EEERKS0_S9_(ptr noundef nonnull align 4 dereferenceable(16) %13, ptr noundef nonnull align 4 dereferenceable(8) %14, ptr noundef nonnull align 4 dereferenceable(8) %15)
  call void @_ZNSt4pairIiS_IS_IiiES0_EEC2IiS1_TnNSt9enable_ifIXaaclsr5_PCCPE18_ConstructiblePairIT_T0_EEclsr5_PCCPE26_ImplicitlyConvertiblePairIS5_S6_EEEbE4typeELb1EEERKiRKS1_(ptr noundef nonnull align 4 dereferenceable(20) %11, ptr noundef nonnull align 4 dereferenceable(4) %12, ptr noundef nonnull align 4 dereferenceable(16) %13)
  call void @_ZNSt6vectorISt4pairIiS0_IS0_IiiES1_EESaIS3_EE9push_backEOS3_(ptr noundef nonnull align 8 dereferenceable(24) @edge, ptr noundef nonnull align 4 dereferenceable(20) %11)
  call void @llvm.lifetime.end.p0(i64 4, ptr %16) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %15) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %14) #9
  call void @llvm.lifetime.end.p0(i64 16, ptr %13) #9
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #9
  call void @llvm.lifetime.end.p0(i64 20, ptr %11) #9
  br label %131

131:                                              ; preds = %111
  %132 = load i32, ptr %10, align 4, !tbaa !5
  %133 = add nsw i32 %132, 1
  store i32 %133, ptr %10, align 4, !tbaa !5
  br label %106, !llvm.loop !14

134:                                              ; preds = %110
  br label %135

135:                                              ; preds = %134
  %136 = load i32, ptr %9, align 4, !tbaa !5
  %137 = add nsw i32 %136, 1
  store i32 %137, ptr %9, align 4, !tbaa !5
  br label %99, !llvm.loop !15

138:                                              ; preds = %104
  call void @llvm.lifetime.start.p0(i64 4, ptr %17) #9
  store i32 0, ptr %17, align 4, !tbaa !5
  br label %139

139:                                              ; preds = %175, %138
  %140 = load i32, ptr %17, align 4, !tbaa !5
  %141 = load i32, ptr @M, align 4, !tbaa !5
  %142 = icmp slt i32 %140, %141
  br i1 %142, label %144, label %143

143:                                              ; preds = %139
  store i32 20, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %17) #9
  br label %178

144:                                              ; preds = %139
  call void @llvm.lifetime.start.p0(i64 4, ptr %18) #9
  store i32 0, ptr %18, align 4, !tbaa !5
  br label %145

145:                                              ; preds = %171, %144
  %146 = load i32, ptr %18, align 4, !tbaa !5
  %147 = load i32, ptr @N, align 4, !tbaa !5
  %148 = sub nsw i32 %147, 1
  %149 = icmp slt i32 %146, %148
  br i1 %149, label %151, label %150

150:                                              ; preds = %145
  store i32 23, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %18) #9
  br label %174

151:                                              ; preds = %145
  call void @llvm.lifetime.start.p0(i64 20, ptr %19) #9
  call void @llvm.lifetime.start.p0(i64 4, ptr %20) #9
  %152 = load i32, ptr %17, align 4, !tbaa !5
  %153 = sext i32 %152 to i64
  %154 = getelementptr inbounds [500 x [500 x i32]], ptr @grid, i64 0, i64 %153
  %155 = load i32, ptr %18, align 4, !tbaa !5
  %156 = sext i32 %155 to i64
  %157 = getelementptr inbounds [500 x i32], ptr %154, i64 0, i64 %156
  %158 = load i32, ptr %157, align 4, !tbaa !5
  %159 = load i32, ptr %17, align 4, !tbaa !5
  %160 = sext i32 %159 to i64
  %161 = getelementptr inbounds [500 x [500 x i32]], ptr @grid, i64 0, i64 %160
  %162 = load i32, ptr %18, align 4, !tbaa !5
  %163 = add nsw i32 %162, 1
  %164 = sext i32 %163 to i64
  %165 = getelementptr inbounds [500 x i32], ptr %161, i64 0, i64 %164
  %166 = load i32, ptr %165, align 4, !tbaa !5
  %167 = sub nsw i32 %158, %166
  %168 = call i32 @llvm.abs.i32(i32 %167, i1 true)
  store i32 %168, ptr %20, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr %21) #9
  call void @llvm.lifetime.start.p0(i64 8, ptr %22) #9
  call void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %22, ptr noundef nonnull align 4 dereferenceable(4) %17, ptr noundef nonnull align 4 dereferenceable(4) %18)
  call void @llvm.lifetime.start.p0(i64 8, ptr %23) #9
  call void @llvm.lifetime.start.p0(i64 4, ptr %24) #9
  %169 = load i32, ptr %18, align 4, !tbaa !5
  %170 = add nsw i32 %169, 1
  store i32 %170, ptr %24, align 4, !tbaa !5
  call void @_ZNSt4pairIiiEC2IRiiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %23, ptr noundef nonnull align 4 dereferenceable(4) %17, ptr noundef nonnull align 4 dereferenceable(4) %24)
  call void @_ZNSt4pairIS_IiiES0_EC2IS0_S0_TnNSt9enable_ifIXaaclsr5_PCCPE18_ConstructiblePairIT_T0_EEclsr5_PCCPE26_ImplicitlyConvertiblePairIS4_S5_EEEbE4typeELb1EEERKS0_S9_(ptr noundef nonnull align 4 dereferenceable(16) %21, ptr noundef nonnull align 4 dereferenceable(8) %22, ptr noundef nonnull align 4 dereferenceable(8) %23)
  call void @_ZNSt4pairIiS_IS_IiiES0_EEC2IiS1_TnNSt9enable_ifIXaaclsr5_PCCPE18_ConstructiblePairIT_T0_EEclsr5_PCCPE26_ImplicitlyConvertiblePairIS5_S6_EEEbE4typeELb1EEERKiRKS1_(ptr noundef nonnull align 4 dereferenceable(20) %19, ptr noundef nonnull align 4 dereferenceable(4) %20, ptr noundef nonnull align 4 dereferenceable(16) %21)
  call void @_ZNSt6vectorISt4pairIiS0_IS0_IiiES1_EESaIS3_EE9push_backEOS3_(ptr noundef nonnull align 8 dereferenceable(24) @edge, ptr noundef nonnull align 4 dereferenceable(20) %19)
  call void @llvm.lifetime.end.p0(i64 4, ptr %24) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %23) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %22) #9
  call void @llvm.lifetime.end.p0(i64 16, ptr %21) #9
  call void @llvm.lifetime.end.p0(i64 4, ptr %20) #9
  call void @llvm.lifetime.end.p0(i64 20, ptr %19) #9
  br label %171

171:                                              ; preds = %151
  %172 = load i32, ptr %18, align 4, !tbaa !5
  %173 = add nsw i32 %172, 1
  store i32 %173, ptr %18, align 4, !tbaa !5
  br label %145, !llvm.loop !16

174:                                              ; preds = %150
  br label %175

175:                                              ; preds = %174
  %176 = load i32, ptr %17, align 4, !tbaa !5
  %177 = add nsw i32 %176, 1
  store i32 %177, ptr %17, align 4, !tbaa !5
  br label %139, !llvm.loop !17

178:                                              ; preds = %143
  %179 = call ptr @_ZNSt6vectorISt4pairIiS0_IS0_IiiES1_EESaIS3_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) @edge) #9
  %180 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator.9", ptr %25, i32 0, i32 0
  store ptr %179, ptr %180, align 8
  %181 = call ptr @_ZNSt6vectorISt4pairIiS0_IS0_IiiES1_EESaIS3_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24) @edge) #9
  %182 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator.9", ptr %26, i32 0, i32 0
  store ptr %181, ptr %182, align 8
  %183 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator.9", ptr %25, i32 0, i32 0
  %184 = load ptr, ptr %183, align 8
  %185 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator.9", ptr %26, i32 0, i32 0
  %186 = load ptr, ptr %185, align 8
  call void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIPSt4pairIiS2_IS2_IiiES3_EESt6vectorIS5_SaIS5_EEEEEvT_SB_(ptr %184, ptr %186)
  call void @llvm.lifetime.start.p0(i64 8, ptr %27) #9
  store ptr @edge, ptr %27, align 8, !tbaa !18
  call void @llvm.lifetime.start.p0(i64 8, ptr %28) #9
  %187 = call ptr @_ZNSt6vectorISt4pairIiS0_IS0_IiiES1_EESaIS3_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) @edge) #9
  %188 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator.9", ptr %28, i32 0, i32 0
  store ptr %187, ptr %188, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr %29) #9
  %189 = call ptr @_ZNSt6vectorISt4pairIiS0_IS0_IiiES1_EESaIS3_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24) @edge) #9
  %190 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator.9", ptr %29, i32 0, i32 0
  store ptr %189, ptr %190, align 8
  br label %191

191:                                              ; preds = %204, %178
  %192 = call noundef zeroext i1 @_ZN9__gnu_cxxneIPSt4pairIiS1_IS1_IiiES2_EESt6vectorIS4_SaIS4_EEEEbRKNS_17__normal_iteratorIT_T0_EESE_(ptr noundef nonnull align 8 dereferenceable(8) %28, ptr noundef nonnull align 8 dereferenceable(8) %29) #9
  br i1 %192, label %194, label %193

193:                                              ; preds = %191
  store i32 26, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %29) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %28) #9
  call void @llvm.lifetime.end.p0(i64 8, ptr %27) #9
  br label %206

194:                                              ; preds = %191
  call void @llvm.lifetime.start.p0(i64 20, ptr %30) #9
  %195 = call noundef nonnull align 4 dereferenceable(20) ptr @_ZNK9__gnu_cxx17__normal_iteratorIPSt4pairIiS1_IS1_IiiES2_EESt6vectorIS4_SaIS4_EEEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %28) #9
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %30, ptr align 4 %195, i64 20, i1 false)
  %196 = getelementptr inbounds %"struct.std::pair.5", ptr %30, i32 0, i32 0
  %197 = load i32, ptr %196, align 4, !tbaa !20
  %198 = getelementptr inbounds %"struct.std::pair.5", ptr %30, i32 0, i32 1
  %199 = getelementptr inbounds %"struct.std::pair.7", ptr %198, i32 0, i32 0
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %31, ptr align 4 %199, i64 8, i1 false)
  %200 = getelementptr inbounds %"struct.std::pair.5", ptr %30, i32 0, i32 1
  %201 = getelementptr inbounds %"struct.std::pair.7", ptr %200, i32 0, i32 1
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %32, ptr align 4 %201, i64 8, i1 false)
  %202 = load i64, ptr %31, align 4
  %203 = load i64, ptr %32, align 4
  call void @_Z5uniteiSt4pairIiiES0_(i32 noundef %197, i64 %202, i64 %203)
  call void @llvm.lifetime.end.p0(i64 20, ptr %30) #9
  br label %204

204:                                              ; preds = %194
  %205 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN9__gnu_cxx17__normal_iteratorIPSt4pairIiS1_IS1_IiiES2_EESt6vectorIS4_SaIS4_EEEppEv(ptr noundef nonnull align 8 dereferenceable(8) %28) #9
  br label %191

206:                                              ; preds = %193
  call void @llvm.lifetime.start.p0(i64 4, ptr %33) #9
  store i32 0, ptr %33, align 4, !tbaa !5
  br label %207

207:                                              ; preds = %238, %206
  %208 = load i32, ptr %33, align 4, !tbaa !5
  %209 = load i32, ptr @M, align 4, !tbaa !5
  %210 = icmp slt i32 %208, %209
  br i1 %210, label %212, label %211

211:                                              ; preds = %207
  store i32 28, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %33) #9
  br label %241

212:                                              ; preds = %207
  call void @llvm.lifetime.start.p0(i64 4, ptr %34) #9
  store i32 0, ptr %34, align 4, !tbaa !5
  br label %213

213:                                              ; preds = %234, %212
  %214 = load i32, ptr %34, align 4, !tbaa !5
  %215 = load i32, ptr @N, align 4, !tbaa !5
  %216 = icmp slt i32 %214, %215
  br i1 %216, label %218, label %217

217:                                              ; preds = %213
  store i32 31, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %34) #9
  br label %237

218:                                              ; preds = %213
  call void @llvm.lifetime.start.p0(i64 4, ptr %35) #9
  %219 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @cin, ptr noundef nonnull align 4 dereferenceable(4) %35)
  %220 = load i32, ptr %35, align 4, !tbaa !5
  %221 = icmp ne i32 %220, 0
  br i1 %221, label %222, label %233

222:                                              ; preds = %218
  %223 = load i32, ptr %33, align 4, !tbaa !5
  %224 = sext i32 %223 to i64
  %225 = getelementptr inbounds [500 x [500 x i32]], ptr @query, i64 0, i64 %224
  %226 = load i32, ptr %34, align 4, !tbaa !5
  %227 = sext i32 %226 to i64
  %228 = getelementptr inbounds [500 x i32], ptr %225, i64 0, i64 %227
  %229 = load i32, ptr %228, align 4, !tbaa !5
  %230 = sext i32 %229 to i64
  %231 = load i64, ptr @ans, align 8, !tbaa !24
  %232 = add nsw i64 %231, %230
  store i64 %232, ptr @ans, align 8, !tbaa !24
  br label %233

233:                                              ; preds = %222, %218
  call void @llvm.lifetime.end.p0(i64 4, ptr %35) #9
  br label %234

234:                                              ; preds = %233
  %235 = load i32, ptr %34, align 4, !tbaa !5
  %236 = add nsw i32 %235, 1
  store i32 %236, ptr %34, align 4, !tbaa !5
  br label %213, !llvm.loop !26

237:                                              ; preds = %217
  br label %238

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

241:                                              ; preds = %211
  %242 = load i64, ptr @ans, align 8, !tbaa !24
  %243 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @cout, i64 noundef %242)
  %244 = load i32, ptr %1, align 4
  ret i32 %244
}

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

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

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

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIiS_IS_IiiES0_EEC2IiS1_TnNSt9enable_ifIXaaclsr5_PCCPE18_ConstructiblePairIT_T0_EEclsr5_PCCPE26_ImplicitlyConvertiblePairIS5_S6_EEEbE4typeELb1EEERKiRKS1_(ptr noundef nonnull align 4 dereferenceable(20), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(16)) unnamed_addr #3 align 2

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

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN9__gnu_cxxneIPSt4pairIiS1_IS1_IiiES2_EESt6vectorIS4_SaIS4_EEEEbRKNS_17__normal_iteratorIT_T0_EESE_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #8

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

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

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

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

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

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


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

%"class.std::vector" = type { %"struct.std::_Vector_base" }
%"struct.std::_Vector_base" = type { %"struct.std::_Vector_base<std::pair<int, std::pair<std::pair<int, int>, std::pair<int, int>>>, std::allocator<std::pair<int, std::pair<std::pair<int, int>, std::pair<int, int>>>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::pair<int, std::pair<std::pair<int, int>, std::pair<int, int>>>, std::allocator<std::pair<int, std::pair<std::pair<int, int>, std::pair<int, int>>>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::pair<int, std::pair<std::pair<int, int>, std::pair<int, int>>>, std::allocator<std::pair<int, std::pair<std::pair<int, int>, std::pair<int, int>>>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::pair<int, std::pair<std::pair<int, int>, std::pair<int, int>>>, std::allocator<std::pair<int, std::pair<std::pair<int, int>, std::pair<int, int>>>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"struct.std::pair" = type { i32, i32 }
%"class.std::vector.0" = type { %"struct.std::_Vector_base.1" }
%"struct.std::_Vector_base.1" = type { %"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl" }
%"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl" = type { %"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl_data" }
%"struct.std::_Vector_base<std::pair<int, int>, std::allocator<std::pair<int, int>>>::_Vector_impl_data" = type { ptr, ptr, ptr }
%"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 }
%"struct.std::pair.5" = type { i32, %"struct.std::pair.7" }
%"struct.std::pair.7" = type { %"struct.std::pair", %"struct.std::pair" }
%"class.__gnu_cxx::__normal_iterator.9" = type { ptr }

@M = external dso_local global i32, align 4
@N = external dso_local global i32, align 4
@T = external dso_local global i32, align 4
@grid = external dso_local global [500 x [500 x i32]], align 16
@query = external dso_local local_unnamed_addr global [500 x [500 x i32]], align 16
@ans = external dso_local local_unnamed_addr global i64, align 8
@edge = external dso_local global %"class.std::vector", align 8
@comp = external dso_local global [500 x [500 x %"struct.std::pair"]], align 16
@mem = external dso_local global [500 x [500 x %"class.std::vector.0"]], align 16
@cin = external dso_local global %"class.std::basic_ifstream", align 8
@cout = external dso_local global %"class.std::basic_ofstream", align 8

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

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

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z5uniteiSt4pairIiiES0_(i32 noundef, i64, i64) local_unnamed_addr #1

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca %"struct.std::pair", align 4
  %4 = alloca %"struct.std::pair", align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca %"struct.std::pair.5", align 4
  %8 = alloca i32, align 4
  %9 = alloca %"struct.std::pair.7", align 4
  %10 = alloca %"struct.std::pair", align 4
  %11 = alloca %"struct.std::pair", align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  %14 = alloca i32, align 4
  %15 = alloca %"struct.std::pair.5", align 4
  %16 = alloca i32, align 4
  %17 = alloca %"struct.std::pair.7", align 4
  %18 = alloca %"struct.std::pair", align 4
  %19 = alloca %"struct.std::pair", align 4
  %20 = alloca i32, align 4
  %21 = alloca %"class.__gnu_cxx::__normal_iterator.9", align 8
  %22 = alloca %"class.__gnu_cxx::__normal_iterator.9", align 8
  %23 = alloca i32, align 4
  %24 = 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) @M)
  %25 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %24, 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) @T)
  %27 = load i32, ptr @M, align 4, !tbaa !5
  %28 = icmp sgt i32 %27, 0
  br i1 %28, label %.preheader25.lr.ph, label %._crit_edge28.thread84

._crit_edge28.thread84:                           ; preds = %0
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #8
  br label %._crit_edge41.thread

.preheader25.lr.ph:                               ; preds = %0
  %29 = load i32, ptr @N, align 4, !tbaa !5
  %30 = icmp sgt i32 %29, 0
  br i1 %30, label %.preheader25, label %.lr.ph33.thread

.lr.ph33.thread:                                  ; preds = %.preheader25.lr.ph
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #8
  br label %._crit_edge34

.preheader25:                                     ; preds = %.preheader25.lr.ph, %._crit_edge
  %31 = phi i32 [ %36, %._crit_edge ], [ %27, %.preheader25.lr.ph ]
  %32 = phi i32 [ %37, %._crit_edge ], [ %29, %.preheader25.lr.ph ]
  %indvars.iv66 = phi i64 [ %indvars.iv.next67, %._crit_edge ], [ 0, %.preheader25.lr.ph ]
  %33 = icmp sgt i32 %32, 0
  br i1 %33, label %.lr.ph, label %._crit_edge

._crit_edge28:                                    ; preds = %._crit_edge
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #8
  store i32 0, ptr %1, align 4, !tbaa !5
  %34 = icmp sgt i32 %36, 0
  br i1 %34, label %.lr.ph33, label %._crit_edge41.thread

.lr.ph33:                                         ; preds = %._crit_edge28
  %.pr = load i32, ptr @N, align 4, !tbaa !5
  %35 = icmp sgt i32 %.pr, 0
  br i1 %35, label %.lr.ph33.split, label %._crit_edge34

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

._crit_edge:                                      ; preds = %._crit_edge.loopexit, %.preheader25
  %36 = phi i32 [ %.pre, %._crit_edge.loopexit ], [ %31, %.preheader25 ]
  %37 = phi i32 [ %42, %._crit_edge.loopexit ], [ %32, %.preheader25 ]
  %indvars.iv.next67 = add nuw nsw i64 %indvars.iv66, 1
  %38 = sext i32 %36 to i64
  %39 = icmp slt i64 %indvars.iv.next67, %38
  br i1 %39, label %.preheader25, label %._crit_edge28, !llvm.loop !9

.lr.ph:                                           ; preds = %.preheader25, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %.preheader25 ]
  %40 = getelementptr inbounds [500 x [500 x i32]], ptr @grid, i64 0, i64 %indvars.iv66, i64 %indvars.iv
  %41 = 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) %40)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %42 = load i32, ptr @N, align 4, !tbaa !5
  %43 = sext i32 %42 to i64
  %44 = icmp slt i64 %indvars.iv.next, %43
  br i1 %44, label %.lr.ph, label %._crit_edge.loopexit, !llvm.loop !12

._crit_edge41.thread:                             ; preds = %._crit_edge28.thread84, %._crit_edge28
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %13) #8
  br label %._crit_edge50

._crit_edge34:                                    ; preds = %._crit_edge31, %.lr.ph33.thread, %.lr.ph33
  %45 = phi i32 [ %27, %.lr.ph33.thread ], [ %36, %.lr.ph33 ], [ %53, %._crit_edge31 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %5) #8
  store i32 0, ptr %5, align 4, !tbaa !5
  %46 = icmp sgt i32 %45, 1
  %47 = load i32, ptr @N, align 4
  %48 = icmp sgt i32 %47, 0
  %or.cond104 = select i1 %46, i1 %48, i1 false
  br i1 %or.cond104, label %.lr.ph40.split, label %._crit_edge41

.lr.ph33.split:                                   ; preds = %.lr.ph33, %._crit_edge31
  %49 = phi i32 [ %53, %._crit_edge31 ], [ %36, %.lr.ph33 ]
  %50 = phi i32 [ %56, %._crit_edge31 ], [ 0, %.lr.ph33 ]
  %51 = phi i32 [ %55, %._crit_edge31 ], [ %.pr, %.lr.ph33 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #8
  store i32 0, ptr %2, align 4, !tbaa !5
  %52 = icmp sgt i32 %51, 0
  br i1 %52, label %.lr.ph30, label %._crit_edge31

._crit_edge31.loopexit:                           ; preds = %.lr.ph30
  %.pre77 = load i32, ptr %1, align 4, !tbaa !5
  %.pre78 = load i32, ptr @M, align 4, !tbaa !5
  br label %._crit_edge31

._crit_edge31:                                    ; preds = %._crit_edge31.loopexit, %.lr.ph33.split
  %53 = phi i32 [ %.pre78, %._crit_edge31.loopexit ], [ %49, %.lr.ph33.split ]
  %54 = phi i32 [ %.pre77, %._crit_edge31.loopexit ], [ %50, %.lr.ph33.split ]
  %55 = phi i32 [ %71, %._crit_edge31.loopexit ], [ %51, %.lr.ph33.split ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #8
  %56 = add nsw i32 %54, 1
  store i32 %56, ptr %1, align 4, !tbaa !5
  %57 = icmp slt i32 %56, %53
  br i1 %57, label %.lr.ph33.split, label %._crit_edge34, !llvm.loop !13

.lr.ph30:                                         ; preds = %.lr.ph33.split, %.lr.ph30
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #8
  call void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %3, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %58 = load i32, ptr %1, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = load i32, ptr %2, align 4, !tbaa !5
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [500 x [500 x %"struct.std::pair"]], ptr @comp, i64 0, i64 %59, i64 %61
  %63 = call noundef nonnull align 4 dereferenceable(8) ptr @_ZNSt4pairIiiEaSEOS0_(ptr noundef nonnull align 4 dereferenceable(8) %62, ptr noundef nonnull align 4 dereferenceable(8) %3) #8
  %64 = load i32, ptr %1, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = load i32, ptr %2, align 4, !tbaa !5
  %67 = sext i32 %66 to i64
  %68 = getelementptr inbounds [500 x [500 x %"class.std::vector.0"]], ptr @mem, i64 0, i64 %65, i64 %67
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #8
  call void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %4, ptr noundef nonnull align 4 dereferenceable(4) %1, ptr noundef nonnull align 4 dereferenceable(4) %2)
  call void @_ZNSt6vectorISt4pairIiiESaIS1_EE9push_backEOS1_(ptr noundef nonnull align 8 dereferenceable(24) %68, ptr noundef nonnull align 4 dereferenceable(8) %4)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #8
  %69 = load i32, ptr %2, align 4, !tbaa !5
  %70 = add nsw i32 %69, 1
  store i32 %70, ptr %2, align 4, !tbaa !5
  %71 = load i32, ptr @N, align 4, !tbaa !5
  %72 = icmp slt i32 %70, %71
  br i1 %72, label %.lr.ph30, label %._crit_edge31.loopexit, !llvm.loop !14

._crit_edge41:                                    ; preds = %._crit_edge38, %._crit_edge34
  %73 = phi i32 [ %45, %._crit_edge34 ], [ %81, %._crit_edge38 ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %5) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %13) #8
  store i32 0, ptr %13, align 4, !tbaa !5
  %74 = icmp sgt i32 %73, 0
  %75 = load i32, ptr @N, align 4
  %76 = icmp sgt i32 %75, 1
  %or.cond106 = select i1 %74, i1 %76, i1 false
  br i1 %or.cond106, label %.lr.ph49.split, label %._crit_edge50

.lr.ph40.split:                                   ; preds = %._crit_edge34, %._crit_edge38
  %77 = phi i32 [ %81, %._crit_edge38 ], [ %45, %._crit_edge34 ]
  %78 = phi i32 [ %84, %._crit_edge38 ], [ 0, %._crit_edge34 ]
  %79 = phi i32 [ %83, %._crit_edge38 ], [ %47, %._crit_edge34 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %6) #8
  store i32 0, ptr %6, align 4, !tbaa !5
  %80 = icmp sgt i32 %79, 0
  br i1 %80, label %.lr.ph37, label %._crit_edge38

._crit_edge38.loopexit:                           ; preds = %.lr.ph37
  %.pre79 = load i32, ptr %5, align 4, !tbaa !5
  %.pre80 = load i32, ptr @M, align 4, !tbaa !5
  br label %._crit_edge38

._crit_edge38:                                    ; preds = %._crit_edge38.loopexit, %.lr.ph40.split
  %81 = phi i32 [ %.pre80, %._crit_edge38.loopexit ], [ %77, %.lr.ph40.split ]
  %82 = phi i32 [ %.pre79, %._crit_edge38.loopexit ], [ %78, %.lr.ph40.split ]
  %83 = phi i32 [ %102, %._crit_edge38.loopexit ], [ %79, %.lr.ph40.split ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %6) #8
  %84 = add nsw i32 %82, 1
  store i32 %84, ptr %5, align 4, !tbaa !5
  %85 = add nsw i32 %81, -1
  %86 = icmp slt i32 %84, %85
  br i1 %86, label %.lr.ph40.split, label %._crit_edge41, !llvm.loop !15

.lr.ph37:                                         ; preds = %.lr.ph40.split, %.lr.ph37
  %storemerge2335 = phi i32 [ %101, %.lr.ph37 ], [ 0, %.lr.ph40.split ]
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %7) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %8) #8
  %87 = load i32, ptr %5, align 4, !tbaa !5
  %88 = sext i32 %87 to i64
  %89 = sext i32 %storemerge2335 to i64
  %90 = getelementptr inbounds [500 x [500 x i32]], ptr @grid, i64 0, i64 %88, i64 %89
  %91 = load i32, ptr %90, align 4, !tbaa !5
  %92 = add nsw i32 %87, 1
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [500 x [500 x i32]], ptr @grid, i64 0, i64 %93, i64 %89
  %95 = load i32, ptr %94, align 4, !tbaa !5
  %96 = sub nsw i32 %91, %95
  %97 = call i32 @llvm.abs.i32(i32 %96, i1 true)
  store i32 %97, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %9) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %10) #8
  call void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %10, ptr noundef nonnull align 4 dereferenceable(4) %5, ptr noundef nonnull align 4 dereferenceable(4) %6)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %11) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %12) #8
  %98 = load i32, ptr %5, align 4, !tbaa !5
  %99 = add nsw i32 %98, 1
  store i32 %99, ptr %12, align 4, !tbaa !5
  call void @_ZNSt4pairIiiEC2IiRiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %11, ptr noundef nonnull align 4 dereferenceable(4) %12, ptr noundef nonnull align 4 dereferenceable(4) %6)
  call void @_ZNSt4pairIS_IiiES0_EC2IS0_S0_TnNSt9enable_ifIXaaclsr5_PCCPE18_ConstructiblePairIT_T0_EEclsr5_PCCPE26_ImplicitlyConvertiblePairIS4_S5_EEEbE4typeELb1EEERKS0_S9_(ptr noundef nonnull align 4 dereferenceable(16) %9, ptr noundef nonnull align 4 dereferenceable(8) %10, ptr noundef nonnull align 4 dereferenceable(8) %11)
  call void @_ZNSt4pairIiS_IS_IiiES0_EEC2IiS1_TnNSt9enable_ifIXaaclsr5_PCCPE18_ConstructiblePairIT_T0_EEclsr5_PCCPE26_ImplicitlyConvertiblePairIS5_S6_EEEbE4typeELb1EEERKiRKS1_(ptr noundef nonnull align 4 dereferenceable(20) %7, ptr noundef nonnull align 4 dereferenceable(4) %8, ptr noundef nonnull align 4 dereferenceable(16) %9)
  call void @_ZNSt6vectorISt4pairIiS0_IS0_IiiES1_EESaIS3_EE9push_backEOS3_(ptr noundef nonnull align 8 dereferenceable(24) @edge, ptr noundef nonnull align 4 dereferenceable(20) %7)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %12) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %11) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %10) #8
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %9) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %8) #8
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %7) #8
  %100 = load i32, ptr %6, align 4, !tbaa !5
  %101 = add nsw i32 %100, 1
  store i32 %101, ptr %6, align 4, !tbaa !5
  %102 = load i32, ptr @N, align 4, !tbaa !5
  %103 = icmp slt i32 %101, %102
  br i1 %103, label %.lr.ph37, label %._crit_edge38.loopexit, !llvm.loop !16

._crit_edge50:                                    ; preds = %._crit_edge47, %._crit_edge41.thread, %._crit_edge41
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %13) #8
  %104 = call ptr @_ZNSt6vectorISt4pairIiS0_IS0_IiiES1_EESaIS3_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) @edge) #8
  %105 = call ptr @_ZNSt6vectorISt4pairIiS0_IS0_IiiES1_EESaIS3_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24) @edge) #8
  call void @_ZSt4sortIN9__gnu_cxx17__normal_iteratorIPSt4pairIiS2_IS2_IiiES3_EESt6vectorIS5_SaIS5_EEEEEvT_SB_(ptr %104, ptr %105)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %21) #8
  %106 = call ptr @_ZNSt6vectorISt4pairIiS0_IS0_IiiES1_EESaIS3_EE5beginEv(ptr noundef nonnull align 8 dereferenceable(24) @edge) #8
  store ptr %106, ptr %21, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %22) #8
  %107 = call ptr @_ZNSt6vectorISt4pairIiS0_IS0_IiiES1_EESaIS3_EE3endEv(ptr noundef nonnull align 8 dereferenceable(24) @edge) #8
  store ptr %107, ptr %22, align 8
  %108 = call noundef zeroext i1 @_ZN9__gnu_cxxneIPSt4pairIiS1_IS1_IiiES2_EESt6vectorIS4_SaIS4_EEEEbRKNS_17__normal_iteratorIT_T0_EESE_(ptr noundef nonnull align 8 dereferenceable(8) %21, ptr noundef nonnull align 8 dereferenceable(8) %22) #8
  br i1 %108, label %.lr.ph54, label %._crit_edge55

.lr.ph49.split:                                   ; preds = %._crit_edge41, %._crit_edge47
  %109 = phi i32 [ %113, %._crit_edge47 ], [ %73, %._crit_edge41 ]
  %110 = phi i32 [ %116, %._crit_edge47 ], [ 0, %._crit_edge41 ]
  %111 = phi i32 [ %115, %._crit_edge47 ], [ %75, %._crit_edge41 ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %14) #8
  store i32 0, ptr %14, align 4, !tbaa !5
  %112 = icmp sgt i32 %111, 1
  br i1 %112, label %.lr.ph46, label %._crit_edge47

._crit_edge47.loopexit:                           ; preds = %.lr.ph46
  %.pre81 = load i32, ptr %13, align 4, !tbaa !5
  %.pre82 = load i32, ptr @M, align 4, !tbaa !5
  br label %._crit_edge47

._crit_edge47:                                    ; preds = %._crit_edge47.loopexit, %.lr.ph49.split
  %113 = phi i32 [ %.pre82, %._crit_edge47.loopexit ], [ %109, %.lr.ph49.split ]
  %114 = phi i32 [ %.pre81, %._crit_edge47.loopexit ], [ %110, %.lr.ph49.split ]
  %115 = phi i32 [ %133, %._crit_edge47.loopexit ], [ %111, %.lr.ph49.split ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %14) #8
  %116 = add nsw i32 %114, 1
  store i32 %116, ptr %13, align 4, !tbaa !5
  %117 = icmp slt i32 %116, %113
  br i1 %117, label %.lr.ph49.split, label %._crit_edge50, !llvm.loop !17

.lr.ph46:                                         ; preds = %.lr.ph49.split, %.lr.ph46
  %storemerge2244 = phi i32 [ %132, %.lr.ph46 ], [ 0, %.lr.ph49.split ]
  call void @llvm.lifetime.start.p0(i64 20, ptr nonnull %15) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %16) #8
  %118 = load i32, ptr %13, align 4, !tbaa !5
  %119 = sext i32 %118 to i64
  %120 = sext i32 %storemerge2244 to i64
  %121 = getelementptr inbounds [500 x [500 x i32]], ptr @grid, i64 0, i64 %119, i64 %120
  %122 = load i32, ptr %121, align 4, !tbaa !5
  %123 = add nsw i32 %storemerge2244, 1
  %124 = sext i32 %123 to i64
  %125 = getelementptr inbounds [500 x [500 x i32]], ptr @grid, i64 0, i64 %119, i64 %124
  %126 = load i32, ptr %125, align 4, !tbaa !5
  %127 = sub nsw i32 %122, %126
  %128 = call i32 @llvm.abs.i32(i32 %127, i1 true)
  store i32 %128, ptr %16, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 16, ptr nonnull %17) #8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %18) #8
  call void @_ZNSt4pairIiiEC2IRiS2_TnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %18, ptr noundef nonnull align 4 dereferenceable(4) %13, ptr noundef nonnull align 4 dereferenceable(4) %14)
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %19) #8
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %20) #8
  %129 = load i32, ptr %14, align 4, !tbaa !5
  %130 = add nsw i32 %129, 1
  store i32 %130, ptr %20, align 4, !tbaa !5
  call void @_ZNSt4pairIiiEC2IRiiTnNSt9enable_ifIXaaclsr5_PCCPE22_MoveConstructiblePairIT_T0_EEclsr5_PCCPE30_ImplicitlyMoveConvertiblePairIS4_S5_EEEbE4typeELb1EEEOS4_OS5_(ptr noundef nonnull align 4 dereferenceable(8) %19, ptr noundef nonnull align 4 dereferenceable(4) %13, ptr noundef nonnull align 4 dereferenceable(4) %20)
  call void @_ZNSt4pairIS_IiiES0_EC2IS0_S0_TnNSt9enable_ifIXaaclsr5_PCCPE18_ConstructiblePairIT_T0_EEclsr5_PCCPE26_ImplicitlyConvertiblePairIS4_S5_EEEbE4typeELb1EEERKS0_S9_(ptr noundef nonnull align 4 dereferenceable(16) %17, ptr noundef nonnull align 4 dereferenceable(8) %18, ptr noundef nonnull align 4 dereferenceable(8) %19)
  call void @_ZNSt4pairIiS_IS_IiiES0_EEC2IiS1_TnNSt9enable_ifIXaaclsr5_PCCPE18_ConstructiblePairIT_T0_EEclsr5_PCCPE26_ImplicitlyConvertiblePairIS5_S6_EEEbE4typeELb1EEERKiRKS1_(ptr noundef nonnull align 4 dereferenceable(20) %15, ptr noundef nonnull align 4 dereferenceable(4) %16, ptr noundef nonnull align 4 dereferenceable(16) %17)
  call void @_ZNSt6vectorISt4pairIiS0_IS0_IiiES1_EESaIS3_EE9push_backEOS3_(ptr noundef nonnull align 8 dereferenceable(24) @edge, ptr noundef nonnull align 4 dereferenceable(20) %15)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %20) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %19) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %18) #8
  call void @llvm.lifetime.end.p0(i64 16, ptr nonnull %17) #8
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %16) #8
  call void @llvm.lifetime.end.p0(i64 20, ptr nonnull %15) #8
  %131 = load i32, ptr %14, align 4, !tbaa !5
  %132 = add nsw i32 %131, 1
  store i32 %132, ptr %14, align 4, !tbaa !5
  %133 = load i32, ptr @N, align 4, !tbaa !5
  %134 = add nsw i32 %133, -1
  %135 = icmp slt i32 %132, %134
  br i1 %135, label %.lr.ph46, label %._crit_edge47.loopexit, !llvm.loop !18

._crit_edge55:                                    ; preds = %.lr.ph54, %._crit_edge50
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %22) #8
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %21) #8
  %136 = load i32, ptr @M, align 4, !tbaa !5
  %137 = icmp sgt i32 %136, 0
  %138 = load i32, ptr @N, align 4
  %139 = icmp sgt i32 %138, 0
  %or.cond = select i1 %137, i1 %139, i1 false
  br i1 %or.cond, label %.preheader, label %._crit_edge60

.lr.ph54:                                         ; preds = %._crit_edge50, %.lr.ph54
  %140 = call noundef nonnull align 4 dereferenceable(20) ptr @_ZNK9__gnu_cxx17__normal_iteratorIPSt4pairIiS1_IS1_IiiES2_EESt6vectorIS4_SaIS4_EEEdeEv(ptr noundef nonnull align 8 dereferenceable(8) %21) #8
  %.sroa.07.0.copyload = load i32, ptr %140, align 4
  %.sroa.4.0..sroa_idx = getelementptr inbounds i8, ptr %140, i64 4
  %.sroa.4.0.copyload = load i64, ptr %.sroa.4.0..sroa_idx, align 4
  %.sroa.5.0..sroa_idx = getelementptr inbounds i8, ptr %140, i64 12
  %.sroa.5.0.copyload = load i64, ptr %.sroa.5.0..sroa_idx, align 4
  call void @_Z5uniteiSt4pairIiiES0_(i32 noundef %.sroa.07.0.copyload, i64 %.sroa.4.0.copyload, i64 %.sroa.5.0.copyload)
  %141 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZN9__gnu_cxx17__normal_iteratorIPSt4pairIiS1_IS1_IiiES2_EESt6vectorIS4_SaIS4_EEEppEv(ptr noundef nonnull align 8 dereferenceable(8) %21) #8
  %142 = call noundef zeroext i1 @_ZN9__gnu_cxxneIPSt4pairIiS1_IS1_IiiES2_EESt6vectorIS4_SaIS4_EEEEbRKNS_17__normal_iteratorIT_T0_EESE_(ptr noundef nonnull align 8 dereferenceable(8) %21, ptr noundef nonnull align 8 dereferenceable(8) %22) #8
  br i1 %142, label %.lr.ph54, label %._crit_edge55

.preheader:                                       ; preds = %._crit_edge55, %._crit_edge58
  %143 = phi i32 [ %148, %._crit_edge58 ], [ %136, %._crit_edge55 ]
  %144 = phi i32 [ %149, %._crit_edge58 ], [ %138, %._crit_edge55 ]
  %indvars.iv74 = phi i64 [ %indvars.iv.next75, %._crit_edge58 ], [ 0, %._crit_edge55 ]
  %145 = icmp sgt i32 %144, 0
  br i1 %145, label %.lr.ph57, label %._crit_edge58

._crit_edge60:                                    ; preds = %._crit_edge58, %._crit_edge55
  %146 = load i64, ptr @ans, align 8, !tbaa !19
  %147 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @cout, i64 noundef %146)
  ret i32 0

._crit_edge58.loopexit:                           ; preds = %160
  %.pre83 = load i32, ptr @M, align 4, !tbaa !5
  br label %._crit_edge58

._crit_edge58:                                    ; preds = %._crit_edge58.loopexit, %.preheader
  %148 = phi i32 [ %.pre83, %._crit_edge58.loopexit ], [ %143, %.preheader ]
  %149 = phi i32 [ %161, %._crit_edge58.loopexit ], [ %144, %.preheader ]
  %indvars.iv.next75 = add nuw nsw i64 %indvars.iv74, 1
  %150 = sext i32 %148 to i64
  %151 = icmp slt i64 %indvars.iv.next75, %150
  br i1 %151, label %.preheader, label %._crit_edge60, !llvm.loop !21

.lr.ph57:                                         ; preds = %.preheader, %160
  %indvars.iv71 = phi i64 [ %indvars.iv.next72, %160 ], [ 0, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %23) #8
  %152 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @cin, ptr noundef nonnull align 4 dereferenceable(4) %23)
  %153 = load i32, ptr %23, align 4, !tbaa !5
  %.not = icmp eq i32 %153, 0
  br i1 %.not, label %160, label %154

154:                                              ; preds = %.lr.ph57
  %155 = getelementptr inbounds [500 x [500 x i32]], ptr @query, i64 0, i64 %indvars.iv74, i64 %indvars.iv71
  %156 = load i32, ptr %155, align 4, !tbaa !5
  %157 = sext i32 %156 to i64
  %158 = load i64, ptr @ans, align 8, !tbaa !19
  %159 = add nsw i64 %158, %157
  store i64 %159, ptr @ans, align 8, !tbaa !19
  br label %160

160:                                              ; preds = %154, %.lr.ph57
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %23) #8
  %indvars.iv.next72 = add nuw nsw i64 %indvars.iv71, 1
  %161 = load i32, ptr @N, align 4, !tbaa !5
  %162 = sext i32 %161 to i64
  %163 = icmp slt i64 %indvars.iv.next72, %162
  br i1 %163, label %.lr.ph57, label %._crit_edge58.loopexit, !llvm.loop !22
}

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 #4

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

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

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

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local void @_ZNSt4pairIiS_IS_IiiES0_EEC2IiS1_TnNSt9enable_ifIXaaclsr5_PCCPE18_ConstructiblePairIT_T0_EEclsr5_PCCPE26_ImplicitlyConvertiblePairIS5_S6_EEEbE4typeELb1EEERKiRKS1_(ptr noundef nonnull align 4 dereferenceable(20), ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(16)) unnamed_addr #2 align 2

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

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZN9__gnu_cxxneIPSt4pairIiS1_IS1_IiiES2_EESt6vectorIS4_SaIS4_EEEEbRKNS_17__normal_iteratorIT_T0_EESE_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #7

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

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

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

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


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