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

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

14:                                               ; preds = %2
  %15 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef @.str, i32 noundef 38, ptr noundef @.str.1)
  store float 0.000000e+00, ptr %3, align 4
  br label %52

16:                                               ; preds = %2
  %17 = load float, ptr %5, align 4, !tbaa !5
  %18 = fcmp ole float %17, 0.000000e+00
  br i1 %18, label %19, label %21

19:                                               ; preds = %16
  %20 = call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef @.str, i32 noundef 41, ptr noundef @.str.2)
  store float 0.000000e+00, ptr %3, align 4
  br label %52

21:                                               ; preds = %16
  br label %22

22:                                               ; preds = %21
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #5
  %23 = load float, ptr %4, align 4, !tbaa !5
  %24 = call float @llvm.floor.f32(float %23)
  %25 = fptoui float %24 to i32
  store i32 %25, ptr %6, align 4, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %7) #5
  %26 = load float, ptr %4, align 4, !tbaa !5
  %27 = load i32, ptr %6, align 4, !tbaa !9
  %28 = uitofp i32 %27 to float
  %29 = fsub float %26, %28
  store float %29, ptr %7, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %8) #5
  store float 0.000000e+00, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.start.p0(i64 4, ptr %9) #5
  store i32 0, ptr %9, align 4, !tbaa !9
  br label %30

30:                                               ; preds = %41, %22
  %31 = load i32, ptr %9, align 4, !tbaa !9
  %32 = load i32, ptr %6, align 4, !tbaa !9
  %33 = icmp ult i32 %31, %32
  br i1 %33, label %34, label %44

34:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %10) #5
  %35 = call float (...) @randf()
  store float %35, ptr %10, align 4, !tbaa !5
  %36 = load float, ptr %10, align 4, !tbaa !5
  %37 = call float @logf(float noundef %36) #5
  %38 = fneg float %37
  %39 = load float, ptr %8, align 4, !tbaa !5
  %40 = fadd float %39, %38
  store float %40, ptr %8, align 4, !tbaa !5
  call void @llvm.lifetime.end.p0(i64 4, ptr %10) #5
  br label %41

41:                                               ; preds = %34
  %42 = load i32, ptr %9, align 4, !tbaa !9
  %43 = add i32 %42, 1
  store i32 %43, ptr %9, align 4, !tbaa !9
  br label %30, !llvm.loop !11

44:                                               ; preds = %30
  call void @llvm.lifetime.start.p0(i64 4, ptr %11) #5
  %45 = load float, ptr %7, align 4, !tbaa !5
  %46 = call float @randgammaf_delta(float noundef %45)
  store float %46, ptr %11, align 4, !tbaa !5
  %47 = load float, ptr %5, align 4, !tbaa !5
  %48 = load float, ptr %11, align 4, !tbaa !5
  %49 = load float, ptr %8, align 4, !tbaa !5
  %50 = fadd float %48, %49
  %51 = fmul float %47, %50
  store float %51, ptr %3, align 4
  call void @llvm.lifetime.end.p0(i64 4, ptr %11) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %9) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %8) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %7) #5
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #5
  br label %52

52:                                               ; preds = %44, %19, %14
  %53 = load float, ptr %3, align 4
  ret float %53
}

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

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

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

declare float @randf(...) #1

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

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

; Function Attrs: nounwind uwtable
declare dso_local float @randgammaf_delta(float noundef) #0

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

@.str = external hidden unnamed_addr constant [81 x i8], align 1
@.str.1 = external hidden unnamed_addr constant [46 x i8], align 1
@.str.2 = external hidden unnamed_addr constant [45 x i8], align 1

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

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

6:                                                ; preds = %2
  %7 = fcmp ugt float %1, 0.000000e+00
  br i1 %7, label %10, label %8

8:                                                ; preds = %6
  %9 = tail call i32 (i32, ptr, i32, ptr, ...) @liquid_error_fl(i32 noundef 3, ptr noundef nonnull @.str, i32 noundef 41, ptr noundef nonnull @.str.2) #4
  br label %22

10:                                               ; preds = %6
  %11 = tail call float @llvm.floor.f32(float %0)
  %12 = fptoui float %11 to i32
  %13 = uitofp i32 %12 to float
  %14 = fsub float %0, %13
  %.not = icmp eq i32 %12, 0
  br i1 %.not, label %._crit_edge, label %.lr.ph

.lr.ph:                                           ; preds = %10, %.lr.ph
  %.01419 = phi float [ %17, %.lr.ph ], [ 0.000000e+00, %10 ]
  %.01518 = phi i32 [ %18, %.lr.ph ], [ 0, %10 ]
  %15 = tail call float (...) @randf() #4
  %16 = tail call float @logf(float noundef %15) #4
  %17 = fsub float %.01419, %16
  %18 = add nuw i32 %.01518, 1
  %exitcond.not = icmp eq i32 %18, %12
  br i1 %exitcond.not, label %._crit_edge, label %.lr.ph, !llvm.loop !5

._crit_edge:                                      ; preds = %.lr.ph, %10
  %.014.lcssa = phi float [ 0.000000e+00, %10 ], [ %17, %.lr.ph ]
  %19 = tail call float @randgammaf_delta(float noundef %14)
  %20 = fadd float %.014.lcssa, %19
  %21 = fmul float %20, %1
  br label %22

22:                                               ; preds = %._crit_edge, %8, %4
  %.0 = phi float [ 0.000000e+00, %4 ], [ 0.000000e+00, %8 ], [ %21, %._crit_edge ]
  ret float %.0
}

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

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

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

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

; Function Attrs: nounwind uwtable
declare dso_local float @randgammaf_delta(float noundef) local_unnamed_addr #0

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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
attributes #3 = { 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 #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 = distinct !{!5, !6}
!6 = !{!"llvm.loop.mustprogress"}


; Effective O3 passes: CorrelatedValuePropagationPass,GVNPass,GlobalOptPass,IndVarSimplifyPass,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,JumpThreadingPass,LCSSAPass,LoopRotatePass,LoopSimplifyPass,LoopUnrollPass,ReassociatePass,SROAPass,SimplifyCFGPass,TailCallElimPass