; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/311 Division 2/Problem E (E)

; 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.__gnu_cxx::__normal_iterator" = type { ptr }

@s = external dso_local global [5001 x i8], align 16
@_Z3ansB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@k = external dso_local global i32, align 4
@dp = external dso_local global [5000 x [5000 x i32]], align 16
@l = external dso_local global i32, align 4
@ROOT = external dso_local global ptr, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6insertii(i32 noundef, i32 noundef) #0

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

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) #2

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: nobuiltin nounwind
declare void @_ZdlPvm(ptr noundef, i64 noundef) #4

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3getP4nodei(ptr noundef, i32 noundef) #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #5 personality ptr @__gxx_personality_v0 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  %12 = alloca %"class.__gnu_cxx::__normal_iterator", align 8
  store i32 0, ptr %1, align 4
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @s, ptr noundef @k)
  %14 = call i64 @strlen(ptr noundef @s) #9
  %15 = trunc i64 %14 to i32
  store i32 %15, ptr @l, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #10
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %16

16:                                               ; preds = %224, %0
  %17 = load i32, ptr %2, align 4, !tbaa !5
  %18 = load i32, ptr @l, align 4, !tbaa !5
  %19 = icmp slt i32 %17, %18
  br i1 %19, label %21, label %20

20:                                               ; preds = %16
  store i32 2, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #10
  br label %227

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

22:                                               ; preds = %66, %21
  %23 = load i32, ptr %2, align 4, !tbaa !5
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = sub nsw i32 %23, %24
  %26 = icmp sge i32 %25, 0
  br i1 %26, label %27, label %33

27:                                               ; preds = %22
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = load i32, ptr %4, align 4, !tbaa !5
  %30 = add nsw i32 %28, %29
  %31 = load i32, ptr @l, align 4, !tbaa !5
  %32 = icmp slt i32 %30, %31
  br label %33

33:                                               ; preds = %27, %22
  %34 = phi i1 [ false, %22 ], [ %32, %27 ]
  br i1 %34, label %36, label %35

35:                                               ; preds = %33
  store i32 5, ptr %3, align 4
  br label %69

36:                                               ; preds = %33
  %37 = load i32, ptr %2, align 4, !tbaa !5
  %38 = load i32, ptr %4, align 4, !tbaa !5
  %39 = sub nsw i32 %37, %38
  %40 = sext i32 %39 to i64
  %41 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %40
  %42 = load i8, ptr %41, align 1, !tbaa !9
  %43 = sext i8 %42 to i32
  %44 = load i32, ptr %2, align 4, !tbaa !5
  %45 = load i32, ptr %4, align 4, !tbaa !5
  %46 = add nsw i32 %44, %45
  %47 = sext i32 %46 to i64
  %48 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %47
  %49 = load i8, ptr %48, align 1, !tbaa !9
  %50 = sext i8 %49 to i32
  %51 = icmp ne i32 %43, %50
  br i1 %51, label %52, label %53

52:                                               ; preds = %36
  store i32 5, ptr %3, align 4
  br label %69

53:                                               ; preds = %36
  %54 = load i32, ptr %2, align 4, !tbaa !5
  %55 = load i32, ptr %4, align 4, !tbaa !5
  %56 = sub nsw i32 %54, %55
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [5000 x [5000 x i32]], ptr @dp, i64 0, i64 %57
  %59 = load i32, ptr %2, align 4, !tbaa !5
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = add nsw i32 %59, %60
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [5000 x i32], ptr %58, i64 0, i64 %62
  %64 = load i32, ptr %63, align 4, !tbaa !5
  %65 = add nsw i32 %64, 1
  store i32 %65, ptr %63, align 4, !tbaa !5
  br label %66

66:                                               ; preds = %53
  %67 = load i32, ptr %4, align 4, !tbaa !5
  %68 = add nsw i32 %67, 2
  store i32 %68, ptr %4, align 4, !tbaa !5
  br label %22, !llvm.loop !10

69:                                               ; preds = %52, %35
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #10
  br label %70

70:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #10
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %71

71:                                               ; preds = %115, %70
  %72 = load i32, ptr %2, align 4, !tbaa !5
  %73 = load i32, ptr %5, align 4, !tbaa !5
  %74 = sub nsw i32 %72, %73
  %75 = icmp sge i32 %74, 0
  br i1 %75, label %76, label %82

