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

; 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
@d = external dso_local global i32, align 4
@last = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@dp = external dso_local global [30002 x [500 x i32]], align 16
@gem = external dso_local global [30002 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 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 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 i32, align 4
  %9 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %10 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str, ptr noundef @n, ptr noundef @d)
  call void @llvm.memset.p0.i64(ptr align 16 @dp, i8 -1, i64 60004000, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #7
  store i32 1, ptr %2, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #7
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %25, %0
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = load i32, ptr @n, align 4, !tbaa !5
  %14 = icmp sle i32 %12, %13
  br i1 %14, label %16, label %15

15:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #7
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #7
  br label %28

16:                                               ; preds = %11
  %17 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef %3)
  %18 = load i32, ptr %3, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [30002 x i32], ptr @gem, i64 0, i64 %19
  %21 = load i32, ptr %20, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %20, align 4, !tbaa !5
  %23 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @last, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %24 = load i32, ptr %23, align 4, !tbaa !5
  store i32 %24, ptr @last, align 4, !tbaa !5
  br label %25

25:                                               ; preds = %16
  %26 = load i32, ptr %2, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %2, align 4, !tbaa !5
  br label %11, !llvm.loop !9

28:                                               ; preds = %15
  %29 = load i32, ptr @d, align 4, !tbaa !5
  %30 = sext i32 %29 to i64
  %31 = getelementptr inbounds [30002 x i32], ptr @gem, i64 0, i64 %30
  %32 = load i32, ptr %31, align 4, !tbaa !5
  %33 = load i32, ptr @d, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %34
  %36 = getelementptr inbounds [500 x i32], ptr %35, i64 0, i64 250
  store i32 %32, ptr %36, align 8, !tbaa !5
  store i32 %32, ptr @ans, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #7
  %37 = load i32, ptr @d, align 4, !tbaa !5
  store i32 %37, ptr %4, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %236, %28
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = load i32, ptr @last, align 4, !tbaa !5
  %41 = icmp sle i32 %39, %40
  br i1 %41, label %43, label %42

42:                                               ; preds = %38
  store i32 5, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #7
  br label %239

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

44:                                               ; preds = %232, %43
  %45 = load i32, ptr %6, align 4, !tbaa !5
  %46 = icmp sle i32 %45, 499
  br i1 %46, label %48, label %47

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

48:                                               ; preds = %44
  %49 = load i32, ptr %4, align 4, !tbaa !5
  %50 = sext i32 %49 to i64
  %51 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %50
  %52 = load i32, ptr %6, align 4, !tbaa !5
  %53 = sext i32 %52 to i64
  %54 = getelementptr inbounds [500 x i32], ptr %51, i64 0, i64 %53
  %55 = load i32, ptr %54, align 4, !tbaa !5
  %56 = icmp sge i32 %55, 0
  br i1 %56, label %57, label %231

57:                                               ; preds = %48
  %58 = load i32, ptr %4, align 4, !tbaa !5
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %59
  %61 = load i32, ptr %6, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [500 x i32], ptr %60, i64 0, i64 %62
  %64 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @ans, ptr noundef nonnull align 4 dereferenceable(4) %63)
  %65 = load i32, ptr %64, align 4, !tbaa !5
  store i32 %65, ptr @ans, align 4, !tbaa !5
  %66 = load i32, ptr %4, align 4, !tbaa !5
  %67 = load i32, ptr @d, align 4, !tbaa !5
  %68 = add nsw i32 %66, %67
  %69 = sub nsw i32 %68, 1
  %70 = load i32, ptr %6, align 4, !tbaa !5
  %71 = add nsw i32 %69, %70
  %72 = sub nsw i32 %71, 250
  %73 = load i32, ptr @last, align 4, !tbaa !5
  %74 = icmp sle i32 %72, %73
  br i1 %74, label %75, label %122

