; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/Zepto Code Rush 2014/Problem B (B)

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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z7inrangeii(i32 noundef, i32 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #1 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %8 = call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  %9 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !5
  %10 = getelementptr i8, ptr %9, i64 -24
  %11 = load i64, ptr %10, align 8
  %12 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %11
  %13 = call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %12, ptr noundef null)
  %14 = load ptr, ptr @_ZSt4cout, align 8, !tbaa !5
  %15 = getelementptr i8, ptr %14, i64 -24
  %16 = load i64, ptr %15, align 8
  %17 = getelementptr inbounds i8, ptr @_ZSt4cout, i64 %16
  %18 = call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %17, ptr noundef null)
  %19 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @n)
  %20 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %19, ptr noundef nonnull align 4 dereferenceable(4) @m)
  %21 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %20, ptr noundef nonnull align 4 dereferenceable(4) @k)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 1, ptr %2, align 4, !tbaa !8
  br label %22

22:                                               ; preds = %102, %0
  %23 = load i32, ptr %2, align 4, !tbaa !8
  %24 = load i32, ptr @n, align 4, !tbaa !8
  %25 = icmp sle i32 %23, %24
  br i1 %25, label %27, label %26

26:                                               ; preds = %22
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %105

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

29:                                               ; preds = %98, %27
  %30 = load i32, ptr %4, align 4, !tbaa !8
  %31 = load i32, ptr @m, align 4, !tbaa !8
  %32 = icmp sle i32 %30, %31
  br i1 %32, label %34, label %33

33:                                               ; preds = %29
  store i32 5, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  br label %101

34:                                               ; preds = %29
  %35 = load i32, ptr %4, align 4, !tbaa !8
  %36 = sub nsw i32 %35, 1
  %37 = sext i32 %36 to i64
  %38 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %37)
  %39 = load i8, ptr %38, align 1, !tbaa !11
  %40 = sext i8 %39 to i32
  %41 = icmp eq i32 %40, 76
  br i1 %41, label %42, label %49

42:                                               ; preds = %34
  %43 = load i32, ptr %2, align 4, !tbaa !8
  %44 = sext i32 %43 to i64
  %45 = getelementptr inbounds [2001 x [2001 x i32]], ptr @grid, i64 0, i64 %44
  %46 = load i32, ptr %4, align 4, !tbaa !8
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [2001 x i32], ptr %45, i64 0, i64 %47
  store i32 1, ptr %48, align 4, !tbaa !8
  br label %97

49:                                               ; preds = %34
  %50 = load i32, ptr %4, align 4, !tbaa !8
  %51 = sub nsw i32 %50, 1
  %52 = sext i32 %51 to i64
  %53 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %52)
  %54 = load i8, ptr %53, align 1, !tbaa !11
  %55 = sext i8 %54 to i32
  %56 = icmp eq i32 %55, 82
  br i1 %56, label %57, label %64

57:                                               ; preds = %49
  %58 = load i32, ptr %2, align 4, !tbaa !8
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [2001 x [2001 x i32]], ptr @grid, i64 0, i64 %59
  %61 = load i32, ptr %4, align 4, !tbaa !8
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [2001 x i32], ptr %60, i64 0, i64 %62
  store i32 2, ptr %63, align 4, !tbaa !8
  br label %96

64:                                               ; preds = %49
  %65 = load i32, ptr %4, align 4, !tbaa !8
  %66 = sub nsw i32 %65, 1
  %67 = sext i32 %66 to i64
  %68 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %67)
  %69 = load i8, ptr %68, align 1, !tbaa !11
  %70 = sext i8 %69 to i32
  %71 = icmp eq i32 %70, 68
  br i1 %71, label %72, label %79

72:                                               ; preds = %64
  %73 = load i32, ptr %2, align 4, !tbaa !8
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [2001 x [2001 x i32]], ptr @grid, i64 0, i64 %74
  %76 = load i32, ptr %4, align 4, !tbaa !8
  %77 = sext i32 %76 to i64
  %78 = getelementptr inbounds [2001 x i32], ptr %75, i64 0, i64 %77
  store i32 3, ptr %78, align 4, !tbaa !8
  br label %95

