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

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

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

14:                                               ; preds = %10
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #7
  br label %32

15:                                               ; preds = %10
  %16 = call i32 (ptr, ...) @__isoc99_scanf(ptr noundef @.str.1, ptr noundef @p)
  %17 = load i32, ptr @p, align 4, !tbaa !5
  %18 = load i32, ptr @d, align 4, !tbaa !5
  %19 = icmp sge i32 %17, %18
  br i1 %19, label %20, label %28

20:                                               ; preds = %15
  %21 = 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) @p)
  %22 = load i32, ptr %21, align 4, !tbaa !5
  store i32 %22, ptr @last, align 4, !tbaa !5
  %23 = load i32, ptr @p, align 4, !tbaa !5
  %24 = sext i32 %23 to i64
  %25 = getelementptr inbounds [30002 x i32], ptr @gems, i64 0, i64 %24
  %26 = load i32, ptr %25, align 4, !tbaa !5
  %27 = add nsw i32 %26, 1
  store i32 %27, ptr %25, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %20, %15
  br label %29

29:                                               ; preds = %28
  %30 = load i32, ptr %2, align 4, !tbaa !5
  %31 = add nsw i32 %30, 1
  store i32 %31, ptr %2, align 4, !tbaa !5
  br label %10, !llvm.loop !9

32:                                               ; preds = %14
  %33 = load i32, ptr @d, align 4, !tbaa !5
  %34 = sext i32 %33 to i64
  %35 = getelementptr inbounds [30002 x i32], ptr @gems, i64 0, i64 %34
  %36 = load i32, ptr %35, align 4, !tbaa !5
  %37 = load i32, ptr @d, align 4, !tbaa !5
  %38 = sext i32 %37 to i64
  %39 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %38
  %40 = getelementptr inbounds [500 x i32], ptr %39, i64 0, i64 250
  store i32 %36, ptr %40, align 8, !tbaa !5
  store i32 %36, ptr @res, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #7
  %41 = load i32, ptr @d, align 4, !tbaa !5
  store i32 %41, ptr %3, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %247, %32
  %43 = load i32, ptr %3, align 4, !tbaa !5
  %44 = load i32, ptr @last, align 4, !tbaa !5
  %45 = icmp sle i32 %43, %44
  br i1 %45, label %47, label %46

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

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

48:                                               ; preds = %243, %47
  %49 = load i32, ptr %5, align 4, !tbaa !5
  %50 = icmp sle i32 %49, 500
  br i1 %50, label %52, label %51

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

52:                                               ; preds = %48
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %54
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = sext i32 %56 to i64
  %58 = getelementptr inbounds [500 x i32], ptr %55, i64 0, i64 %57
  %59 = load i32, ptr %58, align 4, !tbaa !5
  %60 = icmp sge i32 %59, 0
  br i1 %60, label %61, label %242

61:                                               ; preds = %52
  %62 = load i32, ptr %3, align 4, !tbaa !5
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %63
  %65 = load i32, ptr %5, align 4, !tbaa !5
  %66 = sext i32 %65 to i64
  %67 = getelementptr inbounds [500 x i32], ptr %64, i64 0, i64 %66
  %68 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @res, ptr noundef nonnull align 4 dereferenceable(4) %67)
  %69 = load i32, ptr %68, align 4, !tbaa !5
  store i32 %69, ptr @res, align 4, !tbaa !5
  %70 = load i32, ptr @d, align 4, !tbaa !5
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = add nsw i32 %70, %71
  %73 = sub nsw i32 %72, 250
  %74 = sub nsw i32 %73, 1
  %75 = icmp sgt i32 %74, 0
  br i1 %75, label %76, label %133

76:                                               ; preds = %61
  %77 = load i32, ptr %3, align 4, !tbaa !5
  %78 = load i32, ptr @d, align 4, !tbaa !5
  %79 = add nsw i32 %77, %78
  %80 = load i32, ptr %5, align 4, !tbaa !5
  %81 = add nsw i32 %79, %80
  %82 = sub nsw i32 %81, 250
  %83 = sub nsw i32 %82, 1
  %84 = load i32, ptr @last, align 4, !tbaa !5
  %85 = icmp sle i32 %83, %84
  br i1 %85, label %86, label %133