75:                                               ; preds = %57
  %76 = load i32, ptr %4, align 4, !tbaa !5
  %77 = load i32, ptr @d, align 4, !tbaa !5
  %78 = add nsw i32 %76, %77
  %79 = load i32, ptr %6, align 4, !tbaa !5
  %80 = add nsw i32 %78, %79
  %81 = sub nsw i32 %80, 250
  %82 = sub nsw i32 %81, 1
  %83 = sext i32 %82 to i64
  %84 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %83
  %85 = load i32, ptr %6, align 4, !tbaa !5
  %86 = sub nsw i32 %85, 1
  %87 = sext i32 %86 to i64
  %88 = getelementptr inbounds [500 x i32], ptr %84, i64 0, i64 %87
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  %89 = load i32, ptr %4, align 4, !tbaa !5
  %90 = sext i32 %89 to i64
  %91 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %90
  %92 = load i32, ptr %6, align 4, !tbaa !5
  %93 = sext i32 %92 to i64
  %94 = getelementptr inbounds [500 x i32], ptr %91, i64 0, i64 %93
  %95 = load i32, ptr %94, align 4, !tbaa !5
  %96 = load i32, ptr %4, align 4, !tbaa !5
  %97 = load i32, ptr @d, align 4, !tbaa !5
  %98 = add nsw i32 %96, %97
  %99 = load i32, ptr %6, align 4, !tbaa !5
  %100 = add nsw i32 %98, %99
  %101 = sub nsw i32 %100, 250
  %102 = sub nsw i32 %101, 1
  %103 = sext i32 %102 to i64
  %104 = getelementptr inbounds [30002 x i32], ptr @gem, i64 0, i64 %103
  %105 = load i32, ptr %104, align 4, !tbaa !5
  %106 = add nsw i32 %95, %105
  store i32 %106, ptr %7, align 4, !tbaa !5
  %107 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %88, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %108 = load i32, ptr %107, align 4, !tbaa !5
  %109 = load i32, ptr %4, align 4, !tbaa !5
  %110 = load i32, ptr @d, align 4, !tbaa !5
  %111 = add nsw i32 %109, %110
  %112 = load i32, ptr %6, align 4, !tbaa !5
  %113 = add nsw i32 %111, %112
  %114 = sub nsw i32 %113, 250
  %115 = sub nsw i32 %114, 1
  %116 = sext i32 %115 to i64
  %117 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %116
  %118 = load i32, ptr %6, align 4, !tbaa !5
  %119 = sub nsw i32 %118, 1
  %120 = sext i32 %119 to i64
  %121 = getelementptr inbounds [500 x i32], ptr %117, i64 0, i64 %120
  store i32 %108, ptr %121, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  br label %122

122:                                              ; preds = %75, %57
  %123 = load i32, ptr %4, align 4, !tbaa !5
  %124 = load i32, ptr @d, align 4, !tbaa !5
  %125 = add nsw i32 %123, %124
  %126 = load i32, ptr %6, align 4, !tbaa !5
  %127 = add nsw i32 %125, %126
  %128 = sub nsw i32 %127, 250
  %129 = load i32, ptr @last, align 4, !tbaa !5
  %130 = icmp sle i32 %128, %129
  br i1 %130, label %131, label %173

131:                                              ; preds = %122
  %132 = load i32, ptr %4, align 4, !tbaa !5
  %133 = load i32, ptr @d, align 4, !tbaa !5
  %134 = add nsw i32 %132, %133
  %135 = load i32, ptr %6, align 4, !tbaa !5
  %136 = add nsw i32 %134, %135
  %137 = sub nsw i32 %136, 250
  %138 = sext i32 %137 to i64
  %139 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %138
  %140 = load i32, ptr %6, align 4, !tbaa !5
  %141 = sext i32 %140 to i64
  %142 = getelementptr inbounds [500 x i32], ptr %139, i64 0, i64 %141
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  %143 = load i32, ptr %4, align 4, !tbaa !5
  %144 = sext i32 %143 to i64
  %145 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %144
  %146 = load i32, ptr %6, align 4, !tbaa !5
  %147 = sext i32 %146 to i64
  %148 = getelementptr inbounds [500 x i32], ptr %145, i64 0, i64 %147
  %149 = load i32, ptr %148, align 4, !tbaa !5
  %150 = load i32, ptr %4, align 4, !tbaa !5
  %151 = load i32, ptr @d, align 4, !tbaa !5
  %152 = add nsw i32 %150, %151
  %153 = load i32, ptr %6, align 4, !tbaa !5
  %154 = add nsw i32 %152, %153
  %155 = sub nsw i32 %154, 250
  %156 = sext i32 %155 to i64
  %157 = getelementptr inbounds [30002 x i32], ptr @gem, i64 0, i64 %156
  %158 = load i32, ptr %157, align 4, !tbaa !5
  %159 = add nsw i32 %149, %158
  store i32 %159, ptr %8, align 4, !tbaa !5
  %160 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %142, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %161 = load i32, ptr %160, align 4, !tbaa !5
  %162 = load i32, ptr %4, align 4, !tbaa !5
  %163 = load i32, ptr @d, align 4, !tbaa !5
  %164 = add nsw i32 %162, %163
  %165 = load i32, ptr %6, align 4, !tbaa !5
  %166 = add nsw i32 %164, %165
  %167 = sub nsw i32 %166, 250
  %168 = sext i32 %167 to i64
  %169 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %168
  %170 = load i32, ptr %6, align 4, !tbaa !5
  %171 = sext i32 %170 to i64
  %172 = getelementptr inbounds [500 x i32], ptr %169, i64 0, i64 %171
  store i32 %161, ptr %172, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  br label %173