79:                                               ; preds = %64
  %80 = load i32, ptr %4, align 4, !tbaa !8
  %81 = sub nsw i32 %80, 1
  %82 = sext i32 %81 to i64
  %83 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %82)
  %84 = load i8, ptr %83, align 1, !tbaa !11
  %85 = sext i8 %84 to i32
  %86 = icmp eq i32 %85, 85
  br i1 %86, label %87, label %94

87:                                               ; preds = %79
  %88 = load i32, ptr %2, align 4, !tbaa !8
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [2001 x [2001 x i32]], ptr @grid, i64 0, i64 %89
  %91 = load i32, ptr %4, align 4, !tbaa !8
  %92 = sext i32 %91 to i64
  %93 = getelementptr inbounds [2001 x i32], ptr %90, i64 0, i64 %92
  store i32 4, ptr %93, align 4, !tbaa !8
  br label %94

94:                                               ; preds = %87, %79
  br label %95

95:                                               ; preds = %94, %72
  br label %96

96:                                               ; preds = %95, %57
  br label %97

97:                                               ; preds = %96, %42
  br label %98

98:                                               ; preds = %97
  %99 = load i32, ptr %4, align 4, !tbaa !8
  %100 = add nsw i32 %99, 1
  store i32 %100, ptr %4, align 4, !tbaa !8
  br label %29, !llvm.loop !12

101:                                              ; preds = %33
  br label %102

102:                                              ; preds = %101
  %103 = load i32, ptr %2, align 4, !tbaa !8
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %2, align 4, !tbaa !8
  br label %22, !llvm.loop !14

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

106:                                              ; preds = %213, %105
  %107 = load i32, ptr %5, align 4, !tbaa !8
  %108 = load i32, ptr @m, align 4, !tbaa !8
  %109 = icmp sle i32 %107, %108
  br i1 %109, label %111, label %110

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

111:                                              ; preds = %106
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  store i32 0, ptr %6, align 4, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  store i32 2, ptr %7, align 4, !tbaa !8
  br label %112

112:                                              ; preds = %206, %111
  %113 = load i32, ptr %7, align 4, !tbaa !8
  %114 = load i32, ptr @n, align 4, !tbaa !8
  %115 = icmp sle i32 %113, %114
  br i1 %115, label %117, label %116

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

117:                                              ; preds = %112
  %118 = load i32, ptr %7, align 4, !tbaa !8
  %119 = load i32, ptr %5, align 4, !tbaa !8
  %120 = load i32, ptr %7, align 4, !tbaa !8
  %121 = add nsw i32 %119, %120
  %122 = sub nsw i32 %121, 1
  %123 = call noundef zeroext i1 @_Z7inrangeii(i32 noundef %118, i32 noundef %122)
  br i1 %123, label %124, label %139

124:                                              ; preds = %117
  %125 = load i32, ptr %7, align 4, !tbaa !8
  %126 = sext i32 %125 to i64
  %127 = getelementptr inbounds [2001 x [2001 x i32]], ptr @grid, i64 0, i64 %126
  %128 = load i32, ptr %5, align 4, !tbaa !8
  %129 = load i32, ptr %7, align 4, !tbaa !8
  %130 = add nsw i32 %128, %129
  %131 = sub nsw i32 %130, 1
  %132 = sext i32 %131 to i64
  %133 = getelementptr inbounds [2001 x i32], ptr %127, i64 0, i64 %132
  %134 = load i32, ptr %133, align 4, !tbaa !8
  %135 = icmp eq i32 %134, 1
  br i1 %135, label %136, label %139

136:                                              ; preds = %124
  %137 = load i32, ptr %6, align 4, !tbaa !8
  %138 = add nsw i32 %137, 1
  store i32 %138, ptr %6, align 4, !tbaa !8
  br label %139

