; LLVM IR from VastoLorde95/Competitive-Programming :: Hackerrank/101 Hacks/101 Hack 2015/101 Hack April/Problem D (D)

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

%"class.std::basic_ostream" = type { ptr, %"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 }

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@t = external dso_local global [100001 x i32], align 16
@u = external dso_local global i32, align 4
@v = external dso_local global i32, align 4
@tim = external dso_local global i32, align 4
@cities = external dso_local global [100001 x i32], align 16
@res = external dso_local global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #0 {
  %1 = alloca i32, align 4
  %2 = alloca ptr, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  %9 = alloca i32, align 4
  %10 = alloca i32, align 4
  %11 = alloca i32, align 4
  %12 = alloca i32, align 4
  %13 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %14 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @m)
  %15 = load i32, ptr @n, align 4, !tbaa !5
  %16 = add nsw i32 %15, 1
  %17 = zext i32 %16 to i64
  %18 = load i32, ptr @n, align 4, !tbaa !5
  %19 = add nsw i32 %18, 1
  %20 = zext i32 %19 to i64
  %21 = call ptr @llvm.stacksave.p0()
  store ptr %21, ptr %2, align 8
  %22 = mul nuw i64 %17, %20
  %23 = alloca i32, i64 %22, align 16
  store i64 %17, ptr %3, align 8
  store i64 %20, ptr %4, align 8
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #7
  store i32 1, ptr %5, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %34, %0
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = icmp sle i32 %25, %26
  br i1 %27, label %29, label %28

28:                                               ; preds = %24
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #7
  br label %37

29:                                               ; preds = %24
  %30 = load i32, ptr %5, align 4, !tbaa !5
  %31 = sext i32 %30 to i64
  %32 = getelementptr inbounds [100001 x i32], ptr @t, i64 0, i64 %31
  %33 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %32)
  br label %34

34:                                               ; preds = %29
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = add nsw i32 %35, 1
  store i32 %36, ptr %5, align 4, !tbaa !5
  br label %24, !llvm.loop !9

37:                                               ; preds = %28
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  store i32 0, ptr %6, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %60, %37
  %39 = load i32, ptr %6, align 4, !tbaa !5
  %40 = load i32, ptr @m, align 4, !tbaa !5
  %41 = icmp slt i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  br label %63

43:                                               ; preds = %38
  %44 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.2, ptr noundef @u, ptr noundef @v, ptr noundef @tim)
  %45 = load i32, ptr @tim, align 4, !tbaa !5
  %46 = load i32, ptr @v, align 4, !tbaa !5
  %47 = sext i32 %46 to i64
  %48 = mul nsw i64 %47, %20
  %49 = getelementptr inbounds i32, ptr %23, i64 %48
  %50 = load i32, ptr @u, align 4, !tbaa !5
  %51 = sext i32 %50 to i64
  %52 = getelementptr inbounds i32, ptr %49, i64 %51
  store i32 %45, ptr %52, align 4, !tbaa !5
  %53 = load i32, ptr @u, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = mul nsw i64 %54, %20
  %56 = getelementptr inbounds i32, ptr %23, i64 %55
  %57 = load i32, ptr @v, align 4, !tbaa !5
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds i32, ptr %56, i64 %58
  store i32 %45, ptr %59, align 4, !tbaa !5
  br label %60

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

63:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  store i32 0, ptr %7, align 4, !tbaa !5
  br label %64

64:                                               ; preds = %74, %63
  %65 = load i32, ptr %7, align 4, !tbaa !5
  %66 = load i32, ptr @m, align 4, !tbaa !5
  %67 = icmp slt i32 %65, %66
  br i1 %67, label %69, label %68

68:                                               ; preds = %64
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  br label %77

69:                                               ; preds = %64
  %70 = load i32, ptr %7, align 4, !tbaa !5
  %71 = sext i32 %70 to i64
  %72 = getelementptr inbounds [100001 x i32], ptr @cities, i64 0, i64 %71
  %73 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %72)
  br label %74

74:                                               ; preds = %69
  %75 = load i32, ptr %7, align 4, !tbaa !5
  %76 = add nsw i32 %75, 1
  store i32 %76, ptr %7, align 4, !tbaa !5
  br label %64, !llvm.loop !12

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

78:                                               ; preds = %194, %77
  %79 = load i32, ptr %8, align 4, !tbaa !5
  %80 = load i32, ptr @n, align 4, !tbaa !5
  %81 = icmp sle i32 %79, %80
  br i1 %81, label %83, label %82