173:                                              ; preds = %131, %122
  %174 = load i32, ptr %4, align 4, !tbaa !5
  %175 = load i32, ptr @d, align 4, !tbaa !5
  %176 = add nsw i32 %174, %175
  %177 = load i32, ptr %6, align 4, !tbaa !5
  %178 = add nsw i32 %176, %177
  %179 = sub nsw i32 %178, 250
  %180 = add nsw i32 %179, 1
  %181 = load i32, ptr @last, align 4, !tbaa !5
  %182 = icmp sle i32 %180, %181
  br i1 %182, label %183, label %230

183:                                              ; preds = %173
  %184 = load i32, ptr %4, align 4, !tbaa !5
  %185 = load i32, ptr @d, align 4, !tbaa !5
  %186 = add nsw i32 %184, %185
  %187 = load i32, ptr %6, align 4, !tbaa !5
  %188 = add nsw i32 %186, %187
  %189 = sub nsw i32 %188, 250
  %190 = add nsw i32 %189, 1
  %191 = sext i32 %190 to i64
  %192 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %191
  %193 = load i32, ptr %6, align 4, !tbaa !5
  %194 = add nsw i32 %193, 1
  %195 = sext i32 %194 to i64
  %196 = getelementptr inbounds [500 x i32], ptr %192, i64 0, i64 %195
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #7
  %197 = load i32, ptr %4, align 4, !tbaa !5
  %198 = sext i32 %197 to i64
  %199 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %198
  %200 = load i32, ptr %6, align 4, !tbaa !5
  %201 = sext i32 %200 to i64
  %202 = getelementptr inbounds [500 x i32], ptr %199, i64 0, i64 %201
  %203 = load i32, ptr %202, align 4, !tbaa !5
  %204 = load i32, ptr %4, align 4, !tbaa !5
  %205 = load i32, ptr @d, align 4, !tbaa !5
  %206 = add nsw i32 %204, %205
  %207 = load i32, ptr %6, align 4, !tbaa !5
  %208 = add nsw i32 %206, %207
  %209 = sub nsw i32 %208, 250
  %210 = add nsw i32 %209, 1
  %211 = sext i32 %210 to i64
  %212 = getelementptr inbounds [30002 x i32], ptr @gem, i64 0, i64 %211
  %213 = load i32, ptr %212, align 4, !tbaa !5
  %214 = add nsw i32 %203, %213
  store i32 %214, ptr %9, align 4, !tbaa !5
  %215 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %196, ptr noundef nonnull align 4 dereferenceable(4) %9)
  %216 = load i32, ptr %215, align 4, !tbaa !5
  %217 = load i32, ptr %4, align 4, !tbaa !5
  %218 = load i32, ptr @d, align 4, !tbaa !5
  %219 = add nsw i32 %217, %218
  %220 = load i32, ptr %6, align 4, !tbaa !5
  %221 = add nsw i32 %219, %220
  %222 = sub nsw i32 %221, 250
  %223 = add nsw i32 %222, 1
  %224 = sext i32 %223 to i64
  %225 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %224
  %226 = load i32, ptr %6, align 4, !tbaa !5
  %227 = add nsw i32 %226, 1
  %228 = sext i32 %227 to i64
  %229 = getelementptr inbounds [500 x i32], ptr %225, i64 0, i64 %228
  store i32 %216, ptr %229, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #7
  br label %230

230:                                              ; preds = %183, %173
  br label %231

231:                                              ; preds = %230, %48
  br label %232

232:                                              ; preds = %231
  %233 = load i32, ptr %6, align 4, !tbaa !5
  %234 = add nsw i32 %233, 1
  store i32 %234, ptr %6, align 4, !tbaa !5
  br label %44, !llvm.loop !11

235:                                              ; preds = %47
  br label %236

236:                                              ; preds = %235
  %237 = load i32, ptr %4, align 4, !tbaa !5
  %238 = add nsw i32 %237, 1
  store i32 %238, ptr %4, align 4, !tbaa !5
  br label %38, !llvm.loop !12

