#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 fabs(double);
double log(double);
double logGamma(double);
double gammaSeries(double x, double a) {
  int n, maxit = 100;
  double eps = 0.0000003;
  double sum = 1.0 / a, ap = a, gln = logGamma(a), del = sum;
  for (n = 1; n <= maxit; n++) {
    ap++;
    del = del * x / ap;
    sum = sum + del;
    if (fabs(del) < fabs(sum) * eps)
      break;
  }
  return sum * exp(-x + a * log(x) - gln);
}


x86 assembly (clang, -O0):
<gammaSeries>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movl   $0x64,-0x18(%rbp)
movsd  0xeb7(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xea2(%rip),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <logGamma@plt>
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jg     121a <gammaSeries+0xea>
movsd  0xe5a(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x40(%rbp),%xmm0
mulsd  -0x8(%rbp),%xmm0
divsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x40(%rbp),%xmm1
movaps 0xe31(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x28(%rbp),%xmm0
movaps 0xe21(%rip),%xmm2
pand   %xmm2,%xmm0
mulsd  -0x20(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1207 <gammaSeries+0xd7>
jmp    121a <gammaSeries+0xea>
jmp    120c <gammaSeries+0xdc>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1192 <gammaSeries+0x62>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x8(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x8(%rbp),%xmm0
call   1050 <log@plt>
movsd  -0x58(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x38(%rbp),%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gammaSeries>:
sub    $0x28,%rsp
movsd  %xmm1,0x8(%rsp)
movsd  %xmm0,(%rsp)
movsd  0xeb9(%rip),%xmm0
divsd  %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
movapd %xmm1,%xmm0
call   1040 <logGamma@plt>
movapd 0x10(%rsp),%xmm3
movsd  0xe97(%rip),%xmm8
movsd  (%rsp),%xmm5
movsd  %xmm0,0x20(%rsp)
mov    $0x63,%eax
movapd 0xe8f(%rip),%xmm0
movsd  0xe7f(%rip),%xmm1
movsd  0x8(%rsp),%xmm2
movapd %xmm3,%xmm6
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
addsd  %xmm8,%xmm2
mulsd  %xmm5,%xmm3
divsd  %xmm2,%xmm3
addsd  %xmm3,%xmm6
movapd %xmm3,%xmm7
andpd  %xmm0,%xmm7
movapd %xmm6,%xmm4
andpd  %xmm0,%xmm4
mulsd  %xmm1,%xmm4
sub    $0x1,%eax
setb   %cl
ucomisd %xmm7,%xmm4
ja     11d5 <gammaSeries+0xa5>
test   %cl,%cl
je     11a0 <gammaSeries+0x70>
movapd %xmm5,%xmm0
movapd %xmm6,0x10(%rsp)
call   1050 <log@plt>
mulsd  0x8(%rsp),%xmm0
subsd  (%rsp),%xmm0
subsd  0x20(%rsp),%xmm0
call   1030 <exp@plt>
mulsd  0x10(%rsp),%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
define double @gammaSeries(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = alloca i32
%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
store i32 100, i32* %6
store double 3.000000e-07, double* %7
%12 = load double, double* %4
%13 = fdiv double 1.000000e+00, %12
store double %13, double* %8
%14 = load double, double* %4
store double %14, double* %9
%15 = load double, double* %4
%16 = call double @logGamma(double %15)
store double %16, double* %10
%17 = load double, double* %8
store double %17, double* %11
store i32 1, i32* %5
br label %18
18: ; preds = %42, %2
%19 = load i32, i32* %5
%20 = load i32, i32* %6
%21 = icmp sle i32 %19, %20
br i1 %21, label %22, label %45
22: ; preds = %18
%23 = load double, double* %9
%24 = fadd double %23, 1.000000e+00
store double %24, double* %9
%25 = load double, double* %11
%26 = load double, double* %3
%27 = fmul double %25, %26
%28 = load double, double* %9
%29 = fdiv double %27, %28
store double %29, double* %11
%30 = load double, double* %8
%31 = load double, double* %11
%32 = fadd double %30, %31
store double %32, double* %8
%33 = load double, double* %11
%34 = call double @llvm.fabs.f64(double %33)
%35 = load double, double* %8
%36 = call double @llvm.fabs.f64(double %35)
%37 = load double, double* %7
%38 = fmul double %36, %37
%39 = fcmp olt double %34, %38
br i1 %39, label %40, label %41
40: ; preds = %22
br label %45
41: ; preds = %22
br label %42
42: ; preds = %41
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %18
45: ; preds = %40, %18
%46 = load double, double* %8
%47 = load double, double* %3
%48 = fneg double %47
%49 = load double, double* %4
%50 = load double, double* %3
%51 = call double @log(double %50)
%52 = call double @llvm.fmuladd.f64(double %49, double %51, double %48)
%53 = load double, double* %10
%54 = fsub double %52, %53
%55 = call double @exp(double %54)
%56 = fmul double %46, %55
ret double %56
}

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