; LLVM IR from eyangch/competitive-programming :: Codeforces/1622 (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::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"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
@fact = external dso_local global [5005 x i64], align 16
@pfx = external dso_local global [5000 x i64], align 16
@_Z1SB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

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

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z2osxx(i64 noundef, i64 noundef) #1

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef i64 @_Z1wxx(i64 noundef, i64 noundef) #1

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %1 = alloca i32, align 4
  %2 = alloca i64, align 8
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i64, align 8
  %7 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %8 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !5
  %9 = getelementptr i8, ptr %8, i64 -24
  %10 = load i64, ptr %9, align 8
  %11 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %10
  %12 = call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %11, ptr noundef null)
  %13 = call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  store i64 1, ptr @fact, align 16, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 8, ptr %2) #6
  store i64 1, ptr %2, align 8, !tbaa !8
  br label %14

14:                                               ; preds = %29, %0
  %15 = load i64, ptr %2, align 8, !tbaa !8
  %16 = icmp slt i64 %15, 5005
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %14
  %19 = load i64, ptr %2, align 8, !tbaa !8
  %20 = sub nsw i64 %19, 1
  %21 = getelementptr inbounds [5005 x i64], ptr @fact, i64 0, i64 %20
  %22 = load i64, ptr %21, align 8, !tbaa !8
  %23 = load i64, ptr %2, align 8, !tbaa !8
  %24 = mul nsw i64 %22, %23
  %25 = load i64, ptr @MOD, align 8, !tbaa !8
  %26 = srem i64 %24, %25
  %27 = load i64, ptr %2, align 8, !tbaa !8
  %28 = getelementptr inbounds [5005 x i64], ptr @fact, i64 0, i64 %27
  store i64 %26, ptr %28, align 8, !tbaa !8
  br label %29

29:                                               ; preds = %18
  %30 = load i64, ptr %2, align 8, !tbaa !8
  %31 = add nsw i64 %30, 1
  store i64 %31, ptr %2, align 8, !tbaa !8
  br label %14, !llvm.loop !11

32:                                               ; preds = %17
  %33 = 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)
  %34 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %33, ptr noundef nonnull align 8 dereferenceable(8) @K)
  %35 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE(ptr noundef nonnull align 8 dereferenceable(16) %34, ptr noundef nonnull align 8 dereferenceable(32) @_Z1SB5cxx11)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  store i64 0, ptr %3, align 8, !tbaa !8
  br label %36

36:                                               ; preds = %62, %32
  %37 = load i64, ptr %3, align 8, !tbaa !8
  %38 = load i64, ptr @N, align 8, !tbaa !8
  %39 = icmp slt i64 %37, %38
  br i1 %39, label %41, label %40

40:                                               ; preds = %36
  call void @llvm.lifetime.end.p0(i64 8, ptr %3) #6
  br label %65

41:                                               ; preds = %36
  %42 = load i64, ptr %3, align 8, !tbaa !8
  %43 = call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1SB5cxx11, i64 noundef %42)
  %44 = load i8, ptr %43, align 1, !tbaa !13
  %45 = sext i8 %44 to i32
  %46 = sub nsw i32 %45, 48
  %47 = sext i32 %46 to i64
  %48 = load i64, ptr %3, align 8, !tbaa !8
  %49 = getelementptr inbounds [5000 x i64], ptr @pfx, i64 0, i64 %48
  store i64 %47, ptr %49, align 8, !tbaa !8
  %50 = load i64, ptr %3, align 8, !tbaa !8
  %51 = icmp sgt i64 %50, 0
  br i1 %51, label %52, label %61

52:                                               ; preds = %41
  %53 = load i64, ptr %3, align 8, !tbaa !8
  %54 = sub nsw i64 %53, 1
  %55 = getelementptr inbounds [5000 x i64], ptr @pfx, i64 0, i64 %54
  %56 = load i64, ptr %55, align 8, !tbaa !8
  %57 = load i64, ptr %3, align 8, !tbaa !8
  %58 = getelementptr inbounds [5000 x i64], ptr @pfx, i64 0, i64 %57
  %59 = load i64, ptr %58, align 8, !tbaa !8
  %60 = add nsw i64 %59, %56
  store i64 %60, ptr %58, align 8, !tbaa !8
  br label %61

61:                                               ; preds = %52, %41
  br label %62

62:                                               ; preds = %61
  %63 = load i64, ptr %3, align 8, !tbaa !8
  %64 = add nsw i64 %63, 1
  store i64 %64, ptr %3, align 8, !tbaa !8
  br label %36, !llvm.loop !14