82:                                               ; preds = %78
  store i32 11, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  br label %197

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

84:                                               ; preds = %190, %83
  %85 = load i32, ptr %10, align 4, !tbaa !5
  %86 = load i32, ptr @n, align 4, !tbaa !5
  %87 = icmp sle i32 %85, %86
  br i1 %87, label %89, label %88

88:                                               ; preds = %84
  store i32 14, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #7
  br label %193

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

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

94:                                               ; preds = %90
  store i32 17, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #7
  br label %189

95:                                               ; preds = %90
  %96 = load i32, ptr %10, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = mul nsw i64 %97, %20
  %99 = getelementptr inbounds i32, ptr %23, i64 %98
  %100 = load i32, ptr %8, align 4, !tbaa !5
  %101 = sext i32 %100 to i64
  %102 = getelementptr inbounds i32, ptr %99, i64 %101
  %103 = load i32, ptr %102, align 4, !tbaa !5
  %104 = icmp sgt i32 %103, 0
  br i1 %104, label %105, label %185

105:                                              ; preds = %95
  %106 = load i32, ptr %8, align 4, !tbaa !5
  %107 = sext i32 %106 to i64
  %108 = mul nsw i64 %107, %20
  %109 = getelementptr inbounds i32, ptr %23, i64 %108
  %110 = load i32, ptr %11, align 4, !tbaa !5
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds i32, ptr %109, i64 %111
  %113 = load i32, ptr %112, align 4, !tbaa !5
  %114 = icmp sgt i32 %113, 0
  br i1 %114, label %115, label %185

115:                                              ; preds = %105
  %116 = load i32, ptr %10, align 4, !tbaa !5
  %117 = sext i32 %116 to i64
  %118 = mul nsw i64 %117, %20
  %119 = getelementptr inbounds i32, ptr %23, i64 %118
  %120 = load i32, ptr %11, align 4, !tbaa !5
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds i32, ptr %119, i64 %121
  %123 = load i32, ptr %122, align 4, !tbaa !5
  %124 = icmp eq i32 %123, 0
  br i1 %124, label %125, label %150

125:                                              ; preds = %115
  %126 = load i32, ptr %10, align 4, !tbaa !5
  %127 = sext i32 %126 to i64
  %128 = mul nsw i64 %127, %20
  %129 = getelementptr inbounds i32, ptr %23, i64 %128
  %130 = load i32, ptr %8, align 4, !tbaa !5
  %131 = sext i32 %130 to i64
  %132 = getelementptr inbounds i32, ptr %129, i64 %131
  %133 = load i32, ptr %132, align 4, !tbaa !5
  %134 = load i32, ptr %8, align 4, !tbaa !5
  %135 = sext i32 %134 to i64
  %136 = mul nsw i64 %135, %20
  %137 = getelementptr inbounds i32, ptr %23, i64 %136
  %138 = load i32, ptr %11, align 4, !tbaa !5
  %139 = sext i32 %138 to i64
  %140 = getelementptr inbounds i32, ptr %137, i64 %139
  %141 = load i32, ptr %140, align 4, !tbaa !5
  %142 = add nsw i32 %133, %141
  %143 = load i32, ptr %10, align 4, !tbaa !5
  %144 = sext i32 %143 to i64
  %145 = mul nsw i64 %144, %20
  %146 = getelementptr inbounds i32, ptr %23, i64 %145
  %147 = load i32, ptr %11, align 4, !tbaa !5
  %148 = sext i32 %147 to i64
  %149 = getelementptr inbounds i32, ptr %146, i64 %148
  store i32 %142, ptr %149, align 4, !tbaa !5
  br label %184

