#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 log(double);
double q_gamma(double, double, double);
double p_gamma(double a, double x, double log_gamma_a) {
  double y, w;
  int i;
  if (x == 0.0)
    return 0.0;
  if (x >= a + 1.0)
    return 1.0 - q_gamma(a, x, log_gamma_a);
  y = w = exp(a * log(x) - x - log_gamma_a) / a;
  for (i = 1; i < 100; i++) {
    w *= x / (a + i);
    y += w;
    if (fabs(w) < 1E-15)
      break;
  }
  return y;
}


x86 assembly (clang, -O0):
<p_gamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    117c <p_gamma+0x3c>
jp     117c <p_gamma+0x3c>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12a1 <p_gamma+0x161>
movsd  -0x18(%rbp),%xmm0
movsd  0xe77(%rip),%xmm1
addsd  -0x10(%rbp),%xmm1
ucomisd %xmm1,%xmm0
jb     11c5 <p_gamma+0x85>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
call   1030 <q_gamma@plt>
movaps %xmm0,%xmm1
movsd  0xe49(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    12a1 <p_gamma+0x161>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x40(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x20(%rbp),%xmm0
call   1050 <exp@plt>
divsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  %xmm0,-0x28(%rbp)
movl   $0x1,-0x34(%rbp)
cmpl   $0x64,-0x34(%rbp)
jge    1297 <p_gamma+0x157>
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
cvtsi2sdl -0x34(%rbp),%xmm2
addsd  %xmm2,%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xd93(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    1284 <p_gamma+0x144>
jmp    1297 <p_gamma+0x157>
jmp    1289 <p_gamma+0x149>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1225 <p_gamma+0xe5>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p_gamma>:
push   %rbx
sub    $0x20,%rsp
xorpd  %xmm4,%xmm4
ucomisd %xmm4,%xmm1
jne    1155 <p_gamma+0x15>
jnp    122e <p_gamma+0xee>
movapd %xmm0,%xmm3
movsd  0xe9f(%rip),%xmm0
addsd  %xmm3,%xmm0
ucomisd %xmm0,%xmm1
jae    1212 <p_gamma+0xd2>
movapd %xmm1,%xmm0
movsd  %xmm1,0x10(%rsp)
movsd  %xmm3,0x8(%rsp)
movsd  %xmm2,(%rsp)
call   1060 <log@plt>
mulsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
subsd  (%rsp),%xmm0
call   1050 <exp@plt>
movsd  0x8(%rsp),%xmm3
movsd  0x10(%rsp),%xmm2
divsd  %xmm3,%xmm0
mov    $0x1,%ebx
movapd %xmm0,%xmm4
nopl   0x0(%rax,%rax,1)
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
addsd  %xmm3,%xmm1
divsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm2,%xmm4
movsd  %xmm4,(%rsp)
movsd  %xmm2,0x18(%rsp)
movapd %xmm2,%xmm0
call   1040 <fabs@plt>
test   %eax,%eax
jle    1229 <p_gamma+0xe9>
lea    0x1(%rbx),%eax
cmp    $0x63,%ebx
mov    %eax,%ebx
movsd  0x10(%rsp),%xmm2
movsd  0x8(%rsp),%xmm3
movsd  (%rsp),%xmm4
movsd  0x18(%rsp),%xmm0
jne    11c0 <p_gamma+0x80>
jmp    122e <p_gamma+0xee>
movapd %xmm3,%xmm0
call   1030 <q_gamma@plt>
movsd  0xddd(%rip),%xmm4
subsd  %xmm0,%xmm4
jmp    122e <p_gamma+0xee>
movsd  (%rsp),%xmm4
movapd %xmm4,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

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

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