; LLVM IR from ippeb/ACM-ICPC :: algebra/prime_factorization/prime_factorization.ll (Z19prime_factorizationiPiRi)

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

; Function Attrs: mustprogress uwtable
define dso_local void @_Z19prime_factorizationiPiRi(i32 noundef %0, ptr noundef %1, ptr noundef nonnull align 4 dereferenceable(4) %2) #0 {
  %4 = alloca i32, align 4
  %5 = alloca ptr, align 8
  %6 = alloca ptr, align 8
  %7 = alloca i32, align 4
  %8 = alloca i32, align 4
  store i32 %0, ptr %4, align 4, !tbaa !5
  store ptr %1, ptr %5, align 8, !tbaa !9
  store ptr %2, ptr %6, align 8, !tbaa !9
  %9 = load ptr, ptr %6, align 8, !tbaa !9
  store i32 0, ptr %9, align 4, !tbaa !5
  br label %10

10:                                               ; preds = %14, %3
  %11 = load i32, ptr %4, align 4, !tbaa !5
  %12 = srem i32 %11, 2
  %13 = icmp eq i32 %12, 0
  br i1 %13, label %14, label %23

14:                                               ; preds = %10
  %15 = load i32, ptr %4, align 4, !tbaa !5
  %16 = sdiv i32 %15, 2
  store i32 %16, ptr %4, align 4, !tbaa !5
  %17 = load ptr, ptr %5, align 8, !tbaa !9
  %18 = load ptr, ptr %6, align 8, !tbaa !9
  %19 = load i32, ptr %18, align 4, !tbaa !5
  %20 = add nsw i32 %19, 1
  store i32 %20, ptr %18, align 4, !tbaa !5
  %21 = sext i32 %19 to i64
  %22 = getelementptr inbounds i32, ptr %17, i64 %21
  store i32 2, ptr %22, align 4, !tbaa !5
  br label %10, !llvm.loop !11

23:                                               ; preds = %10
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #3
  store i32 3, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #3
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %24)
  %26 = fadd double %25, 1.000000e+00
  %27 = fptosi double %26 to i32
  store i32 %27, ptr %8, align 4, !tbaa !5
  br label %28

28:                                               ; preds = %55, %23
  %29 = load i32, ptr %7, align 4, !tbaa !5
  %30 = load i32, ptr %8, align 4, !tbaa !5
  %31 = icmp slt i32 %29, %30
  br i1 %31, label %32, label %56

32:                                               ; preds = %28
  %33 = load i32, ptr %4, align 4, !tbaa !5
  %34 = load i32, ptr %7, align 4, !tbaa !5
  %35 = srem i32 %33, %34
  %36 = icmp eq i32 %35, 0
  br i1 %36, label %37, label %48

37:                                               ; preds = %32
  %38 = load i32, ptr %7, align 4, !tbaa !5
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = sdiv i32 %39, %38
  store i32 %40, ptr %4, align 4, !tbaa !5
  %41 = load i32, ptr %7, align 4, !tbaa !5
  %42 = load ptr, ptr %5, align 8, !tbaa !9
  %43 = load ptr, ptr %6, align 8, !tbaa !9
  %44 = load i32, ptr %43, align 4, !tbaa !5
  %45 = add nsw i32 %44, 1
  store i32 %45, ptr %43, align 4, !tbaa !5
  %46 = sext i32 %44 to i64
  %47 = getelementptr inbounds i32, ptr %42, i64 %46
  store i32 %41, ptr %47, align 4, !tbaa !5
  br label %55

48:                                               ; preds = %32
  %49 = load i32, ptr %7, align 4, !tbaa !5
  %50 = add nsw i32 %49, 2
  store i32 %50, ptr %7, align 4, !tbaa !5
  %51 = load i32, ptr %4, align 4, !tbaa !5
  %52 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %51)
  %53 = fadd double %52, 1.000000e+00
  %54 = fptosi double %53 to i32
  store i32 %54, ptr %8, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %48, %37
  br label %28, !llvm.loop !13

56:                                               ; preds = %28
  %57 = load i32, ptr %4, align 4, !tbaa !5
  %58 = icmp sgt i32 %57, 1
  br i1 %58, label %59, label %67

59:                                               ; preds = %56
  %60 = load i32, ptr %4, align 4, !tbaa !5
  %61 = load ptr, ptr %5, align 8, !tbaa !9
  %62 = load ptr, ptr %6, align 8, !tbaa !9
  %63 = load i32, ptr %62, align 4, !tbaa !5
  %64 = add nsw i32 %63, 1
  store i32 %64, ptr %62, align 4, !tbaa !5
  %65 = sext i32 %63 to i64
  %66 = getelementptr inbounds i32, ptr %61, i64 %65
  store i32 %60, ptr %66, align 4, !tbaa !5
  br label %67

