; LLVM IR from kazunetakahashi/atcoder :: 2019/0323_AGC032 (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 }
%"class.std::basic_istream" = type { ptr, i64, %"class.std::basic_ios" }

@N = external dso_local global i64, align 8
@A = external dso_local global i64, align 8
@B = external dso_local global i64, align 8
@p = external dso_local global [5010 x i32], align 16
@R = external dso_local global [5010 x [5010 x i64]], align 16
@L = external dso_local global [5010 x [5010 x i64]], align 16
@cost = external dso_local global [5010 x [5010 x i64]], align 16
@_ZSt4cerr = external global %"class.std::basic_ostream", align 8
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZL5infty = external hidden constant i64, align 8
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

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

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

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

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

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

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef) #0 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)) #2

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #4 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  %7 = alloca i32, align 4
  store i32 0, ptr %1, align 4
  %8 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @N)
  %9 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %8, ptr noundef nonnull align 8 dereferenceable(8) @A)
  %10 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %9, ptr noundef nonnull align 8 dereferenceable(8) @B)
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #5
  store i32 0, ptr %2, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %27, %0
  %12 = load i32, ptr %2, align 4, !tbaa !5
  %13 = sext i32 %12 to i64
  %14 = load i64, ptr @N, align 8, !tbaa !9
  %15 = icmp slt i64 %13, %14
  br i1 %15, label %17, label %16

16:                                               ; preds = %11
  call void @llvm.lifetime.end.p0(i64 4, ptr %2) #5
  br label %30

17:                                               ; preds = %11
  %18 = load i32, ptr %2, align 4, !tbaa !5
  %19 = sext i32 %18 to i64
  %20 = getelementptr inbounds [5010 x i32], ptr @p, i64 0, i64 %19
  %21 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %20)
  %22 = load i32, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %22 to i64
  %24 = getelementptr inbounds [5010 x i32], ptr @p, i64 0, i64 %23
  %25 = load i32, ptr %24, align 4, !tbaa !5
  %26 = add nsw i32 %25, -1
  store i32 %26, ptr %24, align 4, !tbaa !5
  br label %27

27:                                               ; preds = %17
  %28 = load i32, ptr %2, align 4, !tbaa !5
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %2, align 4, !tbaa !5
  br label %11, !llvm.loop !11

30:                                               ; preds = %16
  call void @_ZSt4fillIPxxEvT_S1_RKT0_(ptr noundef @cost, ptr noundef getelementptr inbounds (i64, ptr @cost, i64 25100100), ptr noundef nonnull align 8 dereferenceable(8) @_ZL5infty)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #5
  store i32 0, ptr %3, align 4, !tbaa !5
  br label %31

31:                                               ; preds = %106, %30
  %32 = load i32, ptr %3, align 4, !tbaa !5
  %33 = sext i32 %32 to i64
  %34 = load i64, ptr @N, align 8, !tbaa !9
  %35 = icmp slt i64 %33, %34
  br i1 %35, label %37, label %36

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

37:                                               ; preds = %31
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = sext i32 %38 to i64
  %40 = getelementptr inbounds [5010 x [5010 x i64]], ptr @R, i64 0, i64 %39
  %41 = load i32, ptr %3, align 4, !tbaa !5
  %42 = sext i32 %41 to i64
  %43 = getelementptr inbounds [5010 x i64], ptr %40, i64 0, i64 %42
  store i64 0, ptr %43, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #5
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %5, align 4, !tbaa !5
  br label %46

46:                                               ; preds = %102, %37
  %47 = load i32, ptr %5, align 4, !tbaa !5
  %48 = sext i32 %47 to i64
  %49 = load i64, ptr @N, align 8, !tbaa !9
  %50 = icmp slt i64 %48, %49
  br i1 %50, label %52, label %51

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