150:                                              ; preds = %115
  %151 = load i32, ptr %10, align 4, !tbaa !5
  %152 = sext i32 %151 to i64
  %153 = mul nsw i64 %152, %20
  %154 = getelementptr inbounds i32, ptr %23, i64 %153
  %155 = load i32, ptr %11, align 4, !tbaa !5
  %156 = sext i32 %155 to i64
  %157 = getelementptr inbounds i32, ptr %154, i64 %156
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #7
  %158 = load i32, ptr %10, align 4, !tbaa !5
  %159 = sext i32 %158 to i64
  %160 = mul nsw i64 %159, %20
  %161 = getelementptr inbounds i32, ptr %23, i64 %160
  %162 = load i32, ptr %8, align 4, !tbaa !5
  %163 = sext i32 %162 to i64
  %164 = getelementptr inbounds i32, ptr %161, i64 %163
  %165 = load i32, ptr %164, align 4, !tbaa !5
  %166 = load i32, ptr %8, align 4, !tbaa !5
  %167 = sext i32 %166 to i64
  %168 = mul nsw i64 %167, %20
  %169 = getelementptr inbounds i32, ptr %23, i64 %168
  %170 = load i32, ptr %11, align 4, !tbaa !5
  %171 = sext i32 %170 to i64
  %172 = getelementptr inbounds i32, ptr %169, i64 %171
  %173 = load i32, ptr %172, align 4, !tbaa !5
  %174 = add nsw i32 %165, %173
  store i32 %174, ptr %12, align 4, !tbaa !5
  %175 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %157, ptr noundef nonnull align 4 dereferenceable(4) %12)
  %176 = load i32, ptr %175, align 4, !tbaa !5
  %177 = load i32, ptr %10, align 4, !tbaa !5
  %178 = sext i32 %177 to i64
  %179 = mul nsw i64 %178, %20
  %180 = getelementptr inbounds i32, ptr %23, i64 %179
  %181 = load i32, ptr %11, align 4, !tbaa !5
  %182 = sext i32 %181 to i64
  %183 = getelementptr inbounds i32, ptr %180, i64 %182
  store i32 %176, ptr %183, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #7
  br label %184

184:                                              ; preds = %150, %125
  br label %185

185:                                              ; preds = %184, %105, %95
  br label %186

186:                                              ; preds = %185
  %187 = load i32, ptr %11, align 4, !tbaa !5
  %188 = add nsw i32 %187, 1
  store i32 %188, ptr %11, align 4, !tbaa !5
  br label %90, !llvm.loop !13

189:                                              ; preds = %94
  br label %190

190:                                              ; preds = %189
  %191 = load i32, ptr %10, align 4, !tbaa !5
  %192 = add nsw i32 %191, 1
  store i32 %192, ptr %10, align 4, !tbaa !5
  br label %84, !llvm.loop !14

193:                                              ; preds = %88
  br label %194

194:                                              ; preds = %193
  %195 = load i32, ptr %8, align 4, !tbaa !5
  %196 = add nsw i32 %195, 1
  store i32 %196, ptr %8, align 4, !tbaa !5
  br label %78, !llvm.loop !15

197:                                              ; preds = %82
  %198 = load i32, ptr @cities, align 16, !tbaa !5
  %199 = sext i32 %198 to i64
  %200 = getelementptr inbounds [100001 x i32], ptr @t, i64 0, i64 %199
  %201 = load i32, ptr %200, align 4, !tbaa !5
  store i32 %201, ptr @res, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #7
  store i32 1, ptr %13, align 4, !tbaa !5
  br label %202

202:                                              ; preds = %233, %197
  %203 = load i32, ptr %13, align 4, !tbaa !5
  %204 = load i32, ptr @m, align 4, !tbaa !5
  %205 = icmp slt i32 %203, %204
  br i1 %205, label %207, label %206

206:                                              ; preds = %202
  store i32 20, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #7
  br label %236

207:                                              ; preds = %202
  %208 = load i32, ptr %13, align 4, !tbaa !5
  %209 = sext i32 %208 to i64
  %210 = getelementptr inbounds [100001 x i32], ptr @cities, i64 0, i64 %209
  %211 = load i32, ptr %210, align 4, !tbaa !5
  %212 = sext i32 %211 to i64
  %213 = mul nsw i64 %212, %20
  %214 = getelementptr inbounds i32, ptr %23, i64 %213
  %215 = load i32, ptr %13, align 4, !tbaa !5
  %216 = sub nsw i32 %215, 1
  %217 = sext i32 %216 to i64
  %218 = getelementptr inbounds [100001 x i32], ptr @cities, i64 0, i64 %217
  %219 = load i32, ptr %218, align 4, !tbaa !5
  %220 = sext i32 %219 to i64
  %221 = getelementptr inbounds i32, ptr %214, i64 %220
  %222 = load i32, ptr %221, align 4, !tbaa !5
  %223 = load i32, ptr %13, align 4, !tbaa !5
  %224 = sext i32 %223 to i64
  %225 = getelementptr inbounds [100001 x i32], ptr @cities, i64 0, i64 %224
  %226 = load i32, ptr %225, align 4, !tbaa !5
  %227 = sext i32 %226 to i64
  %228 = getelementptr inbounds [100001 x i32], ptr @t, i64 0, i64 %227
  %229 = load i32, ptr %228, align 4, !tbaa !5
  %230 = add nsw i32 %222, %229
  %231 = load i32, ptr @res, align 4, !tbaa !5
  %232 = add nsw i32 %231, %230
  store i32 %232, ptr @res, align 4, !tbaa !5
  br label %233

