#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 */
int /*<<< orphan*/ assert(int);
int cfrac(double, double);
int exp(scalar_t__);
double log(double);
scalar_t__ logGamma(double);
double series(double, double);
double GammaP(double n, double x) {
  assert((n > 0) && (x >= 0));
  if (x <= 0)
    return 0;
  if (x < n + 1)
    return series(n, x) * exp(n * log(x) - x - logGamma(n));
  return 1 - cfrac(n, x) * exp(n * log(x) - x - logGamma(n));
}


x86 assembly (clang, -O0):
<GammaP>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x19(%rbp)
jbe    119b <GammaP+0x3b>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setae  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jb     11c3 <GammaP+0x63>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1300 <GammaP+0x1a0>
movsd  -0x18(%rbp),%xmm1
movsd  0xe30(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1271 <GammaP+0x111>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1030 <series@plt>
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1080 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x38(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1070 <logGamma@plt>
movsd  -0x30(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1060 <exp@plt>
movsd  -0x28(%rbp),%xmm0
cvtsi2sd %eax,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1300 <GammaP+0x1a0>
movsd  -0x10(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
call   1040 <cfrac@plt>
mov    %eax,-0x3c(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x18(%rbp),%xmm0
call   1080 <log@plt>
movaps %xmm0,%xmm2
movsd  -0x50(%rbp),%xmm0
movsd  -0x18(%rbp),%xmm1
movq   %xmm1,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1070 <logGamma@plt>
movsd  -0x48(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
subsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rdi
call   1060 <exp@plt>
mov    -0x3c(%rbp),%ecx
imul   %eax,%ecx
mov    $0x1,%eax
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GammaP>:
push   %rbx
sub    $0x20,%rsp
movsd  %xmm1,0x8(%rsp)
xorpd  %xmm2,%xmm2
movsd  %xmm0,0x10(%rsp)
ucomisd %xmm2,%xmm0
seta   %al
ucomisd %xmm2,%xmm1
setae  %cl
and    %al,%cl
movzbl %cl,%edi
call   1050 <assert@plt>
xorpd  %xmm0,%xmm0
movsd  0x8(%rsp),%xmm1
ucomisd %xmm1,%xmm0
jae    127f <GammaP+0x11f>
movsd  0xe57(%rip),%xmm0
addsd  0x10(%rsp),%xmm0
ucomisd %xmm1,%xmm0
jbe    121b <GammaP+0xbb>
movsd  0x10(%rsp),%xmm0
call   1030 <series@plt>
movsd  %xmm0,0x18(%rsp)
movsd  0x8(%rsp),%xmm0
call   1080 <log@plt>
movapd %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
mulsd  %xmm0,%xmm1
subsd  0x8(%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
call   1070 <logGamma@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rdi
call   1060 <exp@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mulsd  0x18(%rsp),%xmm0
jmp    127f <GammaP+0x11f>
movsd  0x10(%rsp),%xmm0
call   1040 <cfrac@plt>
mov    %eax,%ebx
movsd  0x8(%rsp),%xmm0
call   1080 <log@plt>
movapd %xmm0,%xmm1
movsd  0x10(%rsp),%xmm0
mulsd  %xmm0,%xmm1
subsd  0x8(%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
call   1070 <logGamma@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rdi
call   1060 <exp@plt>
imul   %ebx,%eax
mov    $0x1,%ecx
sub    %eax,%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @GammaP(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %4
store double %1, double* %5
%6 = load double, double* %4
%7 = fcmp ogt double %6, 0.000000e+00
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load double, double* %5
%10 = fcmp oge double %9, 0.000000e+00
br label %11
11: ; preds = %8, %2
%12 = phi i1 [ false, %2 ], [ %10, %8 ]
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load double, double* %5
%16 = fcmp ole double %15, 0.000000e+00
br i1 %16, label %17, label %18
17: ; preds = %11
store double 0.000000e+00, double* %3
br label %60
18: ; preds = %11
%19 = load double, double* %5
%20 = load double, double* %4
%21 = fadd double %20, 1.000000e+00
%22 = fcmp olt double %19, %21
br i1 %22, label %23, label %41
23: ; preds = %18
%24 = load double, double* %4
%25 = load double, double* %5
%26 = call double @series(double %24, double %25)
%27 = load double, double* %4
%28 = load double, double* %5
%29 = call double @log(double %28)
%30 = load double, double* %5
%31 = fneg double %30
%32 = call double @llvm.fmuladd.f64(double %27, double %29, double %31)
%33 = load double, double* %4
%34 = call i64 @logGamma(double %33)
%35 = sitofp i64 %34 to double
%36 = fsub double %32, %35
%37 = fptosi double %36 to i64
%38 = call i32 @exp(i64 %37)
%39 = sitofp i32 %38 to double
%40 = fmul double %26, %39
store double %40, double* %3
br label %60
41: ; preds = %18
%42 = load double, double* %4
%43 = load double, double* %5
%44 = call i32 @cfrac(double %42, double %43)
%45 = load double, double* %4
%46 = load double, double* %5
%47 = call double @log(double %46)
%48 = load double, double* %5
%49 = fneg double %48
%50 = call double @llvm.fmuladd.f64(double %45, double %47, double %49)
%51 = load double, double* %4
%52 = call i64 @logGamma(double %51)
%53 = sitofp i64 %52 to double
%54 = fsub double %50, %53
%55 = fptosi double %54 to i64
%56 = call i32 @exp(i64 %55)
%57 = mul nsw i32 %44, %56
%58 = sub nsw i32 1, %57
%59 = sitofp i32 %58 to double
store double %59, double* %3
br label %60
60: ; preds = %41, %23, %17
%61 = load double, double* %3
ret double %61
}

LLVM IR (-O2):
define double @GammaP(double %0, double %1) {
%3 = fcmp ogt double %0, 0.000000e+00
%4 = fcmp oge double %1, 0.000000e+00
%5 = and i1 %3, %4
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = fcmp ugt double %1, 0.000000e+00
br i1 %8, label %9, label %37
9: ; preds = %2
%10 = fadd double %0, 1.000000e+00
%11 = fcmp ogt double %10, %1
br i1 %11, label %12, label %24
12: ; preds = %9
%13 = tail call double @series(double %0, double %1)
%14 = tail call double @log(double %1)
%15 = fneg double %1
%16 = tail call double @llvm.fmuladd.f64(double %0, double %14, double %15)
%17 = tail call i64 @logGamma(double %0)
%18 = sitofp i64 %17 to double
%19 = fsub double %16, %18
%20 = fptosi double %19 to i64
%21 = tail call i32 @exp(i64 %20)
%22 = sitofp i32 %21 to double
%23 = fmul double %13, %22
br label %37
24: ; preds = %9
%25 = tail call i32 @cfrac(double %0, double %1)
%26 = tail call double @log(double %1)
%27 = fneg double %1
%28 = tail call double @llvm.fmuladd.f64(double %0, double %26, double %27)
%29 = tail call i64 @logGamma(double %0)
%30 = sitofp i64 %29 to double
%31 = fsub double %28, %30
%32 = fptosi double %31 to i64
%33 = tail call i32 @exp(i64 %32)
%34 = mul nsw i32 %33, %25
%35 = sub nsw i32 1, %34
%36 = sitofp i32 %35 to double
br label %37
37: ; preds = %2, %24, %12
%38 = phi double [ %23, %12 ], [ %36, %24 ], [ 0.000000e+00, %2 ]
ret double %38
}