52:                                               ; preds = %46
  %53 = load i32, ptr %3, align 4, !tbaa !5
  %54 = sext i32 %53 to i64
  %55 = getelementptr inbounds [5010 x [5010 x i64]], ptr @R, i64 0, i64 %54
  %56 = load i32, ptr %5, align 4, !tbaa !5
  %57 = sub nsw i32 %56, 1
  %58 = sext i32 %57 to i64
  %59 = getelementptr inbounds [5010 x i64], ptr %55, i64 0, i64 %58
  %60 = load i64, ptr %59, align 8, !tbaa !9
  %61 = load i32, ptr %3, align 4, !tbaa !5
  %62 = sext i32 %61 to i64
  %63 = getelementptr inbounds [5010 x [5010 x i64]], ptr @R, i64 0, i64 %62
  %64 = load i32, ptr %5, align 4, !tbaa !5
  %65 = sext i32 %64 to i64
  %66 = getelementptr inbounds [5010 x i64], ptr %63, i64 0, i64 %65
  store i64 %60, ptr %66, align 8, !tbaa !9
  %67 = load i32, ptr %3, align 4, !tbaa !5
  %68 = sext i32 %67 to i64
  %69 = getelementptr inbounds [5010 x i32], ptr @p, i64 0, i64 %68
  %70 = load i32, ptr %69, align 4, !tbaa !5
  %71 = load i32, ptr %5, align 4, !tbaa !5
  %72 = sext i32 %71 to i64
  %73 = getelementptr inbounds [5010 x i32], ptr @p, i64 0, i64 %72
  %74 = load i32, ptr %73, align 4, !tbaa !5
  %75 = icmp sgt i32 %70, %74
  br i1 %75, label %76, label %85

76:                                               ; preds = %52
  %77 = load i32, ptr %3, align 4, !tbaa !5
  %78 = sext i32 %77 to i64
  %79 = getelementptr inbounds [5010 x [5010 x i64]], ptr @R, i64 0, i64 %78
  %80 = load i32, ptr %5, align 4, !tbaa !5
  %81 = sext i32 %80 to i64
  %82 = getelementptr inbounds [5010 x i64], ptr %79, i64 0, i64 %81
  %83 = load i64, ptr %82, align 8, !tbaa !9
  %84 = add nsw i64 %83, 1
  store i64 %84, ptr %82, align 8, !tbaa !9
  br label %85

85:                                               ; preds = %76, %52
  %86 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cerr, ptr noundef @.str.3)
  %87 = load i32, ptr %3, align 4, !tbaa !5
  %88 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) %86, i32 noundef %87)
  %89 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %88, ptr noundef @.str.1)
  %90 = load i32, ptr %5, align 4, !tbaa !5
  %91 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) %89, i32 noundef %90)
  %92 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %91, ptr noundef @.str.2)
  %93 = load i32, ptr %3, align 4, !tbaa !5
  %94 = sext i32 %93 to i64
  %95 = getelementptr inbounds [5010 x [5010 x i64]], ptr @R, i64 0, i64 %94
  %96 = load i32, ptr %5, align 4, !tbaa !5
  %97 = sext i32 %96 to i64
  %98 = getelementptr inbounds [5010 x i64], ptr %95, i64 0, i64 %97
  %99 = load i64, ptr %98, align 8, !tbaa !9
  %100 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) %92, i64 noundef %99)
  %101 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %100, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %102

102:                                              ; preds = %85
  %103 = load i32, ptr %5, align 4, !tbaa !5
  %104 = add nsw i32 %103, 1
  store i32 %104, ptr %5, align 4, !tbaa !5
  br label %46, !llvm.loop !13

105:                                              ; preds = %51
  br label %106

106:                                              ; preds = %105
  %107 = load i32, ptr %3, align 4, !tbaa !5
  %108 = add nsw i32 %107, 1
  store i32 %108, ptr %3, align 4, !tbaa !5
  br label %31, !llvm.loop !14

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

