#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*/);
double rndgamma1(double);
double rndgamma2(double);
int /*<<< orphan*/ seq_gen_rndu();
double seq_gen_rndgamma(double s) {
  double r = 0.0;
  if (s <= 0.0)
    return 0;
  else if (s < 1.0)
    r = rndgamma1(s);
  else if (s > 1.0)
    r = rndgamma2(s);
  else
    r = -log(seq_gen_rndu());
  return (r);
}


x86 assembly (clang, -O0):
<seq_gen_rndgamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     1170 <seq_gen_rndgamma+0x30>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1200 <seq_gen_rndgamma+0xc0>
movsd  0xe88(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1197 <seq_gen_rndgamma+0x57>
movsd  -0x10(%rbp),%xmm0
call   1060 <rndgamma1@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    11f1 <seq_gen_rndgamma+0xb1>
movsd  -0x10(%rbp),%xmm0
movsd  0xe5c(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    11c2 <seq_gen_rndgamma+0x82>
movsd  -0x10(%rbp),%xmm0
call   1030 <rndgamma2@plt>
movsd  %xmm0,-0x18(%rbp)
jmp    11ec <seq_gen_rndgamma+0xac>
mov    $0x0,%al
call   1040 <seq_gen_rndu@plt>
mov    %eax,%edi
call   1050 <log@plt>
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
jmp    11f1 <seq_gen_rndgamma+0xb1>
jmp    11f6 <seq_gen_rndgamma+0xb6>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<seq_gen_rndgamma>:
push   %rax
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jae    1189 <seq_gen_rndgamma+0x49>
movsd  0xead(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    115f <seq_gen_rndgamma+0x1f>
pop    %rax
jmp    1060 <rndgamma1@plt>
ucomisd 0xe99(%rip),%xmm0
jbe    116f <seq_gen_rndgamma+0x2f>
pop    %rax
jmp    1030 <rndgamma2@plt>
xor    %eax,%eax
call   1040 <seq_gen_rndu@plt>
mov    %eax,%edi
call   1050 <log@plt>
movapd %xmm0,%xmm1
xorpd  0xe87(%rip),%xmm1
movapd %xmm1,%xmm0
pop    %rax
ret

LLVM IR (-O0):
define double @seq_gen_rndgamma(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
store double %0, double* %3
store double 0.000000e+00, double* %4
%5 = load double, double* %3
%6 = fcmp ole double %5, 0.000000e+00
br i1 %6, label %7, label %8
7: ; preds = %1
store double 0.000000e+00, double* %2
br label %28
8: ; preds = %1
%9 = load double, double* %3
%10 = fcmp olt double %9, 1.000000e+00
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load double, double* %3
%13 = call double @rndgamma1(double %12)
store double %13, double* %4
br label %25
14: ; preds = %8
%15 = load double, double* %3
%16 = fcmp ogt double %15, 1.000000e+00
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load double, double* %3
%19 = call double @rndgamma2(double %18)
store double %19, double* %4
br label %24
20: ; preds = %14
%21 = call i32 (...) @seq_gen_rndu()
%22 = call double @log(i32 %21)
%23 = fneg double %22
store double %23, double* %4
br label %24
24: ; preds = %20, %17
br label %25
25: ; preds = %24, %11
br label %26
26: ; preds = %25
%27 = load double, double* %4
store double %27, double* %2
br label %28
28: ; preds = %26, %7
%29 = load double, double* %2
ret double %29
}

LLVM IR (-O2):
define double @seq_gen_rndgamma(double %0) {
%2 = fcmp ugt double %0, 0.000000e+00
br i1 %2, label %3, label %15
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 %15
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 %15
11: ; preds = %7
%12 = tail call i32 (...) @seq_gen_rndu()
%13 = tail call double @log(i32 %12)
%14 = fneg double %13
br label %15
15: ; preds = %9, %11, %5, %1
%16 = phi double [ 0.000000e+00, %1 ], [ %6, %5 ], [ %10, %9 ], [ %14, %11 ]
ret double %16
}