67:                                               ; preds = %59, %56
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #3
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #3
  ret void
}

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

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) #2

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

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 = { inlinehint 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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"any pointer", !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"

; Function Attrs: mustprogress nounwind uwtable
define dso_local void @_Z19prime_factorizationiPiRi(i32 noundef %0, ptr nocapture noundef writeonly %1, ptr nocapture noundef nonnull align 4 dereferenceable(4) %2) local_unnamed_addr #0 {
  store i32 0, ptr %2, align 4, !tbaa !5
  %4 = and i32 %0, 1
  %5 = icmp eq i32 %4, 0
  br i1 %5, label %.lr.ph, label %._crit_edge

.lr.ph:                                           ; preds = %3, %.lr.ph
  %.02224 = phi i32 [ %6, %.lr.ph ], [ %0, %3 ]
  %6 = ashr exact i32 %.02224, 1
  %7 = load i32, ptr %2, align 4, !tbaa !5
  %8 = add nsw i32 %7, 1
  store i32 %8, ptr %2, align 4, !tbaa !5
  %9 = sext i32 %7 to i64
  %10 = getelementptr inbounds i32, ptr %1, i64 %9
  store i32 2, ptr %10, align 4, !tbaa !5
  %11 = and i32 %.02224, 2
  %12 = icmp eq i32 %11, 0
  br i1 %12, label %.lr.ph, label %._crit_edge, !llvm.loop !9

._crit_edge:                                      ; preds = %.lr.ph, %3
  %.022.lcssa = phi i32 [ %0, %3 ], [ %6, %.lr.ph ]
  %13 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %.022.lcssa)
  %14 = fadd double %13, 1.000000e+00
  %15 = fptosi double %14 to i32
  %16 = icmp sgt i32 %15, 3
  br i1 %16, label %.lr.ph29, label %._crit_edge30

.lr.ph29:                                         ; preds = %._crit_edge, %30
  %.027 = phi i32 [ %.1, %30 ], [ %15, %._crit_edge ]
  %.02026 = phi i32 [ %.121, %30 ], [ 3, %._crit_edge ]
  %.12325 = phi i32 [ %.2, %30 ], [ %.022.lcssa, %._crit_edge ]
  %17 = srem i32 %.12325, %.02026
  %18 = sdiv i32 %.12325, %.02026
  %19 = icmp eq i32 %17, 0
  br i1 %19, label %20, label %25

20:                                               ; preds = %.lr.ph29
  %21 = load i32, ptr %2, align 4, !tbaa !5
  %22 = add nsw i32 %21, 1
  store i32 %22, ptr %2, align 4, !tbaa !5
  %23 = sext i32 %21 to i64
  %24 = getelementptr inbounds i32, ptr %1, i64 %23
  store i32 %.02026, ptr %24, align 4, !tbaa !5
  br label %30

25:                                               ; preds = %.lr.ph29
  %26 = add nsw i32 %.02026, 2
  %27 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %.12325)
  %28 = fadd double %27, 1.000000e+00
  %29 = fptosi double %28 to i32
  br label %30

30:                                               ; preds = %25, %20
  %.2 = phi i32 [ %18, %20 ], [ %.12325, %25 ]
  %.121 = phi i32 [ %.02026, %20 ], [ %26, %25 ]
  %.1 = phi i32 [ %.027, %20 ], [ %29, %25 ]
  %31 = icmp slt i32 %.121, %.1
  br i1 %31, label %.lr.ph29, label %._crit_edge30, !llvm.loop !11

._crit_edge30:                                    ; preds = %30, %._crit_edge
  %.123.lcssa = phi i32 [ %.022.lcssa, %._crit_edge ], [ %.2, %30 ]
  %32 = icmp sgt i32 %.123.lcssa, 1
  br i1 %32, label %33, label %38

33:                                               ; preds = %._crit_edge30
  %34 = load i32, ptr %2, align 4, !tbaa !5
  %35 = add nsw i32 %34, 1
  store i32 %35, ptr %2, align 4, !tbaa !5
  %36 = sext i32 %34 to i64
  %37 = getelementptr inbounds i32, ptr %1, i64 %36
  store i32 %.123.lcssa, ptr %37, align 4, !tbaa !5
  br label %38

38:                                               ; preds = %33, %._crit_edge30
  ret void
}

; Function Attrs: inlinehint mustprogress nounwind uwtable
declare dso_local noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef) local_unnamed_addr #1

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 = { inlinehint 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" }

!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 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !10}


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