; LLVM IR from 3ki5tj/minmd :: src/lib/minmd_math/rng (test)

; 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: nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #0

; Function Attrs: nounwind uwtable
declare dso_local double @rng_rand01(ptr noundef) #1

; Function Attrs: nounwind uwtable
declare dso_local double @rng_gauss(ptr noundef) #1

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

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

; Function Attrs: nounwind uwtable
define dso_local double @rng_gamma(ptr noundef %0, double noundef %1) #1 {
  %3 = alloca double, align 8
  %4 = alloca ptr, align 8
  %5 = alloca double, align 8
  %6 = alloca i32, align 4
  %7 = alloca double, align 8
  %8 = alloca double, align 8
  %9 = alloca double, align 8
  %10 = alloca double, align 8
  %11 = alloca double, align 8
  %12 = alloca i32, align 4
  store ptr %0, ptr %4, align 8, !tbaa !5
  store double %1, ptr %5, align 8, !tbaa !9
  call void @llvm.lifetime.start.p0(i64 4, ptr %6) #4
  store i32 0, ptr %6, align 4, !tbaa !11
  call void @llvm.lifetime.start.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.start.p0(i64 8, ptr %11) #4
  %13 = load double, ptr %5, align 8, !tbaa !9
  %14 = fcmp ole double %13, 0.000000e+00
  br i1 %14, label %15, label %16

15:                                               ; preds = %2
  store double 0.000000e+00, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %91

16:                                               ; preds = %2
  %17 = load double, ptr %5, align 8, !tbaa !9
  %18 = fcmp olt double %17, 1.000000e+00
  br i1 %18, label %19, label %22

19:                                               ; preds = %16
  store i32 1, ptr %6, align 4, !tbaa !11
  %20 = load double, ptr %5, align 8, !tbaa !9
  %21 = fadd double %20, 1.000000e+00
  store double %21, ptr %5, align 8, !tbaa !9
  br label %22

22:                                               ; preds = %19, %16
  %23 = load double, ptr %5, align 8, !tbaa !9
  %24 = fsub double %23, 0x3FD5555555555555
  store double %24, ptr %7, align 8, !tbaa !9
  %25 = load double, ptr %7, align 8, !tbaa !9
  %26 = call double @sqrt(double noundef %25) #4
  %27 = fdiv double 0x3FD5555555555555, %26
  store double %27, ptr %8, align 8, !tbaa !9
  br label %28

28:                                               ; preds = %72, %22
  br label %29

29:                                               ; preds = %35, %28
  %30 = load ptr, ptr %4, align 8, !tbaa !5
  %31 = call double @rng_gauss(ptr noundef %30)
  store double %31, ptr %9, align 8, !tbaa !9
  %32 = load double, ptr %8, align 8, !tbaa !9
  %33 = load double, ptr %9, align 8, !tbaa !9
  %34 = call double @llvm.fmuladd.f64(double %32, double %33, double 1.000000e+00)
  store double %34, ptr %10, align 8, !tbaa !9
  br label %35

35:                                               ; preds = %29
  %36 = load double, ptr %10, align 8, !tbaa !9
  %37 = fcmp ole double %36, 0.000000e+00
  br i1 %37, label %29, label %38, !llvm.loop !13

38:                                               ; preds = %35
  %39 = load double, ptr %10, align 8, !tbaa !9
  %40 = load double, ptr %10, align 8, !tbaa !9
  %41 = fmul double %39, %40
  %42 = load double, ptr %10, align 8, !tbaa !9
  %43 = fmul double %42, %41
  store double %43, ptr %10, align 8, !tbaa !9
  %44 = load double, ptr %9, align 8, !tbaa !9
  %45 = load double, ptr %9, align 8, !tbaa !9
  %46 = fmul double %45, %44
  store double %46, ptr %9, align 8, !tbaa !9
  %47 = load ptr, ptr %4, align 8, !tbaa !5
  %48 = call double @rng_rand01(ptr noundef %47)
  store double %48, ptr %11, align 8, !tbaa !9
  %49 = load double, ptr %11, align 8, !tbaa !9
  %50 = load double, ptr %9, align 8, !tbaa !9
  %51 = fmul double 3.310000e-01, %50
  %52 = load double, ptr %9, align 8, !tbaa !9
  %53 = fneg double %51
  %54 = call double @llvm.fmuladd.f64(double %53, double %52, double 1.000000e+00)
  %55 = fcmp ole double %49, %54
  br i1 %55, label %56, label %57

56:                                               ; preds = %38
  br label %73

57:                                               ; preds = %38
  %58 = load double, ptr %11, align 8, !tbaa !9
  %59 = call double @log(double noundef %58) #4
  store double %59, ptr %11, align 8, !tbaa !9
  %60 = load double, ptr %11, align 8, !tbaa !9
  %61 = load double, ptr %9, align 8, !tbaa !9
  %62 = load double, ptr %7, align 8, !tbaa !9
  %63 = load double, ptr %10, align 8, !tbaa !9
  %64 = fsub double 1.000000e+00, %63
  %65 = load double, ptr %10, align 8, !tbaa !9
  %66 = call double @log(double noundef %65) #4
  %67 = fadd double %64, %66
  %68 = fmul double %62, %67
  %69 = call double @llvm.fmuladd.f64(double 5.000000e-01, double %61, double %68)
  %70 = fcmp ole double %60, %69
  br i1 %70, label %71, label %72

