#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 M_E;
double exp(double);
int log(double);
double pow(double, double);
double stub1(unsigned short *);
double stub2(unsigned short *);
double stub3(unsigned short *);
double gamma_dist_knuth_algG(double a, double (*src)(unsigned short *),
                             unsigned short *xi) {
  double p, U, V, X, q;
  p = M_E / (a + M_E);
G2:
  U = (*src)(xi);
  do {
    V = (*src)(xi);
  } while (V == 0);
  if (U < p) {
    X = pow(V, 1 / a);
    q = exp(-X);
  } else {
    X = 1 - log(V);
    q = pow(X, a - 1);
  }
  U = (*src)(xi);
  if (U >= q)
    goto G2;
  return (X);
}


x86 assembly (clang, -O0):
<gamma_dist_knuth_algG>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e94(%rip),%rax
movsd  (%rax),%xmm0
movsd  -0x8(%rbp),%xmm1
mov    0x2e84(%rip),%rax
addsd  (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rdi
call   *%rax
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rdi
call   *%rax
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    11a4 <gamma_dist_knuth_algG+0x74>
jp     11a4 <gamma_dist_knuth_algG+0x74>
jmp    1178 <gamma_dist_knuth_algG+0x48>
movsd  -0x28(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11ff <gamma_dist_knuth_algG+0xcf>
movsd  -0x30(%rbp),%xmm0
movsd  0xe3b(%rip),%xmm1
divsd  -0x8(%rbp),%xmm1
call   1050 <pow@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x40(%rbp)
jmp    123b <gamma_dist_knuth_algG+0x10b>
movsd  -0x30(%rbp),%xmm0
call   1040 <log@plt>
mov    %eax,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
movsd  0xdd3(%rip),%xmm2
subsd  %xmm2,%xmm1
call   1050 <pow@plt>
movsd  %xmm0,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rdi
call   *%rax
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x40(%rbp),%xmm0
jb     125f <gamma_dist_knuth_algG+0x12f>
jmp    1169 <gamma_dist_knuth_algG+0x39>
movsd  -0x38(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gamma_dist_knuth_algG>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e9c(%rip),%rax
movsd  (%rax),%xmm2
movapd %xmm2,%xmm1
addsd  %xmm0,%xmm1
divsd  %xmm1,%xmm2
movsd  %xmm2,0x18(%rsp)
movsd  0xe9e(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  0xe94(%rip),%xmm1
divsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
jmp    11b5 <gamma_dist_knuth_algG+0x85>
call   1040 <log@plt>
mov    $0x1,%ecx
sub    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
movapd %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm1
call   1050 <pow@plt>
movsd  %xmm0,(%rsp)
mov    %r14,%rdi
call   *%rbx
ucomisd (%rsp),%xmm0
jb     11fe <gamma_dist_knuth_algG+0xce>
mov    %r14,%rdi
call   *%rbx
movsd  %xmm0,(%rsp)
nop
mov    %r14,%rdi
call   *%rbx
ucomisd 0xe43(%rip),%xmm0
jne    11d1 <gamma_dist_knuth_algG+0xa1>
jnp    11c0 <gamma_dist_knuth_algG+0x90>
movsd  0x18(%rsp),%xmm1
ucomisd (%rsp),%xmm1
jbe    1180 <gamma_dist_knuth_algG+0x50>
movsd  0x8(%rsp),%xmm1
call   1050 <pow@plt>
movapd %xmm0,0x20(%rsp)
xorpd  0xe29(%rip),%xmm0
call   1030 <exp@plt>
jmp    11a4 <gamma_dist_knuth_algG+0x74>
movaps 0x20(%rsp),%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@M_E = global double 0.000000e+00
define double @gamma_dist_knuth_algG(double %0, double (i16*)* %1, i16* %2) {
%4 = alloca double
%5 = alloca double (i16*)*
%6 = alloca i16*
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double %0, double* %4
store double (i16*)* %1, double (i16*)** %5
store i16* %2, i16** %6
%12 = load double, double* @M_E
%13 = load double, double* %4
%14 = load double, double* @M_E
%15 = fadd double %13, %14
%16 = fdiv double %12, %15
store double %16, double* %7
br label %17
17: ; preds = %56, %3
%18 = load double (i16*)*, double (i16*)** %5
%19 = load i16*, i16** %6
%20 = call double %18(i16* %19)
store double %20, double* %8
br label %21
21: ; preds = %25, %17
%22 = load double (i16*)*, double (i16*)** %5
%23 = load i16*, i16** %6
%24 = call double %22(i16* %23)
store double %24, double* %9
br label %25
25: ; preds = %21
%26 = load double, double* %9
%27 = fcmp oeq double %26, 0.000000e+00
br i1 %27, label %21, label %28
28: ; preds = %25
%29 = load double, double* %8
%30 = load double, double* %7
%31 = fcmp olt double %29, %30
br i1 %31, label %32, label %40
32: ; preds = %28
%33 = load double, double* %9
%34 = load double, double* %4
%35 = fdiv double 1.000000e+00, %34
%36 = call double @pow(double %33, double %35)
store double %36, double* %10
%37 = load double, double* %10
%38 = fneg double %37
%39 = call double @exp(double %38)
store double %39, double* %11
br label %49
40: ; preds = %28
%41 = load double, double* %9
%42 = call i32 @log(double %41)
%43 = sub nsw i32 1, %42
%44 = sitofp i32 %43 to double
store double %44, double* %10
%45 = load double, double* %10
%46 = load double, double* %4
%47 = fsub double %46, 1.000000e+00
%48 = call double @pow(double %45, double %47)
store double %48, double* %11
br label %49
49: ; preds = %40, %32
%50 = load double (i16*)*, double (i16*)** %5
%51 = load i16*, i16** %6
%52 = call double %50(i16* %51)
store double %52, double* %8
%53 = load double, double* %8
%54 = load double, double* %11
%55 = fcmp oge double %53, %54
br i1 %55, label %56, label %57
56: ; preds = %49
br label %17
57: ; preds = %49
%58 = load double, double* %10
ret double %58
}

LLVM IR (-O2):
@M_E = global double 0.000000e+00
define double @gamma_dist_knuth_algG(double %0, double (i16*)* nocapture %1, i16* %2) {
%4 = load double, double* @M_E
%5 = fadd double %4, %0
%6 = fdiv double %4, %5
%7 = fadd double %0, -1.000000e+00
%8 = fdiv double 1.000000e+00, %0
br label %9
9: ; preds = %25, %3
%10 = tail call double %1(i16* %2)
br label %11
11: ; preds = %11, %9
%12 = tail call double %1(i16* %2)
%13 = fcmp oeq double %12, 0.000000e+00
br i1 %13, label %11, label %14
14: ; preds = %11
%15 = fcmp olt double %10, %6
br i1 %15, label %16, label %20
16: ; preds = %14
%17 = tail call double @pow(double %12, double %8)
%18 = fneg double %17
%19 = tail call double @exp(double %18)
br label %25
20: ; preds = %14
%21 = tail call i32 @log(double %12)
%22 = sub nsw i32 1, %21
%23 = sitofp i32 %22 to double
%24 = tail call double @pow(double %23, double %7)
br label %25
25: ; preds = %20, %16
%26 = phi double [ %17, %16 ], [ %23, %20 ]
%27 = phi double [ %19, %16 ], [ %24, %20 ]
%28 = tail call double %1(i16* %2)
%29 = fcmp ult double %28, %27
br i1 %29, label %30, label %9
30: ; preds = %25
ret double %26
}