86:                                               ; preds = %76
  %87 = load i32, ptr %3, align 4, !tbaa !5
  %88 = load i32, ptr @d, align 4, !tbaa !5
  %89 = add nsw i32 %87, %88
  %90 = load i32, ptr %5, align 4, !tbaa !5
  %91 = add nsw i32 %89, %90
  %92 = sub nsw i32 %91, 250
  %93 = sub nsw i32 %92, 1
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %94
  %96 = load i32, ptr %5, align 4, !tbaa !5
  %97 = sub nsw i32 %96, 1
  %98 = sext i32 %97 to i64
  %99 = getelementptr inbounds [500 x i32], ptr %95, i64 0, i64 %98
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #7
  %100 = load i32, ptr %3, align 4, !tbaa !5
  %101 = load i32, ptr @d, align 4, !tbaa !5
  %102 = add nsw i32 %100, %101
  %103 = load i32, ptr %5, align 4, !tbaa !5
  %104 = add nsw i32 %102, %103
  %105 = sub nsw i32 %104, 250
  %106 = sub nsw i32 %105, 1
  %107 = sext i32 %106 to i64
  %108 = getelementptr inbounds [30002 x i32], ptr @gems, i64 0, i64 %107
  %109 = load i32, ptr %108, align 4, !tbaa !5
  %110 = load i32, ptr %3, align 4, !tbaa !5
  %111 = sext i32 %110 to i64
  %112 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %111
  %113 = load i32, ptr %5, align 4, !tbaa !5
  %114 = sext i32 %113 to i64
  %115 = getelementptr inbounds [500 x i32], ptr %112, i64 0, i64 %114
  %116 = load i32, ptr %115, align 4, !tbaa !5
  %117 = add nsw i32 %109, %116
  store i32 %117, ptr %6, align 4, !tbaa !5
  %118 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %99, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %119 = load i32, ptr %118, align 4, !tbaa !5
  %120 = load i32, ptr %3, align 4, !tbaa !5
  %121 = load i32, ptr @d, align 4, !tbaa !5
  %122 = add nsw i32 %120, %121
  %123 = load i32, ptr %5, align 4, !tbaa !5
  %124 = add nsw i32 %122, %123
  %125 = sub nsw i32 %124, 250
  %126 = sub nsw i32 %125, 1
  %127 = sext i32 %126 to i64
  %128 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %127
  %129 = load i32, ptr %5, align 4, !tbaa !5
  %130 = sub nsw i32 %129, 1
  %131 = sext i32 %130 to i64
  %132 = getelementptr inbounds [500 x i32], ptr %128, i64 0, i64 %131
  store i32 %119, ptr %132, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #7
  br label %133

133:                                              ; preds = %86, %76, %61
  %134 = load i32, ptr %3, align 4, !tbaa !5
  %135 = load i32, ptr @d, align 4, !tbaa !5
  %136 = add nsw i32 %134, %135
  %137 = load i32, ptr %5, align 4, !tbaa !5
  %138 = add nsw i32 %136, %137
  %139 = sub nsw i32 %138, 250
  %140 = load i32, ptr @last, align 4, !tbaa !5
  %141 = icmp sle i32 %139, %140
  br i1 %141, label %142, label %184

142:                                              ; preds = %133
  %143 = load i32, ptr %3, align 4, !tbaa !5
  %144 = load i32, ptr @d, align 4, !tbaa !5
  %145 = add nsw i32 %143, %144
  %146 = load i32, ptr %5, align 4, !tbaa !5
  %147 = add nsw i32 %145, %146
  %148 = sub nsw i32 %147, 250
  %149 = sext i32 %148 to i64
  %150 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %149
  %151 = load i32, ptr %5, align 4, !tbaa !5
  %152 = sext i32 %151 to i64
  %153 = getelementptr inbounds [500 x i32], ptr %150, i64 0, i64 %152
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #7
  %154 = load i32, ptr %3, align 4, !tbaa !5
  %155 = load i32, ptr @d, align 4, !tbaa !5
  %156 = add nsw i32 %154, %155
  %157 = load i32, ptr %5, align 4, !tbaa !5
  %158 = add nsw i32 %156, %157
  %159 = sub nsw i32 %158, 250
  %160 = sext i32 %159 to i64
  %161 = getelementptr inbounds [30002 x i32], ptr @gems, i64 0, i64 %160
  %162 = load i32, ptr %161, align 4, !tbaa !5
  %163 = load i32, ptr %3, align 4, !tbaa !5
  %164 = sext i32 %163 to i64
  %165 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %164
  %166 = load i32, ptr %5, align 4, !tbaa !5
  %167 = sext i32 %166 to i64
  %168 = getelementptr inbounds [500 x i32], ptr %165, i64 0, i64 %167
  %169 = load i32, ptr %168, align 4, !tbaa !5
  %170 = add nsw i32 %162, %169
  store i32 %170, ptr %7, align 4, !tbaa !5
  %171 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %153, ptr noundef nonnull align 4 dereferenceable(4) %7)
  %172 = load i32, ptr %171, align 4, !tbaa !5
  %173 = load i32, ptr %3, align 4, !tbaa !5
  %174 = load i32, ptr @d, align 4, !tbaa !5
  %175 = add nsw i32 %173, %174
  %176 = load i32, ptr %5, align 4, !tbaa !5
  %177 = add nsw i32 %175, %176
  %178 = sub nsw i32 %177, 250
  %179 = sext i32 %178 to i64
  %180 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %179
  %181 = load i32, ptr %5, align 4, !tbaa !5
  %182 = sext i32 %181 to i64
  %183 = getelementptr inbounds [500 x i32], ptr %180, i64 0, i64 %182
  store i32 %172, ptr %183, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #7
  br label %184

