#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 genrand_real1();
int log(double);
double pow(double, double);
double rnorm();
int sqrt(int);
double rgamma(double aa) {
  double a = aa;
  if (aa < 1.0) {
    a += 1.0;
  }
  double d, c, x, v, u;
  d = a - 1. / 3.;
  c = 1. / sqrt(9. * d);
  for (;;) {
    do {
      x = rnorm();
      v = 1. + c * x;
    } while (v <= 0.);
    v = v * v * v;
    u = genrand_real1();
    if (u < 1. - 0.0331 * (x * x) * (x * x)) {
      break;
    }
    if (log(u) < 0.5 * x * x + d * (1. - v + log(v))) {
      break;
    }
  }
  if (aa < 1.0) {
    double u;
    do {
      u = genrand_real1();
    } while (u == 0);
    return (d * v) * pow(u, 1.0 / aa);
  }
  return (d * v);
}


x86 assembly (clang, -O0):
<rgamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe8e(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    118f <rgamma+0x3f>
movsd  0xe7b(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe74(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe5b(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
cvtsi2sd %eax,%xmm1
movsd  0xe39(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    11d5 <rgamma+0x85>
mov    $0x0,%al
call   1030 <rnorm@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe09(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x38(%rbp),%xmm0
jae    11d5 <rgamma+0x85>
movsd  -0x38(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1070 <genrand_real1@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
mulsd  -0x30(%rbp),%xmm2
movsd  0xdd3(%rip),%xmm0
mulsd  %xmm2,%xmm0
movsd  -0x30(%rbp),%xmm2
mulsd  -0x30(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
movsd  0xd8a(%rip),%xmm2
addsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1289 <rgamma+0x139>
jmp    131f <rgamma+0x1cf>
movsd  -0x40(%rbp),%xmm0
call   1040 <log@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xd7c(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  0xd36(%rip),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x38(%rbp),%xmm0
call   1040 <log@plt>
movsd  -0x70(%rbp),%xmm4
movsd  -0x68(%rbp),%xmm2
movsd  -0x60(%rbp),%xmm0
movsd  -0x58(%rbp),%xmm3
movsd  -0x50(%rbp),%xmm1
cvtsi2sd %eax,%xmm5
addsd  %xmm5,%xmm4
mulsd  %xmm4,%xmm2
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    131a <rgamma+0x1ca>
jmp    131f <rgamma+0x1cf>
jmp    11d0 <rgamma+0x80>
movsd  0xcd9(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    139c <rgamma+0x24c>
jmp    1337 <rgamma+0x1e7>
mov    $0x0,%al
call   1070 <genrand_real1@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1360 <rgamma+0x210>
jp     1360 <rgamma+0x210>
jmp    1337 <rgamma+0x1e7>
movsd  -0x20(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x78(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  0xc84(%rip),%xmm1
divsd  -0x10(%rbp),%xmm1
call   1050 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x78(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    13ab <rgamma+0x25b>
movsd  -0x20(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rgamma>:
sub    $0x58,%rsp
movsd  0xea4(%rip),%xmm3
movapd %xmm0,%xmm2
addsd  %xmm3,%xmm2
movapd %xmm0,%xmm1
cmpltsd %xmm3,%xmm1
andpd  %xmm1,%xmm2
movapd %xmm0,0x40(%rsp)
andnpd %xmm0,%xmm1
orpd   %xmm2,%xmm1
addsd  0xe81(%rip),%xmm1
movsd  0xe81(%rip),%xmm0
movapd %xmm1,0x10(%rsp)
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0xe4f(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x38(%rsp)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rnorm@plt>
movsd  0x38(%rsp),%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe27(%rip),%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm2,%xmm1
jae    11c0 <rgamma+0x70>
movapd %xmm2,%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
movsd  %xmm0,0x8(%rsp)
call   1070 <genrand_real1@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm1
movapd %xmm1,%xmm2
mulsd  0xe01(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xddd(%rip),%xmm2
ucomisd %xmm0,%xmm2
ja     129a <rgamma+0x14a>
call   1040 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x30(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xdd7(%rip),%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  0xda9(%rip),%xmm1
movsd  (%rsp),%xmm0
subsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
call   1040 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x20(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
ucomisd 0x30(%rsp),%xmm1
jbe    11c0 <rgamma+0x70>
movsd  0xd5e(%rip),%xmm0
ucomisd 0x40(%rsp),%xmm0
jbe    12f2 <rgamma+0x1a2>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1070 <genrand_real1@plt>
ucomisd 0xd69(%rip),%xmm0
jne    12c3 <rgamma+0x173>
jnp    12b0 <rgamma+0x160>
movapd 0x10(%rsp),%xmm1
mulsd  (%rsp),%xmm1
movapd %xmm1,0x10(%rsp)
movsd  0xd24(%rip),%xmm1
divsd  0x40(%rsp),%xmm1
call   1050 <pow@plt>
mulsd  0x10(%rsp),%xmm0
add    $0x58,%rsp
ret
movapd 0x10(%rsp),%xmm0
mulsd  (%rsp),%xmm0
add    $0x58,%rsp
ret

LLVM IR (-O0):
define double @rgamma(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
store double %0, double* %3
%11 = load double, double* %3
store double %11, double* %4
%12 = load double, double* %3
%13 = fcmp olt double %12, 1.000000e+00
br i1 %13, label %14, label %17
14: ; preds = %1
%15 = load double, double* %4
%16 = fadd double %15, 1.000000e+00
store double %16, double* %4
br label %17
17: ; preds = %14, %1
%18 = load double, double* %4
%19 = fsub double %18, 0x3FD5555555555555
store double %19, double* %5
%20 = load double, double* %5
%21 = fmul double 9.000000e+00, %20
%22 = fptosi double %21 to i32
%23 = call i32 @sqrt(i32 %22)
%24 = sitofp i32 %23 to double
%25 = fdiv double 1.000000e+00, %24
store double %25, double* %6
br label %26
26: ; preds = %72, %17
br label %27
27: ; preds = %32, %26
%28 = call double (...) @rnorm()
store double %28, double* %7
%29 = load double, double* %6
%30 = load double, double* %7
%31 = call double @llvm.fmuladd.f64(double %29, double %30, double 1.000000e+00)
store double %31, double* %8
br label %32
32: ; preds = %27
%33 = load double, double* %8
%34 = fcmp ole double %33, 0.000000e+00
br i1 %34, label %27, label %35
35: ; preds = %32
%36 = load double, double* %8
%37 = load double, double* %8
%38 = fmul double %36, %37
%39 = load double, double* %8
%40 = fmul double %38, %39
store double %40, double* %8
%41 = call double (...) @genrand_real1()
store double %41, double* %9
%42 = load double, double* %9
%43 = load double, double* %7
%44 = load double, double* %7
%45 = fmul double %43, %44
%46 = fmul double 3.310000e-02, %45
%47 = load double, double* %7
%48 = load double, double* %7
%49 = fmul double %47, %48
%50 = fneg double %46
%51 = call double @llvm.fmuladd.f64(double %50, double %49, double 1.000000e+00)
%52 = fcmp olt double %42, %51
br i1 %52, label %53, label %54
53: ; preds = %35
br label %73
54: ; preds = %35
%55 = load double, double* %9
%56 = call i32 @log(double %55)
%57 = sitofp i32 %56 to double
%58 = load double, double* %7
%59 = fmul double 5.000000e-01, %58
%60 = load double, double* %7
%61 = load double, double* %5
%62 = load double, double* %8
%63 = fsub double 1.000000e+00, %62
%64 = load double, double* %8
%65 = call i32 @log(double %64)
%66 = sitofp i32 %65 to double
%67 = fadd double %63, %66
%68 = fmul double %61, %67
%69 = call double @llvm.fmuladd.f64(double %59, double %60, double %68)
%70 = fcmp olt double %57, %69
br i1 %70, label %71, label %72
71: ; preds = %54
br label %73
72: ; preds = %54
br label %26
73: ; preds = %71, %53
%74 = load double, double* %3
%75 = fcmp olt double %74, 1.000000e+00
br i1 %75, label %76, label %91
76: ; preds = %73
br label %77
77: ; preds = %79, %76
%78 = call double (...) @genrand_real1()
store double %78, double* %10
br label %79
79: ; preds = %77
%80 = load double, double* %10
%81 = fcmp oeq double %80, 0.000000e+00
br i1 %81, label %77, label %82
82: ; preds = %79
%83 = load double, double* %5
%84 = load double, double* %8
%85 = fmul double %83, %84
%86 = load double, double* %10
%87 = load double, double* %3
%88 = fdiv double 1.000000e+00, %87
%89 = call double @pow(double %86, double %88)
%90 = fmul double %85, %89
store double %90, double* %2
br label %95
91: ; preds = %73
%92 = load double, double* %5
%93 = load double, double* %8
%94 = fmul double %92, %93
store double %94, double* %2
br label %95
95: ; preds = %91, %82
%96 = load double, double* %2
ret double %96
}

LLVM IR (-O2):
define double @rgamma(double %0) {
%2 = fcmp olt double %0, 1.000000e+00
%3 = fadd double %0, 1.000000e+00
%4 = select i1 %2, double %3, double %0
%5 = fadd double %4, 0xBFD5555555555555
%6 = fmul double %5, 9.000000e+00
%7 = fptosi double %6 to i32
%8 = tail call i32 @sqrt(i32 %7)
%9 = sitofp i32 %8 to double
%10 = fdiv double 1.000000e+00, %9
br label %11
11: ; preds = %15, %1
%12 = tail call double (...) @rnorm()
%13 = tail call double @llvm.fmuladd.f64(double %10, double %12, double 1.000000e+00)
%14 = fcmp ugt double %13, 0.000000e+00
br i1 %14, label %16, label %15
15: ; preds = %11, %24
br label %11
16: ; preds = %11
%17 = fmul double %13, %13
%18 = fmul double %13, %17
%19 = tail call double (...) @genrand_real1()
%20 = fmul double %12, %12
%21 = fmul double %20, -3.310000e-02
%22 = tail call double @llvm.fmuladd.f64(double %21, double %20, double 1.000000e+00)
%23 = fcmp olt double %19, %22
br i1 %23, label %35, label %24
24: ; preds = %16
%25 = tail call i32 @log(double %19)
%26 = sitofp i32 %25 to double
%27 = fmul double %12, 5.000000e-01
%28 = fsub double 1.000000e+00, %18
%29 = tail call i32 @log(double %18)
%30 = sitofp i32 %29 to double
%31 = fadd double %28, %30
%32 = fmul double %5, %31
%33 = tail call double @llvm.fmuladd.f64(double %27, double %12, double %32)
%34 = fcmp ogt double %33, %26
br i1 %34, label %35, label %15
35: ; preds = %24, %16
br i1 %2, label %36, label %44
36: ; preds = %35, %36
%37 = tail call double (...) @genrand_real1()
%38 = fcmp oeq double %37, 0.000000e+00
br i1 %38, label %36, label %39
39: ; preds = %36
%40 = fmul double %5, %18
%41 = fdiv double 1.000000e+00, %0
%42 = tail call double @pow(double %37, double %41)
%43 = fmul double %40, %42
br label %46
44: ; preds = %35
%45 = fmul double %5, %18
br label %46
46: ; preds = %44, %39
%47 = phi double [ %43, %39 ], [ %45, %44 ]
ret double %47
}