; LLVM IR from VastoLorde95/Competitive-Programming :: Codeforces/232 Division 1/Problem A (A)

; 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::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"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" }
%"struct.std::_Rb_tree_iterator" = type { ptr }
%"struct.std::pair" = type { i32, i32 }

@n = external dso_local global i32, align 4
@a = external dso_local global [1000 x i32], align 16
@fact = external dso_local global [30001 x i64], align 16
@MOD = external dso_local global i64, align 8
@res = external dso_local global i64, align 8
@c = external dso_local global %"class.std::map", 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 @_Z3invx(i64 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: mustprogress norecurse uwtable
define dso_local noundef i32 @main() #2 {
  %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 %"struct.std::_Rb_tree_iterator", align 8
  %8 = alloca %"struct.std::_Rb_tree_iterator", align 8
  %9 = alloca i32, align 4
  %10 = alloca %"struct.std::_Rb_tree_iterator", align 8
  store i32 0, ptr %1, align 4
  store i64 1, ptr @fact, align 16, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %2) #6
  store i32 1, ptr %2, align 4, !tbaa !9
  br label %11

11:                                               ; preds = %29, %0
  %12 = load i32, ptr %2, align 4, !tbaa !9
  %13 = icmp sle i32 %12, 30000
  br i1 %13, label %15, label %14

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

15:                                               ; preds = %11
  %16 = load i32, ptr %2, align 4, !tbaa !9
  %17 = sub nsw i32 %16, 1
  %18 = sext i32 %17 to i64
  %19 = getelementptr inbounds [30001 x i64], ptr @fact, i64 0, i64 %18
  %20 = load i64, ptr %19, align 8, !tbaa !5
  %21 = load i32, ptr %2, align 4, !tbaa !9
  %22 = sext i32 %21 to i64
  %23 = mul nsw i64 %20, %22
  %24 = load i64, ptr @MOD, align 8, !tbaa !5
  %25 = srem i64 %23, %24
  %26 = load i32, ptr %2, align 4, !tbaa !9
  %27 = sext i32 %26 to i64
  %28 = getelementptr inbounds [30001 x i64], ptr @fact, i64 0, i64 %27
  store i64 %25, ptr %28, align 8, !tbaa !5
  br label %29

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

32:                                               ; preds = %14
  %33 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) @n)
  call void @llvm.lifetime.start.p0(i64 4, ptr %3) #6
  store i32 0, ptr %3, align 4, !tbaa !9
  br label %34

34:                                               ; preds = %80, %32
  %35 = load i32, ptr %3, align 4, !tbaa !9
  %36 = load i32, ptr @n, align 4, !tbaa !9
  %37 = icmp slt i32 %35, %36
  br i1 %37, label %39, label %38

38:                                               ; preds = %34
  store i32 5, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %3) #6
  br label %83

39:                                               ; preds = %34
  %40 = load i32, ptr %3, align 4, !tbaa !9
  %41 = sext i32 %40 to i64
  %42 = getelementptr inbounds [1000 x i32], ptr @a, i64 0, i64 %41
  %43 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %42)
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #6
  %44 = load i32, ptr %3, align 4, !tbaa !9
  %45 = sext i32 %44 to i64
  %46 = getelementptr inbounds [1000 x i32], ptr @a, i64 0, i64 %45
  %47 = load i32, ptr %46, align 4, !tbaa !9
  store i32 %47, ptr %5, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #6
  store i32 2, ptr %6, align 4, !tbaa !9
  br label %48

48:                                               ; preds = %69, %39
  %49 = load i32, ptr %6, align 4, !tbaa !9
  %50 = load i32, ptr %6, align 4, !tbaa !9
  %51 = mul nsw i32 %49, %50
  %52 = load i32, ptr %5, align 4, !tbaa !9
  %53 = icmp sle i32 %51, %52
  br i1 %53, label %55, label %54

54:                                               ; preds = %48
  store i32 8, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #6
  br label %72

55:                                               ; preds = %48
  br label %56

56:                                               ; preds = %61, %55
  %57 = load i32, ptr %5, align 4, !tbaa !9
  %58 = load i32, ptr %6, align 4, !tbaa !9
  %59 = srem i32 %57, %58
  %60 = icmp eq i32 %59, 0
  br i1 %60, label %61, label %68