76:                                               ; preds = %71
  %77 = load i32, ptr %2, align 4, !tbaa !5
  %78 = load i32, ptr %5, align 4, !tbaa !5
  %79 = add nsw i32 %77, %78
  %80 = load i32, ptr @l, align 4, !tbaa !5
  %81 = icmp slt i32 %79, %80
  br label %82

82:                                               ; preds = %76, %71
  %83 = phi i1 [ false, %71 ], [ %81, %76 ]
  br i1 %83, label %85, label %84

84:                                               ; preds = %82
  store i32 8, ptr %3, align 4
  br label %118

85:                                               ; preds = %82
  %86 = load i32, ptr %2, align 4, !tbaa !5
  %87 = load i32, ptr %5, align 4, !tbaa !5
  %88 = sub nsw i32 %86, %87
  %89 = sext i32 %88 to i64
  %90 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %89
  %91 = load i8, ptr %90, align 1, !tbaa !9
  %92 = sext i8 %91 to i32
  %93 = load i32, ptr %2, align 4, !tbaa !5
  %94 = load i32, ptr %5, align 4, !tbaa !5
  %95 = add nsw i32 %93, %94
  %96 = sext i32 %95 to i64
  %97 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %96
  %98 = load i8, ptr %97, align 1, !tbaa !9
  %99 = sext i8 %98 to i32
  %100 = icmp ne i32 %92, %99
  br i1 %100, label %101, label %102

101:                                              ; preds = %85
  store i32 8, ptr %3, align 4
  br label %118

102:                                              ; preds = %85
  %103 = load i32, ptr %2, align 4, !tbaa !5
  %104 = load i32, ptr %5, align 4, !tbaa !5
  %105 = sub nsw i32 %103, %104
  %106 = sext i32 %105 to i64
  %107 = getelementptr inbounds [5000 x [5000 x i32]], ptr @dp, i64 0, i64 %106
  %108 = load i32, ptr %2, align 4, !tbaa !5
  %109 = load i32, ptr %5, align 4, !tbaa !5
  %110 = add nsw i32 %108, %109
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds [5000 x i32], ptr %107, i64 0, i64 %111
  %113 = load i32, ptr %112, align 4, !tbaa !5
  %114 = add nsw i32 %113, 1
  store i32 %114, ptr %112, align 4, !tbaa !5
  br label %115

115:                                              ; preds = %102
  %116 = load i32, ptr %5, align 4, !tbaa !5
  %117 = add nsw i32 %116, 2
  store i32 %117, ptr %5, align 4, !tbaa !5
  br label %71, !llvm.loop !12

118:                                              ; preds = %101, %84
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #10
  br label %119

119:                                              ; preds = %118
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #10
  store i32 1, ptr %6, align 4, !tbaa !5
  br label %120

120:                                              ; preds = %167, %119
  %121 = load i32, ptr %2, align 4, !tbaa !5
  %122 = load i32, ptr %6, align 4, !tbaa !5
  %123 = sub nsw i32 %121, %122
  %124 = add nsw i32 %123, 1
  %125 = icmp sge i32 %124, 0
  br i1 %125, label %126, label %132

126:                                              ; preds = %120
  %127 = load i32, ptr %2, align 4, !tbaa !5
  %128 = load i32, ptr %6, align 4, !tbaa !5
  %129 = add nsw i32 %127, %128
  %130 = load i32, ptr @l, align 4, !tbaa !5
  %131 = icmp slt i32 %129, %130
  br label %132

132:                                              ; preds = %126, %120
  %133 = phi i1 [ false, %120 ], [ %131, %126 ]
  br i1 %133, label %135, label %134

134:                                              ; preds = %132
  store i32 11, ptr %3, align 4
  br label %170

