#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);
int /*<<< orphan*/ printf(char *);
double rndNormal();
double rndu();
double sqrt(double);
double rndgamma(double a) {
  double a0 = a, c, d, u, v, x;
  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)
    printf("\nrndgamma returning 0.\n");
  return v;
}


x86 assembly (clang, -O0):
<rndgamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xe81(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    119c <rndgamma+0x3c>
movsd  0xe6e(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xe5f(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1080 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  0xe41(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11d5 <rndgamma+0x75>
mov    $0x0,%al
call   1050 <rndNormal@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe09(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jae    11d5 <rndgamma+0x75>
movsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1040 <rndu@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm1
movsd  0xdd5(%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  0xd8e(%rip),%xmm2
addsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1285 <rndgamma+0x125>
jmp    131b <rndgamma+0x1bb>
movsd  -0x28(%rbp),%xmm0
call   1060 <log@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xd78(%rip),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  0xd3a(%rip),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1060 <log@plt>
movsd  -0x60(%rbp),%xmm4
movsd  -0x58(%rbp),%xmm2
movsd  -0x50(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm3
movsd  -0x40(%rbp),%xmm1
cvtsi2sd %eax,%xmm5
addsd  %xmm5,%xmm4
mulsd  %xmm4,%xmm2
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1316 <rndgamma+0x1b6>
jmp    131b <rndgamma+0x1bb>
jmp    11d0 <rndgamma+0x70>
movsd  -0x20(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xcce(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1364 <rndgamma+0x204>
mov    $0x0,%al
call   1040 <rndu@plt>
movsd  0xcb4(%rip),%xmm1
divsd  -0x10(%rbp),%xmm1
cvttsd2si %xmm1,%edi
call   1070 <pow@plt>
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1388 <rndgamma+0x228>
jp     1388 <rndgamma+0x228>
lea    0xc9d(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x30(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rndgamma>:
sub    $0x68,%rsp
movapd %xmm0,%xmm2
movsd  0xe90(%rip),%xmm3
movapd %xmm0,%xmm1
addsd  %xmm3,%xmm1
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm1
movapd %xmm2,0x50(%rsp)
andnpd %xmm2,%xmm0
orpd   %xmm1,%xmm0
addsd  0xe71(%rip),%xmm0
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
jb     11ad <rndgamma+0x4d>
sqrtsd %xmm0,%xmm0
jmp    11b2 <rndgamma+0x52>
call   1080 <sqrt@plt>
movsd  0xe56(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x48(%rsp)
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1050 <rndNormal@plt>
movsd  0x48(%rsp),%xmm2
mulsd  %xmm0,%xmm2
addsd  0xe17(%rip),%xmm2
xorpd  %xmm1,%xmm1
ucomisd %xmm2,%xmm1
jae    11d0 <rndgamma+0x70>
movapd %xmm2,%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm1
movsd  %xmm1,0x28(%rsp)
xor    %eax,%eax
movsd  %xmm0,0x8(%rsp)
call   1040 <rndu@plt>
movsd  0x8(%rsp),%xmm2
movapd %xmm2,%xmm1
mulsd  0xdf4(%rip),%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm1
addsd  0xdc8(%rip),%xmm1
ucomisd %xmm0,%xmm1
ja     12b0 <rndgamma+0x150>
call   1060 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x40(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xdc2(%rip),%xmm0
movsd  %xmm0,0x38(%rsp)
movsd  0xd94(%rip),%xmm1
movsd  0x28(%rsp),%xmm0
subsd  %xmm0,%xmm1
movsd  %xmm1,0x30(%rsp)
call   1060 <log@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
addsd  0x30(%rsp),%xmm0
mulsd  0x10(%rsp),%xmm0
movsd  0x38(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
ucomisd 0x40(%rsp),%xmm1
jbe    11d0 <rndgamma+0x70>
movapd 0x50(%rsp),%xmm0
movsd  0xd42(%rip),%xmm1
ucomisd %xmm0,%xmm1
movapd 0x10(%rsp),%xmm1
mulsd  0x28(%rsp),%xmm1
jbe    12fe <rndgamma+0x19e>
xor    %eax,%eax
movapd %xmm1,0x10(%rsp)
call   1040 <rndu@plt>
movsd  0xd1b(%rip),%xmm1
divsd  0x50(%rsp),%xmm1
cvttsd2si %xmm1,%edi
call   1070 <pow@plt>
movapd 0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
jne    1322 <rndgamma+0x1c2>
jp     1322 <rndgamma+0x1c2>
lea    0xd1f(%rip),%rdi
movapd %xmm1,0x10(%rsp)
call   1030 <puts@plt>
movapd 0x10(%rsp),%xmm1
movapd %xmm1,%xmm0
add    $0x68,%rsp
ret

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

LLVM IR (-O2):
@str = [23 x i8] c"\0Arndgamma returning 0.\00"
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
br i1 %43, label %44, label %46
44: ; preds = %41
%45 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
br label %46
46: ; preds = %44, %41
ret double %42
}