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


x86 assembly (clang, -O0):
<q_gamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  0xea1(%rip),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  0xe94(%rip),%xmm0
addsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x18(%rbp),%xmm1
movsd  0xe78(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11c4 <q_gamma+0x84>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
call   1030 <p_gamma@plt>
movaps %xmm0,%xmm1
movsd  0xe4a(%rip),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1316 <q_gamma+0x1d6>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x60(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x58(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1060 <log@plt>
movsd  -0x60(%rbp),%xmm1
movaps %xmm0,%xmm2
movsd  -0x58(%rbp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
subsd  -0x20(%rbp),%xmm0
call   1050 <exp@plt>
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x2,-0x4c(%rbp)
cmpl   $0x64,-0x4c(%rbp)
jge    130c <q_gamma+0x1cc>
mov    -0x4c(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  -0x40(%rbp),%xmm2
subsd  -0x38(%rbp),%xmm2
cvtsi2sdl -0x4c(%rbp),%xmm1
addsd  -0x18(%rbp),%xmm1
mulsd  -0x40(%rbp),%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsi2sdl -0x4c(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x40(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x48(%rbp),%xmm0
movsd  %xmm0,-0x40(%rbp)
mov    -0x4c(%rbp),%eax
sub    $0x1,%eax
cvtsi2sd %eax,%xmm0
subsd  -0x10(%rbp),%xmm0
cvtsi2sdl -0x4c(%rbp),%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x30(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
divsd  -0x38(%rbp),%xmm0
divsd  -0x40(%rbp),%xmm0
call   1040 <fabs@plt>
cvtsi2sd %eax,%xmm1
movsd  0xd1e(%rip),%xmm0
ucomisd %xmm1,%xmm0
jbe    12f9 <q_gamma+0x1b9>
jmp    130c <q_gamma+0x1cc>
jmp    12fe <q_gamma+0x1be>
mov    -0x4c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4c(%rbp)
jmp    1233 <q_gamma+0xf3>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<q_gamma>:
push   %rbx
sub    $0x50,%rsp
movapd %xmm0,%xmm4
movsd  0xeaf(%rip),%xmm3
addsd  %xmm3,%xmm0
ucomisd %xmm1,%xmm0
jbe    1175 <q_gamma+0x35>
movapd %xmm4,%xmm0
call   1030 <p_gamma@plt>
movsd  0xe94(%rip),%xmm5
subsd  %xmm0,%xmm5
jmp    128c <q_gamma+0x14c>
movapd %xmm1,%xmm0
movapd %xmm3,0x30(%rsp)
addsd  %xmm3,%xmm0
subsd  %xmm4,%xmm0
movapd %xmm0,0x20(%rsp)
movapd %xmm1,%xmm0
movsd  %xmm1,0x18(%rsp)
movsd  %xmm4,0x10(%rsp)
movsd  %xmm2,0x8(%rsp)
call   1060 <log@plt>
mulsd  0x10(%rsp),%xmm0
subsd  0x18(%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
call   1050 <exp@plt>
movapd 0x20(%rsp),%xmm4
movapd %xmm0,%xmm5
divsd  %xmm4,%xmm5
mov    $0x2,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movapd 0x30(%rsp),%xmm1
lea    -0x1(%rbx),%eax
xorps  %xmm6,%xmm6
cvtsi2sd %eax,%xmm6
subsd  0x10(%rsp),%xmm6
movapd %xmm4,%xmm2
subsd  %xmm1,%xmm2
xorps  %xmm1,%xmm1
cvtsi2sd %ebx,%xmm1
mulsd  %xmm6,%xmm2
divsd  %xmm1,%xmm6
movapd %xmm4,%xmm3
unpcklpd %xmm1,%xmm3
addsd  0x18(%rsp),%xmm1
movapd %xmm4,0x30(%rsp)
mulsd  %xmm4,%xmm1
addsd  %xmm1,%xmm2
mulsd  %xmm0,%xmm6
movapd %xmm6,0x40(%rsp)
movapd %xmm6,%xmm0
unpcklpd %xmm2,%xmm0
divpd  %xmm3,%xmm0
movapd %xmm0,%xmm1
unpckhpd %xmm0,%xmm1
movapd %xmm1,0x20(%rsp)
divsd  %xmm1,%xmm0
addsd  %xmm0,%xmm5
movsd  %xmm5,0x8(%rsp)
call   1040 <fabs@plt>
test   %eax,%eax
jle    1286 <q_gamma+0x146>
lea    0x1(%rbx),%eax
cmp    $0x63,%ebx
mov    %eax,%ebx
movsd  0x8(%rsp),%xmm5
movapd 0x40(%rsp),%xmm0
movapd 0x20(%rsp),%xmm4
jne    11e0 <q_gamma+0xa0>
jmp    128c <q_gamma+0x14c>
movsd  0x8(%rsp),%xmm5
movapd %xmm5,%xmm0
add    $0x50,%rsp
pop    %rbx
ret

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

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