239:                                              ; preds = %42
  %240 = load i32, ptr @ans, align 4, !tbaa !5
  %241 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %240)
  %242 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %241, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0
}

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

; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4), ptr noundef nonnull align 4 dereferenceable(4)) #4

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

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

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 nounwind willreturn memory(argmem: write) }
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}


; 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
@d = external dso_local global i32, align 4
@last = external dso_local global i32, align 4
@ans = external dso_local global i32, align 4
@dp = external dso_local global [30002 x [500 x i32]], align 16
@gem = external dso_local local_unnamed_addr global [30002 x i32], align 16
@.str = external hidden unnamed_addr constant [5 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [3 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 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @d)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(60004000) @dp, i8 -1, i64 60004000, i1 false)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #8
  store i32 0, ptr %1, align 4, !tbaa !5
  %6 = load i32, ptr @n, align 4, !tbaa !5
  %.not54 = icmp slt i32 %6, 1
  br i1 %.not54, label %.._crit_edge_crit_edge, label %.lr.ph

.._crit_edge_crit_edge:                           ; preds = %0
  %.pre = load i32, ptr @last, align 4, !tbaa !5
  br label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %.._crit_edge_crit_edge
  %7 = phi i32 [ %.pre, %.._crit_edge_crit_edge ], [ %20, %.lr.ph ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #8
  %8 = load i32, ptr @d, align 4, !tbaa !5
  %9 = sext i32 %8 to i64
  %10 = getelementptr inbounds [30002 x i32], ptr @gem, i64 0, i64 %9
  %11 = load i32, ptr %10, align 4, !tbaa !5
  %12 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %9, i64 250
  store i32 %11, ptr %12, align 8, !tbaa !5
  store i32 %11, ptr @ans, align 4, !tbaa !5
  %.not5057 = icmp sgt i32 %8, %7
  br i1 %.not5057, label %._crit_edge59, label %.preheader

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.04755 = phi i32 [ %21, %.lr.ph ], [ 1, %0 ]
  %13 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull %1)
  %14 = load i32, ptr %1, align 4, !tbaa !5
  %15 = sext i32 %14 to i64
  %16 = getelementptr inbounds [30002 x i32], ptr @gem, i64 0, i64 %15
  %17 = load i32, ptr %16, align 4, !tbaa !5
  %18 = add nsw i32 %17, 1
  store i32 %18, ptr %16, align 4, !tbaa !5
  %19 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @last, ptr noundef nonnull align 4 dereferenceable(4) %1)
  %20 = load i32, ptr %19, align 4, !tbaa !5
  store i32 %20, ptr @last, align 4, !tbaa !5
  %21 = add nuw nsw i32 %.04755, 1
  %22 = load i32, ptr @n, align 4, !tbaa !5
  %.not.not = icmp slt i32 %.04755, %22
  br i1 %.not.not, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.preheader:                                       ; preds = %._crit_edge, %30
  %indvars.iv61 = phi i64 [ %indvars.iv.next62, %30 ], [ %9, %._crit_edge ]
  %23 = trunc nsw i64 %indvars.iv61 to i32
  %24 = add i32 %23, -251
  %25 = add i32 %23, -250
  %26 = add i32 %23, -249
  br label %33

._crit_edge59.loopexit:                           ; preds = %30
  %.pre66 = load i32, ptr @ans, align 4, !tbaa !5
  br label %._crit_edge59

._crit_edge59:                                    ; preds = %._crit_edge59.loopexit, %._crit_edge
  %27 = phi i32 [ %.pre66, %._crit_edge59.loopexit ], [ %11, %._crit_edge ]
  %28 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %27)
  %29 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %28, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0

30:                                               ; preds = %100
  %indvars.iv.next62 = add nsw i64 %indvars.iv61, 1
  %31 = load i32, ptr @last, align 4, !tbaa !5
  %32 = sext i32 %31 to i64
  %.not50.not = icmp slt i64 %indvars.iv61, %32
  br i1 %.not50.not, label %.preheader, label %._crit_edge59.loopexit, !llvm.loop !11

33:                                               ; preds = %.preheader, %100
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %100 ]
  %indvars60 = trunc i64 %indvars.iv to i32
  %34 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %indvars.iv61, i64 %indvars.iv
  %35 = load i32, ptr %34, align 4, !tbaa !5
  %36 = icmp sgt i32 %35, -1
  br i1 %36, label %37, label %100