233:                                              ; preds = %207
  %234 = load i32, ptr %13, align 4, !tbaa !5
  %235 = add nsw i32 %234, 1
  store i32 %235, ptr %13, align 4, !tbaa !5
  br label %202, !llvm.loop !16

236:                                              ; preds = %206
  %237 = load i32, ptr @res, align 4, !tbaa !5
  %238 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %237)
  %239 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %238, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  store i32 0, ptr %1, align 4
  store i32 1, ptr %9, align 4
  %240 = load ptr, ptr %2, align 8
  call void @llvm.stackrestore.p0(ptr %240)
  %241 = load i32, ptr %1, align 4
  ret i32 %241
}

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare ptr @llvm.stacksave.p0() #2

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

; 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 nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #4

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

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

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

; Function Attrs: nocallback nofree nosync nounwind willreturn
declare void @llvm.stackrestore.p0(ptr) #2

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

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

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

@n = external dso_local global i32, align 4
@m = external dso_local global i32, align 4
@t = external dso_local global [100001 x i32], align 16
@u = external dso_local global i32, align 4
@v = external dso_local global i32, align 4
@tim = external dso_local global i32, align 4
@cities = external dso_local global [100001 x i32], align 16
@res = external dso_local local_unnamed_addr global i32, align 4
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [7 x i8], align 1
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #0 {
  %1 = alloca i32, align 4
  %2 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @m)
  %3 = load i32, ptr @n, align 4, !tbaa !5
  %4 = add nsw i32 %3, 1
  %5 = zext i32 %4 to i64
  %6 = mul nuw i64 %5, %5
  %7 = alloca i32, i64 %6, align 16
  %.not55 = icmp slt i32 %3, 1
  br i1 %.not55, label %.preheader54, label %.lr.ph

.preheader54:                                     ; preds = %.lr.ph, %0
  %8 = load i32, ptr @m, align 4, !tbaa !5
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph58, label %.preheader52

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 1, %0 ]
  %10 = getelementptr inbounds [100001 x i32], ptr @t, i64 0, i64 %indvars.iv
  %11 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %10)
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = load i32, ptr @n, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %.not.not = icmp slt i64 %indvars.iv, %13
  br i1 %.not.not, label %.lr.ph, label %.preheader54, !llvm.loop !9

.preheader53:                                     ; preds = %.lr.ph58
  %14 = icmp sgt i32 %28, 0
  br i1 %14, label %.lr.ph60, label %.preheader52

.lr.ph58:                                         ; preds = %.preheader54, %.lr.ph58
  %.04457 = phi i32 [ %27, %.lr.ph58 ], [ 0, %.preheader54 ]
  %15 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.2, ptr noundef nonnull @u, ptr noundef nonnull @v, ptr noundef nonnull @tim)
  %16 = load i32, ptr @tim, align 4, !tbaa !5
  %17 = load i32, ptr @v, align 4, !tbaa !5
  %18 = sext i32 %17 to i64
  %19 = mul nsw i64 %18, %5
  %20 = getelementptr inbounds i32, ptr %7, i64 %19
  %21 = load i32, ptr @u, align 4, !tbaa !5
  %22 = sext i32 %21 to i64
  %23 = getelementptr inbounds i32, ptr %20, i64 %22
  store i32 %16, ptr %23, align 4, !tbaa !5
  %24 = mul nsw i64 %22, %5
  %25 = getelementptr inbounds i32, ptr %7, i64 %24
  %26 = getelementptr inbounds i32, ptr %25, i64 %18
  store i32 %16, ptr %26, align 4, !tbaa !5
  %27 = add nuw nsw i32 %.04457, 1
  %28 = load i32, ptr @m, align 4, !tbaa !5
  %29 = icmp slt i32 %27, %28
  br i1 %29, label %.lr.ph58, label %.preheader53, !llvm.loop !11

