#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(int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
double rndgamma1(double);
double rndgamma2(double);
int /*<<< orphan*/ rndu();
double rndgamma(double s) {
  double r = 0;
  if (s <= 0)
    puts("jgl gamma..");
  else if (s < 1)
    r = rndgamma1(s);
  else if (s > 1)
    r = rndgamma2(s);
  else
    r = -log(rndu());
  return (r);
}


x86 assembly (clang, -O0):
<rndgamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movsd  %xmm0,-0x8(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x8(%rbp),%xmm0
jb     1184 <rndgamma+0x34>
lea    0xe8e(%rip),%rdi
call   1030 <puts@plt>
jmp    120a <rndgamma+0xba>
movsd  0xe74(%rip),%xmm0
ucomisd -0x8(%rbp),%xmm0
jbe    11ab <rndgamma+0x5b>
movsd  -0x8(%rbp),%xmm0
call   1070 <rndgamma1@plt>
movsd  %xmm0,-0x10(%rbp)
jmp    1205 <rndgamma+0xb5>
movsd  -0x8(%rbp),%xmm0
movsd  0xe48(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11d6 <rndgamma+0x86>
movsd  -0x8(%rbp),%xmm0
call   1040 <rndgamma2@plt>
movsd  %xmm0,-0x10(%rbp)
jmp    1200 <rndgamma+0xb0>
mov    $0x0,%al
call   1050 <rndu@plt>
mov    %eax,%edi
call   1060 <log@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1205 <rndgamma+0xb5>
jmp    120a <rndgamma+0xba>
movsd  -0x10(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rndgamma>:
push   %rax
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    116f <rndgamma+0x1f>
movsd  0xe9d(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1181 <rndgamma+0x31>
pop    %rax
jmp    1070 <rndgamma1@plt>
lea    0xeaa(%rip),%rdi
call   1030 <puts@plt>
xorpd  %xmm0,%xmm0
pop    %rax
ret
ucomisd 0xe77(%rip),%xmm0
jbe    1191 <rndgamma+0x41>
pop    %rax
jmp    1040 <rndgamma2@plt>
xor    %eax,%eax
call   1050 <rndu@plt>
mov    %eax,%edi
call   1060 <log@plt>
xorpd  0xe69(%rip),%xmm0
pop    %rax
ret

LLVM IR (-O0):
@.str = [12 x i8] c"jgl gamma..\00"
define double @rndgamma(double %0) {
%2 = alloca double
%3 = alloca double
store double %0, double* %2
store double 0.000000e+00, double* %3
%4 = load double, double* %2
%5 = fcmp ole double %4, 0.000000e+00
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = call i32 @puts(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %26
8: ; preds = %1
%9 = load double, double* %2
%10 = fcmp olt double %9, 1.000000e+00
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load double, double* %2
%13 = call double @rndgamma1(double %12)
store double %13, double* %3
br label %25
14: ; preds = %8
%15 = load double, double* %2
%16 = fcmp ogt double %15, 1.000000e+00
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load double, double* %2
%19 = call double @rndgamma2(double %18)
store double %19, double* %3
br label %24
20: ; preds = %14
%21 = call i32 (...) @rndu()
%22 = call double @log(i32 %21)
%23 = fneg double %22
store double %23, double* %3
br label %24
24: ; preds = %20, %17
br label %25
25: ; preds = %24, %11
br label %26
26: ; preds = %25, %6
%27 = load double, double* %3
ret double %27
}

LLVM IR (-O2):
@.str = [12 x i8] c"jgl gamma..\00"
define double @rndgamma(double %0) {
%2 = fcmp ugt double %0, 0.000000e+00
br i1 %2, label %5, label %3
3: ; preds = %1
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %17
5: ; preds = %1
%6 = fcmp olt double %0, 1.000000e+00
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = tail call double @rndgamma1(double %0)
br label %17
9: ; preds = %5
%10 = fcmp ogt double %0, 1.000000e+00
br i1 %10, label %11, label %13
11: ; preds = %9
%12 = tail call double @rndgamma2(double %0)
br label %17
13: ; preds = %9
%14 = tail call i32 (...) @rndu()
%15 = tail call double @log(i32 %14)
%16 = fneg double %15
br label %17
17: ; preds = %7, %13, %11, %3
%18 = phi double [ 0.000000e+00, %3 ], [ %8, %7 ], [ %12, %11 ], [ %16, %13 ]
ret double %18
}