#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 rndu();
double sqrt(double);
double rndgamma2(double s) {
  double r, d, f, g, x;
  static double b, h, ss = 0;
  if (s != ss) {
    b = s - 1.0;
    h = sqrt(3.0 * s - 0.75);
    ss = s;
  }
  for (;;) {
    r = rndu();
    g = r - r * r;
    f = (r - 0.5) * h / sqrt(g);
    x = b + f;
    if (x <= 0.0)
      continue;
    r = rndu();
    d = 64 * r * r * g * g * g;
    if (d * x < x - 2.0 * f * f || log(d) < 2 * (b * log(x / b) - f))
      break;
  }
  return (x);
}


x86 assembly (clang, -O0):
<rndgamma2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
ucomisd 0x2f06(%rip),%xmm0
jne    115b <rndgamma2+0x2b>
jp     115b <rndgamma2+0x2b>
jmp    11ab <rndgamma2+0x7b>
movsd  -0x8(%rbp),%xmm0
movsd  0xea8(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,0x2ecc(%rip)
movsd  -0x8(%rbp),%xmm0
movsd  0xe7f(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe7b(%rip),%xmm1
addsd  %xmm1,%xmm0
call   1050 <sqrt@plt>
movsd  %xmm0,0x2eaa(%rip)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,0x2ea5(%rip)
jmp    11b0 <rndgamma2+0x80>
mov    $0x0,%al
call   1030 <rndu@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe1c(%rip),%xmm1
subsd  %xmm1,%xmm0
mulsd  0x2e40(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1050 <sqrt@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0x2e10(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jb     124d <rndgamma2+0x11d>
jmp    11b0 <rndgamma2+0x80>
mov    $0x0,%al
call   1030 <rndu@plt>
movsd  %xmm0,-0x10(%rbp)
movsd  0xdc7(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  -0x10(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm1
mulsd  -0x30(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
movsd  0xd8a(%rip),%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm3
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm3,%xmm0
addsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
ja     133e <rndgamma2+0x20e>
movsd  -0x18(%rbp),%xmm0
call   1040 <log@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  0x2d60(%rip),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
divsd  0x2d4e(%rip),%xmm0
call   1040 <log@plt>
movsd  -0x48(%rbp),%xmm2
movsd  -0x40(%rbp),%xmm1
movaps %xmm0,%xmm3
movsd  -0x20(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
mulsd  %xmm3,%xmm2
addsd  %xmm0,%xmm2
movsd  0xcf0(%rip),%xmm0
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    1343 <rndgamma2+0x213>
jmp    1348 <rndgamma2+0x218>
jmp    11b0 <rndgamma2+0x80>
movsd  -0x30(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rndgamma2>:
sub    $0x28,%rsp
movapd %xmm0,%xmm2
movsd  0x2f10(%rip),%xmm0
ucomisd %xmm2,%xmm0
jne    1148 <rndgamma2+0x18>
jnp    11b0 <rndgamma2+0x80>
movsd  0xeb0(%rip),%xmm1
addsd  %xmm2,%xmm1
movsd  0xeac(%rip),%xmm0
mulsd  %xmm2,%xmm0
addsd  0xea8(%rip),%xmm0
movsd  %xmm1,0x2ed0(%rip)
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1180 <rndgamma2+0x50>
sqrtsd %xmm0,%xmm0
jmp    1191 <rndgamma2+0x61>
movsd  %xmm2,0x8(%rsp)
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm2
movsd  %xmm0,0x2eaf(%rip)
movsd  %xmm2,0x2eaf(%rip)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <rndu@plt>
movapd %xmm0,%xmm1
movapd %xmm0,%xmm2
mulsd  %xmm0,%xmm2
subsd  %xmm2,%xmm0
addsd  0xe49(%rip),%xmm1
mulsd  0x2e71(%rip),%xmm1
ucomisd 0xe51(%rip),%xmm0
movsd  %xmm0,0x10(%rsp)
jb     11f0 <rndgamma2+0xc0>
sqrtsd %xmm0,%xmm0
jmp    1201 <rndgamma2+0xd1>
nopl   (%rax)
movsd  %xmm1,0x8(%rsp)
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
divsd  %xmm0,%xmm1
movsd  0x2e33(%rip),%xmm2
addsd  %xmm1,%xmm2
xorpd  %xmm0,%xmm0
movsd  %xmm2,0x18(%rsp)
ucomisd %xmm2,%xmm0
jae    11b0 <rndgamma2+0x80>
xor    %eax,%eax
movsd  %xmm1,0x8(%rsp)
call   1030 <rndu@plt>
movsd  0x8(%rsp),%xmm3
movapd %xmm0,%xmm1
mulsd  0xde0(%rip),%xmm0
mulsd  %xmm1,%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
mulsd  %xmm1,%xmm0
movsd  0x18(%rsp),%xmm4
movapd %xmm4,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm3,%xmm2
mulsd  0xdb8(%rip),%xmm2
mulsd  %xmm3,%xmm2
addsd  %xmm4,%xmm2
ucomisd %xmm1,%xmm2
ja     12c2 <rndgamma2+0x192>
call   1040 <log@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x2daf(%rip),%xmm1
movsd  %xmm1,0x20(%rsp)
movsd  0x18(%rsp),%xmm0
divsd  %xmm1,%xmm0
call   1040 <log@plt>
mulsd  0x20(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm0
ucomisd 0x10(%rsp),%xmm0
jbe    11b0 <rndgamma2+0x80>
movsd  0x18(%rsp),%xmm0
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
@rndgamma2.b = internal unnamed_addr global double 0.000000e+00
@rndgamma2.h = internal unnamed_addr global double 0.000000e+00
@rndgamma2.ss = internal unnamed_addr global double 0.000000e+00
define double @rndgamma2(double %0) {
%2 = load double, double* @rndgamma2.ss
%3 = fcmp une double %2, %0
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = fadd double %0, -1.000000e+00
store double %5, double* @rndgamma2.b
%6 = tail call double @llvm.fmuladd.f64(double %0, double 3.000000e+00, double -7.500000e-01)
%7 = tail call double @sqrt(double %6)
store double %7, double* @rndgamma2.h
store double %0, double* @rndgamma2.ss
br label %8
8: ; preds = %4, %1
br label %9
9: ; preds = %21, %8
%10 = tail call double (...) @rndu()
%11 = fneg double %10
%12 = tail call double @llvm.fmuladd.f64(double %11, double %10, double %10)
%13 = fadd double %10, -5.000000e-01
%14 = load double, double* @rndgamma2.h
%15 = fmul double %13, %14
%16 = tail call double @sqrt(double %12)
%17 = fdiv double %15, %16
%18 = load double, double* @rndgamma2.b
%19 = fadd double %18, %17
%20 = fcmp ugt double %19, 0.000000e+00
br i1 %20, label %22, label %21
21: ; preds = %9, %33
br label %9
22: ; preds = %9
%23 = tail call double (...) @rndu()
%24 = fmul double %23, 6.400000e+01
%25 = fmul double %23, %24
%26 = fmul double %12, %25
%27 = fmul double %12, %26
%28 = fmul double %12, %27
%29 = fmul double %19, %28
%30 = fmul double %17, -2.000000e+00
%31 = tail call double @llvm.fmuladd.f64(double %30, double %17, double %19)
%32 = fcmp olt double %29, %31
br i1 %32, label %42, label %33
33: ; preds = %22
%34 = tail call double @log(double %28)
%35 = load double, double* @rndgamma2.b
%36 = fdiv double %19, %35
%37 = tail call double @log(double %36)
%38 = fneg double %17
%39 = tail call double @llvm.fmuladd.f64(double %35, double %37, double %38)
%40 = fmul double %39, 2.000000e+00
%41 = fcmp olt double %34, %40
br i1 %41, label %42, label %21
42: ; preds = %22, %33
ret double %19
}