110:                                              ; preds = %183, %109
  %111 = load i32, ptr %6, align 4, !tbaa !5
  %112 = sext i32 %111 to i64
  %113 = load i64, ptr @N, align 8, !tbaa !9
  %114 = icmp slt i64 %112, %113
  br i1 %114, label %116, label %115

115:                                              ; preds = %110
  store i32 11, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %186

116:                                              ; preds = %110
  %117 = load i32, ptr %6, align 4, !tbaa !5
  %118 = sext i32 %117 to i64
  %119 = getelementptr inbounds [5010 x [5010 x i64]], ptr @L, i64 0, i64 %118
  %120 = load i32, ptr %6, align 4, !tbaa !5
  %121 = sext i32 %120 to i64
  %122 = getelementptr inbounds [5010 x i64], ptr %119, i64 0, i64 %121
  store i64 0, ptr %122, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %123 = load i32, ptr %6, align 4, !tbaa !5
  %124 = sub nsw i32 %123, 1
  store i32 %124, ptr %7, align 4, !tbaa !5
  br label %125

125:                                              ; preds = %179, %116
  %126 = load i32, ptr %7, align 4, !tbaa !5
  %127 = icmp sge i32 %126, 0
  br i1 %127, label %129, label %128

128:                                              ; preds = %125
  store i32 14, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  br label %182

129:                                              ; preds = %125
  %130 = load i32, ptr %6, align 4, !tbaa !5
  %131 = sext i32 %130 to i64
  %132 = getelementptr inbounds [5010 x [5010 x i64]], ptr @L, i64 0, i64 %131
  %133 = load i32, ptr %7, align 4, !tbaa !5
  %134 = add nsw i32 %133, 1
  %135 = sext i32 %134 to i64
  %136 = getelementptr inbounds [5010 x i64], ptr %132, i64 0, i64 %135
  %137 = load i64, ptr %136, align 8, !tbaa !9
  %138 = load i32, ptr %6, align 4, !tbaa !5
  %139 = sext i32 %138 to i64
  %140 = getelementptr inbounds [5010 x [5010 x i64]], ptr @L, i64 0, i64 %139
  %141 = load i32, ptr %7, align 4, !tbaa !5
  %142 = sext i32 %141 to i64
  %143 = getelementptr inbounds [5010 x i64], ptr %140, i64 0, i64 %142
  store i64 %137, ptr %143, align 8, !tbaa !9
  %144 = load i32, ptr %6, align 4, !tbaa !5
  %145 = sext i32 %144 to i64
  %146 = getelementptr inbounds [5010 x i32], ptr @p, i64 0, i64 %145
  %147 = load i32, ptr %146, align 4, !tbaa !5
  %148 = load i32, ptr %7, align 4, !tbaa !5
  %149 = sext i32 %148 to i64
  %150 = getelementptr inbounds [5010 x i32], ptr @p, i64 0, i64 %149
  %151 = load i32, ptr %150, align 4, !tbaa !5
  %152 = icmp slt i32 %147, %151
  br i1 %152, label %153, label %162

153:                                              ; preds = %129
  %154 = load i32, ptr %6, align 4, !tbaa !5
  %155 = sext i32 %154 to i64
  %156 = getelementptr inbounds [5010 x [5010 x i64]], ptr @L, i64 0, i64 %155
  %157 = load i32, ptr %7, align 4, !tbaa !5
  %158 = sext i32 %157 to i64
  %159 = getelementptr inbounds [5010 x i64], ptr %156, i64 0, i64 %158
  %160 = load i64, ptr %159, align 8, !tbaa !9
  %161 = add nsw i64 %160, 1
  store i64 %161, ptr %159, align 8, !tbaa !9
  br label %162

162:                                              ; preds = %153, %129
  %163 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cerr, ptr noundef @.str.4)
  %164 = load i32, ptr %6, align 4, !tbaa !5
  %165 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) %163, i32 noundef %164)
  %166 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %165, ptr noundef @.str.1)
  %167 = load i32, ptr %7, align 4, !tbaa !5
  %168 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) %166, i32 noundef %167)
  %169 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %168, ptr noundef @.str.2)
  %170 = load i32, ptr %6, align 4, !tbaa !5
  %171 = sext i32 %170 to i64
  %172 = getelementptr inbounds [5010 x [5010 x i64]], ptr @L, i64 0, i64 %171
  %173 = load i32, ptr %7, align 4, !tbaa !5
  %174 = sext i32 %173 to i64
  %175 = getelementptr inbounds [5010 x i64], ptr %172, i64 0, i64 %174
  %176 = load i64, ptr %175, align 8, !tbaa !9
  %177 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) %169, i64 noundef %176)
  %178 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %177, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  br label %179

179:                                              ; preds = %162
  %180 = load i32, ptr %7, align 4, !tbaa !5
  %181 = add nsw i32 %180, -1
  store i32 %181, ptr %7, align 4, !tbaa !5
  br label %125, !llvm.loop !15

182:                                              ; preds = %128
  br label %183

183:                                              ; preds = %182
  %184 = load i32, ptr %6, align 4, !tbaa !5
  %185 = add nsw i32 %184, 1
  store i32 %185, ptr %6, align 4, !tbaa !5
  br label %110, !llvm.loop !16

186:                                              ; preds = %115
  %187 = load i64, ptr @N, align 8, !tbaa !9
  %188 = trunc i64 %187 to i32
  %189 = call noundef i64 @_Z4calcii(i32 noundef 0, i32 noundef %188)
  %190 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %189)
  %191 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %190, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  %192 = load i32, ptr %1, align 4
  ret i32 %192
}

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPxxEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) #2

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

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

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


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

@N = external dso_local global i64, align 8
@A = external dso_local global i64, align 8
@B = external dso_local global i64, align 8
@p = external dso_local global [5010 x i32], align 16
@R = external dso_local local_unnamed_addr global [5010 x [5010 x i64]], align 16
@L = external dso_local local_unnamed_addr global [5010 x [5010 x i64]], align 16
@cost = external dso_local global [5010 x [5010 x i64]], align 16
@_ZSt4cerr = external global %"class.std::basic_ostream", align 8
@.str.1 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [5 x i8], align 1
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZL5infty = external hidden constant i64, align 8
@.str.3 = external hidden unnamed_addr constant [3 x i8], align 1
@.str.4 = external hidden unnamed_addr constant [3 x i8], align 1
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

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

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

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

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

; 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 #0 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)) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #3 {
  %1 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) @N)
  %2 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %1, ptr noundef nonnull align 8 dereferenceable(8) @A)
  %3 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %2, ptr noundef nonnull align 8 dereferenceable(8) @B)
  %4 = load i64, ptr @N, align 8, !tbaa !5
  %5 = icmp sgt i64 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  tail call void @_ZSt4fillIPxxEvT_S1_RKT0_(ptr noundef nonnull @cost, ptr noundef nonnull getelementptr inbounds (i8, ptr @cost, i64 200800800), ptr noundef nonnull align 8 dereferenceable(8) @_ZL5infty)
  %6 = load i64, ptr @N, align 8, !tbaa !5
  %7 = icmp sgt i64 %6, 0
  br i1 %7, label %.lr.ph58, label %._crit_edge67

.lr.ph:                                           ; preds = %0, %.lr.ph
  %indvars.iv = phi i64 [ %indvars.iv.next, %.lr.ph ], [ 0, %0 ]
  %8 = getelementptr inbounds [5010 x i32], ptr @p, i64 0, i64 %indvars.iv
  %9 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %8)
  %10 = load i32, ptr %8, align 4, !tbaa !9
  %11 = add nsw i32 %10, -1
  store i32 %11, ptr %8, align 4, !tbaa !9
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %12 = load i64, ptr @N, align 8, !tbaa !5
  %13 = icmp sgt i64 %12, %indvars.iv.next
  br i1 %13, label %.lr.ph, label %._crit_edge, !llvm.loop !11

.loopexit:                                        ; preds = %33, %.lr.ph58
  %14 = phi i64 [ %17, %.lr.ph58 ], [ %43, %33 ]
  %15 = icmp sgt i64 %14, %indvars.iv.next76
  %indvars.iv.next71 = add nuw i64 %indvars.iv70, 1
  br i1 %15, label %.lr.ph58, label %.preheader, !llvm.loop !13

.preheader:                                       ; preds = %.loopexit
  %16 = icmp sgt i64 %14, 0
  br i1 %16, label %.lr.ph66, label %._crit_edge67

.lr.ph58:                                         ; preds = %._crit_edge, %.loopexit
  %17 = phi i64 [ %14, %.loopexit ], [ %6, %._crit_edge ]
  %indvars.iv75 = phi i64 [ %indvars.iv.next76, %.loopexit ], [ 0, %._crit_edge ]
  %indvars.iv70 = phi i64 [ %indvars.iv.next71, %.loopexit ], [ 1, %._crit_edge ]
  %18 = getelementptr inbounds [5010 x [5010 x i64]], ptr @R, i64 0, i64 %indvars.iv75, i64 %indvars.iv75
  store i64 0, ptr %18, align 8, !tbaa !5
  %indvars.iv.next76 = add nuw nsw i64 %indvars.iv75, 1
  %19 = icmp sgt i64 %17, %indvars.iv.next76
  br i1 %19, label %.lr.ph55, label %.loopexit

.lr.ph55:                                         ; preds = %.lr.ph58
  %20 = getelementptr inbounds [5010 x i32], ptr @p, i64 0, i64 %indvars.iv75
  %21 = trunc nuw nsw i64 %indvars.iv75 to i32
  br label %22

22:                                               ; preds = %.lr.ph55, %33
  %indvars.iv72 = phi i64 [ %indvars.iv70, %.lr.ph55 ], [ %indvars.iv.next73, %33 ]
  %23 = add nsw i64 %indvars.iv72, -1
  %24 = getelementptr inbounds [5010 x [5010 x i64]], ptr @R, i64 0, i64 %indvars.iv75, i64 %23
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = getelementptr inbounds [5010 x [5010 x i64]], ptr @R, i64 0, i64 %indvars.iv75, i64 %indvars.iv72
  store i64 %25, ptr %26, align 8, !tbaa !5
  %27 = load i32, ptr %20, align 4, !tbaa !9
  %28 = getelementptr inbounds [5010 x i32], ptr @p, i64 0, i64 %indvars.iv72
  %29 = load i32, ptr %28, align 4, !tbaa !9
  %30 = icmp sgt i32 %27, %29
  br i1 %30, label %31, label %33

31:                                               ; preds = %22
  %32 = add nsw i64 %25, 1
  store i64 %32, ptr %26, align 8, !tbaa !5
  br label %33

33:                                               ; preds = %31, %22
  %34 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cerr, ptr noundef nonnull @.str.3)
  %35 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) %34, i32 noundef %21)
  %36 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %35, ptr noundef nonnull @.str.1)
  %37 = trunc nuw nsw i64 %indvars.iv72 to i32
  %38 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) %36, i32 noundef %37)
  %39 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %38, ptr noundef nonnull @.str.2)
  %40 = load i64, ptr %26, align 8, !tbaa !5
  %41 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) %39, i64 noundef %40)
  %42 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %41, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  %indvars.iv.next73 = add nuw nsw i64 %indvars.iv72, 1
  %43 = load i64, ptr @N, align 8, !tbaa !5
  %44 = icmp sgt i64 %43, %indvars.iv.next73
  br i1 %44, label %22, label %.loopexit, !llvm.loop !14

._crit_edge67:                                    ; preds = %._crit_edge64, %._crit_edge, %.preheader
  %.lcssa = phi i64 [ %14, %.preheader ], [ %6, %._crit_edge ], [ %53, %._crit_edge64 ]
  %45 = trunc i64 %.lcssa to i32
  %46 = tail call noundef i64 @_Z4calcii(i32 noundef 0, i32 noundef %45)
  %47 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %46)
  %48 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %47, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0

.lr.ph66:                                         ; preds = %.preheader, %._crit_edge64
  %49 = phi i64 [ %53, %._crit_edge64 ], [ %14, %.preheader ]
  %indvars.iv78 = phi i64 [ %indvars.iv.next79, %._crit_edge64 ], [ 0, %.preheader ]
  %50 = getelementptr inbounds [5010 x [5010 x i64]], ptr @L, i64 0, i64 %indvars.iv78, i64 %indvars.iv78
  store i64 0, ptr %50, align 8, !tbaa !5
  %.not = icmp eq i64 %indvars.iv78, 0
  br i1 %.not, label %._crit_edge64, label %.lr.ph63

.lr.ph63:                                         ; preds = %.lr.ph66
  %51 = getelementptr inbounds [5010 x i32], ptr @p, i64 0, i64 %indvars.iv78
  %52 = trunc nuw nsw i64 %indvars.iv78 to i32
  br label %55

._crit_edge64.loopexit:                           ; preds = %66
  %.pre = load i64, ptr @N, align 8, !tbaa !5
  br label %._crit_edge64

._crit_edge64:                                    ; preds = %._crit_edge64.loopexit, %.lr.ph66
  %53 = phi i64 [ %.pre, %._crit_edge64.loopexit ], [ %49, %.lr.ph66 ]
  %indvars.iv.next79 = add nuw nsw i64 %indvars.iv78, 1
  %54 = icmp sgt i64 %53, %indvars.iv.next79
  br i1 %54, label %.lr.ph66, label %._crit_edge67, !llvm.loop !15

55:                                               ; preds = %.lr.ph63, %66
  %indvars.iv80 = phi i64 [ %indvars.iv78, %.lr.ph63 ], [ %indvars.iv.next81, %66 ]
  %indvars.iv.next81 = add nsw i64 %indvars.iv80, -1
  %indvars = trunc i64 %indvars.iv.next81 to i32
  %56 = getelementptr inbounds [5010 x [5010 x i64]], ptr @L, i64 0, i64 %indvars.iv78, i64 %indvars.iv80
  %57 = load i64, ptr %56, align 8, !tbaa !5
  %58 = and i64 %indvars.iv.next81, 4294967295
  %59 = getelementptr inbounds [5010 x [5010 x i64]], ptr @L, i64 0, i64 %indvars.iv78, i64 %58
  store i64 %57, ptr %59, align 8, !tbaa !5
  %60 = load i32, ptr %51, align 4, !tbaa !9
  %61 = getelementptr inbounds [5010 x i32], ptr @p, i64 0, i64 %58
  %62 = load i32, ptr %61, align 4, !tbaa !9
  %63 = icmp slt i32 %60, %62
  br i1 %63, label %64, label %66

64:                                               ; preds = %55
  %65 = add nsw i64 %57, 1
  store i64 %65, ptr %59, align 8, !tbaa !5
  br label %66

66:                                               ; preds = %64, %55
  %67 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cerr, ptr noundef nonnull @.str.4)
  %68 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) %67, i32 noundef %52)
  %69 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %68, ptr noundef nonnull @.str.1)
  %70 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) %69, i32 noundef %indvars)
  %71 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_PKc(ptr noundef nonnull align 8 dereferenceable(8) %70, ptr noundef nonnull @.str.2)
  %72 = load i64, ptr %59, align 8, !tbaa !5
  %73 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) %71, i64 noundef %72)
  %74 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %73, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  %75 = icmp sgt i64 %indvars.iv80, 1
  br i1 %75, label %55, label %._crit_edge64.loopexit, !llvm.loop !16
}

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare dso_local void @_ZSt4fillIPxxEvT_S1_RKT0_(ptr noundef, ptr noundef, ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #1

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

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


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