61:                                               ; preds = %56
  %62 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @c, ptr noundef nonnull align 4 dereferenceable(4) %6)
  %63 = load i32, ptr %62, align 4, !tbaa !9
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %62, align 4, !tbaa !9
  %65 = load i32, ptr %6, align 4, !tbaa !9
  %66 = load i32, ptr %5, align 4, !tbaa !9
  %67 = sdiv i32 %66, %65
  store i32 %67, ptr %5, align 4, !tbaa !9
  br label %56, !llvm.loop !13

68:                                               ; preds = %56
  br label %69

69:                                               ; preds = %68
  %70 = load i32, ptr %6, align 4, !tbaa !9
  %71 = add nsw i32 %70, 1
  store i32 %71, ptr %6, align 4, !tbaa !9
  br label %48, !llvm.loop !14

72:                                               ; preds = %54
  %73 = load i32, ptr %5, align 4, !tbaa !9
  %74 = icmp sgt i32 %73, 1
  br i1 %74, label %75, label %79

75:                                               ; preds = %72
  %76 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @c, ptr noundef nonnull align 4 dereferenceable(4) %5)
  %77 = load i32, ptr %76, align 4, !tbaa !9
  %78 = add nsw i32 %77, 1
  store i32 %78, ptr %76, align 4, !tbaa !9
  br label %79

79:                                               ; preds = %75, %72
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #6
  br label %80

80:                                               ; preds = %79
  %81 = load i32, ptr %3, align 4, !tbaa !9
  %82 = add nsw i32 %81, 1
  store i32 %82, ptr %3, align 4, !tbaa !9
  br label %34, !llvm.loop !15

83:                                               ; preds = %38
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %84 = call ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48) @c) #6
  %85 = getelementptr inbounds %"struct.std::_Rb_tree_iterator", ptr %7, i32 0, i32 0
  store ptr %84, ptr %85, align 8
  br label %86

86:                                               ; preds = %124, %83
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %87 = call ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEE3endEv(ptr noundef nonnull align 8 dereferenceable(48) @c) #6
  %88 = getelementptr inbounds %"struct.std::_Rb_tree_iterator", ptr %8, i32 0, i32 0
  store ptr %87, ptr %88, align 8
  %89 = call noundef zeroext i1 @_ZStneRKSt17_Rb_tree_iteratorISt4pairIKiiEES5_(ptr noundef nonnull align 8 dereferenceable(8) %7, ptr noundef nonnull align 8 dereferenceable(8) %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  br i1 %89, label %91, label %90

90:                                               ; preds = %86
  store i32 13, ptr %4, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  br label %127

91:                                               ; preds = %86
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #6
  %92 = call noundef ptr @_ZNKSt17_Rb_tree_iteratorISt4pairIKiiEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %7) #6
  %93 = getelementptr inbounds %"struct.std::pair", ptr %92, i32 0, i32 1
  %94 = load i32, ptr %93, align 4, !tbaa !16
  store i32 %94, ptr %9, align 4, !tbaa !9
  %95 = load i64, ptr @res, align 8, !tbaa !5
  %96 = load i32, ptr %9, align 4, !tbaa !9
  %97 = load i32, ptr @n, align 4, !tbaa !9
  %98 = add nsw i32 %96, %97
  %99 = sub nsw i32 %98, 1
  %100 = sext i32 %99 to i64
  %101 = getelementptr inbounds [30001 x i64], ptr @fact, i64 0, i64 %100
  %102 = load i64, ptr %101, align 8, !tbaa !5
  %103 = mul nsw i64 %95, %102
  %104 = load i64, ptr @MOD, align 8, !tbaa !5
  %105 = srem i64 %103, %104
  store i64 %105, ptr @res, align 8, !tbaa !5
  %106 = load i64, ptr @res, align 8, !tbaa !5
  %107 = load i32, ptr %9, align 4, !tbaa !9
  %108 = sext i32 %107 to i64
  %109 = getelementptr inbounds [30001 x i64], ptr @fact, i64 0, i64 %108
  %110 = load i64, ptr %109, align 8, !tbaa !5
  %111 = call noundef i64 @_Z3invx(i64 noundef %110)
  %112 = mul nsw i64 %106, %111
  %113 = load i64, ptr @MOD, align 8, !tbaa !5
  %114 = srem i64 %112, %113
  %115 = load i32, ptr @n, align 4, !tbaa !9
  %116 = sub nsw i32 %115, 1
  %117 = sext i32 %116 to i64
  %118 = getelementptr inbounds [30001 x i64], ptr @fact, i64 0, i64 %117
  %119 = load i64, ptr %118, align 8, !tbaa !5
  %120 = call noundef i64 @_Z3invx(i64 noundef %119)
  %121 = mul nsw i64 %114, %120
  %122 = load i64, ptr @MOD, align 8, !tbaa !5
  %123 = srem i64 %121, %122
  store i64 %123, ptr @res, align 8, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #6
  br label %124