65:                                               ; preds = %40
  %66 = load i64, ptr @K, align 8, !tbaa !8
  %67 = load i64, ptr @N, align 8, !tbaa !8
  %68 = sub nsw i64 %67, 1
  %69 = call noundef i64 @_Z2osxx(i64 noundef 0, i64 noundef %68)
  %70 = icmp sgt i64 %66, %69
  br i1 %70, label %74, label %71

71:                                               ; preds = %65
  %72 = load i64, ptr @K, align 8, !tbaa !8
  %73 = icmp eq i64 %72, 0
  br i1 %73, label %74, label %77

74:                                               ; preds = %71, %65
  %75 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef 1)
  %76 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %75, i8 noundef signext 10)
  store i32 0, ptr %1, align 4
  br label %184

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

78:                                               ; preds = %90, %77
  %79 = load i64, ptr %5, align 8, !tbaa !8
  %80 = load i64, ptr @N, align 8, !tbaa !8
  %81 = icmp slt i64 %79, %80
  br i1 %81, label %82, label %88

82:                                               ; preds = %78
  %83 = load i64, ptr %4, align 8, !tbaa !8
  %84 = load i64, ptr %5, align 8, !tbaa !8
  %85 = call noundef i64 @_Z2osxx(i64 noundef %83, i64 noundef %84)
  %86 = load i64, ptr @K, align 8, !tbaa !8
  %87 = icmp sle i64 %85, %86
  br label %88

88:                                               ; preds = %82, %78
  %89 = phi i1 [ false, %78 ], [ %87, %82 ]
  br i1 %89, label %90, label %93

90:                                               ; preds = %88
  %91 = load i64, ptr %5, align 8, !tbaa !8
  %92 = add nsw i64 %91, 1
  store i64 %92, ptr %5, align 8, !tbaa !8
  br label %78, !llvm.loop !15

93:                                               ; preds = %88
  %94 = load i64, ptr %5, align 8, !tbaa !8
  %95 = add nsw i64 %94, -1
  store i64 %95, ptr %5, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  store i64 0, ptr %7, align 8, !tbaa !8
  br label %96

96:                                               ; preds = %179, %93
  %97 = load i64, ptr %5, align 8, !tbaa !8
  %98 = load i64, ptr @N, align 8, !tbaa !8
  %99 = icmp slt i64 %97, %98
  br i1 %99, label %100, label %180

100:                                              ; preds = %96
  %101 = load i64, ptr %7, align 8, !tbaa !8
  %102 = load i64, ptr %4, align 8, !tbaa !8
  %103 = load i64, ptr %5, align 8, !tbaa !8
  %104 = call noundef i64 @_Z1wxx(i64 noundef %102, i64 noundef %103)
  %105 = add nsw i64 %101, %104
  %106 = load i64, ptr @MOD, align 8, !tbaa !8
  %107 = srem i64 %105, %106
  store i64 %107, ptr %7, align 8, !tbaa !8
  %108 = load i64, ptr %6, align 8, !tbaa !8
  %109 = load i64, ptr %4, align 8, !tbaa !8
  %110 = icmp sge i64 %108, %109
  br i1 %110, label %111, label %123

111:                                              ; preds = %100
  %112 = load i64, ptr %7, align 8, !tbaa !8
  %113 = load i64, ptr %4, align 8, !tbaa !8
  %114 = load i64, ptr %6, align 8, !tbaa !8
  %115 = call noundef i64 @_Z1wxx(i64 noundef %113, i64 noundef %114)
  %116 = sub nsw i64 %112, %115
  %117 = load i64, ptr @MOD, align 8, !tbaa !8
  %118 = srem i64 %116, %117
  %119 = load i64, ptr @MOD, align 8, !tbaa !8
  %120 = add nsw i64 %118, %119
  %121 = load i64, ptr @MOD, align 8, !tbaa !8
  %122 = srem i64 %120, %121
  store i64 %122, ptr %7, align 8, !tbaa !8
  br label %136

123:                                              ; preds = %100
  %124 = load i64, ptr %6, align 8, !tbaa !8
  %125 = icmp ne i64 %124, -1
  br i1 %125, label %126, label %135

