#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 log(double);
double pow(double, int);
double rand_exp();
double rand_uniopen();
double sqrt(double);
double rand_gamma(double a) {
  double b, c, X, Y, Z, U, V, W;
  if (a < 0.00001) {
    X = a;
  } else if (a <= 1) {
    U = rand_uniopen();
    X = rand_gamma(1 + a) * pow(U, 1 / a);
  } else if (a < 1.00001) {
    X = rand_exp();
  } else {
    b = a - 1;
    c = 3 * a - 0.75;
    for (;;) {
      U = rand_uniopen();
      V = rand_uniopen();
      W = U * (1 - U);
      Y = sqrt(c / W) * (U - 0.5);
      X = b + Y;
      if (X >= 0) {
        Z = 64 * W * W * W * V * V;
        if (Z <= 1 - 2 * Y * Y / X || log(Z) <= 2 * (b * log(X / b) - Y))
          break;
      }
    }
  }
  return X < 1e-30 && X < a ? (a < 1e-30 ? a : 1e-30) : X;
}


x86 assembly (clang, -O0):
<rand_gamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  0xe8b(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    118f <rand_gamma+0x2f>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    13b4 <rand_gamma+0x254>
movsd  0xe71(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jb     11f6 <rand_gamma+0x96>
mov    $0x0,%al
call   1040 <rand_uniopen@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  0xe52(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
call   1060 <rand_gamma@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xe36(%rip),%xmm1
divsd  -0x8(%rbp),%xmm1
cvttsd2si %xmm1,%edi
call   1070 <pow@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    13af <rand_gamma+0x24f>
movsd  0xe12(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    121a <rand_gamma+0xba>
mov    $0x0,%al
call   1030 <rand_exp@plt>
movsd  %xmm0,-0x20(%rbp)
jmp    13aa <rand_gamma+0x24a>
movsd  -0x8(%rbp),%xmm0
movsd  0xde1(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xddb(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdd7(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x0,%al
call   1040 <rand_uniopen@plt>
movsd  %xmm0,-0x38(%rbp)
mov    $0x0,%al
call   1040 <rand_uniopen@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  0xd91(%rip),%xmm1
subsd  -0x38(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%rbp),%xmm0
divsd  -0x48(%rbp),%xmm0
call   1080 <sqrt@plt>
movsd  -0x38(%rbp),%xmm1
movsd  0xd87(%rip),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     13a0 <rand_gamma+0x240>
movsd  0xd61(%rip),%xmm0
mulsd  -0x48(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
mulsd  -0x48(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
mulsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm1
movsd  0xd2e(%rip),%xmm2
mulsd  -0x28(%rbp),%xmm2
mulsd  -0x28(%rbp),%xmm2
divsd  -0x20(%rbp),%xmm2
movsd  0xcef(%rip),%xmm0
subsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jae    1396 <rand_gamma+0x236>
movsd  -0x30(%rbp),%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x20(%rbp),%xmm0
divsd  -0x10(%rbp),%xmm0
call   1050 <log@plt>
movsd  -0x60(%rbp),%xmm2
movsd  -0x58(%rbp),%xmm1
movaps %xmm0,%xmm3
movsd  -0x28(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm3,%xmm2
addsd  %xmm0,%xmm2
movsd  0xca8(%rip),%xmm0
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jb     139b <rand_gamma+0x23b>
jmp    13a5 <rand_gamma+0x245>
jmp    13a0 <rand_gamma+0x240>
jmp    1252 <rand_gamma+0xf2>
jmp    13aa <rand_gamma+0x24a>
jmp    13af <rand_gamma+0x24f>
jmp    13b4 <rand_gamma+0x254>
movsd  0xc84(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    141e <rand_gamma+0x2be>
movsd  -0x20(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    141e <rand_gamma+0x2be>
movsd  0xc5d(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    13fd <rand_gamma+0x29d>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    140f <rand_gamma+0x2af>
movsd  0xc3b(%rip),%xmm0
movsd  %xmm0,-0x68(%rbp)
jmp    140f <rand_gamma+0x2af>
movsd  -0x68(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
jmp    1428 <rand_gamma+0x2c8>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x70(%rbp)
movsd  -0x70(%rbp),%xmm0
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rand_gamma>:
sub    $0x48,%rsp
movapd %xmm0,%xmm3
movsd  0xe90(%rip),%xmm1
ucomisd %xmm0,%xmm1
movapd %xmm0,0x20(%rsp)
ja     1200 <rand_gamma+0xa0>
movsd  0xe80(%rip),%xmm0
movapd 0x20(%rsp),%xmm1
ucomisd %xmm1,%xmm0
jae    11b3 <rand_gamma+0x53>
movsd  0xe74(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1241 <rand_gamma+0xe1>
xor    %eax,%eax
call   1030 <rand_exp@plt>
movapd %xmm0,%xmm3
jmp    1200 <rand_gamma+0xa0>
xor    %eax,%eax
call   1040 <rand_uniopen@plt>
movsd  %xmm0,0x8(%rsp)
movapd 0x20(%rsp),%xmm0
addsd  0xe3a(%rip),%xmm0
call   1060 <rand_gamma@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0xe27(%rip),%xmm0
divsd  0x20(%rsp),%xmm0
cvttsd2si %xmm0,%edi
movsd  0x8(%rsp),%xmm0
call   1070 <pow@plt>
movapd %xmm0,%xmm3
mulsd  0x10(%rsp),%xmm3
movsd  0xe38(%rip),%xmm1
movapd %xmm3,%xmm2
movapd 0x20(%rsp),%xmm0
cmpltsd %xmm0,%xmm2
minsd  %xmm1,%xmm0
andpd  %xmm2,%xmm0
andnpd %xmm3,%xmm2
orpd   %xmm0,%xmm2
movapd %xmm3,%xmm0
cmpltsd %xmm1,%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm3,%xmm0
orpd   %xmm2,%xmm0
add    $0x48,%rsp
ret
movsd  0xdcf(%rip),%xmm0
movsd  0xdcf(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  0xdcb(%rip),%xmm2
movsd  %xmm2,0x40(%rsp)
addsd  %xmm1,%xmm0
movsd  %xmm0,0x10(%rsp)
nopl   (%rax)
xor    %eax,%eax
call   1040 <rand_uniopen@plt>
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1040 <rand_uniopen@plt>
movsd  0x8(%rsp),%xmm4
movapd %xmm0,%xmm2
movsd  0xd72(%rip),%xmm5
subsd  %xmm4,%xmm5
mulsd  %xmm4,%xmm5
movsd  0x40(%rsp),%xmm0
divsd  %xmm5,%xmm0
ucomisd 0xd98(%rip),%xmm0
xorpd  %xmm1,%xmm1
jb     12c0 <rand_gamma+0x160>
sqrtsd %xmm0,%xmm0
jmp    12e7 <rand_gamma+0x187>
nopl   0x0(%rax)
movsd  %xmm2,0x30(%rsp)
movsd  %xmm5,0x18(%rsp)
call   1080 <sqrt@plt>
movsd  0x18(%rsp),%xmm5
movsd  0x30(%rsp),%xmm2
movsd  0x8(%rsp),%xmm4
xorpd  %xmm1,%xmm1
addsd  0xd41(%rip),%xmm4
mulsd  %xmm0,%xmm4
movsd  0x10(%rsp),%xmm3
addsd  %xmm4,%xmm3
ucomisd %xmm1,%xmm3
jb     1270 <rand_gamma+0x110>
movapd %xmm5,%xmm0
mulsd  0xd25(%rip),%xmm0
mulsd  %xmm5,%xmm0
mulsd  %xmm5,%xmm0
mulsd  %xmm2,%xmm0
mulsd  %xmm2,%xmm0
movapd %xmm4,%xmm1
addsd  %xmm4,%xmm1
mulsd  %xmm4,%xmm1
divsd  %xmm3,%xmm1
movsd  0xccd(%rip),%xmm2
subsd  %xmm1,%xmm2
ucomisd %xmm0,%xmm2
jae    1200 <rand_gamma+0xa0>
movapd %xmm3,0x30(%rsp)
movsd  %xmm4,0x8(%rsp)
call   1050 <log@plt>
movsd  %xmm0,0x18(%rsp)
movapd 0x30(%rsp),%xmm0
divsd  0x10(%rsp),%xmm0
call   1050 <log@plt>
movapd 0x30(%rsp),%xmm3
mulsd  0x10(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm0
ucomisd 0x18(%rsp),%xmm0
jb     1270 <rand_gamma+0x110>
jmp    1200 <rand_gamma+0xa0>

LLVM IR (-O0):
define double @rand_gamma(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* %2
%11 = load double, double* %2
%12 = fcmp olt double %11, 1.000000e-05
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = load double, double* %2
store double %14, double* %5
br label %97
15: ; preds = %1
%16 = load double, double* %2
%17 = fcmp ole double %16, 1.000000e+00
br i1 %17, label %18, label %29
18: ; preds = %15
%19 = call double (...) @rand_uniopen()
store double %19, double* %8
%20 = load double, double* %2
%21 = fadd double 1.000000e+00, %20
%22 = call double @rand_gamma(double %21)
%23 = load double, double* %8
%24 = load double, double* %2
%25 = fdiv double 1.000000e+00, %24
%26 = fptosi double %25 to i32
%27 = call double @pow(double %23, i32 %26)
%28 = fmul double %22, %27
store double %28, double* %5
br label %96
29: ; preds = %15
%30 = load double, double* %2
%31 = fcmp olt double %30, 1.000010e+00
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call double (...) @rand_exp()
store double %33, double* %5
br label %95
34: ; preds = %29
%35 = load double, double* %2
%36 = fsub double %35, 1.000000e+00
store double %36, double* %3
%37 = load double, double* %2
%38 = call double @llvm.fmuladd.f64(double 3.000000e+00, double %37, double -7.500000e-01)
store double %38, double* %4
br label %39
39: ; preds = %93, %34
%40 = call double (...) @rand_uniopen()
store double %40, double* %8
%41 = call double (...) @rand_uniopen()
store double %41, double* %9
%42 = load double, double* %8
%43 = load double, double* %8
%44 = fsub double 1.000000e+00, %43
%45 = fmul double %42, %44
store double %45, double* %10
%46 = load double, double* %4
%47 = load double, double* %10
%48 = fdiv double %46, %47
%49 = call double @sqrt(double %48)
%50 = load double, double* %8
%51 = fsub double %50, 5.000000e-01
%52 = fmul double %49, %51
store double %52, double* %6
%53 = load double, double* %3
%54 = load double, double* %6
%55 = fadd double %53, %54
store double %55, double* %5
%56 = load double, double* %5
%57 = fcmp oge double %56, 0.000000e+00
br i1 %57, label %58, label %93
58: ; preds = %39
%59 = load double, double* %10
%60 = fmul double 6.400000e+01, %59
%61 = load double, double* %10
%62 = fmul double %60, %61
%63 = load double, double* %10
%64 = fmul double %62, %63
%65 = load double, double* %9
%66 = fmul double %64, %65
%67 = load double, double* %9
%68 = fmul double %66, %67
store double %68, double* %7
%69 = load double, double* %7
%70 = load double, double* %6
%71 = fmul double 2.000000e+00, %70
%72 = load double, double* %6
%73 = fmul double %71, %72
%74 = load double, double* %5
%75 = fdiv double %73, %74
%76 = fsub double 1.000000e+00, %75
%77 = fcmp ole double %69, %76
br i1 %77, label %91, label %78
78: ; preds = %58
%79 = load double, double* %7
%80 = call double @log(double %79)
%81 = load double, double* %3
%82 = load double, double* %5
%83 = load double, double* %3
%84 = fdiv double %82, %83
%85 = call double @log(double %84)
%86 = load double, double* %6
%87 = fneg double %86
%88 = call double @llvm.fmuladd.f64(double %81, double %85, double %87)
%89 = fmul double 2.000000e+00, %88
%90 = fcmp ole double %80, %89
br i1 %90, label %91, label %92
91: ; preds = %78, %58
br label %94
92: ; preds = %78
br label %93
93: ; preds = %92, %39
br label %39
94: ; preds = %91
br label %95
95: ; preds = %94, %32
br label %96
96: ; preds = %95, %18
br label %97
97: ; preds = %96, %13
%98 = load double, double* %5
%99 = fcmp olt double %98, 1.000000e-30
br i1 %99, label %100, label %112
100: ; preds = %97
%101 = load double, double* %5
%102 = load double, double* %2
%103 = fcmp olt double %101, %102
br i1 %103, label %104, label %112
104: ; preds = %100
%105 = load double, double* %2
%106 = fcmp olt double %105, 1.000000e-30
br i1 %106, label %107, label %109
107: ; preds = %104
%108 = load double, double* %2
br label %110
109: ; preds = %104
br label %110
110: ; preds = %109, %107
%111 = phi double [ %108, %107 ], [ 1.000000e-30, %109 ]
br label %114
112: ; preds = %100, %97
%113 = load double, double* %5
br label %114
114: ; preds = %112, %110
%115 = phi double [ %111, %110 ], [ %113, %112 ]
ret double %115
}

LLVM IR (-O2):
define double @rand_gamma(double %0) {
%2 = fcmp olt double %0, 1.000000e-05
br i1 %2, label %51, label %3
3: ; preds = %1
%4 = fcmp ugt double %0, 1.000000e+00
br i1 %4, label %13, label %5
5: ; preds = %3
%6 = tail call double (...) @rand_uniopen()
%7 = fadd double %0, 1.000000e+00
%8 = tail call double @rand_gamma(double %7)
%9 = fdiv double 1.000000e+00, %0
%10 = fptosi double %9 to i32
%11 = tail call double @pow(double %6, i32 %10)
%12 = fmul double %8, %11
br label %51
13: ; preds = %3
%14 = fcmp olt double %0, 1.000010e+00
br i1 %14, label %15, label %17
15: ; preds = %13
%16 = tail call double (...) @rand_exp()
br label %51
17: ; preds = %13
%18 = fadd double %0, -1.000000e+00
%19 = tail call double @llvm.fmuladd.f64(double %0, double 3.000000e+00, double -7.500000e-01)
br label %20
20: ; preds = %50, %17
%21 = tail call double (...) @rand_uniopen()
%22 = tail call double (...) @rand_uniopen()
%23 = fsub double 1.000000e+00, %21
%24 = fmul double %21, %23
%25 = fdiv double %19, %24
%26 = tail call double @sqrt(double %25)
%27 = fadd double %21, -5.000000e-01
%28 = fmul double %27, %26
%29 = fadd double %18, %28
%30 = fcmp ult double %29, 0.000000e+00
br i1 %30, label %50, label %31
31: ; preds = %20
%32 = fmul double %24, 6.400000e+01
%33 = fmul double %24, %32
%34 = fmul double %24, %33
%35 = fmul double %22, %34
%36 = fmul double %22, %35
%37 = fmul double %28, 2.000000e+00
%38 = fmul double %28, %37
%39 = fdiv double %38, %29
%40 = fsub double 1.000000e+00, %39
%41 = fcmp ugt double %36, %40
br i1 %41, label %42, label %51
42: ; preds = %31
%43 = tail call double @log(double %36)
%44 = fdiv double %29, %18
%45 = tail call double @log(double %44)
%46 = fneg double %28
%47 = tail call double @llvm.fmuladd.f64(double %18, double %45, double %46)
%48 = fmul double %47, 2.000000e+00
%49 = fcmp ugt double %43, %48
br i1 %49, label %50, label %51
50: ; preds = %42, %20
br label %20
51: ; preds = %42, %31, %1, %5, %15
%52 = phi double [ %12, %5 ], [ %16, %15 ], [ %0, %1 ], [ %29, %31 ], [ %29, %42 ]
%53 = fcmp olt double %52, 1.000000e-30
%54 = fcmp olt double %52, %0
%55 = and i1 %53, %54
%56 = fcmp olt double %0, 1.000000e-30
%57 = select i1 %56, double %0, double 1.000000e-30
%58 = select i1 %55, double %57, double %52
ret double %58
}