124:                                              ; preds = %91
  %125 = call ptr @_ZNSt17_Rb_tree_iteratorISt4pairIKiiEEppEi(ptr noundef nonnull align 8 dereferenceable(8) %7, i32 noundef 0) #6
  %126 = getelementptr inbounds %"struct.std::_Rb_tree_iterator", ptr %10, i32 0, i32 0
  store ptr %125, ptr %126, align 8
  br label %86, !llvm.loop !18

127:                                              ; preds = %90
  %128 = load i64, ptr @res, align 8, !tbaa !5
  %129 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %128)
  %130 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %129, ptr noundef @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0
}

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: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) #4 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZStneRKSt17_Rb_tree_iteratorISt4pairIKiiEES5_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEE3endEv(ptr noundef nonnull align 8 dereferenceable(48)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef ptr @_ZNKSt17_Rb_tree_iteratorISt4pairIKiiEEptEv(ptr noundef nonnull align 8 dereferenceable(8)) #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt17_Rb_tree_iteratorISt4pairIKiiEEppEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) #0 align 2

; 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

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

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 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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 = !{!17, !10, i64 4}
!17 = !{!"_ZTSSt4pairIKiiE", !10, i64 0, !10, i64 4}
!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::map" = type { %"class.std::_Rb_tree" }
%"class.std::_Rb_tree" = type { %"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<int, std::pair<const int, int>, std::_Select1st<std::pair<const int, int>>, std::less<int>>::_Rb_tree_impl" = type { [8 x i8], %"struct.std::_Rb_tree_header" }
%"struct.std::_Rb_tree_header" = type { %"struct.std::_Rb_tree_node_base", i64 }
%"struct.std::_Rb_tree_node_base" = type { i32, ptr, ptr, ptr }
%"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" }
%"struct.std::_Rb_tree_iterator" = type { ptr }

@n = external dso_local global i32, align 4
@a = external dso_local global [1000 x i32], align 16
@fact = external dso_local local_unnamed_addr global [30001 x i64], align 16
@MOD = external dso_local local_unnamed_addr global i64, align 8
@res = external dso_local local_unnamed_addr global i64, align 8
@c = external dso_local global %"class.std::map", 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 @_Z3invx(i64 noundef) local_unnamed_addr #0

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

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

; Function Attrs: mustprogress norecurse uwtable
define dso_local noundef i32 @main() local_unnamed_addr #2 {
  %1 = alloca i32, align 4
  %2 = alloca i32, align 4
  %3 = alloca %"struct.std::_Rb_tree_iterator", align 8
  %4 = alloca %"struct.std::_Rb_tree_iterator", align 8
  store i64 1, ptr @fact, align 16, !tbaa !5
  %5 = load i64, ptr @MOD, align 8, !tbaa !5
  br label %10

6:                                                ; preds = %10
  %7 = 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) @n)
  %8 = load i32, ptr @n, align 4, !tbaa !9
  %9 = icmp sgt i32 %8, 0
  br i1 %9, label %.lr.ph19, label %._crit_edge20

10:                                               ; preds = %10, %0
  %11 = phi i64 [ 1, %0 ], [ %19, %10 ]
  %indvars.iv = phi i64 [ 1, %0 ], [ %indvars.iv.next.2, %10 ]
  %12 = mul nsw i64 %11, %indvars.iv
  %13 = srem i64 %12, %5
  %14 = getelementptr inbounds [30001 x i64], ptr @fact, i64 0, i64 %indvars.iv
  store i64 %13, ptr %14, align 8, !tbaa !5
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %15 = mul nsw i64 %13, %indvars.iv.next
  %16 = srem i64 %15, %5
  %17 = getelementptr inbounds [30001 x i64], ptr @fact, i64 0, i64 %indvars.iv.next
  store i64 %16, ptr %17, align 8, !tbaa !5
  %indvars.iv.next.1 = add nuw nsw i64 %indvars.iv, 2
  %18 = mul nsw i64 %16, %indvars.iv.next.1
  %19 = srem i64 %18, %5
  %20 = getelementptr inbounds [30001 x i64], ptr @fact, i64 0, i64 %indvars.iv.next.1
  store i64 %19, ptr %20, align 8, !tbaa !5
  %indvars.iv.next.2 = add nuw nsw i64 %indvars.iv, 3
  %exitcond.not.2 = icmp eq i64 %indvars.iv.next.2, 30001
  br i1 %exitcond.not.2, label %6, label %10, !llvm.loop !11