126:                                              ; preds = %123
  %127 = load i64, ptr %7, align 8, !tbaa !8
  %128 = sub nsw i64 %127, 1
  %129 = load i64, ptr @MOD, align 8, !tbaa !8
  %130 = srem i64 %128, %129
  %131 = load i64, ptr @MOD, align 8, !tbaa !8
  %132 = add nsw i64 %130, %131
  %133 = load i64, ptr @MOD, align 8, !tbaa !8
  %134 = srem i64 %132, %133
  store i64 %134, ptr %7, align 8, !tbaa !8
  br label %135

135:                                              ; preds = %126, %123
  br label %136

136:                                              ; preds = %135, %111
  %137 = load i64, ptr %5, align 8, !tbaa !8
  store i64 %137, ptr %6, align 8, !tbaa !8
  %138 = load i64, ptr %5, align 8, !tbaa !8
  %139 = add nsw i64 %138, 1
  store i64 %139, ptr %5, align 8, !tbaa !8
  %140 = load i64, ptr %5, align 8, !tbaa !8
  %141 = load i64, ptr @N, align 8, !tbaa !8
  %142 = icmp eq i64 %140, %141
  br i1 %142, label %143, label %144

143:                                              ; preds = %136
  br label %180

144:                                              ; preds = %136
  br label %145

145:                                              ; preds = %151, %144
  %146 = load i64, ptr %4, align 8, !tbaa !8
  %147 = load i64, ptr %5, align 8, !tbaa !8
  %148 = call noundef i64 @_Z2osxx(i64 noundef %146, i64 noundef %147)
  %149 = load i64, ptr @K, align 8, !tbaa !8
  %150 = icmp sgt i64 %148, %149
  br i1 %150, label %151, label %154

151:                                              ; preds = %145
  %152 = load i64, ptr %4, align 8, !tbaa !8
  %153 = add nsw i64 %152, 1
  store i64 %153, ptr %4, align 8, !tbaa !8
  br label %145, !llvm.loop !16

154:                                              ; preds = %145
  br label %155

155:                                              ; preds = %167, %154
  %156 = load i64, ptr %5, align 8, !tbaa !8
  %157 = load i64, ptr @N, align 8, !tbaa !8
  %158 = icmp slt i64 %156, %157
  br i1 %158, label %159, label %165

159:                                              ; preds = %155
  %160 = load i64, ptr %4, align 8, !tbaa !8
  %161 = load i64, ptr %5, align 8, !tbaa !8
  %162 = call noundef i64 @_Z2osxx(i64 noundef %160, i64 noundef %161)
  %163 = load i64, ptr @K, align 8, !tbaa !8
  %164 = icmp eq i64 %162, %163
  br label %165

165:                                              ; preds = %159, %155
  %166 = phi i1 [ false, %155 ], [ %164, %159 ]
  br i1 %166, label %167, label %170

167:                                              ; preds = %165
  %168 = load i64, ptr %5, align 8, !tbaa !8
  %169 = add nsw i64 %168, 1
  store i64 %169, ptr %5, align 8, !tbaa !8
  br label %155, !llvm.loop !17

170:                                              ; preds = %165
  %171 = load i64, ptr %5, align 8, !tbaa !8
  %172 = add nsw i64 %171, -1
  store i64 %172, ptr %5, align 8, !tbaa !8
  %173 = load i64, ptr %4, align 8, !tbaa !8
  %174 = load i64, ptr %5, align 8, !tbaa !8
  %175 = call noundef i64 @_Z2osxx(i64 noundef %173, i64 noundef %174)
  %176 = load i64, ptr @K, align 8, !tbaa !8
  %177 = icmp ne i64 %175, %176
  br i1 %177, label %178, label %179

178:                                              ; preds = %170
  br label %180

179:                                              ; preds = %170
  br label %96, !llvm.loop !18

180:                                              ; preds = %178, %143, %96
  %181 = load i64, ptr %7, align 8, !tbaa !8
  %182 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %181)
  %183 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %182, i8 noundef signext 10)
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %6) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  br label %184

184:                                              ; preds = %180, %74
  %185 = load i32, ptr %1, align 4
  ret i32 %185
}

; Function Attrs: mustprogress nounwind uwtable
declare noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264), ptr noundef) #1 align 2

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) #3

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(32)) #3

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