.preheader52:                                     ; preds = %.lr.ph60, %.preheader54, %.preheader53
  %30 = phi i32 [ %28, %.preheader53 ], [ %8, %.preheader54 ], [ %34, %.lr.ph60 ]
  %31 = load i32, ptr @n, align 4, !tbaa !5
  %.not4867 = icmp slt i32 %31, 1
  br i1 %.not4867, label %._crit_edge69, label %.preheader51

.lr.ph60:                                         ; preds = %.preheader53, %.lr.ph60
  %indvars.iv78 = phi i64 [ %indvars.iv.next79, %.lr.ph60 ], [ 0, %.preheader53 ]
  %32 = getelementptr inbounds [100001 x i32], ptr @cities, i64 0, i64 %indvars.iv78
  %33 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %32)
  %indvars.iv.next79 = add nuw nsw i64 %indvars.iv78, 1
  %34 = load i32, ptr @m, align 4, !tbaa !5
  %35 = sext i32 %34 to i64
  %36 = icmp slt i64 %indvars.iv.next79, %35
  br i1 %36, label %.lr.ph60, label %.preheader52, !llvm.loop !12

.preheader51:                                     ; preds = %.preheader52, %._crit_edge66
  %37 = phi i32 [ %55, %._crit_edge66 ], [ %31, %.preheader52 ]
  %indvars.iv87 = phi i64 [ %indvars.iv.next88, %._crit_edge66 ], [ 1, %.preheader52 ]
  %.not4964 = icmp slt i32 %37, 1
  br i1 %.not4964, label %._crit_edge66, label %.preheader.preheader

.preheader.preheader:                             ; preds = %.preheader51
  %38 = mul nuw nsw i64 %indvars.iv87, %5
  %39 = getelementptr inbounds i32, ptr %7, i64 %38
  br label %.preheader

._crit_edge69.loopexit76:                         ; preds = %._crit_edge66
  %.pre93 = load i32, ptr @m, align 4, !tbaa !5
  br label %._crit_edge69

._crit_edge69:                                    ; preds = %._crit_edge69.loopexit76, %.preheader52
  %40 = phi i32 [ %.pre93, %._crit_edge69.loopexit76 ], [ %30, %.preheader52 ]
  %41 = load i32, ptr @cities, align 16, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [100001 x i32], ptr @t, i64 0, i64 %42
  %44 = load i32, ptr %43, align 4, !tbaa !5
  store i32 %44, ptr @res, align 4, !tbaa !5
  %45 = icmp sgt i32 %40, 1
  br i1 %45, label %.lr.ph72.preheader, label %96

.lr.ph72.preheader:                               ; preds = %._crit_edge69
  %wide.trip.count = zext nneg i32 %40 to i64
  %46 = add nsw i64 %wide.trip.count, -1
  %xtraiter = and i64 %46, 1
  %47 = icmp eq i32 %40, 2
  br i1 %47, label %._crit_edge73.unr-lcssa, label %.lr.ph72.preheader.new

.lr.ph72.preheader.new:                           ; preds = %.lr.ph72.preheader
  %unroll_iter = and i64 %46, -2
  br label %.lr.ph72

.preheader:                                       ; preds = %.preheader.preheader, %._crit_edge
  %48 = phi i32 [ %37, %.preheader.preheader ], [ %57, %._crit_edge ]
  %49 = phi i32 [ %37, %.preheader.preheader ], [ %58, %._crit_edge ]
  %indvars.iv84 = phi i64 [ 1, %.preheader.preheader ], [ %indvars.iv.next85, %._crit_edge ]
  %.not5061 = icmp slt i32 %49, 1
  br i1 %.not5061, label %._crit_edge, label %.lr.ph63

.lr.ph63:                                         ; preds = %.preheader
  %50 = mul nuw nsw i64 %indvars.iv84, %5
  %51 = getelementptr inbounds i32, ptr %7, i64 %50
  %52 = getelementptr inbounds i32, ptr %51, i64 %indvars.iv87
  %53 = load i32, ptr %52, align 4, !tbaa !5
  %54 = icmp sgt i32 %53, 0
  br i1 %54, label %.lr.ph63.split, label %._crit_edge

._crit_edge66:                                    ; preds = %._crit_edge, %.preheader51
  %55 = phi i32 [ %37, %.preheader51 ], [ %57, %._crit_edge ]
  %indvars.iv.next88 = add nuw nsw i64 %indvars.iv87, 1
  %56 = sext i32 %55 to i64
  %.not48.not = icmp slt i64 %indvars.iv87, %56
  br i1 %.not48.not, label %.preheader51, label %._crit_edge69.loopexit76, !llvm.loop !13

