#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 */
int log(double);
double pow(double, int);
double rndNormal();
double rndu();
double sqrt(double);
double rndgamma(double a) {
  double a0 = a, c, d, u, v, x, small = 1E-300;
  if (a < 1)
    a++;
  d = a - 1.0 / 3.0;
  c = (1.0 / 3.0) / sqrt(d);
  for (;;) {
    do {
      x = rndNormal();
      v = 1.0 + c * x;
    } while (v <= 0);
    v *= v * v;
    u = rndu();
    if (u < 1 - 0.0331 * x * x * x * x)
      break;
    if (log(u) < 0.5 * x * x + d * (1 - v + log(v)))
      break;
  }
  v *= d;
  if (a0 < 1)
    v *= pow(rndu(), 1 / a0);
  if (v == 0)
    v = small;
  return v;
}


x86 assembly (clang, -O0):
<rndgamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe99(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe84(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    1199 <rndgamma+0x49>
movsd  0xe71(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe6a(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1070 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xe4c(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11d2 <rndgamma+0x82>
mov    $0x0,%al
call   1040 <rndNormal@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe0c(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jae    11d2 <rndgamma+0x82>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <rndu@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  0xde0(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
movsd  0xd91(%rip),%xmm2
addsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1282 <rndgamma+0x132>
jmp    1318 <rndgamma+0x1c8>
movsd  -0x28(%rbp),%xmm0
call   1050 <log@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  0xd83(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  0xd3d(%rip),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1050 <log@plt>
movsd  -0x68(%rbp),%xmm4
movsd  -0x60(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm0
movsd  -0x50(%rbp),%xmm3
movsd  -0x48(%rbp),%xmm1
cvtsi2sd %eax,%xmm5
addsd  %xmm5,%xmm4
mulsd  %xmm4,%xmm2
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1313 <rndgamma+0x1c3>
jmp    1318 <rndgamma+0x1c8>
jmp    11cd <rndgamma+0x7d>
movsd  -0x20(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xcd1(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1361 <rndgamma+0x211>
mov    $0x0,%al
call   1030 <rndu@plt>
movsd  0xcb7(%rip),%xmm1
divsd  -0x10(%rbp),%xmm1
cvttsd2si %xmm1,%edi
call   1060 <pow@plt>
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1383 <rndgamma+0x233>
jp     1383 <rndgamma+0x233>
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rndgamma>:
sub    $0x58,%rsp
movapd %xmm0,%xmm2
movsd  0xea0(%rip),%xmm3
movapd %xmm0,%xmm1
addsd  %xmm3,%xmm1
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm1
movapd %xmm2,0x40(%rsp)
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
addsd  0xe81(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
jb     119d <rndgamma+0x4d>
sqrtsd %xmm0,%xmm0
jmp    11a2 <rndgamma+0x52>
call   1070 <sqrt@plt>
movsd  0xe66(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x38(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <rndNormal@plt>
movsd  0x38(%rsp),%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe27(%rip),%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm2,%xmm1
jae    11c0 <rndgamma+0x70>
movapd %xmm2,%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm1
movsd  %xmm1,0x8(%rsp)
xor    %eax,%eax
movsd  %xmm0,(%rsp)
call   1030 <rndu@plt>
movsd  (%rsp),%xmm2
movapd %xmm2,%xmm1
mulsd  0xe06(%rip),%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm1
addsd  0xdda(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     129c <rndgamma+0x14c>
call   1050 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x30(%rsp)
movsd  (%rsp),%xmm0
mulsd  0xdd5(%rip),%xmm0
movsd  %xmm0,0x28(%rsp)
movsd  0xda7(%rip),%xmm1
movsd  0x8(%rsp),%xmm0
subsd  %xmm0,%xmm1
movsd  %xmm1,0x20(%rsp)
call   1050 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x20(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
mulsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
ucomisd 0x30(%rsp),%xmm1
jbe    11c0 <rndgamma+0x70>
movapd 0x40(%rsp),%xmm0
movsd  0xd56(%rip),%xmm1
ucomisd %xmm0,%xmm1
movapd 0x10(%rsp),%xmm2
mulsd  0x8(%rsp),%xmm2
jbe    12ea <rndgamma+0x19a>
xor    %eax,%eax
movapd %xmm2,0x10(%rsp)
call   1030 <rndu@plt>
movsd  0xd2f(%rip),%xmm1
divsd  0x40(%rsp),%xmm1
cvttsd2si %xmm1,%edi
call   1060 <pow@plt>
movapd 0x10(%rsp),%xmm2
mulsd  %xmm0,%xmm2
xorpd  %xmm0,%xmm0
cmpeqsd %xmm2,%xmm0
movsd  0xd2d(%rip),%xmm1
andpd  %xmm0,%xmm1
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
add    $0x58,%rsp
ret

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

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