; Function Attrs: mustprogress nounwind uwtable
declare noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32), i64 noundef) #1 align 2

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) #5

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #2 = { 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 #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 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 = { 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 #6 = { 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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long long", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = !{!10, !10, i64 0}
!14 = distinct !{!14, !12}
!15 = distinct !{!15, !12}
!16 = distinct !{!16, !12}
!17 = distinct !{!17, !12}
!18 = distinct !{!18, !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::__cxx11::basic_string" = type { %"struct.std::__cxx11::basic_string<char>::_Alloc_hider", i64, %union.anon }
%"struct.std::__cxx11::basic_string<char>::_Alloc_hider" = type { ptr }
%union.anon = type { i64, [8 x i8] }
%"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
@fact = external dso_local local_unnamed_addr global [5005 x i64], align 16
@pfx = external dso_local local_unnamed_addr global [5000 x i64], align 16
@_Z1SB5cxx11 = external dso_local global %"class.std::__cxx11::basic_string", align 8
@_ZSt3cin = external global %"class.std::basic_istream", align 8
@_ZSt4cout = external global %"class.std::basic_ostream", align 8

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #1 {
  %1 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !5
  %2 = getelementptr i8, ptr %1, i64 -24
  %3 = load i64, ptr %2, align 8
  %4 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %3
  %5 = tail call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %4, ptr noundef null)
  %6 = tail call noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext false)
  store i64 1, ptr @fact, align 16, !tbaa !8
  %7 = load i64, ptr @MOD, align 8, !tbaa !8
  br label %21

8:                                                ; preds = %21
  %9 = 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)
  %10 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) %9, ptr noundef nonnull align 8 dereferenceable(8) @K)
  %11 = tail call noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE(ptr noundef nonnull align 8 dereferenceable(16) %10, ptr noundef nonnull align 8 dereferenceable(32) @_Z1SB5cxx11)
  %12 = load i64, ptr @N, align 8, !tbaa !8
  %13 = icmp sgt i64 %12, 0
  br i1 %13, label %14, label %._crit_edge

14:                                               ; preds = %8
  %15 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1SB5cxx11, i64 noundef 0)
  %16 = load i8, ptr %15, align 1, !tbaa !11
  %17 = sext i8 %16 to i64
  %18 = add nsw i64 %17, -48
  store i64 %18, ptr @pfx, align 16, !tbaa !8
  %19 = load i64, ptr @N, align 8, !tbaa !8
  %20 = icmp sgt i64 %19, 1
  br i1 %20, label %.lr.ph.peel.next, label %._crit_edge

21:                                               ; preds = %21, %0
  %22 = phi i64 [ 1, %0 ], [ %32, %21 ]
  %.05362 = phi i64 [ 1, %0 ], [ %34, %21 ]
  %23 = mul nsw i64 %22, %.05362
  %24 = srem i64 %23, %7
  %25 = getelementptr inbounds [5005 x i64], ptr @fact, i64 0, i64 %.05362
  store i64 %24, ptr %25, align 8, !tbaa !8
  %26 = add nuw nsw i64 %.05362, 1
  %27 = mul nsw i64 %24, %26
  %28 = srem i64 %27, %7
  %29 = getelementptr inbounds [5005 x i64], ptr @fact, i64 0, i64 %26
  store i64 %28, ptr %29, align 8, !tbaa !8
  %30 = add nuw nsw i64 %.05362, 2
  %31 = mul nsw i64 %28, %30
  %32 = srem i64 %31, %7
  %33 = getelementptr inbounds [5005 x i64], ptr @fact, i64 0, i64 %30
  store i64 %32, ptr %33, align 8, !tbaa !8
  %34 = add nuw nsw i64 %.05362, 3
  %exitcond.not.2 = icmp eq i64 %34, 5005
  br i1 %exitcond.not.2, label %8, label %21, !llvm.loop !12

._crit_edge:                                      ; preds = %.lr.ph.peel.next, %14, %8
  %.lcssa = phi i64 [ %12, %8 ], [ %19, %14 ], [ %53, %.lr.ph.peel.next ]
  %35 = load i64, ptr @K, align 8, !tbaa !8
  %36 = add nsw i64 %.lcssa, -1
  %37 = tail call noundef i64 @_Z2osxx(i64 noundef 0, i64 noundef %36)
  %38 = icmp sgt i64 %35, %37
  %39 = load i64, ptr @K, align 8
  %40 = icmp eq i64 %39, 0
  %or.cond = select i1 %38, i1 true, i1 %40
  br i1 %or.cond, label %55, label %.preheader61

.preheader61:                                     ; preds = %._crit_edge
  %41 = load i64, ptr @N, align 8, !tbaa !8
  %42 = icmp sgt i64 %41, 0
  br i1 %42, label %.lr.ph65, label %.critedge.preheader

