#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();
double RandN();
double exp(double);
int log(double);
double sqrt(int);
double GammaRand(double a) {
  double boost, d, c, v;
  if (a < 1) {
    boost = exp(log(Rand()) / a);
    a++;
  } else
    boost = 1;
  d = a - 1.0 / 3;
  c = 1.0 / sqrt(9 * d);
  while (1) {
    double x, u;
    do {
      x = RandN();
      v = 1 + c * x;
    } while (v <= 0);
    v = v * v * v;
    x = x * x;
    u = Rand();
    if ((u < 1 - .0331 * x * x) || (log(u) < 0.5 * x + d * (1 - v + log(v))))
      break;
  }
  return (boost * d * v);
}


x86 assembly (clang, -O0):
<GammaRand>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xe9b(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11a6 <GammaRand+0x56>
mov    $0x0,%al
call   1070 <Rand@plt>
call   1050 <log@plt>
cvtsi2sd %eax,%xmm0
divsd  -0x8(%rbp),%xmm0
call   1040 <exp@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  0xe69(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11b3 <GammaRand+0x63>
movsd  0xe52(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe50(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe37(%rip),%xmm0
mulsd  -0x18(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xe16(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    11f8 <GammaRand+0xa8>
mov    $0x0,%al
call   1030 <RandN@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xde6(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jae    11f8 <GammaRand+0xa8>
movsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1070 <Rand@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm1
movsd  0xdab(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
movsd  0xd66(%rip),%xmm2
addsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
ja     1325 <GammaRand+0x1d5>
movsd  -0x38(%rbp),%xmm0
call   1050 <log@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  0xd29(%rip),%xmm0
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <log@plt>
movsd  -0x58(%rbp),%xmm3
movsd  -0x50(%rbp),%xmm2
movsd  -0x48(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm1
cvtsi2sd %eax,%xmm4
addsd  %xmm4,%xmm3
mulsd  %xmm3,%xmm2
movsd  0xd0d(%rip),%xmm3
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    132a <GammaRand+0x1da>
jmp    132f <GammaRand+0x1df>
jmp    11f3 <GammaRand+0xa3>
movsd  -0x10(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GammaRand>:
sub    $0x38,%rsp
movapd %xmm0,%xmm1
movsd  0xea0(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    119d <GammaRand+0x4d>
xor    %eax,%eax
movsd  %xmm1,(%rsp)
call   1070 <Rand@plt>
call   1050 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  (%rsp),%xmm0
call   1040 <exp@plt>
movsd  (%rsp),%xmm1
movsd  %xmm0,0x8(%rsp)
addsd  0xe65(%rip),%xmm1
jmp    11a3 <GammaRand+0x53>
movsd  %xmm0,0x8(%rsp)
addsd  0xe5d(%rip),%xmm1
movsd  0xe5d(%rip),%xmm0
movsd  %xmm1,(%rsp)
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
movsd  0xe33(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x30(%rsp)
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <RandN@plt>
movsd  0x30(%rsp),%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe07(%rip),%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm2,%xmm1
jae    11e0 <GammaRand+0x90>
movapd %xmm2,%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm1
movsd  %xmm1,0x10(%rsp)
mulsd  %xmm0,%xmm0
movsd  %xmm0,0x18(%rsp)
xor    %eax,%eax
call   1070 <Rand@plt>
movsd  0x18(%rsp),%xmm2
movapd %xmm2,%xmm1
mulsd  0xde0(%rip),%xmm1
mulsd  %xmm2,%xmm1
addsd  0xdbc(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     12a9 <GammaRand+0x159>
call   1050 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  0xd9c(%rip),%xmm1
movsd  0x10(%rsp),%xmm0
subsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
call   1050 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x20(%rsp),%xmm0
mulsd  (%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
mulsd  0xd87(%rip),%xmm1
addsd  %xmm0,%xmm1
ucomisd 0x28(%rsp),%xmm1
jbe    11e0 <GammaRand+0x90>
movsd  0x8(%rsp),%xmm0
mulsd  (%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
add    $0x38,%rsp
ret

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

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