; LLVM IR from eyangch/competitive-programming :: Codeforces/1696 (e)

; 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
@fact = external dso_local global [500000 x i64], align 16
@N = external dso_local global i64, align 8
@a = external dso_local global [200001 x i64], align 16
@_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 @_Z3nCrxx(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 i32, align 4
  %7 = alloca i64, align 8
  %8 = alloca i64, align 8
  store i32 0, ptr %1, align 4
  %9 = load ptr, ptr @_ZSt3cin, align 8, !tbaa !5
  %10 = getelementptr i8, ptr %9, i64 -24
  %11 = load i64, ptr %10, align 8
  %12 = getelementptr inbounds i8, ptr @_ZSt3cin, i64 %11
  %13 = call noundef ptr @_ZNSt9basic_iosIcSt11char_traitsIcEE3tieEPSo(ptr noundef nonnull align 8 dereferenceable(264) %12, ptr noundef null)
  %14 = 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 %15

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

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

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

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

33:                                               ; preds = %18
  %34 = 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)
  call void @llvm.lifetime.start.p0(i64 8, ptr %3) #6
  store i64 0, ptr %3, align 8, !tbaa !8
  br label %35

35:                                               ; preds = %45, %33
  %36 = load i64, ptr %3, align 8, !tbaa !8
  %37 = load i64, ptr @N, align 8, !tbaa !8
  %38 = add nsw i64 %37, 1
  %39 = icmp slt i64 %36, %38
  br i1 %39, label %41, label %40

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

41:                                               ; preds = %35
  %42 = load i64, ptr %3, align 8, !tbaa !8
  %43 = getelementptr inbounds [200001 x i64], ptr @a, i64 0, i64 %42
  %44 = call noundef nonnull align 8 dereferenceable(16) ptr @_ZNSirsERx(ptr noundef nonnull align 8 dereferenceable(16) @_ZSt3cin, ptr noundef nonnull align 8 dereferenceable(8) %43)
  br label %45

45:                                               ; preds = %41
  %46 = load i64, ptr %3, align 8, !tbaa !8
  %47 = add nsw i64 %46, 1
  store i64 %47, ptr %3, align 8, !tbaa !8
  br label %35, !llvm.loop !13

48:                                               ; preds = %40
  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
  br label %49

49:                                               ; preds = %77, %48
  %50 = load i64, ptr %5, align 8, !tbaa !8
  %51 = load i64, ptr @N, align 8, !tbaa !8
  %52 = icmp sle i64 %50, %51
  br i1 %52, label %54, label %53

53:                                               ; preds = %49
  store i32 8, ptr %6, align 4
  br label %80

54:                                               ; preds = %49
  %55 = load i64, ptr %5, align 8, !tbaa !8
  %56 = getelementptr inbounds [200001 x i64], ptr @a, i64 0, i64 %55
  %57 = load i64, ptr %56, align 8, !tbaa !8
  %58 = icmp eq i64 %57, 0
  br i1 %58, label %59, label %60

59:                                               ; preds = %54
  store i32 8, ptr %6, align 4
  br label %80

60:                                               ; preds = %54
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #6
  %61 = load i64, ptr %5, align 8, !tbaa !8
  store i64 %61, ptr %7, align 8, !tbaa !8
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #6
  %62 = load i64, ptr %5, align 8, !tbaa !8
  %63 = getelementptr inbounds [200001 x i64], ptr @a, i64 0, i64 %62
  %64 = load i64, ptr %63, align 8, !tbaa !8
  %65 = sub nsw i64 %64, 1
  store i64 %65, ptr %8, align 8, !tbaa !8
  %66 = load i64, ptr %4, align 8, !tbaa !8
  %67 = load i64, ptr %7, align 8, !tbaa !8
  %68 = load i64, ptr %8, align 8, !tbaa !8
  %69 = add nsw i64 %67, %68
  %70 = add nsw i64 %69, 1
  %71 = load i64, ptr %5, align 8, !tbaa !8
  %72 = add nsw i64 %71, 1
  %73 = call noundef i64 @_Z3nCrxx(i64 noundef %70, i64 noundef %72)
  %74 = add nsw i64 %66, %73
  %75 = load i64, ptr @MOD, align 8, !tbaa !8
  %76 = srem i64 %74, %75
  store i64 %76, ptr %4, align 8, !tbaa !8
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #6
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #6
  br label %77

77:                                               ; preds = %60
  %78 = load i64, ptr %5, align 8, !tbaa !8
  %79 = add nsw i64 %78, 1
  store i64 %79, ptr %5, align 8, !tbaa !8
  br label %49, !llvm.loop !14

80:                                               ; preds = %59, %53
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #6
  br label %81

