#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_gamma(double);
double rand_beta(double a, double b) {
  double x, y, r;
  do {
    x = rand_gamma(a);
    y = rand_gamma(b);
    r = 1.0 + x / (x + y);
    r = r - 1.0;
  } while (r <= 0.0 || r >= 1.0);
  return r;
}


x86 assembly (clang, -O0):
<rand_beta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1030 <rand_gamma@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <rand_gamma@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
addsd  -0x20(%rbp),%xmm0
divsd  %xmm0,%xmm1
movsd  0xea5(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe8f(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x1,%al
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
mov    %al,-0x29(%rbp)
jae    11a4 <rand_beta+0x94>
movsd  -0x28(%rbp),%xmm0
movsd  0xe66(%rip),%xmm1
ucomisd %xmm1,%xmm0
setae  %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    1122 <rand_beta+0x12>
movsd  -0x28(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_beta>:
sub    $0x18,%rsp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
nop
movsd  (%rsp),%xmm0
call   1030 <rand_gamma@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x8(%rsp),%xmm0
call   1030 <rand_gamma@plt>
movsd  0x10(%rsp),%xmm1
addsd  %xmm1,%xmm0
divsd  %xmm0,%xmm1
addsd  0xeaf(%rip),%xmm1
addsd  0xeaf(%rip),%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm1,%xmm0
jae    1120 <rand_beta+0x10>
movapd %xmm1,%xmm0
ucomisd 0xe91(%rip),%xmm1
jae    1120 <rand_beta+0x10>
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @rand_beta(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %3
store double %1, double* %4
br label %8
8: ; preds = %27, %2
%9 = load double, double* %3
%10 = call double @rand_gamma(double %9)
store double %10, double* %5
%11 = load double, double* %4
%12 = call double @rand_gamma(double %11)
store double %12, double* %6
%13 = load double, double* %5
%14 = load double, double* %5
%15 = load double, double* %6
%16 = fadd double %14, %15
%17 = fdiv double %13, %16
%18 = fadd double 1.000000e+00, %17
store double %18, double* %7
%19 = load double, double* %7
%20 = fsub double %19, 1.000000e+00
store double %20, double* %7
br label %21
21: ; preds = %8
%22 = load double, double* %7
%23 = fcmp ole double %22, 0.000000e+00
br i1 %23, label %27, label %24
24: ; preds = %21
%25 = load double, double* %7
%26 = fcmp oge double %25, 1.000000e+00
br label %27
27: ; preds = %24, %21
%28 = phi i1 [ true, %21 ], [ %26, %24 ]
br i1 %28, label %8, label %29
29: ; preds = %27
%30 = load double, double* %7
ret double %30
}

LLVM IR (-O2):
define double @rand_beta(double %0, double %1) {
br label %3
3: ; preds = %3, %2
%4 = tail call double @rand_gamma(double %0)
%5 = tail call double @rand_gamma(double %1)
%6 = fadd double %4, %5
%7 = fdiv double %4, %6
%8 = fadd double %7, 1.000000e+00
%9 = fadd double %8, -1.000000e+00
%10 = fcmp ole double %9, 0.000000e+00
%11 = fcmp oge double %9, 1.000000e+00
%12 = or i1 %10, %11
br i1 %12, label %3, label %13
13: ; preds = %3
ret double %9
}