._crit_edge:                                      ; preds = %79, %.lr.ph63, %.preheader
  %57 = phi i32 [ %48, %.preheader ], [ %48, %.lr.ph63 ], [ %80, %79 ]
  %58 = phi i32 [ %49, %.preheader ], [ %49, %.lr.ph63 ], [ %81, %79 ]
  %indvars.iv.next85 = add nuw nsw i64 %indvars.iv84, 1
  %59 = sext i32 %58 to i64
  %.not49.not = icmp slt i64 %indvars.iv84, %59
  br i1 %.not49.not, label %.preheader, label %._crit_edge66, !llvm.loop !15

.lr.ph63.splitthread-pre-split:                   ; preds = %79
  %indvars.iv.next82 = add nuw nsw i64 %indvars.iv81, 1
  %.pr = load i32, ptr %52, align 4, !tbaa !5
  br label %.lr.ph63.split

.lr.ph63.split:                                   ; preds = %.lr.ph63, %.lr.ph63.splitthread-pre-split
  %60 = phi i32 [ %.pr, %.lr.ph63.splitthread-pre-split ], [ %53, %.lr.ph63 ]
  %61 = phi i32 [ %80, %.lr.ph63.splitthread-pre-split ], [ %48, %.lr.ph63 ]
  %62 = phi i32 [ %81, %.lr.ph63.splitthread-pre-split ], [ %49, %.lr.ph63 ]
  %63 = phi i32 [ %82, %.lr.ph63.splitthread-pre-split ], [ %49, %.lr.ph63 ]
  %indvars.iv81 = phi i64 [ %indvars.iv.next82, %.lr.ph63.splitthread-pre-split ], [ 1, %.lr.ph63 ]
  %64 = icmp sgt i32 %60, 0
  br i1 %64, label %65, label %79

65:                                               ; preds = %.lr.ph63.split
  %66 = getelementptr inbounds i32, ptr %39, i64 %indvars.iv81
  %67 = load i32, ptr %66, align 4, !tbaa !5
  %68 = icmp sgt i32 %67, 0
  br i1 %68, label %69, label %79

69:                                               ; preds = %65
  %70 = getelementptr inbounds i32, ptr %51, i64 %indvars.iv81
  %71 = load i32, ptr %70, align 4, !tbaa !5
  %72 = icmp eq i32 %71, 0
  br i1 %72, label %73, label %75

73:                                               ; preds = %69
  %74 = add nuw nsw i32 %67, %60
  store i32 %74, ptr %70, align 4, !tbaa !5
  br label %79

75:                                               ; preds = %69
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #7
  %76 = add nuw nsw i32 %67, %60
  store i32 %76, ptr %1, align 4, !tbaa !5
  %77 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %70, ptr noundef nonnull align 4 dereferenceable(4) %1)
  %78 = load i32, ptr %77, align 4, !tbaa !5
  store i32 %78, ptr %70, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #7
  %.pre = load i32, ptr @n, align 4, !tbaa !5
  br label %79

79:                                               ; preds = %.lr.ph63.split, %65, %75, %73
  %80 = phi i32 [ %61, %.lr.ph63.split ], [ %61, %65 ], [ %.pre, %75 ], [ %61, %73 ]
  %81 = phi i32 [ %62, %.lr.ph63.split ], [ %62, %65 ], [ %.pre, %75 ], [ %62, %73 ]
  %82 = phi i32 [ %63, %.lr.ph63.split ], [ %63, %65 ], [ %.pre, %75 ], [ %63, %73 ]
  %83 = sext i32 %82 to i64
  %.not50.not = icmp slt i64 %indvars.iv81, %83
  br i1 %.not50.not, label %.lr.ph63.splitthread-pre-split, label %._crit_edge, !llvm.loop !16

