; LLVM IR from T-Troll/alienfx-tools :: alienfx-gui/kiss_fft/kiss_fft.ll (Z9kf_factoriPi)

; 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: 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 uwtable
define dso_local void @_Z9kf_factoriPi(i32 noundef %0, ptr noundef %1) #1 {
  %3 = alloca i32, align 4
  %4 = alloca ptr, align 8
  %5 = alloca i32, align 4
  %6 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  store ptr %1, ptr %4, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  store i32 4, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %7 = load i32, ptr %3, align 4, !tbaa !5
  %8 = call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %7)
  %9 = call double @llvm.floor.f64(double %8)
  %10 = fptosi double %9 to i32
  store i32 %10, ptr %6, align 4, !tbaa !5
  br label %11

11:                                               ; preds = %41, %2
  br label %12

12:                                               ; preds = %30, %11
  %13 = load i32, ptr %3, align 4, !tbaa !5
  %14 = load i32, ptr %5, align 4, !tbaa !5
  %15 = srem i32 %13, %14
  %16 = icmp ne i32 %15, 0
  br i1 %16, label %17, label %31

17:                                               ; preds = %12
  %18 = load i32, ptr %5, align 4, !tbaa !5
  switch i32 %18, label %21 [
    i32 4, label %19
    i32 2, label %20
  ]

19:                                               ; preds = %17
  store i32 2, ptr %5, align 4, !tbaa !5
  br label %24

20:                                               ; preds = %17
  store i32 3, ptr %5, align 4, !tbaa !5
  br label %24

21:                                               ; preds = %17
  %22 = load i32, ptr %5, align 4, !tbaa !5
  %23 = add nsw i32 %22, 2
  store i32 %23, ptr %5, align 4, !tbaa !5
  br label %24

24:                                               ; preds = %21, %20, %19
  %25 = load i32, ptr %5, align 4, !tbaa !5
  %26 = load i32, ptr %6, align 4, !tbaa !5
  %27 = icmp sgt i32 %25, %26
  br i1 %27, label %28, label %30

28:                                               ; preds = %24
  %29 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %29, ptr %5, align 4, !tbaa !5
  br label %30

30:                                               ; preds = %28, %24
  br label %12, !llvm.loop !11

31:                                               ; preds = %12
  %32 = load i32, ptr %5, align 4, !tbaa !5
  %33 = load i32, ptr %3, align 4, !tbaa !5
  %34 = sdiv i32 %33, %32
  store i32 %34, ptr %3, align 4, !tbaa !5
  %35 = load i32, ptr %5, align 4, !tbaa !5
  %36 = load ptr, ptr %4, align 8, !tbaa !9
  %37 = getelementptr inbounds i32, ptr %36, i32 1
  store ptr %37, ptr %4, align 8, !tbaa !9
  store i32 %35, ptr %36, align 4, !tbaa !5
  %38 = load i32, ptr %3, align 4, !tbaa !5
  %39 = load ptr, ptr %4, align 8, !tbaa !9
  %40 = getelementptr inbounds i32, ptr %39, i32 1
  store ptr %40, ptr %4, align 8, !tbaa !9
  store i32 %38, ptr %39, align 4, !tbaa !5
  br label %41

41:                                               ; preds = %31
  %42 = load i32, ptr %3, align 4, !tbaa !5
  %43 = icmp sgt i32 %42, 1
  br i1 %43, label %11, label %44, !llvm.loop !13

44:                                               ; preds = %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  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) #2

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { 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 #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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #4 = { 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 @_Z9kf_factoriPi(i32 noundef %0, ptr nocapture noundef writeonly %1) local_unnamed_addr #0 {
  %3 = tail call noundef double @_ZSt4sqrtIiEN9__gnu_cxx11__enable_ifIXsr12__is_integerIT_EE7__valueEdE6__typeES2_(i32 noundef %0)
  %4 = tail call double @llvm.floor.f64(double %3)
  %5 = fptosi double %4 to i32
  br label %6

6:                                                ; preds = %._crit_edge, %2
  %.015 = phi ptr [ %1, %2 ], [ %16, %._crit_edge ]
  %.014 = phi i32 [ 4, %2 ], [ %.1.lcssa, %._crit_edge ]
  %.0 = phi i32 [ %0, %2 ], [ %14, %._crit_edge ]
  %7 = srem i32 %.0, %.014
  %.not17 = icmp eq i32 %7, 0
  br i1 %.not17, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %6, %11
  %.118 = phi i32 [ %spec.select, %11 ], [ %.014, %6 ]
  switch i32 %.118, label %9 [
    i32 4, label %11
    i32 2, label %8
  ]

8:                                                ; preds = %.lr.ph
  br label %11

9:                                                ; preds = %.lr.ph
  %10 = add nsw i32 %.118, 2
  br label %11

11:                                               ; preds = %.lr.ph, %9, %8
  %.2 = phi i32 [ %10, %9 ], [ 3, %8 ], [ 2, %.lr.ph ]
  %12 = icmp sgt i32 %.2, %5
  %spec.select = select i1 %12, i32 %.0, i32 %.2
  %13 = srem i32 %.0, %spec.select
  %.not = icmp eq i32 %13, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %11, %6
  %.1.lcssa = phi i32 [ %.014, %6 ], [ %spec.select, %11 ]
  %14 = sdiv i32 %.0, %.1.lcssa
  %15 = getelementptr inbounds i8, ptr %.015, i64 4
  store i32 %.1.lcssa, ptr %.015, align 4, !tbaa !7
  %16 = getelementptr inbounds i8, ptr %.015, i64 8
  store i32 %14, ptr %15, align 4, !tbaa !7
  %17 = icmp sgt i32 %14, 1
  br i1 %17, label %6, label %18, !llvm.loop !11

18:                                               ; preds = %._crit_edge
  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

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.floor.f64(double) #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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }

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


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