139:                                              ; preds = %136, %124, %117
  %140 = load i32, ptr %7, align 4, !tbaa !8
  %141 = load i32, ptr %5, align 4, !tbaa !8
  %142 = load i32, ptr %7, align 4, !tbaa !8
  %143 = sub nsw i32 %141, %142
  %144 = add nsw i32 %143, 1
  %145 = call noundef zeroext i1 @_Z7inrangeii(i32 noundef %140, i32 noundef %144)
  br i1 %145, label %146, label %161

146:                                              ; preds = %139
  %147 = load i32, ptr %7, align 4, !tbaa !8
  %148 = sext i32 %147 to i64
  %149 = getelementptr inbounds [2001 x [2001 x i32]], ptr @grid, i64 0, i64 %148
  %150 = load i32, ptr %5, align 4, !tbaa !8
  %151 = load i32, ptr %7, align 4, !tbaa !8
  %152 = sub nsw i32 %150, %151
  %153 = add nsw i32 %152, 1
  %154 = sext i32 %153 to i64
  %155 = getelementptr inbounds [2001 x i32], ptr %149, i64 0, i64 %154
  %156 = load i32, ptr %155, align 4, !tbaa !8
  %157 = icmp eq i32 %156, 2
  br i1 %157, label %158, label %161

158:                                              ; preds = %146
  %159 = load i32, ptr %6, align 4, !tbaa !8
  %160 = add nsw i32 %159, 1
  store i32 %160, ptr %6, align 4, !tbaa !8
  br label %161

161:                                              ; preds = %158, %146, %139
  %162 = load i32, ptr %7, align 4, !tbaa !8
  %163 = load i32, ptr %7, align 4, !tbaa !8
  %164 = add nsw i32 %162, %163
  %165 = sub nsw i32 %164, 1
  %166 = load i32, ptr %5, align 4, !tbaa !8
  %167 = call noundef zeroext i1 @_Z7inrangeii(i32 noundef %165, i32 noundef %166)
  br i1 %167, label %168, label %183

168:                                              ; preds = %161
  %169 = load i32, ptr %7, align 4, !tbaa !8
  %170 = load i32, ptr %7, align 4, !tbaa !8
  %171 = add nsw i32 %169, %170
  %172 = sub nsw i32 %171, 1
  %173 = sext i32 %172 to i64
  %174 = getelementptr inbounds [2001 x [2001 x i32]], ptr @grid, i64 0, i64 %173
  %175 = load i32, ptr %5, align 4, !tbaa !8
  %176 = sext i32 %175 to i64
  %177 = getelementptr inbounds [2001 x i32], ptr %174, i64 0, i64 %176
  %178 = load i32, ptr %177, align 4, !tbaa !8
  %179 = icmp eq i32 %178, 4
  br i1 %179, label %180, label %183

180:                                              ; preds = %168
  %181 = load i32, ptr %6, align 4, !tbaa !8
  %182 = add nsw i32 %181, 1
  store i32 %182, ptr %6, align 4, !tbaa !8
  br label %183

183:                                              ; preds = %180, %168, %161
  %184 = load i32, ptr %7, align 4, !tbaa !8
  %185 = load i32, ptr %7, align 4, !tbaa !8
  %186 = sub nsw i32 %184, %185
  %187 = add nsw i32 %186, 1
  %188 = load i32, ptr %5, align 4, !tbaa !8
  %189 = call noundef zeroext i1 @_Z7inrangeii(i32 noundef %187, i32 noundef %188)
  br i1 %189, label %190, label %205