.lr.ph.peel.next:                                 ; preds = %14, %.lr.ph.peel.next
  %.05263 = phi i64 [ %52, %.lr.ph.peel.next ], [ 1, %14 ]
  %43 = tail call noundef nonnull align 1 dereferenceable(1) ptr @_ZNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEixEm(ptr noundef nonnull align 8 dereferenceable(32) @_Z1SB5cxx11, i64 noundef %.05263)
  %44 = load i8, ptr %43, align 1, !tbaa !11
  %45 = sext i8 %44 to i64
  %46 = add nsw i64 %45, -48
  %47 = getelementptr inbounds [5000 x i64], ptr @pfx, i64 0, i64 %.05263
  %48 = add nsw i64 %.05263, -1
  %49 = getelementptr inbounds [5000 x i64], ptr @pfx, i64 0, i64 %48
  %50 = load i64, ptr %49, align 8, !tbaa !8
  %51 = add nsw i64 %50, %46
  store i64 %51, ptr %47, align 8, !tbaa !8
  %52 = add nuw nsw i64 %.05263, 1
  %53 = load i64, ptr @N, align 8, !tbaa !8
  %54 = icmp slt i64 %52, %53
  br i1 %54, label %.lr.ph.peel.next, label %._crit_edge, !llvm.loop !14

55:                                               ; preds = %._crit_edge
  %56 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEi(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i32 noundef 1)
  br label %106

.lr.ph65:                                         ; preds = %.preheader61, %59
  %.04764 = phi i64 [ %60, %59 ], [ 0, %.preheader61 ]
  %57 = tail call noundef i64 @_Z2osxx(i64 noundef 0, i64 noundef %.04764)
  %58 = load i64, ptr @K, align 8, !tbaa !8
  %.not = icmp sgt i64 %57, %58
  br i1 %.not, label %.critedge.loopexit, label %59

59:                                               ; preds = %.lr.ph65
  %60 = add nuw nsw i64 %.04764, 1
  %61 = load i64, ptr @N, align 8, !tbaa !8
  %62 = icmp slt i64 %60, %61
  br i1 %62, label %.lr.ph65, label %.critedge.loopexit, !llvm.loop !16

.critedge.loopexit:                               ; preds = %59, %.lr.ph65
  %.047.lcssa.ph = phi i64 [ %.04764, %.lr.ph65 ], [ %60, %59 ]
  %63 = add nsw i64 %.047.lcssa.ph, -1
  br label %.critedge.preheader

.critedge.preheader:                              ; preds = %.critedge.loopexit, %.preheader61
  %.148.ph = phi i64 [ -1, %.preheader61 ], [ %63, %.critedge.loopexit ]
  br label %.critedge

.critedge:                                        ; preds = %.critedge.preheader, %.critedge3
  %.050 = phi i64 [ %.151, %.critedge3 ], [ 0, %.critedge.preheader ]
  %.148 = phi i64 [ %101, %.critedge3 ], [ %.148.ph, %.critedge.preheader ]
  %.046 = phi i64 [ %.148, %.critedge3 ], [ -1, %.critedge.preheader ]
  %.0 = phi i64 [ %.1, %.critedge3 ], [ 0, %.critedge.preheader ]
  %64 = load i64, ptr @N, align 8, !tbaa !8
  %65 = icmp slt i64 %.148, %64
  br i1 %65, label %66, label %104

66:                                               ; preds = %.critedge
  %67 = tail call noundef i64 @_Z1wxx(i64 noundef %.050, i64 noundef %.148)
  %68 = add nsw i64 %67, %.0
  %69 = load i64, ptr @MOD, align 8, !tbaa !8
  %70 = srem i64 %68, %69
  %.not56 = icmp slt i64 %.046, %.050
  br i1 %.not56, label %78, label %71

71:                                               ; preds = %66
  %72 = tail call noundef i64 @_Z1wxx(i64 noundef %.050, i64 noundef %.046)
  %73 = sub nsw i64 %70, %72
  %74 = load i64, ptr @MOD, align 8, !tbaa !8
  %75 = srem i64 %73, %74
  %76 = add nsw i64 %75, %74
  %77 = srem i64 %76, %74
  br label %84

78:                                               ; preds = %66
  %.not57 = icmp eq i64 %.046, -1
  br i1 %.not57, label %84, label %79