184:                                              ; preds = %142, %133
  %185 = load i32, ptr %3, align 4, !tbaa !5
  %186 = load i32, ptr @d, align 4, !tbaa !5
  %187 = add nsw i32 %185, %186
  %188 = load i32, ptr %5, align 4, !tbaa !5
  %189 = add nsw i32 %187, %188
  %190 = sub nsw i32 %189, 250
  %191 = add nsw i32 %190, 1
  %192 = load i32, ptr @last, align 4, !tbaa !5
  %193 = icmp sle i32 %191, %192
  br i1 %193, label %194, label %241

194:                                              ; preds = %184
  %195 = load i32, ptr %3, align 4, !tbaa !5
  %196 = load i32, ptr @d, align 4, !tbaa !5
  %197 = add nsw i32 %195, %196
  %198 = load i32, ptr %5, align 4, !tbaa !5
  %199 = add nsw i32 %197, %198
  %200 = sub nsw i32 %199, 250
  %201 = add nsw i32 %200, 1
  %202 = sext i32 %201 to i64
  %203 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %202
  %204 = load i32, ptr %5, align 4, !tbaa !5
  %205 = add nsw i32 %204, 1
  %206 = sext i32 %205 to i64
  %207 = getelementptr inbounds [500 x i32], ptr %203, i64 0, i64 %206
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #7
  %208 = load i32, ptr %3, align 4, !tbaa !5
  %209 = load i32, ptr @d, align 4, !tbaa !5
  %210 = add nsw i32 %208, %209
  %211 = load i32, ptr %5, align 4, !tbaa !5
  %212 = add nsw i32 %210, %211
  %213 = sub nsw i32 %212, 250
  %214 = add nsw i32 %213, 1
  %215 = sext i32 %214 to i64
  %216 = getelementptr inbounds [30002 x i32], ptr @gems, i64 0, i64 %215
  %217 = load i32, ptr %216, align 4, !tbaa !5
  %218 = load i32, ptr %3, align 4, !tbaa !5
  %219 = sext i32 %218 to i64
  %220 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %219
  %221 = load i32, ptr %5, align 4, !tbaa !5
  %222 = sext i32 %221 to i64
  %223 = getelementptr inbounds [500 x i32], ptr %220, i64 0, i64 %222
  %224 = load i32, ptr %223, align 4, !tbaa !5
  %225 = add nsw i32 %217, %224
  store i32 %225, ptr %8, align 4, !tbaa !5
  %226 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %207, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %227 = load i32, ptr %226, align 4, !tbaa !5
  %228 = load i32, ptr %3, align 4, !tbaa !5
  %229 = load i32, ptr @d, align 4, !tbaa !5
  %230 = add nsw i32 %228, %229
  %231 = load i32, ptr %5, align 4, !tbaa !5
  %232 = add nsw i32 %230, %231
  %233 = sub nsw i32 %232, 250
  %234 = add nsw i32 %233, 1
  %235 = sext i32 %234 to i64
  %236 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %235
  %237 = load i32, ptr %5, align 4, !tbaa !5
  %238 = add nsw i32 %237, 1
  %239 = sext i32 %238 to i64
  %240 = getelementptr inbounds [500 x i32], ptr %236, i64 0, i64 %239
  store i32 %227, ptr %240, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #7
  br label %241