190:                                              ; preds = %183
  %191 = load i32, ptr %7, align 4, !tbaa !8
  %192 = load i32, ptr %7, align 4, !tbaa !8
  %193 = sub nsw i32 %191, %192
  %194 = add nsw i32 %193, 1
  %195 = sext i32 %194 to i64
  %196 = getelementptr inbounds [2001 x [2001 x i32]], ptr @grid, i64 0, i64 %195
  %197 = load i32, ptr %5, align 4, !tbaa !8
  %198 = sext i32 %197 to i64
  %199 = getelementptr inbounds [2001 x i32], ptr %196, i64 0, i64 %198
  %200 = load i32, ptr %199, align 4, !tbaa !8
  %201 = icmp eq i32 %200, 3
  br i1 %201, label %202, label %205

202:                                              ; preds = %190
  %203 = load i32, ptr %6, align 4, !tbaa !8
  %204 = add nsw i32 %203, 1
  store i32 %204, ptr %6, align 4, !tbaa !8
  br label %205

205:                                              ; preds = %202, %190, %183
  br label %206

206:                                              ; preds = %205
  %207 = load i32, ptr %7, align 4, !tbaa !8
  %208 = add nsw i32 %207, 1
  store i32 %208, ptr %7, align 4, !tbaa !8
  br label %112, !llvm.loop !15

209:                                              ; preds = %116
  %210 = load i32, ptr %6, align 4, !tbaa !8
  %211 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %210)
  %212 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %211, ptr noundef @.str)
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %213

213:                                              ; preds = %209
  %214 = load i32, ptr %5, align 4, !tbaa !8
  %215 = add nsw i32 %214, 1
  store i32 %215, ptr %5, align 4, !tbaa !8
  br label %106, !llvm.loop !16

216:                                              ; preds = %110
  %217 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef @.str.2)
  ret i32 0
}

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) #2

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264), ptr noundef) #0 align 2

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

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

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

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

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

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

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

attributes #0 = { 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 #1 = { 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 #2 = { "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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { 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 #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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = !{!10, !10, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !13}


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

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_Z7inrangeii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = tail call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  %2 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !5
  %3 = getelementptr i8, ptr %2, i64 -24
  %4 = load i64, ptr %3, align 8
  %5 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %4
  %6 = tail call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %5, ptr noundef null)
  %7 = load ptr, ptr @_ZSt4cout, align 8, !tbaa !5
  %8 = getelementptr i8, ptr %7, i64 -24
  %9 = load i64, ptr %8, align 8
  %10 = getelementptr inbounds i8, ptr @_ZSt4cout, i64 %9
  %11 = tail call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %10, ptr noundef null)
  %12 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @n)
  %13 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %12, ptr noundef nonnull align 4 dereferenceable(4) @m)
  %14 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) %13, ptr noundef nonnull align 4 dereferenceable(4) @k)
  %15 = load i32, ptr @n, align 4, !tbaa !8
  %.not62 = icmp slt i32 %15, 1
  br i1 %.not62, label %..preheader59_crit_edge, label %.lr.ph65

..preheader59_crit_edge:                          ; preds = %0
  %.pre = load i32, ptr @m, align 4, !tbaa !8
  br label %.preheader59

.preheader59:                                     ; preds = %._crit_edge, %..preheader59_crit_edge
  %16 = phi i32 [ %.pre, %..preheader59_crit_edge ], [ %19, %._crit_edge ]
  %.not5371 = icmp slt i32 %16, 1
  br i1 %.not5371, label %._crit_edge73, label %.preheader

.lr.ph65:                                         ; preds = %0, %._crit_edge
  %indvars.iv75 = phi i64 [ %indvars.iv.next76, %._crit_edge ], [ 1, %0 ]
  %17 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11)
  %18 = load i32, ptr @m, align 4, !tbaa !8
  %.not5560 = icmp slt i32 %18, 1
  br i1 %.not5560, label %._crit_edge, label %.lr.ph

._crit_edge:                                      ; preds = %39, %.lr.ph65
  %19 = phi i32 [ %18, %.lr.ph65 ], [ %40, %39 ]
  %indvars.iv.next76 = add nuw nsw i64 %indvars.iv75, 1
  %20 = load i32, ptr @n, align 4, !tbaa !8
  %21 = sext i32 %20 to i64
  %.not.not = icmp slt i64 %indvars.iv75, %21
  br i1 %.not.not, label %.lr.ph65, label %.preheader59, !llvm.loop !11