81:                                               ; preds = %80
  %82 = load i64, ptr %4, align 8, !tbaa !8
  %83 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %82)
  %84 = call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %83, i8 noundef signext 10)
  call void @llvm.lifetime.end.p0(i64 8, ptr %4) #6
  %85 = load i32, ptr %1, align 4
  ret i32 %85
}

; 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

; 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: 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

; 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 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


; Optimized IR (opt -passes='default<O3>'):
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

%"class.std::basic_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
@fact = external dso_local local_unnamed_addr global [500000 x i64], align 16
@N = external dso_local global i64, align 8
@a = external dso_local global [200001 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 nounwind uwtable
declare dso_local noundef i64 @_Z3nCrxx(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 %11

8:                                                ; preds = %11
  %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 = load i64, ptr @N, align 8, !tbaa !8
  %.not25 = icmp slt i64 %10, 0
  br i1 %.not25, label %._crit_edge, label %.lr.ph

11:                                               ; preds = %17, %0
  %12 = phi i64 [ 1, %0 ], [ %19, %17 ]
  %.024 = phi i64 [ 1, %0 ], [ %21, %17 ]
  %13 = mul nsw i64 %12, %.024
  %14 = srem i64 %13, %7
  %15 = getelementptr inbounds [500000 x i64], ptr @fact, i64 0, i64 %.024
  store i64 %14, ptr %15, align 8, !tbaa !8
  %16 = add nuw nsw i64 %.024, 1
  %exitcond.not = icmp eq i64 %16, 500000
  br i1 %exitcond.not, label %8, label %17, !llvm.loop !11

17:                                               ; preds = %11
  %18 = mul nsw i64 %14, %16
  %19 = srem i64 %18, %7
  %20 = getelementptr inbounds [500000 x i64], ptr @fact, i64 0, i64 %16
  store i64 %19, ptr %20, align 8, !tbaa !8
  %21 = add nuw nsw i64 %.024, 2
  br label %11

.preheader:                                       ; preds = %.lr.ph
  %22 = icmp slt i64 %26, 0
  br i1 %22, label %._crit_edge, label %.lr.ph30

.lr.ph:                                           ; preds = %8, %.lr.ph
  %.01926 = phi i64 [ %25, %.lr.ph ], [ 0, %8 ]
  %23 = getelementptr inbounds [200001 x i64], ptr @a, i64 0, i64 %.01926
  %24 = 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) %23)
  %25 = add nuw nsw i64 %.01926, 1
  %26 = load i64, ptr @N, align 8, !tbaa !8
  %.not.not = icmp slt i64 %.01926, %26
  br i1 %.not.not, label %.lr.ph, label %.preheader, !llvm.loop !13

.lr.ph30:                                         ; preds = %.preheader, %30
  %.02029 = phi i64 [ %32, %30 ], [ 0, %.preheader ]
  %.02128 = phi i64 [ %36, %30 ], [ 0, %.preheader ]
  %27 = getelementptr inbounds [200001 x i64], ptr @a, i64 0, i64 %.02029
  %28 = load i64, ptr %27, align 8, !tbaa !8
  %29 = icmp eq i64 %28, 0
  br i1 %29, label %._crit_edge, label %30

30:                                               ; preds = %.lr.ph30
  %31 = add i64 %28, %.02029
  %32 = add nuw nsw i64 %.02029, 1
  %33 = tail call noundef i64 @_Z3nCrxx(i64 noundef %31, i64 noundef %32)
  %34 = add nsw i64 %33, %.02128
  %35 = load i64, ptr @MOD, align 8, !tbaa !8
  %36 = srem i64 %34, %35
  %37 = load i64, ptr @N, align 8, !tbaa !8
  %.not23.not = icmp slt i64 %.02029, %37
  br i1 %.not23.not, label %.lr.ph30, label %._crit_edge, !llvm.loop !14

._crit_edge:                                      ; preds = %30, %.lr.ph30, %8, %.preheader
  %.021.lcssa = phi i64 [ 0, %.preheader ], [ 0, %8 ], [ %.02128, %.lr.ph30 ], [ %36, %30 ]
  %38 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZNSolsEx(ptr noundef nonnull align 8 dereferenceable(8) @_ZSt4cout, i64 noundef %.021.lcssa)
  %39 = tail call noundef nonnull align 8 dereferenceable(8) ptr @_ZStlsISt11char_traitsIcEERSt13basic_ostreamIcT_ES5_c(ptr noundef nonnull align 8 dereferenceable(8) %38, 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

; 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: 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

; 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 = distinct !{!11, !12}
!12 = !{!"llvm.loop.mustprogress"}
!13 = distinct !{!13, !12}
!14 = distinct !{!14, !12}


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