#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);
double gamma_contfrac(double const, double const);
double gamma_series(double const, double const);
double __attribute__((const))
pgamma(const double x, const double a, const double b, const int tail) {
  double res, p, q;
  assert(x >= 0.);
  assert(a > 0.);
  assert(b > 0.);
  assert(tail == 0 || tail == 1);
  if (1. + a < x * b) {
    q = gamma_contfrac(x * b, a);
    if (tail == 1)
      res = q;
    else
      res = 1. - q;
  } else {
    p = gamma_series(x * b, a);
    if (tail == 1)
      res = 1. - p;
    else
      res = p;
  }
  assert(res >= 0. && res <= 1.);
  return res;
}


x86 assembly (clang, -O0):
<pgamma>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movsd  %xmm0,-0x8(%rbp)
movsd  %xmm1,-0x10(%rbp)
movsd  %xmm2,-0x18(%rbp)
mov    %edi,-0x1c(%rbp)
movsd  -0x8(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
setae  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
seta   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    $0x1,%al
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x39(%rbp)
je     11ae <pgamma+0x7e>
cmpl   $0x1,-0x1c(%rbp)
sete   %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movsd  0xe3d(%rip),%xmm1
addsd  -0x10(%rbp),%xmm1
movsd  -0x8(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1225 <pgamma+0xf5>
movsd  -0x8(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1050 <gamma_contfrac@plt>
movsd  %xmm0,-0x38(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    120e <pgamma+0xde>
movsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1220 <pgamma+0xf0>
movsd  0xdea(%rip),%xmm0
subsd  -0x38(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    126e <pgamma+0x13e>
movsd  -0x8(%rbp),%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
call   1030 <gamma_series@plt>
movsd  %xmm0,-0x30(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    125f <pgamma+0x12f>
movsd  0xdb0(%rip),%xmm0
subsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    1269 <pgamma+0x139>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
jmp    126e <pgamma+0x13e>
movsd  -0x28(%rbp),%xmm0
xor    %eax,%eax
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
mov    %al,-0x3a(%rbp)
jb     1298 <pgamma+0x168>
movsd  0xd73(%rip),%xmm0
ucomisd -0x28(%rbp),%xmm0
setae  %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
movsd  -0x28(%rbp),%xmm0
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pgamma>:
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,0x18(%rsp)
xorpd  %xmm1,%xmm1
xor    %edi,%edi
ucomisd %xmm1,%xmm0
setae  %dil
call   1040 <assert@plt>
xor    %edi,%edi
movsd  0x10(%rsp),%xmm0
ucomisd 0xe9c(%rip),%xmm0
seta   %dil
call   1040 <assert@plt>
xor    %edi,%edi
movsd  0x8(%rsp),%xmm0
ucomisd 0xe83(%rip),%xmm0
seta   %dil
call   1040 <assert@plt>
xor    %edi,%edi
cmp    $0x2,%ebx
setb   %dil
call   1040 <assert@plt>
movsd  0x10(%rsp),%xmm1
movsd  0xe56(%rip),%xmm0
addsd  %xmm1,%xmm0
movsd  0x18(%rsp),%xmm2
mulsd  0x8(%rsp),%xmm2
ucomisd %xmm0,%xmm2
movapd %xmm2,%xmm0
jbe    11e0 <pgamma+0xb0>
call   1050 <gamma_contfrac@plt>
movapd %xmm0,%xmm1
movsd  0xe2b(%rip),%xmm0
subsd  %xmm1,%xmm0
cmp    $0x1,%ebx
jne    11f6 <pgamma+0xc6>
jmp    11fa <pgamma+0xca>
call   1030 <gamma_series@plt>
movsd  0xe13(%rip),%xmm1
subsd  %xmm0,%xmm1
cmp    $0x1,%ebx
je     11fa <pgamma+0xca>
movapd %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm1
setae  %al
movsd  0xded(%rip),%xmm0
ucomisd %xmm1,%xmm0
setae  %cl
and    %al,%cl
movzbl %cl,%edi
call   1040 <assert@plt>
movsd  0x8(%rsp),%xmm0
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @pgamma(double %0, double %1, double %2, i32 %3) {
%5 = alloca double
%6 = alloca double
%7 = alloca double
%8 = alloca i32
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
store i32 %3, i32* %8
%12 = load double, double* %5
%13 = fcmp oge double %12, 0.000000e+00
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load double, double* %6
%17 = fcmp ogt double %16, 0.000000e+00
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load double, double* %7
%21 = fcmp ogt double %20, 0.000000e+00
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i32, i32* %8
%25 = icmp eq i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %4
%27 = load i32, i32* %8
%28 = icmp eq i32 %27, 1
br label %29
29: ; preds = %26, %4
%30 = phi i1 [ true, %4 ], [ %28, %26 ]
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = load double, double* %6
%34 = fadd double 1.000000e+00, %33
%35 = load double, double* %5
%36 = load double, double* %7
%37 = fmul double %35, %36
%38 = fcmp olt double %34, %37
br i1 %38, label %39, label %53
39: ; preds = %29
%40 = load double, double* %5
%41 = load double, double* %7
%42 = fmul double %40, %41
%43 = load double, double* %6
%44 = call double @gamma_contfrac(double %42, double %43)
store double %44, double* %11
%45 = load i32, i32* %8
%46 = icmp eq i32 %45, 1
br i1 %46, label %47, label %49
47: ; preds = %39
%48 = load double, double* %11
store double %48, double* %9
br label %52
49: ; preds = %39
%50 = load double, double* %11
%51 = fsub double 1.000000e+00, %50
store double %51, double* %9
br label %52
52: ; preds = %49, %47
br label %67
53: ; preds = %29
%54 = load double, double* %5
%55 = load double, double* %7
%56 = fmul double %54, %55
%57 = load double, double* %6
%58 = call double @gamma_series(double %56, double %57)
store double %58, double* %10
%59 = load i32, i32* %8
%60 = icmp eq i32 %59, 1
br i1 %60, label %61, label %64
61: ; preds = %53
%62 = load double, double* %10
%63 = fsub double 1.000000e+00, %62
store double %63, double* %9
br label %66
64: ; preds = %53
%65 = load double, double* %10
store double %65, double* %9
br label %66
66: ; preds = %64, %61
br label %67
67: ; preds = %66, %52
%68 = load double, double* %9
%69 = fcmp oge double %68, 0.000000e+00
br i1 %69, label %70, label %73
70: ; preds = %67
%71 = load double, double* %9
%72 = fcmp ole double %71, 1.000000e+00
br label %73
73: ; preds = %70, %67
%74 = phi i1 [ false, %67 ], [ %72, %70 ]
%75 = zext i1 %74 to i32
%76 = call i32 @assert(i32 %75)
%77 = load double, double* %9
ret double %77
}

LLVM IR (-O2):
define double @pgamma(double %0, double %1, double %2, i32 %3) {
%5 = fcmp oge double %0, 0.000000e+00
%6 = zext i1 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = fcmp ogt double %1, 0.000000e+00
%9 = zext i1 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = fcmp ogt double %2, 0.000000e+00
%12 = zext i1 %11 to i32
%13 = tail call i32 @assert(i32 %12)
%14 = icmp ult i32 %3, 2
%15 = zext i1 %14 to i32
%16 = tail call i32 @assert(i32 %15)
%17 = fadd double %1, 1.000000e+00
%18 = fmul double %0, %2
%19 = fcmp olt double %17, %18
br i1 %19, label %20, label %23
20: ; preds = %4
%21 = tail call double @gamma_contfrac(double %18, double %1)
%22 = fsub double 1.000000e+00, %21
br label %26
23: ; preds = %4
%24 = tail call double @gamma_series(double %18, double %1)
%25 = fsub double 1.000000e+00, %24
br label %26
26: ; preds = %23, %20
%27 = phi double [ %24, %23 ], [ %22, %20 ]
%28 = phi double [ %25, %23 ], [ %21, %20 ]
%29 = icmp eq i32 %3, 1
%30 = select i1 %29, double %28, double %27
%31 = fcmp oge double %30, 0.000000e+00
%32 = fcmp ole double %30, 1.000000e+00
%33 = and i1 %31, %32
%34 = zext i1 %33 to i32
%35 = tail call i32 @assert(i32 %34)
ret double %30
}