241:                                              ; preds = %194, %184
  br label %242

242:                                              ; preds = %241, %52
  br label %243

243:                                              ; preds = %242
  %244 = load i32, ptr %5, align 4, !tbaa !5
  %245 = add nsw i32 %244, 1
  store i32 %245, ptr %5, align 4, !tbaa !5
  br label %48, !llvm.loop !11

246:                                              ; preds = %51
  br label %247

247:                                              ; preds = %246
  %248 = load i32, ptr %3, align 4, !tbaa !5
  %249 = add nsw i32 %248, 1
  store i32 %249, ptr %3, align 4, !tbaa !5
  br label %42, !llvm.loop !12

250:                                              ; preds = %46
  %251 = load i32, ptr @res, align 4, !tbaa !5
  %252 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %251)
  %253 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %252, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0
}

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

declare i32 @__isoc99_scanf(ptr noundef, ...) #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) #2

; 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 = { nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #3 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #4 = { inlinehint mustprogress 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
@dp = external dso_local global [30002 x [500 x i32]], align 16
@gems = external dso_local local_unnamed_addr global [30002 x i32], align 16
@p = external dso_local global i32, align 4
@res = external dso_local global i32, align 4
@last = 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
@_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
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(60004000) @dp, i8 -1, i64 60004000, i1 false)
  tail call void @llvm.memset.p0.i64(ptr noundef nonnull align 16 dereferenceable(120008) @gems, i8 0, i64 120008, i1 false)
  %4 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str, ptr noundef nonnull @n, ptr noundef nonnull @d)
  %5 = load i32, ptr @n, align 4, !tbaa !5
  %6 = icmp sgt i32 %5, 0
  br i1 %6, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %24, %0
  %7 = load i32, ptr @d, align 4, !tbaa !5
  %8 = sext i32 %7 to i64
  %9 = getelementptr inbounds [30002 x i32], ptr @gems, i64 0, i64 %8
  %10 = load i32, ptr %9, align 4, !tbaa !5
  %11 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %8, i64 250
  store i32 %10, ptr %11, align 8, !tbaa !5
  store i32 %10, ptr @res, align 4, !tbaa !5
  %12 = load i32, ptr @last, align 4, !tbaa !5
  %.not58 = icmp sgt i32 %7, %12
  br i1 %.not58, label %._crit_edge60, label %.preheader

.lr.ph:                                           ; preds = %0, %24
  %.04856 = phi i32 [ %25, %24 ], [ 0, %0 ]
  %13 = tail call i32 (ptr, ...) @__isoc99_scanf(ptr noundef nonnull @.str.1, ptr noundef nonnull @p)
  %14 = load i32, ptr @p, align 4, !tbaa !5
  %15 = load i32, ptr @d, align 4, !tbaa !5
  %.not55 = icmp slt i32 %14, %15
  br i1 %.not55, label %24, label %16

16:                                               ; preds = %.lr.ph
  %17 = tail 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) @p)
  %18 = load i32, ptr %17, align 4, !tbaa !5
  store i32 %18, ptr @last, align 4, !tbaa !5
  %19 = load i32, ptr @p, align 4, !tbaa !5
  %20 = sext i32 %19 to i64
  %21 = getelementptr inbounds [30002 x i32], ptr @gems, i64 0, i64 %20
  %22 = load i32, ptr %21, align 4, !tbaa !5
  %23 = add nsw i32 %22, 1
  store i32 %23, ptr %21, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %.lr.ph, %16
  %25 = add nuw nsw i32 %.04856, 1
  %26 = load i32, ptr @n, align 4, !tbaa !5
  %27 = icmp slt i32 %25, %26
  br i1 %27, label %.lr.ph, label %._crit_edge, !llvm.loop !9

.preheader:                                       ; preds = %._crit_edge, %35
  %indvars.iv62 = phi i64 [ %indvars.iv.next63, %35 ], [ %8, %._crit_edge ]
  %28 = trunc nsw i64 %indvars.iv62 to i32
  %29 = add i32 %28, -251
  %30 = add i32 %28, -250
  %31 = add i32 %28, -249
  br label %38

._crit_edge60.loopexit:                           ; preds = %35
  %.pre67 = load i32, ptr @res, align 4, !tbaa !5
  br label %._crit_edge60