.lr.ph:                                           ; preds = %.lr.ph65, %39
  %indvars.iv = phi i64 [ %indvars.iv.next, %39 ], [ 1, %.lr.ph65 ]
  %22 = add nsw i64 %indvars.iv, -1
  %23 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %22)
  %24 = load i8, ptr %23, align 1, !tbaa !13
  %25 = icmp eq i8 %24, 76
  br i1 %25, label %.sink.split, label %26

26:                                               ; preds = %.lr.ph
  %27 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %22)
  %28 = load i8, ptr %27, align 1, !tbaa !13
  %29 = icmp eq i8 %28, 82
  br i1 %29, label %.sink.split, label %30

30:                                               ; preds = %26
  %31 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %22)
  %32 = load i8, ptr %31, align 1, !tbaa !13
  %33 = icmp eq i8 %32, 68
  br i1 %33, label %.sink.split, label %34

34:                                               ; preds = %30
  %35 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1sB5cxx11, i64 noundef %22)
  %36 = load i8, ptr %35, align 1, !tbaa !13
  %37 = icmp eq i8 %36, 85
  br i1 %37, label %.sink.split, label %39

.sink.split:                                      ; preds = %34, %30, %26, %.lr.ph
  %.sink = phi i32 [ 1, %.lr.ph ], [ 2, %26 ], [ 3, %30 ], [ 4, %34 ]
  %38 = getelementptr inbounds [2001 x [2001 x i32]], ptr @grid, i64 0, i64 %indvars.iv75, i64 %indvars.iv
  store i32 %.sink, ptr %38, align 4, !tbaa !8
  br label %39

39:                                               ; preds = %.sink.split, %34
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %40 = load i32, ptr @m, align 4, !tbaa !8
  %41 = sext i32 %40 to i64
  %.not55.not = icmp slt i64 %indvars.iv, %41
  br i1 %.not55.not, label %.lr.ph, label %._crit_edge, !llvm.loop !14

.preheader:                                       ; preds = %.preheader59, %._crit_edge70
  %indvars.iv81 = phi i64 [ %indvars.iv.next82, %._crit_edge70 ], [ 1, %.preheader59 ]
  %42 = load i32, ptr @n, align 4, !tbaa !8
  %.not5466 = icmp slt i32 %42, 2
  br i1 %.not5466, label %._crit_edge70, label %.lr.ph69

.lr.ph69:                                         ; preds = %.preheader
  %43 = add nsw i64 %indvars.iv81, -1
  %44 = getelementptr inbounds [2001 x i32], ptr getelementptr inbounds (i8, ptr @grid, i64 8004), i64 0, i64 %indvars.iv81
  %45 = trunc nuw nsw i64 %43 to i32
  %46 = trunc nuw nsw i64 %indvars.iv81 to i32
  br label %52

._crit_edge73:                                    ; preds = %._crit_edge70, %.preheader59
  %47 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, ptr noundef nonnull @.str.2)
  ret i32 0

._crit_edge70:                                    ; preds = %89, %.preheader
  %.049.lcssa = phi i32 [ 0, %.preheader ], [ %.4, %89 ]
  %48 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %.049.lcssa)
  %49 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %48, ptr noundef nonnull @.str)
  %indvars.iv.next82 = add nuw nsw i64 %indvars.iv81, 1
  %50 = load i32, ptr @m, align 4, !tbaa !8
  %51 = sext i32 %50 to i64
  %.not53.not = icmp slt i64 %indvars.iv81, %51
  br i1 %.not53.not, label %.preheader, label %._crit_edge73, !llvm.loop !15