71:                                               ; preds = %57
  br label %73

72:                                               ; preds = %57
  br label %28

73:                                               ; preds = %71, %56
  %74 = load double, ptr %7, align 8, !tbaa !9
  %75 = load double, ptr %10, align 8, !tbaa !9
  %76 = fmul double %74, %75
  store double %76, ptr %9, align 8, !tbaa !9
  %77 = load i32, ptr %6, align 4, !tbaa !11
  %78 = icmp ne i32 %77, 0
  br i1 %78, label %79, label %89

79:                                               ; preds = %73
  %80 = load ptr, ptr %4, align 8, !tbaa !5
  %81 = call double @rng_rand01(ptr noundef %80)
  %82 = fsub double 1.000000e+00, %81
  %83 = load double, ptr %5, align 8, !tbaa !9
  %84 = fsub double %83, 1.000000e+00
  %85 = fdiv double 1.000000e+00, %84
  %86 = call double @pow(double noundef %82, double noundef %85) #4
  %87 = load double, ptr %9, align 8, !tbaa !9
  %88 = fmul double %87, %86
  store double %88, ptr %9, align 8, !tbaa !9
  br label %89

89:                                               ; preds = %79, %73
  %90 = load double, ptr %9, align 8, !tbaa !9
  store double %90, ptr %3, align 8
  store i32 1, ptr %12, align 4
  br label %91

91:                                               ; preds = %89, %15
  call void @llvm.lifetime.end.p0(i64 8, ptr %11) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %10) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %9) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %8) #4
  call void @llvm.lifetime.end.p0(i64 8, ptr %7) #4
  call void @llvm.lifetime.end.p0(i64 4, ptr %6) #4
  %92 = load double, ptr %3, align 8
  ret double %92
}

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

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

attributes #0 = { nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
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 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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 = !{!"any pointer", !7, i64 0}
!7 = !{!"omnipotent char", !8, i64 0}
!8 = !{!"Simple C/C++ TBAA"}
!9 = !{!10, !10, i64 0}
!10 = !{!"double", !7, i64 0}
!11 = !{!12, !12, i64 0}
!12 = !{!"int", !7, i64 0}
!13 = distinct !{!13, !14}
!14 = !{!"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 double @rng_rand01(ptr noundef) local_unnamed_addr #0

; Function Attrs: nounwind uwtable
declare dso_local double @rng_gauss(ptr noundef) local_unnamed_addr #0

; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #1

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

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

4:                                                ; preds = %2
  %5 = fcmp uge double %1, 1.000000e+00
  %6 = fadd double %1, 1.000000e+00
  %.032 = select i1 %5, double %1, double %6
  %7 = fadd double %.032, 0xBFD5555555555555
  %8 = tail call double @sqrt(double noundef %7) #3
  %9 = fdiv double 0x3FD5555555555555, %8
  br label %10

10:                                               ; preds = %.backedge, %4
  %11 = tail call double @rng_gauss(ptr noundef %0)
  %12 = tail call double @llvm.fmuladd.f64(double %9, double %11, double 1.000000e+00)
  %13 = fcmp ugt double %12, 0.000000e+00
  br i1 %13, label %14, label %.backedge

.backedge:                                        ; preds = %10, %22
  br label %10, !llvm.loop !5

14:                                               ; preds = %10
  %15 = fmul double %12, %12
  %16 = fmul double %12, %15
  %17 = fmul double %11, %11
  %18 = tail call double @rng_rand01(ptr noundef %0)
  %19 = fmul double %17, -3.310000e-01
  %20 = tail call double @llvm.fmuladd.f64(double %19, double %17, double 1.000000e+00)
  %21 = fcmp ugt double %18, %20
  br i1 %21, label %22, label %30

22:                                               ; preds = %14
  %23 = tail call double @log(double noundef %18) #3
  %24 = fsub double 1.000000e+00, %16
  %25 = tail call double @log(double noundef %16) #3
  %26 = fadd double %24, %25
  %27 = fmul double %7, %26
  %28 = tail call double @llvm.fmuladd.f64(double %17, double 5.000000e-01, double %27)
  %29 = fcmp ugt double %23, %28
  br i1 %29, label %.backedge, label %30

30:                                               ; preds = %22, %14
  %31 = fmul double %7, %16
  br i1 %5, label %39, label %32

32:                                               ; preds = %30
  %33 = tail call double @rng_rand01(ptr noundef %0)
  %34 = fsub double 1.000000e+00, %33
  %35 = fadd double %6, -1.000000e+00
  %36 = fdiv double 1.000000e+00, %35
  %37 = tail call double @pow(double noundef %34, double noundef %36) #3
  %38 = fmul double %31, %37
  br label %39

39:                                               ; preds = %30, %32, %2
  %.031 = phi double [ 0.000000e+00, %2 ], [ %38, %32 ], [ %31, %30 ]
  ret double %.031
}

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

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

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 nocallback nofree nosync nounwind speculatable willreturn memory(none) }
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 = { 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,InferFunctionAttrsPass,InstCombinePass,InstSimplifyPass,LCSSAPass,LoopUnrollPass,SROAPass,SimplifyCFGPass,TailCallElimPass