; LLVM IR from jgaeddert/liquid-dsp :: src/math/src/math.gamma (liquid_lngammaf)

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

@.str = external hidden unnamed_addr constant [80 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [40 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local float @liquid_lngammaf(float noundef %0) #0 {
  %2 = alloca float, align 4
  %3 = alloca float, align 4
  %4 = alloca float, align 4
  %5 = alloca i32, align 4
  store float %0, ptr %3, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #5
  %6 = load float, ptr %3, align 4, !tbaa !5
  %7 = fcmp olt float %6, 0.000000e+00
  br i1 %7, label %8, label %10

8:                                                ; preds = %1
  %9 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef @.str, i32 noundef 47, ptr noundef @.str.1)
  store float 0.000000e+00, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %45

10:                                               ; preds = %1
  %11 = load float, ptr %3, align 4, !tbaa !5
  %12 = fcmp olt float %11, 1.000000e+01
  br i1 %12, label %13, label %20

13:                                               ; preds = %10
  %14 = load float, ptr %3, align 4, !tbaa !5
  %15 = fadd float %14, 1.000000e+00
  %16 = call float @liquid_lngammaf(float noundef %15)
  %17 = load float, ptr %3, align 4, !tbaa !5
  %18 = call float @logf(float noundef %17) #5
  %19 = fsub float %16, %18
  store float %19, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %45

20:                                               ; preds = %10
  %21 = call float @logf(float noundef 0x401921FB60000000) #5
  %22 = fpext float %21 to double
  %23 = load float, ptr %3, align 4, !tbaa !5
  %24 = fpext float %23 to double
  %25 = call double @log(double noundef %24) #5
  %26 = fsub double %22, %25
  %27 = fmul double 5.000000e-01, %26
  %28 = fptrunc double %27 to float
  store float %28, ptr %4, align 4, !tbaa !5
  %29 = load float, ptr %3, align 4, !tbaa !5
  %30 = load float, ptr %3, align 4, !tbaa !5
  %31 = load float, ptr %3, align 4, !tbaa !5
  %32 = load float, ptr %3, align 4, !tbaa !5
  %33 = fdiv float 0x3FB99999A0000000, %32
  %34 = fneg float %33
  %35 = call float @llvm.fmuladd.f32(float 1.200000e+01, float %31, float %34)
  %36 = fdiv float 1.000000e+00, %35
  %37 = fadd float %30, %36
  %38 = call float @logf(float noundef %37) #5
  %39 = fsub float %38, 1.000000e+00
  %40 = load float, ptr %4, align 4, !tbaa !5
  %41 = call float @llvm.fmuladd.f32(float %29, float %39, float %40)
  store float %41, ptr %4, align 4, !tbaa !5
  br label %42

42:                                               ; preds = %20
  br label %43

43:                                               ; preds = %42
  %44 = load float, ptr %4, align 4, !tbaa !5
  store float %44, ptr %2, align 4
  store i32 1, ptr %5, align 4
  br label %45

45:                                               ; preds = %43, %13, %8
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #5
  %46 = load float, ptr %2, align 4
  ret float %46
}

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

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) #2

; Function Attrs: nounwind
declare float @logf(float noundef) #3

; Function Attrs: nounwind
declare double @log(double noundef) #3

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #4

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

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" }
attributes #1 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 "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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #5 = { 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"

@.str = external hidden unnamed_addr constant [80 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [40 x i8], align 1

; Function Attrs: nounwind uwtable
define dso_local float @liquid_lngammaf(float noundef %0) local_unnamed_addr #0 {
  %2 = fcmp olt float %0, 0.000000e+00
  br i1 %2, label %3, label %5

3:                                                ; preds = %1
  %4 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef nonnull @.str, i32 noundef 47, ptr noundef nonnull @.str.1) #4
  br label %common.ret13

5:                                                ; preds = %1
  %6 = fcmp olt float %0, 1.000000e+01
  br i1 %6, label %7, label %12

common.ret13:                                     ; preds = %12, %3, %7
  %common.ret13.op = phi float [ %11, %7 ], [ 0.000000e+00, %3 ], [ %24, %12 ]
  ret float %common.ret13.op

7:                                                ; preds = %5
  %8 = fadd float %0, 1.000000e+00
  %9 = tail call float @liquid_lngammaf(float noundef %8)
  %10 = tail call float @logf(float noundef %0) #4
  %11 = fsub float %9, %10
  br label %common.ret13

12:                                               ; preds = %5
  %13 = fpext float %0 to double
  %14 = tail call double @log(double noundef %13) #4
  %15 = fsub double 0x3FFD67F1C0000000, %14
  %16 = fmul double %15, 5.000000e-01
  %17 = fptrunc double %16 to float
  %18 = fdiv float 0xBFB99999A0000000, %0
  %19 = tail call float @llvm.fmuladd.f32(float %0, float 1.200000e+01, float %18)
  %20 = fdiv float 1.000000e+00, %19
  %21 = fadd float %20, %0
  %22 = tail call float @logf(float noundef %21) #4
  %23 = fadd float %22, -1.000000e+00
  %24 = tail call float @llvm.fmuladd.f32(float %0, float %23, float %17)
  br label %common.ret13
}

declare i32 @liquid_error_fl(i32 noundef, ptr noundef, i32 noundef, ptr noundef, ...) local_unnamed_addr #1

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare float @logf(float noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nofree nounwind willreturn memory(write)
declare double @log(double noundef) local_unnamed_addr #2

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare float @llvm.fmuladd.f32(float, float, float) #3

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" }
attributes #1 = { "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 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 #3 = { mustprogress 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)"}


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