; LLVM IR from xirc/cp-algorithm :: atcoder/abc169/D/main.ll (Z19prime_factorizationl)

; 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<long, std::pair<const long, int>, std::_Select1st<std::pair<const long, int>>, std::less<long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long, std::pair<const long, int>, std::_Select1st<std::pair<const long, int>>, std::less<long>>::_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 }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z19prime_factorizationl(ptr dead_on_unwind noalias writable sret(%"class.std::map") align 8 %0, i64 noundef %1) #0 personality ptr @__gxx_personality_v0 {
  %3 = alloca ptr, align 8
  %4 = alloca i64, align 8
  %5 = alloca i64, align 8
  %6 = alloca i1, align 1
  %7 = alloca i64, align 8
  %8 = alloca ptr, align 8
  %9 = alloca i32, align 4
  store ptr %0, ptr %3, align 8
  store i64 %1, ptr %4, align 8, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 8, ptr %5) #3
  %10 = load i64, ptr %4, align 8, !tbaa !5
  store i64 %10, ptr %5, align 8, !tbaa !5
  store i1 false, ptr %6, align 1
  call void @_ZNSt3mapIliSt4lessIlESaISt4pairIKliEEEC2Ev(ptr noundef nonnull align 8 dereferenceable(48) %0) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #3
  store i64 2, ptr %7, align 8, !tbaa !5
  br label %11

11:                                               ; preds = %37, %2
  %12 = load i64, ptr %7, align 8, !tbaa !5
  %13 = load i64, ptr %7, align 8, !tbaa !5
  %14 = mul nsw i64 %12, %13
  %15 = load i64, ptr %4, align 8, !tbaa !5
  %16 = icmp sle i64 %14, %15
  br i1 %16, label %18, label %17

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

18:                                               ; preds = %11
  br label %19

19:                                               ; preds = %26, %18
  %20 = load i64, ptr %5, align 8, !tbaa !5
  %21 = load i64, ptr %7, align 8, !tbaa !5
  %22 = srem i64 %20, %21
  %23 = icmp eq i64 %22, 0
  br i1 %23, label %24, label %36

24:                                               ; preds = %19
  %25 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIliSt4lessIlESaISt4pairIKliEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull align 8 dereferenceable(8) %7)
          to label %26 unwind label %32

26:                                               ; preds = %24
  %27 = load i32, ptr %25, align 4, !tbaa !9
  %28 = add nsw i32 %27, 1
  store i32 %28, ptr %25, align 4, !tbaa !9
  %29 = load i64, ptr %7, align 8, !tbaa !5
  %30 = load i64, ptr %5, align 8, !tbaa !5
  %31 = sdiv i64 %30, %29
  store i64 %31, ptr %5, align 8, !tbaa !5
  br label %19, !llvm.loop !11

32:                                               ; preds = %24
  %33 = landingpad { ptr, i32 }
          cleanup
  %34 = extractvalue { ptr, i32 } %33, 0
  store ptr %34, ptr %8, align 8
  %35 = extractvalue { ptr, i32 } %33, 1
  store i32 %35, ptr %9, align 4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #3
  br label %56

36:                                               ; preds = %19
  br label %37

37:                                               ; preds = %36
  %38 = load i64, ptr %7, align 8, !tbaa !5
  %39 = add nsw i64 %38, 1
  store i64 %39, ptr %7, align 8, !tbaa !5
  br label %11, !llvm.loop !13

40:                                               ; preds = %17
  %41 = load i64, ptr %5, align 8, !tbaa !5
  %42 = icmp sgt i64 %41, 1
  br i1 %42, label %43, label %52

43:                                               ; preds = %40
  %44 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIliSt4lessIlESaISt4pairIKliEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull align 8 dereferenceable(8) %5)
          to label %45 unwind label %48

45:                                               ; preds = %43
  %46 = load i32, ptr %44, align 4, !tbaa !9
  %47 = add nsw i32 %46, 1
  store i32 %47, ptr %44, align 4, !tbaa !9
  br label %52

48:                                               ; preds = %43
  %49 = landingpad { ptr, i32 }
          cleanup
  %50 = extractvalue { ptr, i32 } %49, 0
  store ptr %50, ptr %8, align 8
  %51 = extractvalue { ptr, i32 } %49, 1
  store i32 %51, ptr %9, align 4
  br label %56

52:                                               ; preds = %45, %40
  store i1 true, ptr %6, align 1
  %53 = load i1, ptr %6, align 1
  br i1 %53, label %55, label %54

54:                                               ; preds = %52
  call void @_ZNSt3mapIliSt4lessIlESaISt4pairIKliEEED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %0) #3
  br label %55

55:                                               ; preds = %54, %52
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  ret void

56:                                               ; preds = %48, %32
  call void @_ZNSt3mapIliSt4lessIlESaISt4pairIKliEEED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %0) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr %5) #3
  br label %57

57:                                               ; preds = %56
  %58 = load ptr, ptr %8, align 8
  %59 = load i32, ptr %9, align 4
  %60 = insertvalue { ptr, i32 } poison, ptr %58, 0
  %61 = insertvalue { ptr, i32 } %60, i32 %59, 1
  resume { ptr, i32 } %61
}

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

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

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

