#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 gammln(double);
double log(double);
void gamma_series_rep(double *gamser, double a, double x, double *gln) {
  int n;
  double sum, del, ap;
  *gln = gammln(a);
  if (x <= 0.0) {
    if (x < 0.0)
      *gamser = 0.0;
    return;
  } else {
    ap = a;
    del = sum = 1.0 / a;
    for (n = 1; n <= 100; n++) {
      ++ap;
      del *= x / ap;
      sum += del;
      if (fabs(del) < fabs(sum) * 3.0e-7) {
        *gamser = sum * exp(-x + a * log(x) - (*gln));
        return;
      }
    }
    return;
  }
}


x86 assembly (clang, -O0):
<gamma_series_rep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <gammln@plt>
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     1188 <gamma_series_rep+0x58>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1183 <gamma_series_rep+0x53>
mov    -0x8(%rbp),%rax
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rax)
jmp    12b7 <gamma_series_rep+0x187>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  0xe66(%rip),%xmm0
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  %xmm0,-0x38(%rbp)
movl   $0x1,-0x24(%rbp)
cmpl   $0x64,-0x24(%rbp)
jg     12b2 <gamma_series_rep+0x182>
movsd  0xe3e(%rip),%xmm0
addsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
mulsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x38(%rbp),%xmm1
movaps 0xe15(%rip),%xmm0
pand   %xmm0,%xmm1
movsd  -0x30(%rbp),%xmm0
movaps 0xe05(%rip),%xmm2
pand   %xmm2,%xmm0
movsd  0xdf1(%rip),%xmm2
mulsd  %xmm2,%xmm0
ucomisd %xmm1,%xmm0
jbe    129f <gamma_series_rep+0x16f>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x18(%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  -0x18(%rbp),%xmm0
call   1040 <log@plt>
movsd  -0x58(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x20(%rbp),%rax
subsd  (%rax),%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
mulsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
jmp    12b7 <gamma_series_rep+0x187>
jmp    12a4 <gamma_series_rep+0x174>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11b0 <gamma_series_rep+0x80>
jmp    12b7 <gamma_series_rep+0x187>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gamma_series_rep>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rbx
movsd  %xmm1,0x8(%rsp)
mov    %rdi,%r14
movsd  %xmm0,(%rsp)
call   1050 <gammln@plt>
movsd  0x8(%rsp),%xmm7
movsd  %xmm0,(%rbx)
xorpd  %xmm1,%xmm1
ucomisd %xmm7,%xmm1
jae    11da <gamma_series_rep+0xaa>
movsd  0xe96(%rip),%xmm8
movapd %xmm8,%xmm3
movsd  (%rsp),%xmm9
divsd  %xmm9,%xmm3
mov    $0x64,%eax
movapd 0xe89(%rip),%xmm1
movsd  0xe79(%rip),%xmm0
movapd %xmm9,%xmm4
movapd %xmm3,%xmm2
nopl   0x0(%rax,%rax,1)
movapd %xmm3,%xmm5
addsd  %xmm8,%xmm4
movapd %xmm7,%xmm3
divsd  %xmm4,%xmm3
mulsd  %xmm5,%xmm3
addsd  %xmm3,%xmm2
movapd %xmm3,%xmm5
andpd  %xmm1,%xmm5
movapd %xmm2,%xmm6
andpd  %xmm1,%xmm6
mulsd  %xmm0,%xmm6
ucomisd %xmm5,%xmm6
ja     11de <gamma_series_rep+0xae>
add    $0xffffffff,%eax
jne    11a0 <gamma_series_rep+0x70>
jmp    1210 <gamma_series_rep+0xe0>
ja     120b <gamma_series_rep+0xdb>
jmp    1210 <gamma_series_rep+0xe0>
movapd %xmm7,%xmm0
movapd %xmm2,0x10(%rsp)
call   1040 <log@plt>
mulsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
subsd  (%rbx),%xmm0
call   1030 <exp@plt>
movapd 0x10(%rsp),%xmm1
mulsd  %xmm0,%xmm1
movsd  %xmm1,(%r14)
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
define void @gamma_series_rep(double* nocapture writeonly %0, double %1, double %2, double* nocapture %3) {
%5 = tail call double @gammln(double %1)
store double %5, double* %3
%6 = fcmp ugt double %2, 0.000000e+00
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = fcmp olt double %2, 0.000000e+00
br i1 %8, label %35, label %37
9: ; preds = %4
%10 = fdiv double 1.000000e+00, %1
br label %14
11: ; preds = %14
%12 = add nuw nsw i32 %18, 1
%13 = icmp eq i32 %12, 101
br i1 %13, label %37, label %14
14: ; preds = %9, %11
%15 = phi double [ %1, %9 ], [ %19, %11 ]
%16 = phi double [ %10, %9 ], [ %21, %11 ]
%17 = phi double [ %10, %9 ], [ %22, %11 ]
%18 = phi i32 [ 1, %9 ], [ %12, %11 ]
%19 = fadd double %15, 1.000000e+00
%20 = fdiv double %2, %19
%21 = fmul double %16, %20
%22 = fadd double %17, %21
%23 = tail call double @llvm.fabs.f64(double %21)
%24 = tail call double @llvm.fabs.f64(double %22)
%25 = fmul double %24, 3.000000e-07
%26 = fcmp olt double %23, %25
br i1 %26, label %27, label %11
27: ; preds = %14
%28 = fneg double %2
%29 = tail call double @log(double %2)
%30 = tail call double @llvm.fmuladd.f64(double %1, double %29, double %28)
%31 = load double, double* %3
%32 = fsub double %30, %31
%33 = tail call double @exp(double %32)
%34 = fmul double %22, %33
br label %35
35: ; preds = %7, %27
%36 = phi double [ %34, %27 ], [ 0.000000e+00, %7 ]
store double %36, double* %0
br label %37
37: ; preds = %11, %35, %7
ret void
}