#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);
double kf_lgamma(double);
double log(double);
double _kf_gammap(double s, double z) {
  double sum, x;
  int k;
  for (k = 1, sum = x = 1.; k < 100; ++k) {
    sum += (x *= z / (s + k));
    if (x / sum < 1e-14)
      break;
  }
  return exp(s * log(z) - z - kf_lgamma(s + 1.) + log(sum));
}


x86 assembly (clang, -O0):
<_kf_gammap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movl   $0x1,-0x24(%rbp)
movsd  0xeaf(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xea2(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
cmpl   $0x64,-0x24(%rbp)
jge    11cc <_kf_gammap+0x9c>
movsd  -0x10(%rbp),%xmm0
movsd  -0x8(%rbp),%xmm1
cvtsi2sdl -0x24(%rbp),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x20(%rbp),%xmm1
divsd  -0x18(%rbp),%xmm1
movsd  0xe5e(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    11b9 <_kf_gammap+0x89>
jmp    11cc <_kf_gammap+0x9c>
jmp    11be <_kf_gammap+0x8e>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1163 <_kf_gammap+0x33>
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x40(%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,-0x38(%rbp)
movsd  0xde7(%rip),%xmm0
addsd  -0x8(%rbp),%xmm0
call   1030 <kf_lgamma@plt>
movaps %xmm0,%xmm1
movsd  -0x38(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1050 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
addsd  %xmm1,%xmm0
call   1040 <exp@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_kf_gammap>:
sub    $0x18,%rsp
movapd %xmm1,%xmm6
movapd %xmm0,%xmm5
movsd  0xebc(%rip),%xmm1
mov    $0x1,%eax
movsd  0xeb7(%rip),%xmm0
movapd %xmm1,%xmm4
cs nopw 0x0(%rax,%rax,1)
nop
xorps  %xmm2,%xmm2
cvtsi2sd %eax,%xmm2
movapd %xmm1,%xmm3
addsd  %xmm5,%xmm2
movapd %xmm6,%xmm1
divsd  %xmm2,%xmm1
mulsd  %xmm3,%xmm1
addsd  %xmm1,%xmm4
movapd %xmm1,%xmm2
divsd  %xmm4,%xmm2
ucomisd %xmm2,%xmm0
ja     1197 <_kf_gammap+0x67>
lea    0x1(%rax),%ecx
cmp    $0x63,%eax
mov    %ecx,%eax
jne    1160 <_kf_gammap+0x30>
movapd %xmm6,%xmm0
movsd  %xmm4,0x10(%rsp)
movsd  %xmm5,0x8(%rsp)
movsd  %xmm6,(%rsp)
call   1050 <log@plt>
movsd  0x8(%rsp),%xmm1
mulsd  %xmm1,%xmm0
subsd  (%rsp),%xmm0
movsd  %xmm0,(%rsp)
addsd  0xe33(%rip),%xmm1
movapd %xmm1,%xmm0
call   1030 <kf_lgamma@plt>
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x10(%rsp),%xmm0
call   1050 <log@plt>
addsd  (%rsp),%xmm0
add    $0x18,%rsp
jmp    1040 <exp@plt>

LLVM IR (-O0):
define double @_kf_gammap(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca i32
store double %0, double* %3
store double %1, double* %4
store i32 1, i32* %7
store double 1.000000e+00, double* %6
store double 1.000000e+00, double* %5
br label %8
8: ; preds = %28, %2
%9 = load i32, i32* %7
%10 = icmp slt i32 %9, 100
br i1 %10, label %11, label %31
11: ; preds = %8
%12 = load double, double* %4
%13 = load double, double* %3
%14 = load i32, i32* %7
%15 = sitofp i32 %14 to double
%16 = fadd double %13, %15
%17 = fdiv double %12, %16
%18 = load double, double* %6
%19 = fmul double %18, %17
store double %19, double* %6
%20 = load double, double* %5
%21 = fadd double %20, %19
store double %21, double* %5
%22 = load double, double* %6
%23 = load double, double* %5
%24 = fdiv double %22, %23
%25 = fcmp olt double %24, 0x3D06849B86A12B9B
br i1 %25, label %26, label %27
26: ; preds = %11
br label %31
27: ; preds = %11
br label %28
28: ; preds = %27
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %8
31: ; preds = %26, %8
%32 = load double, double* %3
%33 = load double, double* %4
%34 = call double @log(double %33)
%35 = load double, double* %4
%36 = fneg double %35
%37 = call double @llvm.fmuladd.f64(double %32, double %34, double %36)
%38 = load double, double* %3
%39 = fadd double %38, 1.000000e+00
%40 = call double @kf_lgamma(double %39)
%41 = fsub double %37, %40
%42 = load double, double* %5
%43 = call double @log(double %42)
%44 = fadd double %41, %43
%45 = call double @exp(double %44)
ret double %45
}

LLVM IR (-O2):
define double @_kf_gammap(double %0, double %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i32 [ 1, %2 ], [ %14, %3 ]
%5 = phi double [ 1.000000e+00, %2 ], [ %10, %3 ]
%6 = phi double [ 1.000000e+00, %2 ], [ %11, %3 ]
%7 = sitofp i32 %4 to double
%8 = fadd double %7, %0
%9 = fdiv double %1, %8
%10 = fmul double %5, %9
%11 = fadd double %6, %10
%12 = fdiv double %10, %11
%13 = fcmp olt double %12, 0x3D06849B86A12B9B
%14 = add nuw nsw i32 %4, 1
%15 = icmp eq i32 %14, 100
%16 = select i1 %13, i1 true, i1 %15
br i1 %16, label %17, label %3
17: ; preds = %3
%18 = tail call double @log(double %1)
%19 = fneg double %1
%20 = tail call double @llvm.fmuladd.f64(double %0, double %18, double %19)
%21 = fadd double %0, 1.000000e+00
%22 = tail call double @kf_lgamma(double %21)
%23 = fsub double %20, %22
%24 = tail call double @log(double %11)
%25 = fadd double %23, %24
%26 = tail call double @exp(double %25)
ret double %26
}