135:                                              ; preds = %132
  %136 = load i32, ptr %2, align 4, !tbaa !5
  %137 = load i32, ptr %6, align 4, !tbaa !5
  %138 = sub nsw i32 %136, %137
  %139 = add nsw i32 %138, 1
  %140 = sext i32 %139 to i64
  %141 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %140
  %142 = load i8, ptr %141, align 1, !tbaa !9
  %143 = sext i8 %142 to i32
  %144 = load i32, ptr %2, align 4, !tbaa !5
  %145 = load i32, ptr %6, align 4, !tbaa !5
  %146 = add nsw i32 %144, %145
  %147 = sext i32 %146 to i64
  %148 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %147
  %149 = load i8, ptr %148, align 1, !tbaa !9
  %150 = sext i8 %149 to i32
  %151 = icmp ne i32 %143, %150
  br i1 %151, label %152, label %153

152:                                              ; preds = %135
  store i32 11, ptr %3, align 4
  br label %170

153:                                              ; preds = %135
  %154 = load i32, ptr %2, align 4, !tbaa !5
  %155 = load i32, ptr %6, align 4, !tbaa !5
  %156 = sub nsw i32 %154, %155
  %157 = add nsw i32 %156, 1
  %158 = sext i32 %157 to i64
  %159 = getelementptr inbounds [5000 x [5000 x i32]], ptr @dp, i64 0, i64 %158
  %160 = load i32, ptr %2, align 4, !tbaa !5
  %161 = load i32, ptr %6, align 4, !tbaa !5
  %162 = add nsw i32 %160, %161
  %163 = sext i32 %162 to i64
  %164 = getelementptr inbounds [5000 x i32], ptr %159, i64 0, i64 %163
  %165 = load i32, ptr %164, align 4, !tbaa !5
  %166 = add nsw i32 %165, 1
  store i32 %166, ptr %164, align 4, !tbaa !5
  br label %167

167:                                              ; preds = %153
  %168 = load i32, ptr %6, align 4, !tbaa !5
  %169 = add nsw i32 %168, 2
  store i32 %169, ptr %6, align 4, !tbaa !5
  br label %120, !llvm.loop !13

170:                                              ; preds = %152, %134
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #10
  br label %171

171:                                              ; preds = %170
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #10
  store i32 2, ptr %7, align 4, !tbaa !5
  br label %172

172:                                              ; preds = %219, %171
  %173 = load i32, ptr %2, align 4, !tbaa !5
  %174 = load i32, ptr %7, align 4, !tbaa !5
  %175 = sub nsw i32 %173, %174
  %176 = add nsw i32 %175, 1
  %177 = icmp sge i32 %176, 0
  br i1 %177, label %178, label %184

178:                                              ; preds = %172
  %179 = load i32, ptr %2, align 4, !tbaa !5
  %180 = load i32, ptr %7, align 4, !tbaa !5
  %181 = add nsw i32 %179, %180
  %182 = load i32, ptr @l, align 4, !tbaa !5
  %183 = icmp slt i32 %181, %182
  br label %184

184:                                              ; preds = %178, %172
  %185 = phi i1 [ false, %172 ], [ %183, %178 ]
  br i1 %185, label %187, label %186

186:                                              ; preds = %184
  store i32 14, ptr %3, align 4
  br label %222

187:                                              ; preds = %184
  %188 = load i32, ptr %2, align 4, !tbaa !5
  %189 = load i32, ptr %7, align 4, !tbaa !5
  %190 = sub nsw i32 %188, %189
  %191 = add nsw i32 %190, 1
  %192 = sext i32 %191 to i64
  %193 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %192
  %194 = load i8, ptr %193, align 1, !tbaa !9
  %195 = sext i8 %194 to i32
  %196 = load i32, ptr %2, align 4, !tbaa !5
  %197 = load i32, ptr %7, align 4, !tbaa !5
  %198 = add nsw i32 %196, %197
  %199 = sext i32 %198 to i64
  %200 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %199
  %201 = load i8, ptr %200, align 1, !tbaa !9
  %202 = sext i8 %201 to i32
  %203 = icmp ne i32 %195, %202
  br i1 %203, label %204, label %205

204:                                              ; preds = %187
  store i32 14, ptr %3, align 4
  br label %222

