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

; 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 [81 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [43 x i8], align 1

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

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

declare float @randf(...) #0

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

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

; Function Attrs: nounwind uwtable
define dso_local float @randgammaf_delta(float noundef %0) #3 {
  %2 = alloca float, align 4
  %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 float, align 4
  %10 = alloca float, align 4
  %11 = alloca float, align 4
  store float %0, ptr %3, align 4, !tbaa !5
  %12 = load float, ptr %3, align 4, !tbaa !5
  %13 = fcmp olt float %12, 0.000000e+00
  br i1 %13, label %17, label %14

14:                                               ; preds = %1
  %15 = load float, ptr %3, align 4, !tbaa !5
  %16 = fcmp oge float %15, 1.000000e+00
  br i1 %16, label %17, label %19

17:                                               ; preds = %14, %1
  %18 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef @.str, i32 noundef 135, ptr noundef @.str.7)
  store float 0.000000e+00, ptr %2, align 4
  br label %71

19:                                               ; preds = %14
  call void @llvm.lifetime.start.p0(i64 4, ptr %4) #4
  %20 = load float, ptr %3, align 4, !tbaa !5
  %21 = fdiv float 1.000000e+00, %20
  store float %21, ptr %4, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %5) #4
  %22 = call float @expf(float noundef 1.000000e+00) #4, !tbaa !9
  store float %22, ptr %5, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  %23 = load float, ptr %5, align 4, !tbaa !5
  %24 = load float, ptr %5, align 4, !tbaa !5
  %25 = load float, ptr %3, align 4, !tbaa !5
  %26 = fadd float %24, %25
  %27 = fdiv float %23, %26
  store float %27, ptr %6, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #4
  store float 0.000000e+00, 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 float 0.000000e+00, ptr %9, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #4
  store float 0.000000e+00, 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
  br label %28

28:                                               ; preds = %68, %19
  br label %29

29:                                               ; preds = %28
  %30 = call float (...) @randf()
  store float %30, ptr %7, align 4, !tbaa !5
  %31 = call float (...) @randf()
  store float %31, ptr %8, align 4, !tbaa !5
  %32 = call float (...) @randf()
  store float %32, ptr %9, align 4, !tbaa !5
  %33 = load float, ptr %9, align 4, !tbaa !5
  %34 = load float, ptr %6, align 4, !tbaa !5
  %35 = fcmp ole float %33, %34
  br i1 %35, label %36, label %46

36:                                               ; preds = %29
  %37 = load float, ptr %8, align 4, !tbaa !5
  %38 = load float, ptr %4, align 4, !tbaa !5
  %39 = call float @powf(float noundef %37, float noundef %38) #4
  store float %39, ptr %10, align 4, !tbaa !5
  %40 = load float, ptr %7, align 4, !tbaa !5
  %41 = load float, ptr %10, align 4, !tbaa !5
  %42 = load float, ptr %3, align 4, !tbaa !5
  %43 = fsub float %42, 1.000000e+00
  %44 = call float @powf(float noundef %41, float noundef %43) #4
  %45 = fmul float %40, %44
  store float %45, ptr %11, align 4, !tbaa !5
  br label %55

46:                                               ; preds = %29
  %47 = load float, ptr %8, align 4, !tbaa !5
  %48 = call float @logf(float noundef %47) #4
  %49 = fsub float 1.000000e+00, %48
  store float %49, ptr %10, align 4, !tbaa !5
  %50 = load float, ptr %7, align 4, !tbaa !5
  %51 = load float, ptr %10, align 4, !tbaa !5
  %52 = fneg float %51
  %53 = call float @expf(float noundef %52) #4, !tbaa !9
  %54 = fmul float %50, %53
  store float %54, ptr %11, align 4, !tbaa !5
  br label %55

55:                                               ; preds = %46, %36
  %56 = load float, ptr %11, align 4, !tbaa !5
  %57 = load float, ptr %10, align 4, !tbaa !5
  %58 = load float, ptr %3, align 4, !tbaa !5
  %59 = fsub float %58, 1.000000e+00
  %60 = call float @powf(float noundef %57, float noundef %59) #4
  %61 = load float, ptr %10, align 4, !tbaa !5
  %62 = fneg float %61
  %63 = call float @expf(float noundef %62) #4, !tbaa !9
  %64 = fmul float %60, %63
  %65 = fcmp ogt float %56, %64
  br i1 %65, label %66, label %67

66:                                               ; preds = %55
  br label %68

67:                                               ; preds = %55
  br label %69

68:                                               ; preds = %66
  br label %28

69:                                               ; preds = %67
  %70 = load float, ptr %10, align 4, !tbaa !5
  store float %70, ptr %2, align 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
  call void @llvm.lifetime.end.p0(i64 4, ptr %4) #4
  br label %71

71:                                               ; preds = %69, %17
  %72 = load float, ptr %2, align 4
  ret float %72
}

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

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

attributes #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 = { 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 #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}


; 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 [81 x i8], align 1
@.str.7 = external hidden unnamed_addr constant [43 x i8], align 1

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

declare float @randf(...) local_unnamed_addr #0

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

; Function Attrs: nounwind uwtable
define dso_local noundef float @randgammaf_delta(float noundef %0) local_unnamed_addr #2 {
  %2 = fcmp olt float %0, 0.000000e+00
  %3 = fcmp oge float %0, 1.000000e+00
  %or.cond = or i1 %2, %3
  br i1 %or.cond, label %4, label %6

4:                                                ; preds = %1
  %5 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef nonnull @.str, i32 noundef 135, ptr noundef nonnull @.str.7) #3
  br label %.loopexit

6:                                                ; preds = %1
  %7 = fdiv float 1.000000e+00, %0
  %8 = fadd float %0, 0x4005BF0A80000000
  %9 = fdiv float 0x4005BF0A80000000, %8
  %10 = fadd float %0, -1.000000e+00
  br label %11

11:                                               ; preds = %24, %6
  %12 = tail call float (...) @randf() #3
  %13 = tail call float (...) @randf() #3
  %14 = tail call float (...) @randf() #3
  %15 = fcmp ugt float %14, %9
  br i1 %15, label %19, label %16

16:                                               ; preds = %11
  %17 = tail call float @powf(float noundef %13, float noundef %7) #3
  %18 = tail call float @powf(float noundef %17, float noundef %10) #3
  %.pre = fneg float %17
  br label %24

19:                                               ; preds = %11
  %20 = tail call float @logf(float noundef %13) #3
  %21 = fsub float 1.000000e+00, %20
  %22 = fneg float %21
  %23 = tail call float @expf(float noundef %22) #3, !tbaa !5
  br label %24

24:                                               ; preds = %19, %16
  %.pre-phi = phi float [ %22, %19 ], [ %.pre, %16 ]
  %.023 = phi float [ %21, %19 ], [ %17, %16 ]
  %.pn = phi float [ %23, %19 ], [ %18, %16 ]
  %.0 = fmul float %12, %.pn
  %25 = tail call float @powf(float noundef %.023, float noundef %10) #3
  %26 = tail call float @expf(float noundef %.pre-phi) #3, !tbaa !5
  %27 = fmul float %25, %26
  %28 = fcmp ogt float %.0, %27
  br i1 %28, label %11, label %.loopexit

.loopexit:                                        ; preds = %24, %4
  %.024 = phi float [ 0.000000e+00, %4 ], [ %.023, %24 ]
  ret float %.024
}

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

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

attributes #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 = { 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 = { 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"}


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