; LLVM IR from jgaeddert/liquid-dsp :: src/nco/src (nco_crcf)

; 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: nounwind uwtable
define dso_local i32 @nco_crcf_constrain(float noundef %0) #0 {
  %2 = alloca float, align 4
  store float %0, ptr %2, align 4, !tbaa !5
  br label %3

3:                                                ; preds = %7, %1
  %4 = load float, ptr %2, align 4, !tbaa !5
  %5 = fpext float %4 to double
  %6 = fcmp oge double %5, 0x401921FB54442D18
  br i1 %6, label %7, label %12

7:                                                ; preds = %3
  %8 = load float, ptr %2, align 4, !tbaa !5
  %9 = fpext float %8 to double
  %10 = fsub double %9, 0x401921FB54442D18
  %11 = fptrunc double %10 to float
  store float %11, ptr %2, align 4, !tbaa !5
  br label %3, !llvm.loop !9

12:                                               ; preds = %3
  br label %13

13:                                               ; preds = %16, %12
  %14 = load float, ptr %2, align 4, !tbaa !5
  %15 = fcmp olt float %14, 0.000000e+00
  br i1 %15, label %16, label %21

16:                                               ; preds = %13
  %17 = load float, ptr %2, align 4, !tbaa !5
  %18 = fpext float %17 to double
  %19 = fadd double %18, 0x401921FB54442D18
  %20 = fptrunc double %19 to float
  store float %20, ptr %2, align 4, !tbaa !5
  br label %13, !llvm.loop !11

21:                                               ; preds = %13
  %22 = load float, ptr %2, align 4, !tbaa !5
  %23 = fpext float %22 to double
  %24 = fdiv double %23, 0x401921FB54442D18
  %25 = fmul double %24, 0x41EFFFFFFFE00000
  %26 = fptoui double %25 to i32
  ret i32 %26
}

attributes #0 = { 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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10}
!10 = !{!"llvm.loop.mustprogress"}
!11 = distinct !{!11, !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: nofree norecurse nosync nounwind memory(none) uwtable
define dso_local i32 @nco_crcf_constrain(float noundef %0) local_unnamed_addr #0 {
  %2 = fpext float %0 to double
  %3 = fcmp ult double %2, 0x401921FB54442D18
  br i1 %3, label %.preheader, label %.lr.ph

.preheader:                                       ; preds = %.lr.ph, %1
  %.0.lcssa = phi float [ %0, %1 ], [ %7, %.lr.ph ]
  %4 = fcmp olt float %.0.lcssa, 0.000000e+00
  br i1 %4, label %.lr.ph7, label %._crit_edge

.lr.ph:                                           ; preds = %1, %.lr.ph
  %5 = phi double [ %8, %.lr.ph ], [ %2, %1 ]
  %6 = fadd double %5, 0xC01921FB54442D18
  %7 = fptrunc double %6 to float
  %8 = fpext float %7 to double
  %9 = fcmp ult double %8, 0x401921FB54442D18
  br i1 %9, label %.preheader, label %.lr.ph, !llvm.loop !5

.lr.ph7:                                          ; preds = %.preheader, %.lr.ph7
  %.16 = phi float [ %12, %.lr.ph7 ], [ %.0.lcssa, %.preheader ]
  %10 = fpext float %.16 to double
  %11 = fadd double %10, 0x401921FB54442D18
  %12 = fptrunc double %11 to float
  %13 = fcmp olt float %12, 0.000000e+00
  br i1 %13, label %.lr.ph7, label %._crit_edge, !llvm.loop !7

._crit_edge:                                      ; preds = %.lr.ph7, %.preheader
  %.1.lcssa = phi float [ %.0.lcssa, %.preheader ], [ %12, %.lr.ph7 ]
  %14 = fpext float %.1.lcssa to double
  %15 = fdiv double %14, 0x401921FB54442D18
  %16 = fmul double %15, 0x41EFFFFFFFE00000
  %17 = fptoui double %16 to i32
  ret i32 %17
}

attributes #0 = { nofree norecurse nosync nounwind 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}


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