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


x86 assembly (clang, -O0):
<rndgamma2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
ucomisd 0x2f06(%rip),%xmm0
jne    115b <rndgamma2+0x2b>
jp     115b <rndgamma2+0x2b>
jmp    11b3 <rndgamma2+0x83>
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
cvttsd2si %xmm0,%edi
call   1050 <sqrt@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x2ea2(%rip)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,0x2e9d(%rip)
jmp    11b8 <rndgamma2+0x88>
jmp    11bd <rndgamma2+0x8d>
mov    $0x0,%al
call   1030 <ran1@plt>
movsd  %xmm0,-0x10(%rbp)
mov    $0x1,%al
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x31(%rbp)
jne    11e6 <rndgamma2+0xb6>
jp     11e6 <rndgamma2+0xb6>
jmp    1202 <rndgamma2+0xd2>
movsd  -0x10(%rbp),%xmm0
movsd  0xe1d(%rip),%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    1212 <rndgamma2+0xe2>
jmp    1217 <rndgamma2+0xe7>
jmp    11bd <rndgamma2+0x8d>
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  0xdc1(%rip),%xmm1
subsd  %xmm1,%xmm0
mulsd  0x2de5(%rip),%xmm0
movsd  %xmm0,-0x40(%rbp)
cvttsd2si -0x28(%rbp),%edi
call   1050 <sqrt@plt>
movsd  -0x40(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0x2db4(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jb     12a9 <rndgamma2+0x179>
jmp    11b8 <rndgamma2+0x88>
jmp    12ae <rndgamma2+0x17e>
mov    $0x0,%al
call   1030 <ran1@plt>
movsd  %xmm0,-0x10(%rbp)
mov    $0x1,%al
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x41(%rbp)
jne    12d7 <rndgamma2+0x1a7>
jp     12d7 <rndgamma2+0x1a7>
jmp    12f3 <rndgamma2+0x1c3>
movsd  -0x10(%rbp),%xmm0
movsd  0xd2c(%rip),%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x41(%rbp)
mov    -0x41(%rbp),%al
test   $0x1,%al
jne    1303 <rndgamma2+0x1d3>
jmp    1308 <rndgamma2+0x1d8>
jmp    12ae <rndgamma2+0x17e>
movsd  0xd18(%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  0xcdb(%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     13f1 <rndgamma2+0x2c1>
cvttsd2si -0x18(%rbp),%edi
call   1040 <log@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  0x2cb1(%rip),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x30(%rbp),%xmm0
divsd  0x2c9f(%rip),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <log@plt>
movsd  -0x58(%rbp),%xmm2
movsd  -0x50(%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  0xc3d(%rip),%xmm0
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    13f6 <rndgamma2+0x2c6>
jmp    13fb <rndgamma2+0x2cb>
jmp    11b8 <rndgamma2+0x88>
movsd  -0x30(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rndgamma2>:
sub    $0x28,%rsp
movsd  0x2f14(%rip),%xmm1
ucomisd %xmm0,%xmm1
jne    1144 <rndgamma2+0x14>
jnp    11a0 <rndgamma2+0x70>
movsd  0xeb4(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x2ee8(%rip)
movsd  0xea8(%rip),%xmm1
mulsd  %xmm0,%xmm1
addsd  0xea4(%rip),%xmm1
cvttsd2si %xmm1,%edi
movsd  %xmm0,0x8(%rsp)
call   1050 <sqrt@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm0,0x2ebe(%rip)
movsd  0x8(%rsp),%xmm0
movsd  %xmm0,0x2eb8(%rip)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <ran1@plt>
ucomisd 0xe89(%rip),%xmm0
jne    11b3 <rndgamma2+0x83>
jnp    11a0 <rndgamma2+0x70>
ucomisd 0xe5d(%rip),%xmm0
jne    11bf <rndgamma2+0x8f>
jnp    11a0 <rndgamma2+0x70>
movapd %xmm0,%xmm1
mulsd  %xmm0,%xmm1
movapd %xmm0,%xmm2
subsd  %xmm1,%xmm2
addsd  0xe49(%rip),%xmm0
mulsd  0x2e69(%rip),%xmm0
movsd  %xmm0,0x8(%rsp)
movsd  %xmm2,0x10(%rsp)
cvttsd2si %xmm2,%edi
call   1050 <sqrt@plt>
movsd  0x8(%rsp),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
divsd  %xmm0,%xmm1
movsd  0x2e33(%rip),%xmm2
addsd  %xmm1,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm2,%xmm0
jae    11a0 <rndgamma2+0x70>
movsd  %xmm2,0x18(%rsp)
movsd  %xmm1,0x8(%rsp)
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <ran1@plt>
ucomisd 0xdf9(%rip),%xmm0
jne    1243 <rndgamma2+0x113>
jnp    1230 <rndgamma2+0x100>
ucomisd 0xdcd(%rip),%xmm0
jne    124f <rndgamma2+0x11f>
jnp    1230 <rndgamma2+0x100>
movapd %xmm0,%xmm1
mulsd  0xdcd(%rip),%xmm1
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
movsd  0x8(%rsp),%xmm3
movapd %xmm3,%xmm2
mulsd  0xd9f(%rip),%xmm2
mulsd  %xmm3,%xmm2
addsd  %xmm4,%xmm2
ucomisd %xmm1,%xmm2
ja     12f1 <rndgamma2+0x1c1>
cvttsd2si %xmm0,%edi
call   1040 <log@plt>
movsd  %xmm0,0x10(%rsp)
movsd  0x2d8a(%rip),%xmm1
movsd  %xmm1,0x20(%rsp)
movsd  0x18(%rsp),%xmm0
divsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <log@plt>
movsd  0x18(%rsp),%xmm4
mulsd  0x20(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
addsd  %xmm0,%xmm0
ucomisd 0x10(%rsp),%xmm0
jbe    11a0 <rndgamma2+0x70>
movaps %xmm4,%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
@d = global i32 0
@f = global double 0.000000e+00
@g = global i32 0
@r = global i32 0
@x = global i32 0
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 %20
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 = fptosi double %15 to i32
%17 = call i32 @sqrt(i32 %16)
%18 = sitofp i32 %17 to double
store double %18, double* @rndgamma2.h
%19 = load double, double* %2
store double %19, double* @rndgamma2.ss
br label %20
20: ; preds = %11, %1
br label %21
21: ; preds = %99, %51, %20
br label %22
22: ; preds = %30, %21
%23 = call double (...) @ran1()
store double %23, double* %3
%24 = fcmp oeq double %23, 0.000000e+00
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load double, double* %3
%27 = fcmp oeq double %26, 1.000000e+00
br label %28
28: ; preds = %25, %22
%29 = phi i1 [ true, %22 ], [ %27, %25 ]
br i1 %29, label %30, label %31
30: ; preds = %28
br label %22
31: ; preds = %28
%32 = load double, double* %3
%33 = load double, double* %3
%34 = load double, double* %3
%35 = fneg double %33
%36 = call double @llvm.fmuladd.f64(double %35, double %34, double %32)
store double %36, double* %6
%37 = load double, double* %3
%38 = fsub double %37, 5.000000e-01
%39 = load double, double* @rndgamma2.h
%40 = fmul double %38, %39
%41 = load double, double* %6
%42 = fptosi double %41 to i32
%43 = call i32 @sqrt(i32 %42)
%44 = sitofp i32 %43 to double
%45 = fdiv double %40, %44
store double %45, double* %5
%46 = load double, double* @rndgamma2.b
%47 = load double, double* %5
%48 = fadd double %46, %47
store double %48, double* %7
%49 = load double, double* %7
%50 = fcmp ole double %49, 0.000000e+00
br i1 %50, label %51, label %52
51: ; preds = %31
br label %21
52: ; preds = %31
br label %53
53: ; preds = %61, %52
%54 = call double (...) @ran1()
store double %54, double* %3
%55 = fcmp oeq double %54, 0.000000e+00
br i1 %55, label %59, label %56
56: ; preds = %53
%57 = load double, double* %3
%58 = fcmp oeq double %57, 1.000000e+00
br label %59
59: ; preds = %56, %53
%60 = phi i1 [ true, %53 ], [ %58, %56 ]
br i1 %60, label %61, label %62
61: ; preds = %59
br label %53
62: ; preds = %59
%63 = load double, double* %3
%64 = fmul double 6.400000e+01, %63
%65 = load double, double* %3
%66 = fmul double %64, %65
%67 = load double, double* %6
%68 = fmul double %66, %67
%69 = load double, double* %6
%70 = fmul double %68, %69
%71 = load double, double* %6
%72 = fmul double %70, %71
store double %72, double* %4
%73 = load double, double* %4
%74 = load double, double* %7
%75 = fmul double %73, %74
%76 = load double, double* %7
%77 = load double, double* %5
%78 = fmul double 2.000000e+00, %77
%79 = load double, double* %5
%80 = fneg double %78
%81 = call double @llvm.fmuladd.f64(double %80, double %79, double %76)
%82 = fcmp olt double %75, %81
br i1 %82, label %98, label %83
83: ; preds = %62
%84 = load double, double* %4
%85 = fptosi double %84 to i32
%86 = call double @log(i32 %85)
%87 = load double, double* @rndgamma2.b
%88 = load double, double* %7
%89 = load double, double* @rndgamma2.b
%90 = fdiv double %88, %89
%91 = fptosi double %90 to i32
%92 = call double @log(i32 %91)
%93 = load double, double* %5
%94 = fneg double %93
%95 = call double @llvm.fmuladd.f64(double %87, double %92, double %94)
%96 = fmul double 2.000000e+00, %95
%97 = fcmp olt double %86, %96
br i1 %97, label %98, label %99
98: ; preds = %83, %62
br label %100
99: ; preds = %83
br label %21
100: ; preds = %98
%101 = load double, double* %7
ret double %101
}

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
@d = global i32 0
@f = global double 0.000000e+00
@g = global i32 0
@r = global i32 0
@x = global i32 0
define double @rndgamma2(double %0) {
%2 = load double, double* @rndgamma2.ss
%3 = fcmp une double %2, %0
br i1 %3, label %4, label %10
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 = fptosi double %6 to i32
%8 = tail call i32 @sqrt(i32 %7)
%9 = sitofp i32 %8 to double
store double %9, double* @rndgamma2.h
store double %0, double* @rndgamma2.ss
br label %10
10: ; preds = %1, %4
br label %11
11: ; preds = %16, %10
%12 = tail call double (...) @ran1()
%13 = fcmp oeq double %12, 0.000000e+00
%14 = fcmp oeq double %12, 1.000000e+00
%15 = or i1 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %11, %17, %45
br label %11
17: ; preds = %11
%18 = fneg double %12
%19 = tail call double @llvm.fmuladd.f64(double %18, double %12, double %12)
%20 = fadd double %12, -5.000000e-01
%21 = load double, double* @rndgamma2.h
%22 = fmul double %20, %21
%23 = fptosi double %19 to i32
%24 = tail call i32 @sqrt(i32 %23)
%25 = sitofp i32 %24 to double
%26 = fdiv double %22, %25
%27 = load double, double* @rndgamma2.b
%28 = fadd double %27, %26
%29 = fcmp ugt double %28, 0.000000e+00
br i1 %29, label %30, label %16
30: ; preds = %17, %30
%31 = tail call double (...) @ran1()
%32 = fcmp oeq double %31, 0.000000e+00
%33 = fcmp oeq double %31, 1.000000e+00
%34 = or i1 %32, %33
br i1 %34, label %30, label %35
35: ; preds = %30
%36 = fmul double %31, 6.400000e+01
%37 = fmul double %31, %36
%38 = fmul double %19, %37
%39 = fmul double %19, %38
%40 = fmul double %19, %39
%41 = fmul double %28, %40
%42 = fmul double %26, -2.000000e+00
%43 = tail call double @llvm.fmuladd.f64(double %42, double %26, double %28)
%44 = fcmp olt double %41, %43
br i1 %44, label %56, label %45
45: ; preds = %35
%46 = fptosi double %40 to i32
%47 = tail call double @log(i32 %46)
%48 = load double, double* @rndgamma2.b
%49 = fdiv double %28, %48
%50 = fptosi double %49 to i32
%51 = tail call double @log(i32 %50)
%52 = fneg double %26
%53 = tail call double @llvm.fmuladd.f64(double %48, double %51, double %52)
%54 = fmul double %53, 2.000000e+00
%55 = fcmp olt double %47, %54
br i1 %55, label %56, label %16
56: ; preds = %35, %45
ret double %28
}