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

; 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
declare dso_local float @liquid_lngammaf(float noundef) #0

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

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

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

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

; Function Attrs: nounwind
declare float @expf(float noundef) #2

; Function Attrs: nounwind uwtable
define dso_local float @liquid_lnlowergammaf(float noundef %0, float noundef %1) #0 {
  %3 = alloca float, align 4
  %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 i32, align 4
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  %12 = alloca float, align 4
  %13 = alloca float, align 4
  store float %0, ptr %3, align 4, !tbaa !5
  store float %1, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %14 = load float, ptr %3, align 4, !tbaa !5
  %15 = load float, ptr %4, align 4, !tbaa !5
  %16 = call float @logf(float noundef %15) #4
  %17 = fmul float %14, %16
  store float %17, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %18 = load float, ptr %3, align 4, !tbaa !5
  %19 = call float @liquid_lngammaf(float noundef %18)
  store float %19, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  %20 = load float, ptr %4, align 4, !tbaa !5
  %21 = fneg float %20
  store float %21, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #4
  store float 0.000000e+00, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #4
  store i32 0, ptr %9, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  %22 = load float, ptr %4, align 4, !tbaa !5
  %23 = call float @logf(float noundef %22) #4
  store float %23, ptr %10, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #4
  store float 0.000000e+00, ptr %11, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %12) #4
  store float 0.000000e+00, ptr %12, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %13) #4
  store float 0.000000e+00, ptr %13, align 4, !tbaa !5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %24

24:                                               ; preds = %66, %2
  %25 = load i32, ptr %9, align 4, !tbaa !9
  %26 = icmp ult i32 %25, 1000
  br i1 %26, label %27, label %69

27:                                               ; preds = %24
  %28 = load float, ptr %13, align 4, !tbaa !5
  store float %28, ptr %11, align 4, !tbaa !5
  %29 = load i32, ptr %9, align 4, !tbaa !9
  %30 = uitofp i32 %29 to float
  %31 = load float, ptr %10, align 4, !tbaa !5
  %32 = load float, ptr %3, align 4, !tbaa !5
  %33 = load i32, ptr %9, align 4, !tbaa !9
  %34 = uitofp i32 %33 to float
  %35 = fadd float %32, %34
  %36 = fadd float %35, 1.000000e+00
  %37 = call float @liquid_lngammaf(float noundef %36)
  %38 = fneg float %37
  %39 = call float @llvm.fmuladd.f32(float %30, float %31, float %38)
  store float %39, ptr %13, align 4, !tbaa !5
  %40 = load float, ptr %13, align 4, !tbaa !5
  %41 = call float @expf(float noundef %40) #4, !tbaa !9
  %42 = load float, ptr %8, align 4, !tbaa !5
  %43 = fadd float %42, %41
  store float %43, ptr %8, align 4, !tbaa !5
  %44 = load i32, ptr %9, align 4, !tbaa !9
  %45 = icmp eq i32 %44, 0
  br i1 %45, label %50, label %46

46:                                               ; preds = %27
  %47 = load float, ptr %13, align 4, !tbaa !5
  %48 = load float, ptr %12, align 4, !tbaa !5
  %49 = fcmp ogt float %47, %48
  br i1 %49, label %50, label %52

50:                                               ; preds = %46, %27
  %51 = load float, ptr %13, align 4, !tbaa !5
  store float %51, ptr %12, align 4, !tbaa !5
  br label %52

52:                                               ; preds = %50, %46
  %53 = load i32, ptr %9, align 4, !tbaa !9
  %54 = icmp ugt i32 %53, 50
  br i1 %54, label %55, label %65

55:                                               ; preds = %52
  %56 = load float, ptr %11, align 4, !tbaa !5
  %57 = load float, ptr %13, align 4, !tbaa !5
  %58 = fcmp ogt float %56, %57
  br i1 %58, label %59, label %65

59:                                               ; preds = %55
  %60 = load float, ptr %12, align 4, !tbaa !5
  %61 = load float, ptr %13, align 4, !tbaa !5
  %62 = fsub float %60, %61
  %63 = fcmp ogt float %62, 2.000000e+01
  br i1 %63, label %64, label %65

64:                                               ; preds = %59
  br label %69

65:                                               ; preds = %59, %55, %52
  br label %66

