; LLVM IR from jgaeddert/liquid-dsp :: src/random/src (randricek)

; 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: nounwind
declare float @sqrtf(float noundef) #1

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

; Function Attrs: nounwind uwtable
define dso_local float @randricekf_cdf(float noundef %0, float noundef %1, float noundef %2) #2 {
  %4 = alloca float, align 4
  %5 = alloca float, align 4
  %6 = alloca float, align 4
  %7 = alloca float, align 4
  %8 = alloca float, align 4
  %9 = alloca float, align 4
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  %12 = alloca i32, align 4
  %13 = alloca float, align 4
  store float %0, ptr %5, align 4, !tbaa !5
  store float %1, ptr %6, align 4, !tbaa !5
  store float %2, ptr %7, align 4, !tbaa !5
  %14 = load float, ptr %5, align 4, !tbaa !5
  %15 = fcmp ole float %14, 0.000000e+00
  br i1 %15, label %16, label %17

16:                                               ; preds = %3
  store float 0.000000e+00, ptr %4, align 4
  br label %64

17:                                               ; preds = %3
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  %18 = load float, ptr %7, align 4, !tbaa !5
  %19 = load float, ptr %6, align 4, !tbaa !5
  %20 = fmul float %18, %19
  %21 = load float, ptr %6, align 4, !tbaa !5
  %22 = fadd float %21, 1.000000e+00
  %23 = fdiv float %20, %22
  %24 = call float @sqrtf(float noundef %23) #4
  store float %24, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  %25 = load float, ptr %7, align 4, !tbaa !5
  %26 = fmul float 5.000000e-01, %25
  %27 = load float, ptr %6, align 4, !tbaa !5
  %28 = fadd float %27, 1.000000e+00
  %29 = fdiv float %26, %28
  %30 = call float @sqrtf(float noundef %29) #4
  store float %30, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %31 = load float, ptr %8, align 4, !tbaa !5
  %32 = load float, ptr %9, align 4, !tbaa !5
  %33 = fdiv float %31, %32
  store float %33, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  %34 = load float, ptr %5, align 4, !tbaa !5
  %35 = load float, ptr %9, align 4, !tbaa !5
  %36 = fdiv float %34, %35
  store float %36, ptr %11, align 4, !tbaa !5
  %37 = load float, ptr %10, align 4, !tbaa !5
  %38 = load float, ptr %11, align 4, !tbaa !5
  %39 = fdiv float %37, %38
  %40 = fcmp ogt float %39, 3.000000e+00
  br i1 %40, label %41, label %42

41:                                               ; preds = %17
  store float 0.000000e+00, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %63

42:                                               ; preds = %17
  %43 = load float, ptr %11, align 4, !tbaa !5
  %44 = load float, ptr %10, align 4, !tbaa !5
  %45 = fdiv float %43, %44
  %46 = fcmp ogt float %45, 3.000000e+00
  br i1 %46, label %47, label %48

47:                                               ; preds = %42
  store float 1.000000e+00, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %63

48:                                               ; preds = %42
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  %49 = load float, ptr %10, align 4, !tbaa !5
  %50 = load float, ptr %11, align 4, !tbaa !5
  %51 = call float @liquid_MarcumQ1f(float noundef %49, float noundef %50)
  %52 = fsub float 1.000000e+00, %51
  store float %52, ptr %13, align 4, !tbaa !5
  %53 = load float, ptr %13, align 4, !tbaa !5
  %54 = fcmp olt float %53, 0.000000e+00
  br i1 %54, label %55, label %56

55:                                               ; preds = %48
  store float 0.000000e+00, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %62

56:                                               ; preds = %48
  %57 = load float, ptr %13, align 4, !tbaa !5
  %58 = fcmp ogt float %57, 1.000000e+00
  br i1 %58, label %59, label %60

59:                                               ; preds = %56
  store float 1.000000e+00, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %62

60:                                               ; preds = %56
  %61 = load float, ptr %13, align 4, !tbaa !5
  store float %61, ptr %4, align 4
  store i32 1, ptr %12, align 4
  br label %62

62:                                               ; preds = %60, %59, %55
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  br label %63

63:                                               ; preds = %62, %47, %41
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #4
  br label %64

64:                                               ; preds = %63, %16
  %65 = load float, ptr %4, align 4
  ret float %65
}

declare float @liquid_MarcumQ1f(float noundef, float noundef) #3

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
attributes #1 = { nounwind "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 = { 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 = { "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 #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 = !{!"float", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}


; 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 nounwind willreturn memory(write)
declare float @sqrtf(float noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
define dso_local float @randricekf_cdf(float noundef %0, float noundef %1, float noundef %2) local_unnamed_addr #1 {
  %4 = fcmp ugt float %0, 0.000000e+00
  br i1 %4, label %5, label %30

5:                                                ; preds = %3
  %6 = fmul float %1, %2
  %7 = fadd float %1, 1.000000e+00
  %8 = fdiv float %6, %7
  %9 = tail call float @sqrtf(float noundef %8) #3
  %10 = fmul float %2, 5.000000e-01
  %11 = fdiv float %10, %7
  %12 = tail call float @sqrtf(float noundef %11) #3
  %13 = insertelement <2 x float> poison, float %9, i64 0
  %14 = insertelement <2 x float> %13, float %0, i64 1
  %15 = insertelement <2 x float> poison, float %12, i64 0
  %16 = shufflevector <2 x float> %15, <2 x float> poison, <2 x i32> zeroinitializer
  %17 = fdiv <2 x float> %14, %16
  %18 = extractelement <2 x float> %17, i64 0
  %19 = extractelement <2 x float> %17, i64 1
  %20 = fdiv float %18, %19
  %21 = fcmp ogt float %20, 3.000000e+00
  br i1 %21, label %30, label %22

22:                                               ; preds = %5
  %23 = fdiv float %19, %18
  %24 = fcmp ogt float %23, 3.000000e+00
  br i1 %24, label %30, label %25

25:                                               ; preds = %22
  %26 = tail call float @liquid_MarcumQ1f(float noundef %18, float noundef %19) #3
  %27 = fsub float 1.000000e+00, %26
  %28 = fcmp olt float %27, 0.000000e+00
  %29 = fcmp ogt float %27, 1.000000e+00
  %. = select i1 %29, float 1.000000e+00, float %27
  %.0 = select i1 %28, float 0.000000e+00, float %.
  br label %30

30:                                               ; preds = %25, %5, %22, %3
  %.2 = phi float [ 0.000000e+00, %3 ], [ %.0, %25 ], [ 0.000000e+00, %5 ], [ 1.000000e+00, %22 ]
  ret float %.2
}

declare float @liquid_MarcumQ1f(float noundef, float noundef) local_unnamed_addr #2

attributes #0 = { mustprogress nofree nounwind willreturn memory(write) "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 = { 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 = { "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)"}


; Effective O3 passes: EarlyCSEPass,GlobalOptPass,InferFunctionAttrsPass,InstCombinePass,ReassociatePass,SLPVectorizerPass,SROAPass,SimplifyCFGPass,TailCallElimPass