205:                                              ; preds = %187
  %206 = load i32, ptr %2, align 4, !tbaa !5
  %207 = load i32, ptr %7, align 4, !tbaa !5
  %208 = sub nsw i32 %206, %207
  %209 = add nsw i32 %208, 1
  %210 = sext i32 %209 to i64
  %211 = getelementptr inbounds [5000 x [5000 x i32]], ptr @dp, i64 0, i64 %210
  %212 = load i32, ptr %2, align 4, !tbaa !5
  %213 = load i32, ptr %7, align 4, !tbaa !5
  %214 = add nsw i32 %212, %213
  %215 = sext i32 %214 to i64
  %216 = getelementptr inbounds [5000 x i32], ptr %211, i64 0, i64 %215
  %217 = load i32, ptr %216, align 4, !tbaa !5
  %218 = add nsw i32 %217, 1
  store i32 %218, ptr %216, align 4, !tbaa !5
  br label %219

219:                                              ; preds = %205
  %220 = load i32, ptr %7, align 4, !tbaa !5
  %221 = add nsw i32 %220, 2
  store i32 %221, ptr %7, align 4, !tbaa !5
  br label %172, !llvm.loop !14

222:                                              ; preds = %204, %186
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #10
  br label %223

223:                                              ; preds = %222
  br label %224

224:                                              ; preds = %223
  %225 = load i32, ptr %2, align 4, !tbaa !5
  %226 = add nsw i32 %225, 1
  store i32 %226, ptr %2, align 4, !tbaa !5
  br label %16, !llvm.loop !15

227:                                              ; preds = %20
  %228 = call noalias noundef nonnull ptr @_Znwm(i64 noundef 24) #11
  invoke void @_ZN4nodeC2Ev(ptr noundef nonnull align 8 dereferenceable(20) %228)
          to label %229 unwind label %235

229:                                              ; preds = %227
  store ptr %228, ptr @ROOT, align 8, !tbaa !16
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #10
  store i32 0, ptr %10, align 4, !tbaa !5
  br label %230

230:                                              ; preds = %242, %229
  %231 = load i32, ptr %10, align 4, !tbaa !5
  %232 = load i32, ptr @l, align 4, !tbaa !5
  %233 = icmp slt i32 %231, %232
  br i1 %233, label %239, label %234

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

235:                                              ; preds = %227
  %236 = landingpad { ptr, i32 }
          cleanup
  %237 = extractvalue { ptr, i32 } %236, 0
  store ptr %237, ptr %8, align 8
  %238 = extractvalue { ptr, i32 } %236, 1
  store i32 %238, ptr %9, align 4
  call void @_ZdlPvm(ptr noundef %228, i64 noundef 24) #12
  br label %259

239:                                              ; preds = %230
  %240 = load i32, ptr %10, align 4, !tbaa !5
  %241 = load i32, ptr %10, align 4, !tbaa !5
  call void @_Z6insertii(i32 noundef %240, i32 noundef %241)
  br label %242

242:                                              ; preds = %239
  %243 = load i32, ptr %10, align 4, !tbaa !5
  %244 = add nsw i32 %243, 1
  store i32 %244, ptr %10, align 4, !tbaa !5
  br label %230, !llvm.loop !18

245:                                              ; preds = %234
  %246 = load ptr, ptr @ROOT, align 8, !tbaa !16
  %247 = load i32, ptr @k, align 4, !tbaa !5
  %248 = call noundef i32 @_Z3getP4nodei(ptr noundef %246, i32 noundef %247)
  %249 = call ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5beginEv(ptr noundef nonnull align 8 dereferenceable(32) @_Z3ansB5cxx11) #10
  %250 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %11, i32 0, i32 0
  store ptr %249, ptr %250, align 8
  %251 = call ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE3endEv(ptr noundef nonnull align 8 dereferenceable(32) @_Z3ansB5cxx11) #10
  %252 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %12, i32 0, i32 0
  store ptr %251, ptr %252, align 8
  %253 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %11, i32 0, i32 0
  %254 = load ptr, ptr %253, align 8
  %255 = getelementptr inbounds %"class.__gnu_cxx::__normal_iterator", ptr %12, i32 0, i32 0
  %256 = load ptr, ptr %255, align 8
  call void @_ZSt7reverseIN9__gnu_cxx17__normal_iteratorIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEEvT_SA_(ptr %254, ptr %256)
  %257 = call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) @_Z3ansB5cxx11) #10
  %258 = call i32 (ptr, ...) @printf(ptr noundef @.str.3, ptr noundef %257)
  ret i32 0