66:                                               ; preds = %65
  %67 = load i32, ptr %9, align 4, !tbaa !9
  %68 = add i32 %67, 1
  store i32 %68, ptr %9, align 4, !tbaa !9
  br label %24, !llvm.loop !11

69:                                               ; preds = %64, %24
  %70 = load float, ptr %5, align 4, !tbaa !5
  %71 = load float, ptr %6, align 4, !tbaa !5
  %72 = fadd float %70, %71
  %73 = load float, ptr %7, align 4, !tbaa !5
  %74 = fadd float %72, %73
  %75 = load float, ptr %8, align 4, !tbaa !5
  %76 = call float @logf(float noundef %75) #4
  %77 = fadd float %74, %76
  call void @llvm.lifetime.end.p0(i64 4, ptr %13) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %12) #4
  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
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %5) #4
  ret float %77
}

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


; 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: nounwind uwtable
declare dso_local float @liquid_lngammaf(float noundef) local_unnamed_addr #0

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

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

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

; Function Attrs: nounwind uwtable
define dso_local float @liquid_lnlowergammaf(float noundef %0, float noundef %1) local_unnamed_addr #0 {
.peel.next:
  %2 = tail call float @logf(float noundef %1) #3
  %3 = tail call float @liquid_lngammaf(float noundef %0)
  %4 = tail call float @logf(float noundef %1) #3
  %5 = fadd float %0, 0.000000e+00
  %6 = fadd float %5, 1.000000e+00
  %7 = tail call float @liquid_lngammaf(float noundef %6)
  %8 = fneg float %7
  %9 = tail call float @llvm.fmuladd.f32(float %4, float 0.000000e+00, float %8)
  %10 = tail call float @expf(float noundef %9) #3, !tbaa !5
  %11 = fadd float %10, 0.000000e+00
  br label %12

12:                                               ; preds = %12, %.peel.next
  %.037 = phi float [ %9, %.peel.next ], [ %18, %12 ]
  %.02636 = phi float [ %9, %.peel.next ], [ %.1, %12 ]
  %.02735 = phi float [ %11, %.peel.next ], [ %20, %12 ]
  %.02934 = phi i32 [ 1, %.peel.next ], [ %26, %12 ]
  %13 = uitofp nneg i32 %.02934 to float
  %14 = fadd float %13, %0
  %15 = fadd float %14, 1.000000e+00
  %16 = tail call float @liquid_lngammaf(float noundef %15)
  %17 = fneg float %16
  %18 = tail call float @llvm.fmuladd.f32(float %13, float %4, float %17)
  %19 = tail call float @expf(float noundef %18) #3, !tbaa !5
  %20 = fadd float %.02735, %19
  %21 = fcmp ogt float %18, %.02636
  %.1 = select i1 %21, float %18, float %.02636
  %22 = icmp ugt i32 %.02934, 50
  %23 = fcmp ogt float %.037, %18
  %or.cond31 = and i1 %22, %23
  %24 = fsub float %.1, %18
  %25 = fcmp ogt float %24, 2.000000e+01
  %or.cond33 = select i1 %or.cond31, i1 %25, i1 false
  %26 = add nuw nsw i32 %.02934, 1
  %exitcond.not = icmp eq i32 %26, 1000
  %or.cond = select i1 %or.cond33, i1 true, i1 %exitcond.not
  br i1 %or.cond, label %.loopexit, label %12, !llvm.loop !9

.loopexit:                                        ; preds = %12
  %27 = fmul float %2, %0
  %28 = fadd float %27, %3
  %29 = fsub float %28, %1
  %30 = tail call float @logf(float noundef %20) #3
  %31 = fadd float %29, %30
  ret float %31
}

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 = { 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 #2 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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)"}
!5 = !{!6, !6, i64 0}
!6 = !{!"int", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = distinct !{!9, !10, !11}
!10 = !{!"llvm.loop.mustprogress"}
!11 = !{!"llvm.loop.peeled.count", i32 1}


; Effective O3 passes: BDCEPass,EarlyCSEPass,GVNPass,GlobalOptPass,IPSCCPPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopFullUnrollPass,LoopRotatePass,LoopUnrollPass,ReassociatePass,SCCPPass,SROAPass,SimplifyCFGPass,TailCallElimPass