#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 exp(double);
int fabs(double);
double kf_lgamma(double);
double log(double);
double _kf_gammaq(double s, double z) {
  int j;
  double C, D, f;
  f = 1. + z - s;
  C = f;
  D = 0.;
  for (j = 1; j < 100; ++j) {
    double a = j * (s - j), b = (j << 1) + 1 + z - s, d;
    D = b + a * D;
    if (D < 1e-290)
      D = 1e-290;
    C = b + a / C;
    if (C < 1e-290)
      C = 1e-290;
    D = 1. / D;
    d = C * D;
    f *= d;
    if (fabs(d - 1.) < 1e-14)
      break;
  }
  return exp(s * log(z) - z - kf_lgamma(s) - log(f));
}


x86 assembly (clang, -O0):
<_kf_gammaq>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  0xea6(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x64,-0x14(%rbp)
jge    12ac <_kf_gammaq+0x16c>
cvtsi2sdl -0x14(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x14(%rbp),%xmm2
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
cvtsi2sd %eax,%xmm0
addsd  -0x10(%rbp),%xmm0
subsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x40(%rbp),%xmm1
movsd  -0x38(%rbp),%xmm0
movsd  -0x28(%rbp),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe20(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
jbe    1200 <_kf_gammaq+0xc0>
movsd  0xe0d(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  -0x38(%rbp),%xmm1
divsd  -0x20(%rbp),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xde8(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1238 <_kf_gammaq+0xf8>
movsd  0xdd5(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xdc0(%rip),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x48(%rbp),%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  0xd8b(%rip),%xmm1
subsd  %xmm1,%xmm0
call   1030 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xd86(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1299 <_kf_gammaq+0x159>
jmp    12ac <_kf_gammaq+0x16c>
jmp    129e <_kf_gammaq+0x15e>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1182 <_kf_gammaq+0x42>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x60(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1040 <kf_lgamma@plt>
movaps %xmm0,%xmm1
movsd  -0x58(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
subsd  %xmm1,%xmm0
call   1050 <exp@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_kf_gammaq>:
push   %r14
push   %rbx
sub    $0x28,%rsp
movsd  0xeb1(%rip),%xmm3
movsd  %xmm1,0x8(%rsp)
addsd  %xmm1,%xmm3
movsd  %xmm0,0x18(%rsp)
subsd  %xmm0,%xmm3
xorpd  %xmm4,%xmm4
mov    $0x1,%r14d
mov    $0x3,%ebx
movsd  %xmm3,0x10(%rsp)
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %r14d,%xmm0
movsd  0x18(%rsp),%xmm2
movapd %xmm2,%xmm1
subsd  %xmm0,%xmm1
mulsd  %xmm0,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %ebx,%xmm0
addsd  0x8(%rsp),%xmm0
subsd  %xmm2,%xmm0
mulsd  %xmm1,%xmm4
addsd  %xmm0,%xmm4
movsd  0xe4d(%rip),%xmm5
movapd %xmm5,%xmm2
maxsd  %xmm4,%xmm2
movsd  0xe35(%rip),%xmm4
divsd  %xmm2,%xmm4
movsd  %xmm4,0x20(%rsp)
divsd  %xmm3,%xmm1
addsd  %xmm0,%xmm1
movapd %xmm5,%xmm0
maxsd  %xmm1,%xmm0
movsd  %xmm0,(%rsp)
mulsd  %xmm4,%xmm0
movsd  0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
addsd  0xe0a(%rip),%xmm0
call   1030 <fabs@plt>
movsd  0x20(%rsp),%xmm4
movsd  (%rsp),%xmm3
test   %eax,%eax
jle    122e <_kf_gammaq+0xee>
lea    0x1(%r14),%eax
add    $0x2,%ebx
cmp    $0x63,%r14d
mov    %eax,%r14d
jne    1180 <_kf_gammaq+0x40>
movsd  0x8(%rsp),%xmm0
call   1060 <log@plt>
movapd %xmm0,%xmm1
movsd  0x18(%rsp),%xmm0
mulsd  %xmm0,%xmm1
subsd  0x8(%rsp),%xmm1
movsd  %xmm1,(%rsp)
call   1040 <kf_lgamma@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x10(%rsp),%xmm0
call   1060 <log@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x28,%rsp
pop    %rbx
pop    %r14
jmp    1050 <exp@plt>

LLVM IR (-O0):
define double @_kf_gammaq(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double %0, double* %3
store double %1, double* %4
%12 = load double, double* %4
%13 = fadd double 1.000000e+00, %12
%14 = load double, double* %3
%15 = fsub double %13, %14
store double %15, double* %8
%16 = load double, double* %8
store double %16, double* %6
store double 0.000000e+00, double* %7
store i32 1, i32* %5
br label %17
17: ; preds = %68, %2
%18 = load i32, i32* %5
%19 = icmp slt i32 %18, 100
br i1 %19, label %20, label %71
20: ; preds = %17
%21 = load i32, i32* %5
%22 = sitofp i32 %21 to double
%23 = load double, double* %3
%24 = load i32, i32* %5
%25 = sitofp i32 %24 to double
%26 = fsub double %23, %25
%27 = fmul double %22, %26
store double %27, double* %9
%28 = load i32, i32* %5
%29 = shl i32 %28, 1
%30 = add nsw i32 %29, 1
%31 = sitofp i32 %30 to double
%32 = load double, double* %4
%33 = fadd double %31, %32
%34 = load double, double* %3
%35 = fsub double %33, %34
store double %35, double* %10
%36 = load double, double* %10
%37 = load double, double* %9
%38 = load double, double* %7
%39 = call double @llvm.fmuladd.f64(double %37, double %38, double %36)
store double %39, double* %7
%40 = load double, double* %7
%41 = fcmp olt double %40, 1.000000e-290
br i1 %41, label %42, label %43
42: ; preds = %20
store double 1.000000e-290, double* %7
br label %43
43: ; preds = %42, %20
%44 = load double, double* %10
%45 = load double, double* %9
%46 = load double, double* %6
%47 = fdiv double %45, %46
%48 = fadd double %44, %47
store double %48, double* %6
%49 = load double, double* %6
%50 = fcmp olt double %49, 1.000000e-290
br i1 %50, label %51, label %52
51: ; preds = %43
store double 1.000000e-290, double* %6
br label %52
52: ; preds = %51, %43
%53 = load double, double* %7
%54 = fdiv double 1.000000e+00, %53
store double %54, double* %7
%55 = load double, double* %6
%56 = load double, double* %7
%57 = fmul double %55, %56
store double %57, double* %11
%58 = load double, double* %11
%59 = load double, double* %8
%60 = fmul double %59, %58
store double %60, double* %8
%61 = load double, double* %11
%62 = fsub double %61, 1.000000e+00
%63 = call i32 @fabs(double %62)
%64 = sitofp i32 %63 to double
%65 = fcmp olt double %64, 0x3D06849B86A12B9B
br i1 %65, label %66, label %67
66: ; preds = %52
br label %71
67: ; preds = %52
br label %68
68: ; preds = %67
%69 = load i32, i32* %5
%70 = add nsw i32 %69, 1
store i32 %70, i32* %5
br label %17
71: ; preds = %66, %17
%72 = load double, double* %3
%73 = load double, double* %4
%74 = call double @log(double %73)
%75 = load double, double* %4
%76 = fneg double %75
%77 = call double @llvm.fmuladd.f64(double %72, double %74, double %76)
%78 = load double, double* %3
%79 = call double @kf_lgamma(double %78)
%80 = fsub double %77, %79
%81 = load double, double* %8
%82 = call double @log(double %81)
%83 = fsub double %80, %82
%84 = call double @exp(double %83)
ret double %84
}

LLVM IR (-O2):
define double @_kf_gammaq(double %0, double %1) {
%3 = fadd double %1, 1.000000e+00
%4 = fsub double %3, %0
br label %5
5: ; preds = %5, %2
%6 = phi i32 [ 1, %2 ], [ %31, %5 ]
%7 = phi double [ %4, %2 ], [ %24, %5 ]
%8 = phi double [ 0.000000e+00, %2 ], [ %25, %5 ]
%9 = phi double [ %4, %2 ], [ %27, %5 ]
%10 = sitofp i32 %6 to double
%11 = fsub double %0, %10
%12 = fmul double %11, %10
%13 = shl nuw nsw i32 %6, 1
%14 = or i32 %13, 1
%15 = sitofp i32 %14 to double
%16 = fadd double %15, %1
%17 = fsub double %16, %0
%18 = tail call double @llvm.fmuladd.f64(double %12, double %8, double %17)
%19 = fcmp olt double %18, 1.000000e-290
%20 = select i1 %19, double 1.000000e-290, double %18
%21 = fdiv double %12, %7
%22 = fadd double %21, %17
%23 = fcmp olt double %22, 1.000000e-290
%24 = select i1 %23, double 1.000000e-290, double %22
%25 = fdiv double 1.000000e+00, %20
%26 = fmul double %24, %25
%27 = fmul double %9, %26
%28 = fadd double %26, -1.000000e+00
%29 = tail call i32 @fabs(double %28)
%30 = icmp slt i32 %29, 1
%31 = add nuw nsw i32 %6, 1
%32 = icmp eq i32 %31, 100
%33 = select i1 %30, i1 true, i1 %32
br i1 %33, label %34, label %5
34: ; preds = %5
%35 = tail call double @log(double %1)
%36 = fneg double %1
%37 = tail call double @llvm.fmuladd.f64(double %0, double %35, double %36)
%38 = tail call double @kf_lgamma(double %0)
%39 = fsub double %37, %38
%40 = tail call double @log(double %27)
%41 = fsub double %39, %40
%42 = tail call double @exp(double %41)
ret double %42
}