#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 r;
double rndgamma1(double);
double rndgamma2(double);
int x;
double gammadev(double s) {
  double ran1(), r = 0, x;
  if (s <= 0)
    return (-1);
  else if (s < 1)
    r = rndgamma1(s);
  else if (s > 1)
    r = rndgamma2(s);
  else {
    while (((x = ran1()) == 0) || (x == 1))
      ;
    r = -log(ran1());
  }
  r /= s;
  return (r);
}


x86 assembly (clang, -O0):
<gammadev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1175 <gammadev+0x35>
movsd  0xe9d(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1275 <gammadev+0x135>
movsd  0xe83(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    119c <gammadev+0x5c>
movsd  -0x10(%rbp),%xmm0
call   1060 <rndgamma1@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    1253 <gammadev+0x113>
movsd  -0x10(%rbp),%xmm0
movsd  0xe57(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11c7 <gammadev+0x87>
movsd  -0x10(%rbp),%xmm0
call   1030 <rndgamma2@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    124e <gammadev+0x10e>
jmp    11cc <gammadev+0x8c>
mov    $0x0,%al
call   1040 <ran1@plt>
movsd  %xmm0,-0x20(%rbp)
mov    $0x1,%al
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x21(%rbp)
jne    11f5 <gammadev+0xb5>
jp     11f5 <gammadev+0xb5>
jmp    1211 <gammadev+0xd1>
movsd  -0x20(%rbp),%xmm0
movsd  0xdfe(%rip),%xmm1
ucomisd %xmm1,%xmm0
sete   %al
setnp  %cl
and    %cl,%al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
test   $0x1,%al
jne    1221 <gammadev+0xe1>
jmp    1226 <gammadev+0xe6>
jmp    11cc <gammadev+0x8c>
mov    $0x0,%al
call   1040 <ran1@plt>
call   1050 <log@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    1253 <gammadev+0x113>
jmp    1258 <gammadev+0x118>
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gammadev>:
push   %rax
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    1165 <gammadev+0x25>
movsd  0xeb5(%rip),%xmm1
ucomisd %xmm0,%xmm1
movsd  %xmm0,(%rsp)
jbe    116f <gammadev+0x2f>
call   1060 <rndgamma1@plt>
jmp    11b3 <gammadev+0x73>
movsd  0xe93(%rip),%xmm0
pop    %rax
ret
ucomisd 0xe91(%rip),%xmm0
jbe    1180 <gammadev+0x40>
call   1030 <rndgamma2@plt>
jmp    11b3 <gammadev+0x73>
xor    %eax,%eax
call   1040 <ran1@plt>
ucomisd 0xe81(%rip),%xmm0
jne    1193 <gammadev+0x53>
jnp    1180 <gammadev+0x40>
ucomisd 0xe6d(%rip),%xmm0
jne    119f <gammadev+0x5f>
jnp    1180 <gammadev+0x40>
xor    %eax,%eax
call   1040 <ran1@plt>
call   1050 <log@plt>
xorpd  0xe6d(%rip),%xmm0
movsd  (%rsp),%xmm1
divsd  %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
@r = global double 0.000000e+00
@x = global i32 0
define double @gammadev(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %3
store double 0.000000e+00, double* %4
%6 = load double, double* %3
%7 = fcmp ole double %6, 0.000000e+00
br i1 %7, label %8, label %9
8: ; preds = %1
store double -1.000000e+00, double* %2
br label %42
9: ; preds = %1
%10 = load double, double* %3
%11 = fcmp olt double %10, 1.000000e+00
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = load double, double* %3
%14 = call double @rndgamma1(double %13)
store double %14, double* %4
br label %36
15: ; preds = %9
%16 = load double, double* %3
%17 = fcmp ogt double %16, 1.000000e+00
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = load double, double* %3
%20 = call double @rndgamma2(double %19)
store double %20, double* %4
br label %35
21: ; preds = %15
br label %22
22: ; preds = %30, %21
%23 = call double (...) @ran1()
store double %23, double* %5
%24 = fcmp oeq double %23, 0.000000e+00
br i1 %24, label %28, label %25
25: ; preds = %22
%26 = load double, double* %5
%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 = call double (...) @ran1()
%33 = call double @log(double %32)
%34 = fneg double %33
store double %34, double* %4
br label %35
35: ; preds = %31, %18
br label %36
36: ; preds = %35, %12
br label %37
37: ; preds = %36
%38 = load double, double* %3
%39 = load double, double* %4
%40 = fdiv double %39, %38
store double %40, double* %4
%41 = load double, double* %4
store double %41, double* %2
br label %42
42: ; preds = %37, %8
%43 = load double, double* %2
ret double %43
}

LLVM IR (-O2):
@r = global double 0.000000e+00
@x = global i32 0
define double @gammadev(double %0) {
%2 = fcmp ugt double %0, 0.000000e+00
br i1 %2, label %3, label %23
3: ; preds = %1
%4 = fcmp olt double %0, 1.000000e+00
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call double @rndgamma1(double %0)
br label %20
7: ; preds = %3
%8 = fcmp ogt double %0, 1.000000e+00
br i1 %8, label %9, label %11
9: ; preds = %7
%10 = tail call double @rndgamma2(double %0)
br label %20
11: ; preds = %7, %11
%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 %11, label %16
16: ; preds = %11
%17 = tail call double (...) @ran1()
%18 = tail call double @log(double %17)
%19 = fneg double %18
br label %20
20: ; preds = %5, %16, %9
%21 = phi double [ %6, %5 ], [ %10, %9 ], [ %19, %16 ]
%22 = fdiv double %21, %0
br label %23
23: ; preds = %1, %20
%24 = phi double [ %22, %20 ], [ -1.000000e+00, %1 ]
ret double %24
}