#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_PI;
int exp(double);
double log(double);
double sqrt(int);
double stub1(unsigned short *);
double stub2(unsigned short *);
double tan(double);
double gamma_dist_knuth_algA(double a, double (*src)(unsigned short *),
                             unsigned short *xi) {
  double U, Y, X, V;
A1:
  U = (*src)(xi);
  Y = tan(M_PI * U);
  X = (sqrt((2 * a) - 1) * Y) + a - 1;
  if (X <= 0)
    goto A1;
  V = (*src)(xi);
  if (V >
      ((1 + (Y * Y)) * exp((a - 1) * log(X / (a - 1)) - sqrt(2 * a - 1) * Y)))
    goto A1;
  return (X);
}


x86 assembly (clang, -O0):
<gamma_dist_knuth_algA>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rdi
call   *%rax
movsd  %xmm0,-0x20(%rbp)
mov    0x2e7d(%rip),%rax
movsd  (%rax),%xmm0
mulsd  -0x20(%rbp),%xmm0
call   1040 <tan@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x8(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xe79(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
movsd  -0x28(%rbp),%xmm2
movsd  -0x8(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  0xe4a(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x30(%rbp),%xmm0
jb     11d2 <gamma_dist_knuth_algA+0x92>
jmp    1155 <gamma_dist_knuth_algA+0x15>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rdi
call   *%rax
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdff(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x8(%rbp),%xmm0
movsd  0xde9(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
movsd  0xdce(%rip),%xmm2
subsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
call   1050 <log@plt>
movsd  %xmm0,-0x58(%rbp)
movsd  -0x8(%rbp),%xmm0
addsd  %xmm0,%xmm0
movsd  0xdb3(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1060 <sqrt@plt>
movsd  -0x58(%rbp),%xmm2
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  -0x48(%rbp),%xmm1
movsd  -0x40(%rbp),%xmm0
cvtsi2sd %eax,%xmm2
mulsd  %xmm2,%xmm1
ucomisd %xmm1,%xmm0
jbe    12b9 <gamma_dist_knuth_algA+0x179>
jmp    1155 <gamma_dist_knuth_algA+0x15>
movsd  -0x30(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gamma_dist_knuth_algA>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
movapd %xmm0,%xmm1
addsd  %xmm0,%xmm1
movsd  0xea0(%rip),%xmm2
addsd  %xmm2,%xmm1
cvttsd2si %xmm1,%ebp
movsd  %xmm0,0x30(%rsp)
addsd  %xmm2,%xmm0
movsd  %xmm0,0x8(%rsp)
mov    0x2e69(%rip),%r15
nop
mov    %r14,%rdi
call   *%rbx
mulsd  (%r15),%xmm0
call   1040 <tan@plt>
movsd  %xmm0,(%rsp)
mov    %ebp,%edi
call   1060 <sqrt@plt>
movapd %xmm0,%xmm1
mulsd  (%rsp),%xmm1
addsd  0x30(%rsp),%xmm1
addsd  0xe4e(%rip),%xmm1
xorpd  %xmm0,%xmm0
movsd  %xmm1,0x10(%rsp)
ucomisd %xmm1,%xmm0
jae    1180 <gamma_dist_knuth_algA+0x40>
mov    %r14,%rdi
call   *%rbx
movsd  %xmm0,0x28(%rsp)
movsd  (%rsp),%xmm0
mulsd  %xmm0,%xmm0
addsd  0xe2a(%rip),%xmm0
movsd  %xmm0,0x20(%rsp)
movsd  0x10(%rsp),%xmm0
divsd  0x8(%rsp),%xmm0
call   1050 <log@plt>
movsd  %xmm0,0x18(%rsp)
mov    %ebp,%edi
call   1060 <sqrt@plt>
mulsd  (%rsp),%xmm0
movsd  0x18(%rsp),%xmm1
mulsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
call   1030 <exp@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x20(%rsp),%xmm0
movsd  0x28(%rsp),%xmm1
ucomisd %xmm0,%xmm1
ja     1180 <gamma_dist_knuth_algA+0x40>
movsd  0x10(%rsp),%xmm0
add    $0x38,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
define double @gamma_dist_knuth_algA(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
store double %0, double* %4
store double (i16*)* %1, double (i16*)** %5
store i16* %2, i16** %6
br label %11
11: ; preds = %57, %29, %3
%12 = load double (i16*)*, double (i16*)** %5
%13 = load i16*, i16** %6
%14 = call double %12(i16* %13)
store double %14, double* %7
%15 = load double, double* @M_PI
%16 = load double, double* %7
%17 = fmul double %15, %16
%18 = call double @tan(double %17)
store double %18, double* %8
%19 = load double, double* %4
%20 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %19, double -1.000000e+00)
%21 = fptosi double %20 to i32
%22 = call double @sqrt(i32 %21)
%23 = load double, double* %8
%24 = load double, double* %4
%25 = call double @llvm.fmuladd.f64(double %22, double %23, double %24)
%26 = fsub double %25, 1.000000e+00
store double %26, double* %9
%27 = load double, double* %9
%28 = fcmp ole double %27, 0.000000e+00
br i1 %28, label %29, label %30
29: ; preds = %11
br label %11
30: ; preds = %11
%31 = load double (i16*)*, double (i16*)** %5
%32 = load i16*, i16** %6
%33 = call double %31(i16* %32)
store double %33, double* %10
%34 = load double, double* %10
%35 = load double, double* %8
%36 = load double, double* %8
%37 = call double @llvm.fmuladd.f64(double %35, double %36, double 1.000000e+00)
%38 = load double, double* %4
%39 = fsub double %38, 1.000000e+00
%40 = load double, double* %9
%41 = load double, double* %4
%42 = fsub double %41, 1.000000e+00
%43 = fdiv double %40, %42
%44 = call double @log(double %43)
%45 = load double, double* %4
%46 = call double @llvm.fmuladd.f64(double 2.000000e+00, double %45, double -1.000000e+00)
%47 = fptosi double %46 to i32
%48 = call double @sqrt(i32 %47)
%49 = load double, double* %8
%50 = fmul double %48, %49
%51 = fneg double %50
%52 = call double @llvm.fmuladd.f64(double %39, double %44, double %51)
%53 = call i32 @exp(double %52)
%54 = sitofp i32 %53 to double
%55 = fmul double %37, %54
%56 = fcmp ogt double %34, %55
br i1 %56, label %57, label %58
57: ; preds = %30
br label %11
58: ; preds = %30
%59 = load double, double* %9
ret double %59
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
define double @gamma_dist_knuth_algA(double %0, double (i16*)* nocapture %1, i16* %2) {
%4 = tail call double @llvm.fmuladd.f64(double %0, double 2.000000e+00, double -1.000000e+00)
%5 = fptosi double %4 to i32
%6 = fadd double %0, -1.000000e+00
br label %7
7: ; preds = %16, %3
%8 = tail call double %1(i16* %2)
%9 = load double, double* @M_PI
%10 = fmul double %8, %9
%11 = tail call double @tan(double %10)
%12 = tail call double @sqrt(i32 %5)
%13 = tail call double @llvm.fmuladd.f64(double %12, double %11, double %0)
%14 = fadd double %13, -1.000000e+00
%15 = fcmp ugt double %14, 0.000000e+00
br i1 %15, label %17, label %16
16: ; preds = %7, %17
br label %7
17: ; preds = %7
%18 = tail call double %1(i16* %2)
%19 = tail call double @llvm.fmuladd.f64(double %11, double %11, double 1.000000e+00)
%20 = fdiv double %14, %6
%21 = tail call double @log(double %20)
%22 = tail call double @sqrt(i32 %5)
%23 = fneg double %22
%24 = fmul double %11, %23
%25 = tail call double @llvm.fmuladd.f64(double %6, double %21, double %24)
%26 = tail call i32 @exp(double %25)
%27 = sitofp i32 %26 to double
%28 = fmul double %19, %27
%29 = fcmp ogt double %18, %28
br i1 %29, label %16, label %30
30: ; preds = %17
ret double %14
}