52:                                               ; preds = %.lr.ph69, %89
  %indvars.iv78 = phi i64 [ 2, %.lr.ph69 ], [ %indvars.iv.next79, %89 ]
  %.04967 = phi i32 [ 0, %.lr.ph69 ], [ %.4, %89 ]
  %indvars80 = trunc i64 %indvars.iv78 to i32
  %53 = add nuw i32 %45, %indvars80
  %54 = tail call noundef zeroext i1 @_Z7inrangeii(i32 noundef %indvars80, i32 noundef %53)
  br i1 %54, label %55, label %62

55:                                               ; preds = %52
  %56 = add nuw nsw i64 %43, %indvars.iv78
  %sext = shl i64 %56, 32
  %57 = ashr exact i64 %sext, 32
  %58 = getelementptr inbounds [2001 x [2001 x i32]], ptr @grid, i64 0, i64 %indvars.iv78, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !8
  %60 = icmp eq i32 %59, 1
  %61 = zext i1 %60 to i32
  %spec.select = add nsw i32 %.04967, %61
  br label %62

62:                                               ; preds = %55, %52
  %.1 = phi i32 [ %.04967, %52 ], [ %spec.select, %55 ]
  %63 = sub nsw i32 %46, %indvars80
  %64 = add nsw i32 %63, 1
  %65 = tail call noundef zeroext i1 @_Z7inrangeii(i32 noundef %indvars80, i32 noundef %64)
  br i1 %65, label %66, label %73

66:                                               ; preds = %62
  %67 = sub nsw i64 %indvars.iv81, %indvars.iv78
  %68 = add nsw i64 %67, 1
  %69 = getelementptr inbounds [2001 x [2001 x i32]], ptr @grid, i64 0, i64 %indvars.iv78, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !8
  %71 = icmp eq i32 %70, 2
  %72 = zext i1 %71 to i32
  %spec.select56 = add nsw i32 %.1, %72
  br label %73

73:                                               ; preds = %66, %62
  %.2 = phi i32 [ %.1, %62 ], [ %spec.select56, %66 ]
  %74 = shl nuw nsw i64 %indvars.iv78, 1
  %75 = add nsw i64 %74, -1
  %76 = trunc nsw i64 %75 to i32
  %77 = tail call noundef zeroext i1 @_Z7inrangeii(i32 noundef %76, i32 noundef %46)
  br i1 %77, label %78, label %83

78:                                               ; preds = %73
  %79 = getelementptr inbounds [2001 x [2001 x i32]], ptr @grid, i64 0, i64 %75, i64 %indvars.iv81
  %80 = load i32, ptr %79, align 4, !tbaa !8
  %81 = icmp eq i32 %80, 4
  %82 = zext i1 %81 to i32
  %spec.select57 = add nsw i32 %.2, %82
  br label %83

83:                                               ; preds = %78, %73
  %.3 = phi i32 [ %.2, %73 ], [ %spec.select57, %78 ]
  %84 = tail call noundef zeroext i1 @_Z7inrangeii(i32 noundef 1, i32 noundef %46)
  br i1 %84, label %85, label %89

85:                                               ; preds = %83
  %86 = load i32, ptr %44, align 4, !tbaa !8
  %87 = icmp eq i32 %86, 3
  %88 = zext i1 %87 to i32
  %spec.select58 = add nsw i32 %.3, %88
  br label %89

89:                                               ; preds = %85, %83
  %.4 = phi i32 [ %.3, %83 ], [ %spec.select58, %85 ]
  %indvars.iv.next79 = add nuw nsw i64 %indvars.iv78, 1
  %90 = load i32, ptr @n, align 4, !tbaa !8
  %91 = sext i32 %90 to i64
  %.not54.not = icmp slt i64 %indvars.iv78, %91
  br i1 %.not54.not, label %52, label %._crit_edge70, !llvm.loop !16
}

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) local_unnamed_addr #2

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264), ptr noundef) local_unnamed_addr #0 align 2

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

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) local_unnamed_addr #3

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

attributes #0 = { 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 #1 = { 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 #2 = { "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 = { 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" }

!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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"int", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}


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