._crit_edge60:                                    ; preds = %._crit_edge60.loopexit, %._crit_edge
  %32 = phi i32 [ %.pre67, %._crit_edge60.loopexit ], [ %10, %._crit_edge ]
  %33 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef %32)
  %34 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %33, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0

35:                                               ; preds = %102
  %indvars.iv.next63 = add nsw i64 %indvars.iv62, 1
  %36 = load i32, ptr @last, align 4, !tbaa !5
  %37 = sext i32 %36 to i64
  %.not.not = icmp slt i64 %indvars.iv62, %37
  br i1 %.not.not, label %.preheader, label %._crit_edge60.loopexit, !llvm.loop !11

38:                                               ; preds = %.preheader, %102
  %indvars.iv = phi i64 [ 0, %.preheader ], [ %indvars.iv.next, %102 ]
  %indvars61 = trunc i64 %indvars.iv to i32
  %39 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %indvars.iv62, i64 %indvars.iv
  %40 = load i32, ptr %39, align 4, !tbaa !5
  %41 = icmp sgt i32 %40, -1
  br i1 %41, label %42, label %102

42:                                               ; preds = %38
  %43 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) @res, ptr noundef nonnull align 4 dereferenceable(4) %39)
  %44 = load i32, ptr %43, align 4, !tbaa !5
  store i32 %44, ptr @res, align 4, !tbaa !5
  %45 = load i32, ptr @d, align 4, !tbaa !5
  %46 = add nsw i32 %45, %indvars61
  %47 = icmp sgt i32 %46, 251
  %.pre65 = load i32, ptr @last, align 4, !tbaa !5
  br i1 %47, label %48, label %65

48:                                               ; preds = %42
  %49 = add i32 %29, %indvars61
  %50 = add i32 %49, %45
  %.not52 = icmp sgt i32 %50, %.pre65
  br i1 %.not52, label %65, label %51

51:                                               ; preds = %48
  %52 = sext i32 %50 to i64
  %53 = add nsw i64 %indvars.iv, -1
  %54 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %52, i64 %53
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #8
  %55 = getelementptr inbounds [30002 x i32], ptr @gems, i64 0, i64 %52
  %56 = load i32, ptr %55, align 4, !tbaa !5
  %57 = load i32, ptr %39, align 4, !tbaa !5
  %58 = add nsw i32 %57, %56
  store i32 %58, ptr %1, align 4, !tbaa !5
  %59 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZSt3maxIiERKT_S2_S2_(ptr noundef nonnull align 4 dereferenceable(4) %54, ptr noundef nonnull align 4 dereferenceable(4) %1)
  %60 = load i32, ptr %59, align 4, !tbaa !5
  %61 = load i32, ptr @d, align 4, !tbaa !5
  %62 = add i32 %49, %61
  %63 = sext i32 %62 to i64
  %64 = getelementptr inbounds [30002 x [500 x i32]], ptr @dp, i64 0, i64 %63, i64 %53
  store i32 %60, ptr %64, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #8
  %.pre = load i32, ptr @last, align 4, !tbaa !5
  br label %65

65:                                               ; preds = %51, %48, %42
  %66 = phi i32 [ %.pre, %51 ], [ %.pre65, %48 ], [ %.pre65, %42 ]
  %67 = phi i32 [ %61, %51 ], [ %45, %48 ], [ %45, %42 ]
  %68 = add i32 %30, %indvars61
  %69 = add i32 %68, %67
  %.not53 = icmp sgt i32 %69, %66
  br i1 %.not53, label %83, label %70

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

83:                                               ; preds = %70, %65
  %84 = phi i32 [ %.pre66, %70 ], [ %66, %65 ]
  %85 = phi i32 [ %79, %70 ], [ %67, %65 ]
  %86 = add i32 %31, %indvars61
  %87 = add i32 %86, %85
  %.not54 = icmp sgt i32 %87, %84
  br i1 %.not54, label %102, label %88

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

102:                                              ; preds = %38, %88, %83
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond.not = icmp eq i64 %indvars.iv.next, 501
  br i1 %exitcond.not, label %35, label %38, !llvm.loop !12
}

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

; Function Attrs: nofree nounwind
declare noundef i32 @__isoc99_scanf(ptr nocapture noundef readonly, ...) local_unnamed_addr #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 = { mustprogress nocallback nofree nounwind willreturn memory(argmem: write) }
attributes #2 = { 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 #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,JumpThreadingPass,LICMPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass