; LLVM IR from eyangch/competitive-programming :: Codeforces/1467 (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_istream" = type { ptr, i64, %"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_ostream" = type { ptr, %"class.std::basic_ios" }

@MOD = external dso_local global i64, align 8
@N = external dso_local global i64, align 8
@K = external dso_local global i64, align 8
@Q = external dso_local global i64, align 8
@a = external dso_local global [5000 x i64], align 16
@oc = external dso_local global [5000 x i64], align 16
@dp = external dso_local global [5001 x [5000 x i64]], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_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 i64, align 8
  %3 = alloca i32, align 4
  %4 = alloca i64, align 8
  %5 = alloca i32, align 4
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  %9 = alloca i64, align 8
  %10 = alloca i64, align 8
  %11 = alloca i64, align 8
  %12 = alloca i64, align 8
  %13 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %14 = 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)
  %15 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %14, ptr noundef nonnull align 8 dereferenceable(8) @K)
  %16 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %15, ptr noundef nonnull align 8 dereferenceable(8) @Q)
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #4
  store i64 0, ptr %2, align 8, !tbaa !5
  br label %17

17:                                               ; preds = %26, %0
  %18 = load i64, ptr %2, align 8, !tbaa !5
  %19 = load i64, ptr @N, align 8, !tbaa !5
  %20 = icmp slt i64 %18, %19
  br i1 %20, label %22, label %21

21:                                               ; preds = %17
  call void @llvm.lifetime.end.p0(i64 8, ptr %2) #4
  br label %29

22:                                               ; preds = %17
  %23 = load i64, ptr %2, align 8, !tbaa !5
  %24 = getelementptr inbounds [5000 x i64], ptr @a, i64 0, i64 %23
  %25 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %24)
  br label %26

26:                                               ; preds = %22
  %27 = load i64, ptr %2, align 8, !tbaa !5
  %28 = add nsw i64 %27, 1
  store i64 %28, ptr %2, align 8, !tbaa !5
  br label %17, !llvm.loop !9

29:                                               ; preds = %21
  %30 = load i64, ptr @N, align 8, !tbaa !5
  %31 = getelementptr inbounds i64, ptr @dp, i64 %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #4
  store i32 1, ptr %3, align 4, !tbaa !11
  call void @_ZSt4fillIPxiEvT_S1_RKT0_(ptr noundef @dp, ptr noundef %31, ptr noundef nonnull align 4 dereferenceable(4) %3)
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %4) #4
  store i64 1, ptr %4, align 8, !tbaa !5
  br label %32

32:                                               ; preds = %97, %29
  %33 = load i64, ptr %4, align 8, !tbaa !5
  %34 = load i64, ptr @K, align 8, !tbaa !5
  %35 = add nsw i64 %34, 1
  %36 = icmp slt i64 %33, %35
  br i1 %36, label %38, label %37

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

38:                                               ; preds = %32
  %39 = load i64, ptr %4, align 8, !tbaa !5
  %40 = sub nsw i64 %39, 1
  %41 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %40
  %42 = getelementptr inbounds [5000 x i64], ptr %41, i64 0, i64 1
  %43 = load i64, ptr %42, align 8, !tbaa !5
  %44 = load i64, ptr %4, align 8, !tbaa !5
  %45 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %44
  %46 = getelementptr inbounds [5000 x i64], ptr %45, i64 0, i64 0
  store i64 %43, ptr %46, align 16, !tbaa !5
  %47 = load i64, ptr %4, align 8, !tbaa !5
  %48 = sub nsw i64 %47, 1
  %49 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %48
  %50 = load i64, ptr @N, align 8, !tbaa !5
  %51 = sub nsw i64 %50, 2
  %52 = getelementptr inbounds [5000 x i64], ptr %49, i64 0, i64 %51
  %53 = load i64, ptr %52, align 8, !tbaa !5
  %54 = load i64, ptr %4, align 8, !tbaa !5
  %55 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %54
  %56 = load i64, ptr @N, align 8, !tbaa !5
  %57 = sub nsw i64 %56, 1
  %58 = getelementptr inbounds [5000 x i64], ptr %55, i64 0, i64 %57
  store i64 %53, ptr %58, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %6) #4
  store i64 1, ptr %6, align 8, !tbaa !5
  br label %59

59:                                               ; preds = %93, %38
  %60 = load i64, ptr %6, align 8, !tbaa !5
  %61 = load i64, ptr @N, align 8, !tbaa !5
  %62 = sub nsw i64 %61, 1
  %63 = icmp slt i64 %60, %62
  br i1 %63, label %65, label %64

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

65:                                               ; preds = %59
  %66 = load i64, ptr %4, align 8, !tbaa !5
  %67 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %66
  %68 = load i64, ptr %6, align 8, !tbaa !5
  %69 = getelementptr inbounds [5000 x i64], ptr %67, i64 0, i64 %68
  %70 = load i64, ptr %69, align 8, !tbaa !5
  %71 = load i64, ptr %4, align 8, !tbaa !5
  %72 = sub nsw i64 %71, 1
  %73 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %72
  %74 = load i64, ptr %6, align 8, !tbaa !5
  %75 = sub nsw i64 %74, 1
  %76 = getelementptr inbounds [5000 x i64], ptr %73, i64 0, i64 %75
  %77 = load i64, ptr %76, align 8, !tbaa !5
  %78 = add nsw i64 %70, %77
  %79 = load i64, ptr %4, align 8, !tbaa !5
  %80 = sub nsw i64 %79, 1
  %81 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %80
  %82 = load i64, ptr %6, align 8, !tbaa !5
  %83 = add nsw i64 %82, 1
  %84 = getelementptr inbounds [5000 x i64], ptr %81, i64 0, i64 %83
  %85 = load i64, ptr %84, align 8, !tbaa !5
  %86 = add nsw i64 %78, %85
  %87 = load i64, ptr @MOD, align 8, !tbaa !5
  %88 = srem i64 %86, %87
  %89 = load i64, ptr %4, align 8, !tbaa !5
  %90 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %89
  %91 = load i64, ptr %6, align 8, !tbaa !5
  %92 = getelementptr inbounds [5000 x i64], ptr %90, i64 0, i64 %91
  store i64 %88, ptr %92, align 8, !tbaa !5
  br label %93

93:                                               ; preds = %65
  %94 = load i64, ptr %6, align 8, !tbaa !5
  %95 = add nsw i64 %94, 1
  store i64 %95, ptr %6, align 8, !tbaa !5
  br label %59, !llvm.loop !13

96:                                               ; preds = %64
  br label %97

97:                                               ; preds = %96
  %98 = load i64, ptr %4, align 8, !tbaa !5
  %99 = add nsw i64 %98, 1
  store i64 %99, ptr %4, align 8, !tbaa !5
  br label %32, !llvm.loop !14

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

101:                                              ; preds = %139, %100
  %102 = load i64, ptr %7, align 8, !tbaa !5
  %103 = load i64, ptr @K, align 8, !tbaa !5
  %104 = add nsw i64 %103, 1
  %105 = icmp slt i64 %102, %104
  br i1 %105, label %107, label %106

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

107:                                              ; preds = %101
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  store i64 0, ptr %8, align 8, !tbaa !5
  br label %108

108:                                              ; preds = %135, %107
  %109 = load i64, ptr %8, align 8, !tbaa !5
  %110 = load i64, ptr @N, align 8, !tbaa !5
  %111 = icmp slt i64 %109, %110
  br i1 %111, label %113, label %112

112:                                              ; preds = %108
  store i32 14, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  br label %138

113:                                              ; preds = %108
  %114 = load i64, ptr %8, align 8, !tbaa !5
  %115 = getelementptr inbounds [5000 x i64], ptr @oc, i64 0, i64 %114
  %116 = load i64, ptr %115, align 8, !tbaa !5
  %117 = load i64, ptr %7, align 8, !tbaa !5
  %118 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %117
  %119 = load i64, ptr %8, align 8, !tbaa !5
  %120 = getelementptr inbounds [5000 x i64], ptr %118, i64 0, i64 %119
  %121 = load i64, ptr %120, align 8, !tbaa !5
  %122 = load i64, ptr @K, align 8, !tbaa !5
  %123 = load i64, ptr %7, align 8, !tbaa !5
  %124 = sub nsw i64 %122, %123
  %125 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %124
  %126 = load i64, ptr %8, align 8, !tbaa !5
  %127 = getelementptr inbounds [5000 x i64], ptr %125, i64 0, i64 %126
  %128 = load i64, ptr %127, align 8, !tbaa !5
  %129 = mul nsw i64 %121, %128
  %130 = add nsw i64 %116, %129
  %131 = load i64, ptr @MOD, align 8, !tbaa !5
  %132 = srem i64 %130, %131
  %133 = load i64, ptr %8, align 8, !tbaa !5
  %134 = getelementptr inbounds [5000 x i64], ptr @oc, i64 0, i64 %133
  store i64 %132, ptr %134, align 8, !tbaa !5
  br label %135

135:                                              ; preds = %113
  %136 = load i64, ptr %8, align 8, !tbaa !5
  %137 = add nsw i64 %136, 1
  store i64 %137, ptr %8, align 8, !tbaa !5
  br label %108, !llvm.loop !15

138:                                              ; preds = %112
  br label %139

139:                                              ; preds = %138
  %140 = load i64, ptr %7, align 8, !tbaa !5
  %141 = add nsw i64 %140, 1
  store i64 %141, ptr %7, align 8, !tbaa !5
  br label %101, !llvm.loop !16

142:                                              ; preds = %106
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  store i64 0, ptr %9, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  store i64 0, ptr %10, align 8, !tbaa !5
  br label %143

143:                                              ; preds = %160, %142
  %144 = load i64, ptr %10, align 8, !tbaa !5
  %145 = load i64, ptr @N, align 8, !tbaa !5
  %146 = icmp slt i64 %144, %145
  br i1 %146, label %148, label %147

147:                                              ; preds = %143
  store i32 17, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  br label %163

148:                                              ; preds = %143
  %149 = load i64, ptr %9, align 8, !tbaa !5
  %150 = load i64, ptr %10, align 8, !tbaa !5
  %151 = getelementptr inbounds [5000 x i64], ptr @oc, i64 0, i64 %150
  %152 = load i64, ptr %151, align 8, !tbaa !5
  %153 = load i64, ptr %10, align 8, !tbaa !5
  %154 = getelementptr inbounds [5000 x i64], ptr @a, i64 0, i64 %153
  %155 = load i64, ptr %154, align 8, !tbaa !5
  %156 = mul nsw i64 %152, %155
  %157 = add nsw i64 %149, %156
  %158 = load i64, ptr @MOD, align 8, !tbaa !5
  %159 = srem i64 %157, %158
  store i64 %159, ptr %9, align 8, !tbaa !5
  br label %160

160:                                              ; preds = %148
  %161 = load i64, ptr %10, align 8, !tbaa !5
  %162 = add nsw i64 %161, 1
  store i64 %162, ptr %10, align 8, !tbaa !5
  br label %143, !llvm.loop !17

163:                                              ; preds = %147
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  store i64 0, ptr %11, align 8, !tbaa !5
  br label %164

164:                                              ; preds = %197, %163
  %165 = load i64, ptr %11, align 8, !tbaa !5
  %166 = load i64, ptr @Q, align 8, !tbaa !5
  %167 = icmp slt i64 %165, %166
  br i1 %167, label %169, label %168

168:                                              ; preds = %164
  store i32 20, ptr %5, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  br label %200

169:                                              ; preds = %164
  call void @llvm.lifetime.start.p0(i64 8, ptr %12) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %13) #4
  %170 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %12)
  %171 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %170, ptr noundef nonnull align 8 dereferenceable(8) %13)
  %172 = load i64, ptr %12, align 8, !tbaa !5
  %173 = add nsw i64 %172, -1
  store i64 %173, ptr %12, align 8, !tbaa !5
  %174 = load i64, ptr %9, align 8, !tbaa !5
  %175 = load i64, ptr %12, align 8, !tbaa !5
  %176 = getelementptr inbounds [5000 x i64], ptr @oc, i64 0, i64 %175
  %177 = load i64, ptr %176, align 8, !tbaa !5
  %178 = load i64, ptr %13, align 8, !tbaa !5
  %179 = load i64, ptr %12, align 8, !tbaa !5
  %180 = getelementptr inbounds [5000 x i64], ptr @a, i64 0, i64 %179
  %181 = load i64, ptr %180, align 8, !tbaa !5
  %182 = sub nsw i64 %178, %181
  %183 = mul nsw i64 %177, %182
  %184 = add nsw i64 %174, %183
  %185 = load i64, ptr @MOD, align 8, !tbaa !5
  %186 = srem i64 %184, %185
  %187 = load i64, ptr @MOD, align 8, !tbaa !5
  %188 = add nsw i64 %186, %187
  %189 = load i64, ptr @MOD, align 8, !tbaa !5
  %190 = srem i64 %188, %189
  store i64 %190, ptr %9, align 8, !tbaa !5
  %191 = load i64, ptr %13, align 8, !tbaa !5
  %192 = load i64, ptr %12, align 8, !tbaa !5
  %193 = getelementptr inbounds [5000 x i64], ptr @a, i64 0, i64 %192
  store i64 %191, ptr %193, align 8, !tbaa !5
  %194 = load i64, ptr %9, align 8, !tbaa !5
  %195 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %194)
  %196 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %195, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  call void @llvm.lifetime.end.p0(i64 8, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %12) #4
  br label %197

197:                                              ; preds = %169
  %198 = load i64, ptr %11, align 8, !tbaa !5
  %199 = add nsw i64 %198, 1
  store i64 %199, ptr %11, align 8, !tbaa !5
  br label %164, !llvm.loop !18

200:                                              ; preds = %168
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  %201 = load i32, ptr %1, align 4
  ret i32 %201
}

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

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

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

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

; Function Attrs: mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8), i64 noundef) #1 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) #1 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)) #3

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 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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 = !{!"long long", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !10}
!14 = distinct !{!14, !10}
!15 = distinct !{!15, !10}
!16 = distinct !{!16, !10}
!17 = distinct !{!17, !10}
!18 = distinct !{!18, !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_istream" = type { ptr, i64, %"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_ostream" = type { ptr, %"class.std::basic_ios" }

@MOD = external dso_local local_unnamed_addr global i64, align 8
@N = external dso_local global i64, align 8
@K = external dso_local global i64, align 8
@Q = external dso_local global i64, align 8
@a = external dso_local global [5000 x i64], align 16
@oc = external dso_local local_unnamed_addr global [5000 x i64], align 16
@dp = external dso_local global [5001 x [5000 x i64]], align 16
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_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 i64, align 8
  %3 = alloca i64, align 8
  %4 = 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)
  %5 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %4, ptr noundef nonnull align 8 dereferenceable(8) @K)
  %6 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %5, ptr noundef nonnull align 8 dereferenceable(8) @Q)
  %7 = load i64, ptr @N, align 8, !tbaa !5
  %8 = icmp sgt i64 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

._crit_edge:                                      ; preds = %.lr.ph, %0
  %.lcssa51 = phi i64 [ %7, %0 ], [ %39, %.lr.ph ]
  %9 = getelementptr inbounds i64, ptr @dp, i64 %.lcssa51
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4
  store i32 1, ptr %1, align 4, !tbaa !9
  call void @_ZSt4fillIPxiEvT_S1_RKT0_(ptr noundef nonnull @dp, ptr noundef nonnull %9, ptr noundef nonnull align 4 dereferenceable(4) %1)
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4
  %10 = load i64, ptr @K, align 8, !tbaa !5
  %.not57 = icmp slt i64 %10, 1
  %.pre.pre = load i64, ptr @N, align 8, !tbaa !5
  br i1 %.not57, label %.preheader50, label %.lr.ph60

.lr.ph60:                                         ; preds = %._crit_edge
  %11 = add nsw i64 %.pre.pre, -2
  %12 = add i64 %.pre.pre, -1
  %13 = icmp sgt i64 %.pre.pre, 2
  %14 = load i64, ptr @MOD, align 8
  br i1 %13, label %.lr.ph55.us, label %.lr.ph60.split.preheader

.lr.ph60.split.preheader:                         ; preds = %.lr.ph60
  %xtraiter = and i64 %10, 1
  %15 = icmp eq i64 %10, 1
  br i1 %15, label %.preheader50.loopexit87.unr-lcssa, label %.lr.ph60.split.preheader.new

.lr.ph60.split.preheader.new:                     ; preds = %.lr.ph60.split.preheader
  %unroll_iter = and i64 %10, 9223372036854775806
  br label %.lr.ph60.split

.lr.ph55.us:                                      ; preds = %.lr.ph60, %._crit_edge56.us
  %.04458.us = phi i64 [ %35, %._crit_edge56.us ], [ 1, %.lr.ph60 ]
  %16 = add nsw i64 %.04458.us, -1
  %17 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %16, i64 1
  %18 = load i64, ptr %17, align 8, !tbaa !5
  %19 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %.04458.us
  store i64 %18, ptr %19, align 16, !tbaa !5
  %20 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %16, i64 %11
  %21 = load i64, ptr %20, align 8, !tbaa !5
  %22 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %.04458.us, i64 %12
  store i64 %21, ptr %22, align 8, !tbaa !5
  br label %23

23:                                               ; preds = %.lr.ph55.us, %23
  %.04353.us = phi i64 [ 1, %.lr.ph55.us ], [ %30, %23 ]
  %24 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %.04458.us, i64 %.04353.us
  %25 = load i64, ptr %24, align 8, !tbaa !5
  %26 = add nsw i64 %.04353.us, -1
  %27 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %16, i64 %26
  %28 = load i64, ptr %27, align 8, !tbaa !5
  %29 = add nsw i64 %28, %25
  %30 = add nuw nsw i64 %.04353.us, 1
  %31 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %16, i64 %30
  %32 = load i64, ptr %31, align 8, !tbaa !5
  %33 = add nsw i64 %29, %32
  %34 = srem i64 %33, %14
  store i64 %34, ptr %24, align 8, !tbaa !5
  %exitcond78.not = icmp eq i64 %30, %12
  br i1 %exitcond78.not, label %._crit_edge56.us, label %23, !llvm.loop !11

._crit_edge56.us:                                 ; preds = %23
  %35 = add nuw i64 %.04458.us, 1
  %exitcond79.not = icmp eq i64 %.04458.us, %10
  br i1 %exitcond79.not, label %.preheader50, label %.lr.ph55.us, !llvm.loop !13

.lr.ph:                                           ; preds = %0, %.lr.ph
  %.04552 = phi i64 [ %38, %.lr.ph ], [ 0, %0 ]
  %36 = getelementptr inbounds [5000 x i64], ptr @a, i64 0, i64 %.04552
  %37 = 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) %36)
  %38 = add nuw nsw i64 %.04552, 1
  %39 = load i64, ptr @N, align 8, !tbaa !5
  %40 = icmp slt i64 %38, %39
  br i1 %40, label %.lr.ph, label %._crit_edge, !llvm.loop !14

.preheader50.loopexit87.unr-lcssa:                ; preds = %.lr.ph60.split, %.lr.ph60.split.preheader
  %.04458.unr = phi i64 [ 1, %.lr.ph60.split.preheader ], [ %77, %.lr.ph60.split ]
  %lcmp.mod.not = icmp eq i64 %xtraiter, 0
  br i1 %lcmp.mod.not, label %.preheader50, label %.lr.ph60.split.epil

.lr.ph60.split.epil:                              ; preds = %.preheader50.loopexit87.unr-lcssa
  %41 = add nsw i64 %.04458.unr, -1
  %42 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %41, i64 1
  %43 = load i64, ptr %42, align 8, !tbaa !5
  %44 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %.04458.unr
  store i64 %43, ptr %44, align 16, !tbaa !5
  %45 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %41, i64 %11
  %46 = load i64, ptr %45, align 8, !tbaa !5
  %47 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %.04458.unr, i64 %12
  store i64 %46, ptr %47, align 8, !tbaa !5
  br label %.preheader50

.preheader50:                                     ; preds = %.lr.ph60.split.epil, %.preheader50.loopexit87.unr-lcssa, %._crit_edge56.us, %._crit_edge
  %.not4765 = icmp slt i64 %10, 0
  br i1 %.not4765, label %.preheader48, label %.preheader49.lr.ph

.preheader49.lr.ph:                               ; preds = %.preheader50
  %48 = icmp sgt i64 %.pre.pre, 0
  %49 = load i64, ptr @MOD, align 8
  br i1 %48, label %.preheader49.us, label %.preheader

.preheader49.us:                                  ; preds = %.preheader49.lr.ph, %._crit_edge64.us
  %.04266.us = phi i64 [ %62, %._crit_edge64.us ], [ 0, %.preheader49.lr.ph ]
  %50 = sub nsw i64 %10, %.04266.us
  br label %51

51:                                               ; preds = %.preheader49.us, %51
  %.04162.us = phi i64 [ 0, %.preheader49.us ], [ %61, %51 ]
  %52 = getelementptr inbounds [5000 x i64], ptr @oc, i64 0, i64 %.04162.us
  %53 = load i64, ptr %52, align 8, !tbaa !5
  %54 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %.04266.us, i64 %.04162.us
  %55 = load i64, ptr %54, align 8, !tbaa !5
  %56 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %50, i64 %.04162.us
  %57 = load i64, ptr %56, align 8, !tbaa !5
  %58 = mul nsw i64 %57, %55
  %59 = add nsw i64 %58, %53
  %60 = srem i64 %59, %49
  store i64 %60, ptr %52, align 8, !tbaa !5
  %61 = add nuw nsw i64 %.04162.us, 1
  %exitcond80.not = icmp eq i64 %61, %.pre.pre
  br i1 %exitcond80.not, label %._crit_edge64.us, label %51, !llvm.loop !15

._crit_edge64.us:                                 ; preds = %51
  %62 = add nuw i64 %.04266.us, 1
  %exitcond81.not = icmp eq i64 %.04266.us, %10
  br i1 %exitcond81.not, label %.preheader48, label %.preheader49.us, !llvm.loop !16

.lr.ph60.split:                                   ; preds = %.lr.ph60.split, %.lr.ph60.split.preheader.new
  %.04458 = phi i64 [ 1, %.lr.ph60.split.preheader.new ], [ %77, %.lr.ph60.split ]
  %niter = phi i64 [ 0, %.lr.ph60.split.preheader.new ], [ %niter.next.1, %.lr.ph60.split ]
  %63 = add nsw i64 %.04458, -1
  %64 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %63, i64 1
  %65 = load i64, ptr %64, align 8, !tbaa !5
  %66 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %.04458
  store i64 %65, ptr %66, align 16, !tbaa !5
  %67 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %63, i64 %11
  %68 = load i64, ptr %67, align 8, !tbaa !5
  %69 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %.04458, i64 %12
  store i64 %68, ptr %69, align 8, !tbaa !5
  %70 = add nuw i64 %.04458, 1
  %71 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %.04458, i64 1
  %72 = load i64, ptr %71, align 8, !tbaa !5
  %73 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %70
  store i64 %72, ptr %73, align 16, !tbaa !5
  %74 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %.04458, i64 %11
  %75 = load i64, ptr %74, align 8, !tbaa !5
  %76 = getelementptr inbounds [5001 x [5000 x i64]], ptr @dp, i64 0, i64 %70, i64 %12
  store i64 %75, ptr %76, align 8, !tbaa !5
  %77 = add nuw i64 %.04458, 2
  %niter.next.1 = add nuw i64 %niter, 2
  %niter.ncmp.1 = icmp eq i64 %niter.next.1, %unroll_iter
  br i1 %niter.ncmp.1, label %.preheader50.loopexit87.unr-lcssa, label %.lr.ph60.split, !llvm.loop !13

.preheader48:                                     ; preds = %._crit_edge64.us, %.preheader50
  %78 = icmp sgt i64 %.pre.pre, 0
  br i1 %78, label %.lr.ph69, label %.preheader

.lr.ph69:                                         ; preds = %.preheader48
  %79 = load i64, ptr @MOD, align 8, !tbaa !5
  %xtraiter89 = and i64 %.pre.pre, 1
  %80 = icmp eq i64 %.pre.pre, 1
  br i1 %80, label %.preheader.loopexit.unr-lcssa, label %.lr.ph69.new

.lr.ph69.new:                                     ; preds = %.lr.ph69
  %unroll_iter92 = and i64 %.pre.pre, 9223372036854775806
  br label %90

.preheader.loopexit.unr-lcssa:                    ; preds = %90, %.lr.ph69
  %.lcssa.ph = phi i64 [ poison, %.lr.ph69 ], [ %105, %90 ]
  %.03968.unr = phi i64 [ 0, %.lr.ph69 ], [ %106, %90 ]
  %.04067.unr = phi i64 [ 0, %.lr.ph69 ], [ %105, %90 ]
  %lcmp.mod90.not = icmp eq i64 %xtraiter89, 0
  br i1 %lcmp.mod90.not, label %.preheader, label %.preheader.loopexit.epilog-lcssa

.preheader.loopexit.epilog-lcssa:                 ; preds = %.preheader.loopexit.unr-lcssa
  %81 = getelementptr inbounds [5000 x i64], ptr @oc, i64 0, i64 %.03968.unr
  %82 = load i64, ptr %81, align 8, !tbaa !5
  %83 = getelementptr inbounds [5000 x i64], ptr @a, i64 0, i64 %.03968.unr
  %84 = load i64, ptr %83, align 8, !tbaa !5
  %85 = mul nsw i64 %84, %82
  %86 = add nsw i64 %85, %.04067.unr
  %87 = srem i64 %86, %79
  br label %.preheader

.preheader:                                       ; preds = %.preheader.loopexit.epilog-lcssa, %.preheader.loopexit.unr-lcssa, %.preheader49.lr.ph, %.preheader48
  %.040.lcssa = phi i64 [ 0, %.preheader48 ], [ 0, %.preheader49.lr.ph ], [ %.lcssa.ph, %.preheader.loopexit.unr-lcssa ], [ %87, %.preheader.loopexit.epilog-lcssa ]
  %88 = load i64, ptr @Q, align 8, !tbaa !5
  %89 = icmp sgt i64 %88, 0
  br i1 %89, label %.lr.ph73, label %._crit_edge74

90:                                               ; preds = %90, %.lr.ph69.new
  %.03968 = phi i64 [ 0, %.lr.ph69.new ], [ %106, %90 ]
  %.04067 = phi i64 [ 0, %.lr.ph69.new ], [ %105, %90 ]
  %niter93 = phi i64 [ 0, %.lr.ph69.new ], [ %niter93.next.1, %90 ]
  %91 = getelementptr inbounds [5000 x i64], ptr @oc, i64 0, i64 %.03968
  %92 = load i64, ptr %91, align 16, !tbaa !5
  %93 = getelementptr inbounds [5000 x i64], ptr @a, i64 0, i64 %.03968
  %94 = load i64, ptr %93, align 16, !tbaa !5
  %95 = mul nsw i64 %94, %92
  %96 = add nsw i64 %95, %.04067
  %97 = srem i64 %96, %79
  %98 = or disjoint i64 %.03968, 1
  %99 = getelementptr inbounds [5000 x i64], ptr @oc, i64 0, i64 %98
  %100 = load i64, ptr %99, align 8, !tbaa !5
  %101 = getelementptr inbounds [5000 x i64], ptr @a, i64 0, i64 %98
  %102 = load i64, ptr %101, align 8, !tbaa !5
  %103 = mul nsw i64 %102, %100
  %104 = add nsw i64 %103, %97
  %105 = srem i64 %104, %79
  %106 = add nuw nsw i64 %.03968, 2
  %niter93.next.1 = add i64 %niter93, 2
  %niter93.ncmp.1 = icmp eq i64 %niter93.next.1, %unroll_iter92
  br i1 %niter93.ncmp.1, label %.preheader.loopexit.unr-lcssa, label %90, !llvm.loop !17

._crit_edge74:                                    ; preds = %.lr.ph73, %.preheader
  ret i32 0

.lr.ph73:                                         ; preds = %.preheader, %.lr.ph73
  %.072 = phi i64 [ %125, %.lr.ph73 ], [ 0, %.preheader ]
  %.171 = phi i64 [ %122, %.lr.ph73 ], [ %.040.lcssa, %.preheader ]
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %2) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #4
  %107 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %2)
  %108 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %107, ptr noundef nonnull align 8 dereferenceable(8) %3)
  %109 = load i64, ptr %2, align 8, !tbaa !5
  %110 = add nsw i64 %109, -1
  store i64 %110, ptr %2, align 8, !tbaa !5
  %111 = getelementptr inbounds [5000 x i64], ptr @oc, i64 0, i64 %110
  %112 = load i64, ptr %111, align 8, !tbaa !5
  %113 = load i64, ptr %3, align 8, !tbaa !5
  %114 = getelementptr inbounds [5000 x i64], ptr @a, i64 0, i64 %110
  %115 = load i64, ptr %114, align 8, !tbaa !5
  %116 = sub nsw i64 %113, %115
  %117 = mul nsw i64 %116, %112
  %118 = add nsw i64 %117, %.171
  %119 = load i64, ptr @MOD, align 8, !tbaa !5
  %120 = srem i64 %118, %119
  %121 = add nsw i64 %120, %119
  %122 = srem i64 %121, %119
  store i64 %113, ptr %114, align 8, !tbaa !5
  %123 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %122)
  %124 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %123, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %2) #4
  %125 = add nuw nsw i64 %.072, 1
  %126 = load i64, ptr @Q, align 8, !tbaa !5
  %127 = icmp slt i64 %125, %126
  br i1 %127, label %.lr.ph73, label %._crit_edge74, !llvm.loop !18
}

; 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 #1 align 2

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

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

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

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

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 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 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #3 = { 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 #4 = { 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 = !{!"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}
!17 = distinct !{!17, !12}
!18 = distinct !{!18, !12}


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