37:                                               ; preds = %33
  %38 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @ans, ptr noundef nonnull align 4 dereferenceable(4) %34)
  %39 = load i32, ptr %38, align 4, !tbaa !5
  store i32 %39, ptr @ans, align 4, !tbaa !5
  %40 = load i32, ptr @d, align 4, !tbaa !5
  %41 = add nsw i32 %40, %23
  %42 = add nsw i32 %indvars60, -251
  %43 = add i32 %42, %41
  %44 = load i32, ptr @last, align 4, !tbaa !5
  %.not51 = icmp sgt i32 %43, %44
  br i1 %.not51, label %63, label %45

45:                                               ; preds = %37
  %46 = trunc i64 %indvars.iv to i32
  %47 = add i32 %46, -251
  %48 = add i32 %47, %41
  %49 = sext i32 %48 to i64
  %50 = add nsw i64 %indvars.iv, -1
  %51 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %49, i64 %50
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #8
  %52 = load i32, ptr %34, align 4, !tbaa !5
  %53 = getelementptr inbounds [30002 x i32], ptr @gem, i64 0, i64 %49
  %54 = load i32, ptr %53, align 4, !tbaa !5
  %55 = add nsw i32 %54, %52
  store i32 %55, ptr %2, align 4, !tbaa !5
  %56 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %51, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %57 = load i32, ptr %56, align 4, !tbaa !5
  %58 = load i32, ptr @d, align 4, !tbaa !5
  %59 = add i32 %24, %indvars60
  %60 = add i32 %59, %58
  %61 = sext i32 %60 to i64
  %62 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %61, i64 %50
  store i32 %57, ptr %62, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #8
  %.pre64 = load i32, ptr @last, align 4, !tbaa !5
  br label %63

63:                                               ; preds = %45, %37
  %64 = phi i32 [ %.pre64, %45 ], [ %44, %37 ]
  %65 = phi i32 [ %58, %45 ], [ %40, %37 ]
  %66 = add i32 %25, %indvars60
  %67 = add i32 %66, %65
  %.not52 = icmp sgt i32 %67, %64
  br i1 %.not52, label %81, label %68

68:                                               ; preds = %63
  %69 = sext i32 %67 to i64
  %70 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %69, i64 %indvars.iv
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %3) #8
  %71 = load i32, ptr %34, align 4, !tbaa !5
  %72 = getelementptr inbounds [30002 x i32], ptr @gem, i64 0, i64 %69
  %73 = load i32, ptr %72, align 4, !tbaa !5
  %74 = add nsw i32 %73, %71
  store i32 %74, ptr %3, align 4, !tbaa !5
  %75 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %70, ptr noundef nonnull align 4 dereferenceable(4) %3)
  %76 = load i32, ptr %75, align 4, !tbaa !5
  %77 = load i32, ptr @d, align 4, !tbaa !5
  %78 = add i32 %66, %77
  %79 = sext i32 %78 to i64
  %80 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %79, i64 %indvars.iv
  store i32 %76, ptr %80, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %3) #8
  %.pre65 = load i32, ptr @last, align 4, !tbaa !5
  br label %81

81:                                               ; preds = %68, %63
  %82 = phi i32 [ %.pre65, %68 ], [ %64, %63 ]
  %83 = phi i32 [ %77, %68 ], [ %65, %63 ]
  %84 = add i32 %26, %indvars60
  %85 = add i32 %84, %83
  %.not53 = icmp sgt i32 %85, %82
  br i1 %.not53, label %100, label %86

86:                                               ; preds = %81
  %87 = sext i32 %85 to i64
  %88 = add nuw nsw i64 %indvars.iv, 1
  %89 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %87, i64 %88
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %4) #8
  %90 = load i32, ptr %34, align 4, !tbaa !5
  %91 = getelementptr inbounds [30002 x i32], ptr @gem, i64 0, i64 %87
  %92 = load i32, ptr %91, align 4, !tbaa !5
  %93 = add nsw i32 %92, %90
  store i32 %93, ptr %4, align 4, !tbaa !5
  %94 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %89, ptr noundef nonnull align 4 dereferenceable(4) %4)
  %95 = load i32, ptr %94, align 4, !tbaa !5
  %96 = load i32, ptr @d, align 4, !tbaa !5
  %97 = add i32 %84, %96
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %98, i64 %88
  store i32 %95, ptr %99, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %4) #8
  br label %100

100:                                              ; preds = %33, %86, %81
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 500
  br i1 %exitcond.not, label %30, label %33, !llvm.loop !12
}

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

; Function Attrs: mustprogress nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p0.i64(ptr nocapture writeonly, i8, i64, i1 immarg) #2

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

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

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

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

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

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

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

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


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