#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
double rand_gauss(int /*<<< orphan*/, int);
double rand_uniform(int /*<<< orphan*/, double);
double sqrt(double);
double rand_wald(double a, double b) {
  double c, x, u;
  if ((a <= 0) || (b < 0))
    return 0;
  if (b < 1e-6)
    return a;
  c = (a * a * a) / b;
  x = rand_gauss(0, 1);
  x *= x;
  x *= a;
  x = a + a / (2 * c) * (x - sqrt(x * (4 * c + x)));
  u = rand_uniform(0, a + x);
  if (u <= a)
    return x;
  else
    return a * a / x;
}


x86 assembly (clang, -O0):
<rand_wald>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jae    115e <rand_wald+0x2e>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    116b <rand_wald+0x3b>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    129c <rand_wald+0x16c>
movsd  0xe8d(%rip),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    118d <rand_wald+0x5d>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    129c <rand_wald+0x16c>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
xor    %edi,%edi
mov    $0x1,%esi
call   1030 <rand_gauss@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe24(%rip),%xmm1
mulsd  -0x20(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x28(%rbp),%xmm2
movsd  0xded(%rip),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movsd  -0x48(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm3
movsd  -0x38(%rbp),%xmm0
subsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
xor    %edi,%edi
call   1040 <rand_uniform@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1288 <rand_wald+0x158>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    129c <rand_wald+0x16c>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_wald>:
sub    $0x28,%rsp
xorpd  %xmm3,%xmm3
ucomisd %xmm0,%xmm3
jae    1245 <rand_wald+0x115>
xorpd  %xmm2,%xmm2
ucomisd %xmm1,%xmm2
ja     1245 <rand_wald+0x115>
movsd  0xea8(%rip),%xmm2
ucomisd %xmm1,%xmm2
jbe    1167 <rand_wald+0x37>
movapd %xmm0,%xmm3
jmp    1245 <rand_wald+0x115>
movapd %xmm0,%xmm2
mulsd  %xmm0,%xmm2
movsd  %xmm2,0x20(%rsp)
mulsd  %xmm0,%xmm2
divsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
xor    %edi,%edi
mov    $0x1,%esi
movsd  %xmm0,0x10(%rsp)
call   1030 <rand_gauss@plt>
movsd  0x10(%rsp),%xmm1
movapd %xmm0,%xmm3
mulsd  %xmm0,%xmm3
mulsd  %xmm1,%xmm3
movsd  0x8(%rsp),%xmm4
movapd %xmm4,%xmm0
addsd  %xmm4,%xmm0
movapd %xmm1,%xmm2
divsd  %xmm0,%xmm2
mulsd  0xe43(%rip),%xmm4
addsd  %xmm3,%xmm4
mulsd  %xmm3,%xmm4
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm4
movapd %xmm4,%xmm0
jb     11e1 <rand_wald+0xb1>
sqrtsd %xmm0,%xmm0
jmp    1204 <rand_wald+0xd4>
movsd  %xmm2,0x8(%rsp)
movsd  %xmm3,0x18(%rsp)
call   1050 <sqrt@plt>
movsd  0x18(%rsp),%xmm3
movsd  0x8(%rsp),%xmm2
movsd  0x10(%rsp),%xmm1
subsd  %xmm0,%xmm3
mulsd  %xmm3,%xmm2
addsd  %xmm1,%xmm2
movsd  %xmm2,0x8(%rsp)
movapd %xmm2,%xmm0
addsd  %xmm1,%xmm0
xor    %edi,%edi
call   1040 <rand_uniform@plt>
movsd  0x10(%rsp),%xmm1
ucomisd %xmm0,%xmm1
jae    123f <rand_wald+0x10f>
movsd  0x20(%rsp),%xmm3
divsd  0x8(%rsp),%xmm3
jmp    1245 <rand_wald+0x115>
movsd  0x8(%rsp),%xmm3
movapd %xmm3,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @rand_wald(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
store double %0, double* %4
store double %1, double* %5
%9 = load double, double* %4
%10 = fcmp ole double %9, 0.000000e+00
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load double, double* %5
%13 = fcmp olt double %12, 0.000000e+00
br i1 %13, label %14, label %15
14: ; preds = %11, %2
store double 0.000000e+00, double* %3
br label %64
15: ; preds = %11
%16 = load double, double* %5
%17 = fcmp olt double %16, 0x3EB0C6F7A0B5ED8D
br i1 %17, label %18, label %20
18: ; preds = %15
%19 = load double, double* %4
store double %19, double* %3
br label %64
20: ; preds = %15
%21 = load double, double* %4
%22 = load double, double* %4
%23 = fmul double %21, %22
%24 = load double, double* %4
%25 = fmul double %23, %24
%26 = load double, double* %5
%27 = fdiv double %25, %26
store double %27, double* %6
%28 = call double @rand_gauss(i32 0, i32 1)
store double %28, double* %7
%29 = load double, double* %7
%30 = load double, double* %7
%31 = fmul double %30, %29
store double %31, double* %7
%32 = load double, double* %4
%33 = load double, double* %7
%34 = fmul double %33, %32
store double %34, double* %7
%35 = load double, double* %4
%36 = load double, double* %4
%37 = load double, double* %6
%38 = fmul double 2.000000e+00, %37
%39 = fdiv double %36, %38
%40 = load double, double* %7
%41 = load double, double* %7
%42 = load double, double* %6
%43 = load double, double* %7
%44 = call double @llvm.fmuladd.f64(double 4.000000e+00, double %42, double %43)
%45 = fmul double %41, %44
%46 = call double @sqrt(double %45)
%47 = fsub double %40, %46
%48 = call double @llvm.fmuladd.f64(double %39, double %47, double %35)
store double %48, double* %7
%49 = load double, double* %4
%50 = load double, double* %7
%51 = fadd double %49, %50
%52 = call double @rand_uniform(i32 0, double %51)
store double %52, double* %8
%53 = load double, double* %8
%54 = load double, double* %4
%55 = fcmp ole double %53, %54
br i1 %55, label %56, label %58
56: ; preds = %20
%57 = load double, double* %7
store double %57, double* %3
br label %64
58: ; preds = %20
%59 = load double, double* %4
%60 = load double, double* %4
%61 = fmul double %59, %60
%62 = load double, double* %7
%63 = fdiv double %61, %62
store double %63, double* %3
br label %64
64: ; preds = %58, %56, %18, %14
%65 = load double, double* %3
ret double %65
}

LLVM IR (-O2):
define double @rand_wald(double %0, double %1) {
%3 = fcmp ole double %0, 0.000000e+00
%4 = fcmp olt double %1, 0.000000e+00
%5 = or i1 %3, %4
br i1 %5, label %27, label %6
6: ; preds = %2
%7 = fcmp olt double %1, 0x3EB0C6F7A0B5ED8D
br i1 %7, label %27, label %8
8: ; preds = %6
%9 = fmul double %0, %0
%10 = fmul double %9, %0
%11 = fdiv double %10, %1
%12 = tail call double @rand_gauss(i32 0, i32 1)
%13 = fmul double %12, %12
%14 = fmul double %13, %0
%15 = fmul double %11, 2.000000e+00
%16 = fdiv double %0, %15
%17 = tail call double @llvm.fmuladd.f64(double %11, double 4.000000e+00, double %14)
%18 = fmul double %14, %17
%19 = tail call double @sqrt(double %18)
%20 = fsub double %14, %19
%21 = tail call double @llvm.fmuladd.f64(double %16, double %20, double %0)
%22 = fadd double %21, %0
%23 = tail call double @rand_uniform(i32 0, double %22)
%24 = fcmp ugt double %23, %0
br i1 %24, label %25, label %27
25: ; preds = %8
%26 = fdiv double %9, %21
br label %27
27: ; preds = %8, %6, %2, %25
%28 = phi double [ %26, %25 ], [ 0.000000e+00, %2 ], [ %0, %6 ], [ %21, %8 ]
ret double %28
}