._crit_edge20:                                    ; preds = %45, %6
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #6
  %21 = call ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48) @c) #6
  store ptr %21, ptr %3, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #6
  %22 = call ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEE3endEv(ptr noundef nonnull align 8 dereferenceable(48) @c) #6
  store ptr %22, ptr %4, align 8
  %23 = call noundef zeroext i1 @_ZStneRKSt17_Rb_tree_iteratorISt4pairIKiiEES5_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  br i1 %23, label %.lr.ph22, label %._crit_edge23

.lr.ph19:                                         ; preds = %6, %45
  %indvars.iv26 = phi i64 [ %indvars.iv.next27, %45 ], [ 0, %6 ]
  %24 = getelementptr inbounds [1000 x i32], ptr @a, i64 0, i64 %indvars.iv26
  %25 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERi(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 4 dereferenceable(4) %24)
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #6
  %26 = load i32, ptr %24, align 4, !tbaa !9
  store i32 %26, ptr %1, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %2) #6
  store i32 2, ptr %2, align 4, !tbaa !9
  %.not14 = icmp slt i32 %26, 4
  br i1 %.not14, label %._crit_edge15, label %.preheader

.preheader:                                       ; preds = %.lr.ph19, %._crit_edge
  %.pr29 = phi i32 [ %.pr, %._crit_edge ], [ %26, %.lr.ph19 ]
  %27 = phi i32 [ %39, %._crit_edge ], [ 2, %.lr.ph19 ]
  %28 = srem i32 %.pr29, %27
  %29 = icmp eq i32 %28, 0
  br i1 %29, label %.lr.ph, label %._crit_edge

._crit_edge15:                                    ; preds = %._crit_edge, %.lr.ph19
  %.lcssa12 = phi i32 [ %26, %.lr.ph19 ], [ %.pr, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %2) #6
  %30 = icmp sgt i32 %.lcssa12, 1
  br i1 %30, label %41, label %45

.lr.ph:                                           ; preds = %.preheader, %.lr.ph
  %31 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @c, ptr noundef nonnull align 4 dereferenceable(4) %2)
  %32 = load i32, ptr %31, align 4, !tbaa !9
  %33 = add nsw i32 %32, 1
  store i32 %33, ptr %31, align 4, !tbaa !9
  %34 = load i32, ptr %2, align 4, !tbaa !9
  %35 = load i32, ptr %1, align 4, !tbaa !9
  %36 = sdiv i32 %35, %34
  store i32 %36, ptr %1, align 4, !tbaa !9
  %37 = srem i32 %36, %34
  %38 = icmp eq i32 %37, 0
  br i1 %38, label %.lr.ph, label %._crit_edge, !llvm.loop !13

._crit_edge:                                      ; preds = %.lr.ph, %.preheader
  %.pr = phi i32 [ %.pr29, %.preheader ], [ %36, %.lr.ph ]
  %.lcssa = phi i32 [ %27, %.preheader ], [ %34, %.lr.ph ]
  %39 = add nsw i32 %.lcssa, 1
  store i32 %39, ptr %2, align 4, !tbaa !9
  %40 = mul nsw i32 %39, %39
  %.not = icmp sgt i32 %40, %.pr
  br i1 %.not, label %._crit_edge15, label %.preheader, !llvm.loop !14

41:                                               ; preds = %._crit_edge15
  %42 = call noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) @c, ptr noundef nonnull align 4 dereferenceable(4) %1)
  %43 = load i32, ptr %42, align 4, !tbaa !9
  %44 = add nsw i32 %43, 1
  store i32 %44, ptr %42, align 4, !tbaa !9
  br label %45

45:                                               ; preds = %41, %._crit_edge15
  call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #6
  %indvars.iv.next27 = add nuw nsw i64 %indvars.iv26, 1
  %46 = load i32, ptr @n, align 4, !tbaa !9
  %47 = sext i32 %46 to i64
  %48 = icmp slt i64 %indvars.iv.next27, %47
  br i1 %48, label %.lr.ph19, label %._crit_edge20, !llvm.loop !15

