; LLVM IR from kdrag0n/fxdsp :: util/fft.ll (ZN5fxdsp13next_fft_sizeEi)

; 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 nounwind uwtable
define dso_local noundef i32 @_ZN5fxdsp13next_fft_sizeEi(i32 noundef %0) #0 {
  %2 = alloca i32, align 4
  %3 = alloca i32, align 4
  %4 = alloca i32, align 4
  %5 = alloca i32, align 4
  store i32 %0, ptr %3, align 4, !tbaa !5
  %6 = load i32, ptr %3, align 4, !tbaa !5
  %7 = srem i32 %6, 2
  %8 = icmp ne i32 %7, 0
  br i1 %8, label %9, label %12

9:                                                ; preds = %1
  %10 = load i32, ptr %3, align 4, !tbaa !5
  %11 = add nsw i32 %10, 1
  store i32 %11, ptr %3, align 4, !tbaa !5
  br label %12

12:                                               ; preds = %9, %1
  br label %13

13:                                               ; preds = %48, %12
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #2
  %14 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %14, ptr %4, align 4, !tbaa !5
  br label %15

15:                                               ; preds = %19, %13
  %16 = load i32, ptr %4, align 4, !tbaa !5
  %17 = srem i32 %16, 2
  %18 = icmp eq i32 %17, 0
  br i1 %18, label %19, label %22

19:                                               ; preds = %15
  %20 = load i32, ptr %4, align 4, !tbaa !5
  %21 = sdiv i32 %20, 2
  store i32 %21, ptr %4, align 4, !tbaa !5
  br label %15, !llvm.loop !9

22:                                               ; preds = %15
  br label %23

23:                                               ; preds = %27, %22
  %24 = load i32, ptr %4, align 4, !tbaa !5
  %25 = srem i32 %24, 3
  %26 = icmp eq i32 %25, 0
  br i1 %26, label %27, label %30

27:                                               ; preds = %23
  %28 = load i32, ptr %4, align 4, !tbaa !5
  %29 = sdiv i32 %28, 3
  store i32 %29, ptr %4, align 4, !tbaa !5
  br label %23, !llvm.loop !11

30:                                               ; preds = %23
  br label %31

31:                                               ; preds = %35, %30
  %32 = load i32, ptr %4, align 4, !tbaa !5
  %33 = srem i32 %32, 5
  %34 = icmp eq i32 %33, 0
  br i1 %34, label %35, label %38

35:                                               ; preds = %31
  %36 = load i32, ptr %4, align 4, !tbaa !5
  %37 = sdiv i32 %36, 5
  store i32 %37, ptr %4, align 4, !tbaa !5
  br label %31, !llvm.loop !12

38:                                               ; preds = %31
  %39 = load i32, ptr %4, align 4, !tbaa !5
  %40 = icmp sle i32 %39, 1
  br i1 %40, label %41, label %43

41:                                               ; preds = %38
  %42 = load i32, ptr %3, align 4, !tbaa !5
  store i32 %42, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %46

43:                                               ; preds = %38
  %44 = load i32, ptr %3, align 4, !tbaa !5
  %45 = add nsw i32 %44, 2
  store i32 %45, ptr %3, align 4, !tbaa !5
  store i32 0, ptr %5, align 4
  br label %46

46:                                               ; preds = %43, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #2
  %47 = load i32, ptr %5, align 4
  switch i32 %47, label %51 [
    i32 0, label %48
    i32 1, label %49
  ]

48:                                               ; preds = %46
  br label %13, !llvm.loop !13

49:                                               ; preds = %46
  %50 = load i32, ptr %2, align 4
  ret i32 %50

51:                                               ; preds = %46
  unreachable
}

; 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

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


; 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 nofree norecurse nosync nounwind willreturn memory(none) uwtable
define dso_local noundef i32 @_ZN5fxdsp13next_fft_sizeEi(i32 noundef %0) local_unnamed_addr #0 {
  %2 = and i32 %0, 1
  %spec.select = add i32 %2, %0
  br label %3

3:                                                ; preds = %._crit_edge, %1
  %.116 = phi i32 [ %spec.select, %1 ], [ %19, %._crit_edge ]
  br label %4

4:                                                ; preds = %4, %3
  %.014 = phi i32 [ %.116, %3 ], [ %7, %4 ]
  %5 = and i32 %.014, 1
  %6 = icmp eq i32 %5, 0
  %7 = ashr exact i32 %.014, 1
  br i1 %6, label %4, label %.preheader20, !llvm.loop !5

.preheader20:                                     ; preds = %4
  %8 = srem i32 %.014, 3
  %9 = icmp eq i32 %8, 0
  br i1 %9, label %.lr.ph, label %.preheader

.preheader:                                       ; preds = %.lr.ph, %.preheader20
  %.1.lcssa = phi i32 [ %.014, %.preheader20 ], [ %12, %.lr.ph ]
  %10 = srem i32 %.1.lcssa, 5
  %11 = icmp eq i32 %10, 0
  br i1 %11, label %.lr.ph23, label %._crit_edge

.lr.ph:                                           ; preds = %.preheader20, %.lr.ph
  %.121 = phi i32 [ %12, %.lr.ph ], [ %.014, %.preheader20 ]
  %12 = sdiv i32 %.121, 3
  %13 = srem i32 %12, 3
  %14 = icmp eq i32 %13, 0
  br i1 %14, label %.lr.ph, label %.preheader, !llvm.loop !7

.lr.ph23:                                         ; preds = %.preheader, %.lr.ph23
  %.222 = phi i32 [ %15, %.lr.ph23 ], [ %.1.lcssa, %.preheader ]
  %15 = sdiv i32 %.222, 5
  %16 = srem i32 %15, 5
  %17 = icmp eq i32 %16, 0
  br i1 %17, label %.lr.ph23, label %._crit_edge, !llvm.loop !8

._crit_edge:                                      ; preds = %.lr.ph23, %.preheader
  %.2.lcssa = phi i32 [ %.1.lcssa, %.preheader ], [ %15, %.lr.ph23 ]
  %18 = icmp sgt i32 %.2.lcssa, 1
  %19 = add nsw i32 %.116, 2
  br i1 %18, label %3, label %20

20:                                               ; preds = %._crit_edge
  ret i32 %.116
}

attributes #0 = { mustprogress nofree norecurse nosync nounwind willreturn memory(none) 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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}
!7 = distinct !{!7, !6}
!8 = distinct !{!8, !6}


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