259:                                              ; preds = %235
  %260 = load ptr, ptr %8, align 8
  %261 = load i32, ptr %9, align 4
  %262 = insertvalue { ptr, i32 } poison, ptr %260, 0
  %263 = insertvalue { ptr, i32 } %262, i32 %261, 1
  resume { ptr, i32 } %263
}

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

; Function Attrs: nounwind willreturn memory(read)
declare i64 @strlen(ptr noundef) #7

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

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

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

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

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

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

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

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


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

%"class.std::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }

@s = external dso_local global [5001 x i8], align 16
@_Z3ansB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@k = external dso_local global i32, align 4
@dp = external dso_local local_unnamed_addr global [5000 x [5000 x i32]], align 16
@l = external dso_local local_unnamed_addr global i32, align 4
@ROOT = external dso_local local_unnamed_addr global ptr, align 8
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.3 = external hidden unnamed_addr constant [4 x i8], align 1

; Function Attrs: mustprogress uwtable
declare dso_local void @_Z6insertii(i32 noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: nobuiltin allocsize(0)
declare noundef nonnull ptr @_Znwm(i64 noundef) local_unnamed_addr #1

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

declare i32 @__gxx_personality_v0(...)

; Function Attrs: mustprogress uwtable
declare dso_local noundef i32 @_Z3getP4nodei(ptr noundef, i32 noundef) local_unnamed_addr #0

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 personality ptr @__gxx_personality_v0 {
  %1 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @s, ptr noundef nonnull @k)
  %2 = tail call i64 @strlen(ptr noundef nonnull dereferenceable(1) @s) #7
  %3 = trunc i64 %2 to i32
  store i32 %3, ptr @l, align 4, !tbaa !5
  %4 = icmp sgt i32 %3, 0
  br i1 %4, label %.preheader.preheader, label %._crit_edge

.preheader.preheader:                             ; preds = %0
  %5 = and i64 %2, 2147483647
  %wide.trip.count = and i64 %2, 2147483647
  br label %.lr.ph.preheader

.lr.ph.preheader:                                 ; preds = %.critedge6, %.preheader.preheader
  %indvars.iv113 = phi i64 [ 0, %.preheader.preheader ], [ %indvars.iv.next114, %.critedge6 ]
  %6 = trunc nuw nsw i64 %indvars.iv113 to i32
  br label %.lr.ph

._crit_edge:                                      ; preds = %.critedge6, %0
  %7 = tail call noalias noundef nonnull dereferenceable(24) ptr @_Znwm(i64 noundef 24) #8
  tail call void @_ZN4nodeC2Ev(ptr noundef nonnull align 8 dereferenceable(20) %7)
  store ptr %7, ptr @ROOT, align 8, !tbaa !9
  %8 = load i32, ptr @l, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph99, label %._crit_edge100

.lr.ph:                                           ; preds = %.lr.ph.preheader, %19
  %indvars.iv = phi i64 [ 0, %.lr.ph.preheader ], [ %indvars.iv.next, %19 ]
  %10 = phi i32 [ %6, %.lr.ph.preheader ], [ %24, %19 ]
  %11 = add nuw nsw i64 %indvars.iv, %indvars.iv113
  %12 = icmp ult i64 %11, %5
  br i1 %12, label %13, label %.critedge

13:                                               ; preds = %.lr.ph
  %14 = zext nneg i32 %10 to i64
  %15 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %14
  %16 = load i8, ptr %15, align 1, !tbaa !11
  %17 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %11
  %18 = load i8, ptr %17, align 1, !tbaa !11
  %.not = icmp eq i8 %16, %18
  br i1 %.not, label %19, label %.critedge

19:                                               ; preds = %13
  %20 = getelementptr inbounds [5000 x [5000 x i32]], ptr @dp, i64 0, i64 %14, i64 %11
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %20, align 4, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 2
  %23 = trunc nuw i64 %indvars.iv.next to i32
  %24 = sub nsw i32 %6, %23
  %25 = icmp sgt i32 %24, -1
  br i1 %25, label %.lr.ph, label %.critedge, !llvm.loop !12

.critedge:                                        ; preds = %19, %.lr.ph, %13
  %26 = add nsw i64 %indvars.iv113, -1
  %.not101 = icmp eq i64 %indvars.iv113, 0
  br i1 %.not101, label %.lr.ph89.preheader, label %.lr.ph85

.lr.ph85:                                         ; preds = %.critedge, %35
  %indvars.iv104 = phi i64 [ %indvars.iv.next105, %35 ], [ 1, %.critedge ]
  %.in = phi i64 [ %39, %35 ], [ %26, %.critedge ]
  %27 = add nuw nsw i64 %indvars.iv104, %indvars.iv113
  %28 = icmp ult i64 %27, %5
  br i1 %28, label %29, label %.lr.ph89.preheader

29:                                               ; preds = %.lr.ph85
  %30 = and i64 %.in, 4294967295
  %31 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %30
  %32 = load i8, ptr %31, align 1, !tbaa !11
  %33 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %27
  %34 = load i8, ptr %33, align 1, !tbaa !11
  %.not78 = icmp eq i8 %32, %34
  br i1 %.not78, label %35, label %.lr.ph89.preheader

35:                                               ; preds = %29
  %36 = getelementptr inbounds [5000 x [5000 x i32]], ptr @dp, i64 0, i64 %30, i64 %27
  %37 = load i32, ptr %36, align 4, !tbaa !5
  %38 = add nsw i32 %37, 1
  store i32 %38, ptr %36, align 4, !tbaa !5
  %indvars.iv.next105 = add nuw nsw i64 %indvars.iv104, 2
  %39 = sub nsw i64 %indvars.iv113, %indvars.iv.next105
  %40 = icmp sgt i64 %39, -1
  br i1 %40, label %.lr.ph85, label %.lr.ph89.preheader, !llvm.loop !14

.lr.ph89.preheader:                               ; preds = %29, %.lr.ph85, %35, %.critedge
  %41 = trunc nuw nsw i64 %indvars.iv113 to i32
  br label %.lr.ph89

.lr.ph89:                                         ; preds = %.lr.ph89.preheader, %51
  %indvars.iv107 = phi i64 [ 1, %.lr.ph89.preheader ], [ %indvars.iv.next108, %51 ]
  %42 = phi i32 [ %41, %.lr.ph89.preheader ], [ %57, %51 ]
  %43 = add nuw nsw i64 %indvars.iv107, %indvars.iv113
  %44 = icmp ult i64 %43, %5
  br i1 %44, label %45, label %.critedge4

45:                                               ; preds = %.lr.ph89
  %46 = zext nneg i32 %42 to i64
  %47 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %46
  %48 = load i8, ptr %47, align 1, !tbaa !11
  %49 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %43
  %50 = load i8, ptr %49, align 1, !tbaa !11
  %.not79 = icmp eq i8 %48, %50
  br i1 %.not79, label %51, label %.critedge4

51:                                               ; preds = %45
  %52 = getelementptr inbounds [5000 x [5000 x i32]], ptr @dp, i64 0, i64 %46, i64 %43
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = add nsw i32 %53, 1
  store i32 %54, ptr %52, align 4, !tbaa !5
  %indvars.iv.next108 = add nuw nsw i64 %indvars.iv107, 2
  %55 = trunc nuw i64 %indvars.iv.next108 to i32
  %56 = sub nsw i32 %41, %55
  %57 = add nsw i32 %56, 1
  %58 = icmp sgt i32 %56, -2
  br i1 %58, label %.lr.ph89, label %.critedge4, !llvm.loop !15

.critedge4:                                       ; preds = %51, %.lr.ph89, %45
  br i1 %.not101, label %.critedge6, label %.lr.ph93.preheader

.lr.ph93.preheader:                               ; preds = %.critedge4
  %59 = trunc nsw i64 %26 to i32
  %60 = trunc nuw nsw i64 %indvars.iv113 to i32
  br label %.lr.ph93

.lr.ph93:                                         ; preds = %.lr.ph93.preheader, %71
  %indvars.iv110 = phi i64 [ 2, %.lr.ph93.preheader ], [ %indvars.iv.next111, %71 ]
  %61 = phi i32 [ %59, %.lr.ph93.preheader ], [ %77, %71 ]
  %62 = add nuw nsw i64 %indvars.iv110, %indvars.iv113
  %63 = trunc nuw i64 %62 to i32
  %64 = icmp slt i32 %63, %3
  br i1 %64, label %65, label %.critedge6

65:                                               ; preds = %.lr.ph93
  %66 = zext nneg i32 %61 to i64
  %67 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %66
  %68 = load i8, ptr %67, align 1, !tbaa !11
  %69 = getelementptr inbounds [5001 x i8], ptr @s, i64 0, i64 %62
  %70 = load i8, ptr %69, align 1, !tbaa !11
  %.not80 = icmp eq i8 %68, %70
  br i1 %.not80, label %71, label %.critedge6

71:                                               ; preds = %65
  %72 = getelementptr inbounds [5000 x [5000 x i32]], ptr @dp, i64 0, i64 %66, i64 %62
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = add nsw i32 %73, 1
  store i32 %74, ptr %72, align 4, !tbaa !5
  %indvars.iv.next111 = add nuw nsw i64 %indvars.iv110, 2
  %75 = trunc nuw i64 %indvars.iv.next111 to i32
  %76 = sub nsw i32 %60, %75
  %77 = add nsw i32 %76, 1
  %78 = icmp sgt i32 %76, -2
  br i1 %78, label %.lr.ph93, label %.critedge6, !llvm.loop !16

.critedge6:                                       ; preds = %71, %.lr.ph93, %65, %.critedge4
  %indvars.iv.next114 = add nuw nsw i64 %indvars.iv113, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next114, %wide.trip.count
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph.preheader, !llvm.loop !17

._crit_edge100.loopexit:                          ; preds = %.lr.ph99
  %.pre = load ptr, ptr @ROOT, align 8, !tbaa !9
  br label %._crit_edge100

._crit_edge100:                                   ; preds = %._crit_edge100.loopexit, %._crit_edge
  %79 = phi ptr [ %.pre, %._crit_edge100.loopexit ], [ %7, %._crit_edge ]
  %80 = load i32, ptr @k, align 4, !tbaa !5
  %81 = tail call noundef i32 @_Z3getP4nodei(ptr noundef %79, i32 noundef %80)
  %82 = tail call ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5beginEv(ptr noundef nonnull align 8 dereferenceable(32) @_Z3ansB5cxx11) #9
  %83 = tail call ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE3endEv(ptr noundef nonnull align 8 dereferenceable(32) @_Z3ansB5cxx11) #9
  tail call void @_ZSt7reverseIN9__gnu_cxx17__normal_iteratorIPcNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEEvT_SA_(ptr %82, ptr %83)
  %84 = tail call noundef ptr @_ZNKSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEE5c_strEv(ptr noundef nonnull align 8 dereferenceable(32) @_Z3ansB5cxx11) #9
  %85 = tail call i32 (ptr, ...) @printf(ptr noundef nonnull dereferenceable(1) @.str.3, ptr noundef %84)
  ret i32 0

.lr.ph99:                                         ; preds = %._crit_edge, %.lr.ph99
  %.06597 = phi i32 [ %86, %.lr.ph99 ], [ 0, %._crit_edge ]
  tail call void @_Z6insertii(i32 noundef %.06597, i32 noundef %.06597)
  %86 = add nuw nsw i32 %.06597, 1
  %87 = load i32, ptr @l, align 4, !tbaa !5
  %88 = icmp slt i32 %86, %87
  br i1 %88, label %.lr.ph99, label %._crit_edge100.loopexit, !llvm.loop !18
}

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

; Function Attrs: mustprogress nofree nounwind willreturn memory(argmem: read)
declare i64 @strlen(ptr nocapture noundef) local_unnamed_addr #5

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

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

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

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

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

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { nobuiltin allocsize(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 = { nofree nounwind "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #5 = { mustprogress nofree nounwind willreturn memory(argmem: read) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #6 = { inlinehint mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #7 = { nounwind willreturn memory(read) }
attributes #8 = { builtin allocsize(0) }
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 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !7, i64 0}
!11 = !{!7, !7, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13}
!15 = distinct !{!15, !13}
!16 = distinct !{!16, !13}
!17 = distinct !{!17, !13}
!18 = distinct !{!18, !13}


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