79:                                               ; preds = %78
  %80 = add nsw i64 %70, -1
  %81 = srem i64 %80, %69
  %82 = add nsw i64 %81, %69
  %83 = srem i64 %82, %69
  br label %84

84:                                               ; preds = %78, %79, %71
  %.1 = phi i64 [ %77, %71 ], [ %83, %79 ], [ %70, %78 ]
  %85 = add nsw i64 %.148, 1
  %86 = load i64, ptr @N, align 8, !tbaa !8
  %87 = icmp eq i64 %85, %86
  br i1 %87, label %104, label %.preheader60

.preheader60:                                     ; preds = %84, %.preheader60
  %.151 = phi i64 [ %91, %.preheader60 ], [ %.050, %84 ]
  %88 = tail call noundef i64 @_Z2osxx(i64 noundef %.151, i64 noundef %85)
  %89 = load i64, ptr @K, align 8, !tbaa !8
  %90 = icmp sgt i64 %88, %89
  %91 = add nsw i64 %.151, 1
  br i1 %90, label %.preheader60, label %.preheader, !llvm.loop !17

.preheader:                                       ; preds = %.preheader60
  %92 = load i64, ptr @N, align 8, !tbaa !8
  %93 = icmp slt i64 %85, %92
  br i1 %93, label %.lr.ph70, label %.critedge3

.lr.ph70:                                         ; preds = %.preheader, %97
  %.24969 = phi i64 [ %98, %97 ], [ %85, %.preheader ]
  %94 = tail call noundef i64 @_Z2osxx(i64 noundef %.151, i64 noundef %.24969)
  %95 = load i64, ptr @K, align 8, !tbaa !8
  %96 = icmp eq i64 %94, %95
  br i1 %96, label %97, label %.critedge3

97:                                               ; preds = %.lr.ph70
  %98 = add nsw i64 %.24969, 1
  %99 = load i64, ptr @N, align 8, !tbaa !8
  %100 = icmp slt i64 %98, %99
  br i1 %100, label %.lr.ph70, label %.critedge3, !llvm.loop !18

.critedge3:                                       ; preds = %.lr.ph70, %97, %.preheader
  %.249.lcssa = phi i64 [ %85, %.preheader ], [ %98, %97 ], [ %.24969, %.lr.ph70 ]
  %101 = add nsw i64 %.249.lcssa, -1
  %102 = tail call noundef i64 @_Z2osxx(i64 noundef %.151, i64 noundef %101)
  %103 = load i64, ptr @K, align 8, !tbaa !8
  %.not58 = icmp eq i64 %102, %103
  br i1 %.not58, label %.critedge, label %104, !llvm.loop !19

104:                                              ; preds = %.critedge3, %84, %.critedge
  %.2 = phi i64 [ %.1, %84 ], [ %.1, %.critedge3 ], [ %.0, %.critedge ]
  %105 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %.2)
  br label %106

106:                                              ; preds = %104, %55
  %.sink = phi ptr [ %105, %104 ], [ %56, %55 ]
  %107 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %.sink, i8 noundef signext 10)
  ret i32 0
}

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

declare noundef zeroext i1 @_ZNSt8ios_base15sync_with_stdioEb(i1 noundef zeroext) local_unnamed_addr #2

declare noundef nonnull align 8 dereferenceable(16) ptr @_ZStrsIcSt11char_traitsIcESaIcEERSt13basic_istreamIT_T0_ES7_RNSt7__cxx1112basic_stringIS4_S5_T1_EE(ptr noundef nonnull align 8 dereferenceable(16), ptr noundef nonnull align 8 dereferenceable(32)) local_unnamed_addr #2

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

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

; Function Attrs: inlinehint mustprogress uwtable
declare noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8), i8 noundef signext) local_unnamed_addr #4

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 #3 align 2

attributes #0 = { 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 #1 = { 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 #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 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 = { 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" }

!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 = !{!"vtable pointer", !7, i64 0}
!7 = !{!"Simple C++ TBAA"}
!8 = !{!9, !9, i64 0}
!9 = !{!"long long", !10, i64 0}
!10 = !{!"omnipotent char", !7, i64 0}
!11 = !{!10, !10, i64 0}
!12 = distinct !{!12, !13}
!13 = !{!"llvm.loop.mustprogress"}
!14 = distinct !{!14, !13, !15}
!15 = !{!"llvm.loop.peeled.count", i32 1}
!16 = distinct !{!16, !13}
!17 = distinct !{!17, !13}
!18 = distinct !{!18, !13}
!19 = distinct !{!19, !13}


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