._crit_edge73.unr-lcssa:                          ; preds = %.lr.ph72, %.lr.ph72.preheader
  %.lcssa.ph = phi i32 [ poison, %.lr.ph72.preheader ], [ %125, %.lr.ph72 ]
  %.unr = phi i32 [ %41, %.lr.ph72.preheader ], [ %115, %.lr.ph72 ]
  %indvars.iv90.unr = phi i64 [ 1, %.lr.ph72.preheader ], [ %indvars.iv.next91.1, %.lr.ph72 ]
  %.unr109 = phi i32 [ %44, %.lr.ph72.preheader ], [ %125, %.lr.ph72 ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %._crit_edge73, label %.lr.ph72.epil

.lr.ph72.epil:                                    ; preds = %._crit_edge73.unr-lcssa
  %84 = getelementptr inbounds [100001 x i32], ptr @cities, i64 0, i64 %indvars.iv90.unr
  %85 = load i32, ptr %84, align 4, !tbaa !5
  %86 = sext i32 %85 to i64
  %87 = mul nsw i64 %86, %5
  %88 = getelementptr inbounds i32, ptr %7, i64 %87
  %89 = sext i32 %.unr to i64
  %90 = getelementptr inbounds i32, ptr %88, i64 %89
  %91 = load i32, ptr %90, align 4, !tbaa !5
  %92 = getelementptr inbounds [100001 x i32], ptr @t, i64 0, i64 %86
  %93 = load i32, ptr %92, align 4, !tbaa !5
  %94 = add nsw i32 %93, %91
  %95 = add nsw i32 %94, %.unr109
  br label %._crit_edge73

._crit_edge73:                                    ; preds = %._crit_edge73.unr-lcssa, %.lr.ph72.epil
  %.lcssa = phi i32 [ %.lcssa.ph, %._crit_edge73.unr-lcssa ], [ %95, %.lr.ph72.epil ]
  store i32 %.lcssa, ptr @res, align 4, !tbaa !5
  br label %96

96:                                               ; preds = %._crit_edge73, %._crit_edge69
  %97 = phi i32 [ %.lcssa, %._crit_edge73 ], [ %44, %._crit_edge69 ]
  %98 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %97)
  %99 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %98, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0

.lr.ph72:                                         ; preds = %.lr.ph72, %.lr.ph72.preheader.new
  %100 = phi i32 [ %41, %.lr.ph72.preheader.new ], [ %115, %.lr.ph72 ]
  %indvars.iv90 = phi i64 [ 1, %.lr.ph72.preheader.new ], [ %indvars.iv.next91.1, %.lr.ph72 ]
  %101 = phi i32 [ %44, %.lr.ph72.preheader.new ], [ %125, %.lr.ph72 ]
  %niter = phi i64 [ 0, %.lr.ph72.preheader.new ], [ %niter.next.1, %.lr.ph72 ]
  %102 = getelementptr inbounds [100001 x i32], ptr @cities, i64 0, i64 %indvars.iv90
  %103 = load i32, ptr %102, align 4, !tbaa !5
  %104 = sext i32 %103 to i64
  %105 = mul nsw i64 %104, %5
  %106 = getelementptr inbounds i32, ptr %7, i64 %105
  %107 = sext i32 %100 to i64
  %108 = getelementptr inbounds i32, ptr %106, i64 %107
  %109 = load i32, ptr %108, align 4, !tbaa !5
  %110 = getelementptr inbounds [100001 x i32], ptr @t, i64 0, i64 %104
  %111 = load i32, ptr %110, align 4, !tbaa !5
  %112 = add nsw i32 %111, %109
  %113 = add nsw i32 %112, %101
  %indvars.iv.next91 = add nuw nsw i64 %indvars.iv90, 1
  %114 = getelementptr inbounds [100001 x i32], ptr @cities, i64 0, i64 %indvars.iv.next91
  %115 = load i32, ptr %114, align 4, !tbaa !5
  %116 = sext i32 %115 to i64
  %117 = mul nsw i64 %116, %5
  %118 = getelementptr inbounds i32, ptr %7, i64 %117
  %119 = sext i32 %103 to i64
  %120 = getelementptr inbounds i32, ptr %118, i64 %119
  %121 = load i32, ptr %120, align 4, !tbaa !5
  %122 = getelementptr inbounds [100001 x i32], ptr @t, i64 0, i64 %116
  %123 = load i32, ptr %122, align 4, !tbaa !5
  %124 = add nsw i32 %123, %121
  %125 = add nsw i32 %124, %113
  %indvars.iv.next91.1 = add nuw nsw i64 %indvars.iv90, 2
  %niter.next.1 = add i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %._crit_edge73.unr-lcssa, label %.lr.ph72, !llvm.loop !17
}

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

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

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3minIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) 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 #4

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

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

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

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

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


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