declare i32 @__gxx_personality_v0(...)

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

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

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


; 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<long, std::pair<const long, int>, std::_Select1st<std::pair<const long, int>>, std::less<long>>::_Rb_tree_impl" }
%"struct.std::_Rb_tree<long, std::pair<const long, int>, std::_Select1st<std::pair<const long, int>>, std::less<long>>::_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 }

; Function Attrs: mustprogress uwtable
define dso_local void @_Z19prime_factorizationl(ptr dead_on_unwind noalias nonnull writable sret(%"class.std::map") align 8 %0, i64 noundef %1) local_unnamed_addr #0 personality ptr @__gxx_personality_v0 {
  %3 = alloca i64, align 8
  %4 = alloca i64, align 8
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %3) #3
  store i64 %1, ptr %3, align 8, !tbaa !5
  tail call void @_ZNSt3mapIliSt4lessIlESaISt4pairIKliEEEC2Ev(ptr noundef nonnull align 8 dereferenceable(48) %0) #3
  call void @llvm.lifetime.start.p0(i64 8, ptr nonnull %4) #3
  store i64 2, ptr %4, align 8, !tbaa !5
  %.not7 = icmp slt i64 %1, 4
  br i1 %.not7, label %._crit_edge8, label %.preheader

.preheader:                                       ; preds = %2, %._crit_edge
  %5 = phi i64 [ %23, %._crit_edge ], [ 2, %2 ]
  %6 = phi i64 [ %22, %._crit_edge ], [ %1, %2 ]
  %7 = srem i64 %6, %5
  %8 = icmp eq i64 %7, 0
  br i1 %8, label %.lr.ph, label %._crit_edge

._crit_edge8:                                     ; preds = %._crit_edge, %2
  %9 = phi i64 [ %1, %2 ], [ %22, %._crit_edge ]
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  %10 = icmp sgt i64 %9, 1
  br i1 %10, label %25, label %32

.lr.ph:                                           ; preds = %.preheader, %13
  %11 = phi i64 [ %17, %13 ], [ %6, %.preheader ]
  %12 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIliSt4lessIlESaISt4pairIKliEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull align 8 dereferenceable(8) %4)
          to label %13 unwind label %20

13:                                               ; preds = %.lr.ph
  %14 = load i32, ptr %12, align 4, !tbaa !9
  %15 = add nsw i32 %14, 1
  store i32 %15, ptr %12, align 4, !tbaa !9
  %16 = load i64, ptr %4, align 8, !tbaa !5
  %17 = sdiv i64 %11, %16
  store i64 %17, ptr %3, align 8, !tbaa !5
  %18 = srem i64 %17, %16
  %19 = icmp eq i64 %18, 0
  br i1 %19, label %.lr.ph, label %._crit_edge, !llvm.loop !11

20:                                               ; preds = %.lr.ph
  %21 = landingpad { ptr, i32 }
          cleanup
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %4) #3
  br label %33

._crit_edge:                                      ; preds = %13, %.preheader
  %22 = phi i64 [ %6, %.preheader ], [ %17, %13 ]
  %.lcssa = phi i64 [ %5, %.preheader ], [ %16, %13 ]
  %23 = add nsw i64 %.lcssa, 1
  store i64 %23, ptr %4, align 8, !tbaa !5
  %24 = mul nsw i64 %23, %23
  %.not = icmp sgt i64 %24, %1
  br i1 %.not, label %._crit_edge8, label %.preheader, !llvm.loop !13

25:                                               ; preds = %._crit_edge8
  %26 = invoke noundef nonnull align 4 dereferenceable(4) ptr @_ZNSt3mapIliSt4lessIlESaISt4pairIKliEEEixERS3_(ptr noundef nonnull align 8 dereferenceable(48) %0, ptr noundef nonnull align 8 dereferenceable(8) %3)
          to label %27 unwind label %30

27:                                               ; preds = %25
  %28 = load i32, ptr %26, align 4, !tbaa !9
  %29 = add nsw i32 %28, 1
  store i32 %29, ptr %26, align 4, !tbaa !9
  br label %32

30:                                               ; preds = %25
  %31 = landingpad { ptr, i32 }
          cleanup
  br label %33

32:                                               ; preds = %._crit_edge8, %27
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  ret void

33:                                               ; preds = %30, %20
  %.pn = phi { ptr, i32 } [ %21, %20 ], [ %31, %30 ]
  call void @_ZNSt3mapIliSt4lessIlESaISt4pairIKliEEED2Ev(ptr noundef nonnull align 8 dereferenceable(48) %0) #3
  call void @llvm.lifetime.end.p0(i64 8, ptr nonnull %3) #3
  resume { ptr, i32 } %.pn
}

; 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 nounwind uwtable
declare dso_local void @_ZNSt3mapIliSt4lessIlESaISt4pairIKliEEEC2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #2 align 2

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

declare i32 @__gxx_personality_v0(...)

; 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 nounwind uwtable
declare dso_local void @_ZNSt3mapIliSt4lessIlESaISt4pairIKliEEED2Ev(ptr noundef nonnull align 8 dereferenceable(48)) unnamed_addr #2 align 2

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


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