._crit_edge23:                                    ; preds = %.lr.ph22, %._crit_edge20
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #6
  %49 = load i64, ptr @res, align 8, !tbaa !5
  %50 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %49)
  %51 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEPFRSoS_E(ptr noundef nonnull align 8 dereferenceable(8) %50, ptr noundef nonnull @_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_)
  ret i32 0

.lr.ph22:                                         ; preds = %._crit_edge20, %.lr.ph22
  %52 = call noundef ptr @_ZNKSt17_Rb_tree_iteratorISt4pairIKiiEEptEv(ptr noundef nonnull align 8 dereferenceable(8) %3) #6
  %53 = getelementptr inbounds i8, ptr %52, i64 4
  %54 = load i32, ptr %53, align 4, !tbaa !16
  %55 = load i64, ptr @res, align 8, !tbaa !5
  %56 = load i32, ptr @n, align 4, !tbaa !9
  %57 = add i32 %54, -1
  %58 = add i32 %57, %56
  %59 = sext i32 %58 to i64
  %60 = getelementptr inbounds [30001 x i64], ptr @fact, i64 0, i64 %59
  %61 = load i64, ptr %60, align 8, !tbaa !5
  %62 = mul nsw i64 %61, %55
  %63 = load i64, ptr @MOD, align 8, !tbaa !5
  %64 = srem i64 %62, %63
  store i64 %64, ptr @res, align 8, !tbaa !5
  %65 = sext i32 %54 to i64
  %66 = getelementptr inbounds [30001 x i64], ptr @fact, i64 0, i64 %65
  %67 = load i64, ptr %66, align 8, !tbaa !5
  %68 = call noundef i64 @_Z3invx(i64 noundef %67)
  %69 = mul nsw i64 %68, %64
  %70 = load i64, ptr @MOD, align 8, !tbaa !5
  %71 = srem i64 %69, %70
  %72 = load i32, ptr @n, align 4, !tbaa !9
  %73 = add nsw i32 %72, -1
  %74 = sext i32 %73 to i64
  %75 = getelementptr inbounds [30001 x i64], ptr @fact, i64 0, i64 %74
  %76 = load i64, ptr %75, align 8, !tbaa !5
  %77 = call noundef i64 @_Z3invx(i64 noundef %76)
  %78 = mul nsw i64 %77, %71
  %79 = load i64, ptr @MOD, align 8, !tbaa !5
  %80 = srem i64 %78, %79
  store i64 %80, ptr @res, align 8, !tbaa !5
  %81 = call ptr @_ZNSt17_Rb_tree_iteratorISt4pairIKiiEEppEi(ptr noundef nonnull align 8 dereferenceable(8) %3, i32 noundef 0) #6
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #6
  %82 = call ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEE3endEv(ptr noundef nonnull align 8 dereferenceable(48) @c) #6
  store ptr %82, ptr %4, align 8
  %83 = call noundef zeroext i1 @_ZStneRKSt17_Rb_tree_iteratorISt4pairIKiiEES5_(ptr noundef nonnull align 8 dereferenceable(8) %3, ptr noundef nonnull align 8 dereferenceable(8) %4) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #6
  br i1 %83, label %.lr.ph22, label %._crit_edge23, !llvm.loop !18
}

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

; Function Attrs: mustprogress uwtable
declare dso_local noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48), ptr noundef nonnull align 4 dereferenceable(4)) local_unnamed_addr #4 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEE5beginEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #0 align 2

; Function Attrs: mustprogress nounwind uwtable
declare dso_local noundef zeroext i1 @_ZStneRKSt17_Rb_tree_iteratorISt4pairIKiiEES5_(ptr noundef nonnull align 8 dereferenceable(8), ptr noundef nonnull align 8 dereferenceable(8)) local_unnamed_addr #0

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt3mapIiiSt4lessIiESaISt4pairIKiiEEE3endEv(ptr noundef nonnull align 8 dereferenceable(48)) local_unnamed_addr #0 align 2

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

; Function Attrs: mustprogress nounwind uwtable
declare dso_local ptr @_ZNSt17_Rb_tree_iteratorISt4pairIKiiEEppEi(ptr noundef nonnull align 8 dereferenceable(8), i32 noundef) local_unnamed_addr #0 align 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 #4 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 #4 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)) #5

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 nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = !{!"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 = !{!17, !10, i64 4}
!17 = !{!"_ZTSSt4pairIKiiE", !10, i64 0, !10, i64 4}
!18 = distinct !{!18, !12}


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