// File: /workspace/github_c_makefile_star2_O0/c-zhou[P]yahs/binomlite.c
// Function: bpser
static double bpser(double a, double b, double x, double eps, int log_p)
{
/* -----------------------------------------------------------------------
 * Power SERies expansion for evaluating I_x(a,b) when
 *           b <= 1 or b*x <= 0.7.   eps is the tolerance used.
 * NB: if log_p is 1, also use it if   (b < 40  & lambda > 650)
 * ----------------------------------------------------------------------- */

    int i, m;
    double ans, c, t, u, z, a0, b0, apb;

    if (x == 0.) {
        return R_D__0;
    }
/* ----------------------------------------------------------------------- */
/*          compute the factor  x^a/(a*Beta(a,b)) */
/* ----------------------------------------------------------------------- */
    a0 = fmin2(a,b);
    if (a0 >= 1.) { /*         ------     1 <= a0 <= b0  ------ */
        z = a * log(x) - betaln(a, b);
        ans = log_p ? z - log(a) : exp(z) / a;
    } else {
        b0 = fmax2(a,b);

    if (b0 < 8.) {

        if (b0 <= 1.) { /*     ------     a0 < 1     and  b0 <= 1  ------ */
            
            if(log_p) {
                ans = a * log(x);
            } else {
                ans = pow(x, a);
                if (ans == 0.) /* once underflow, always underflow .. */
                    return ans;
            }
            apb = a + b;
            if (apb > 1.) {
                u = a + b - 1.;
                z = (gam1(u) + 1.) / apb;
            } else {
                z = gam1(apb) + 1.;
            }
            c = (gam1(a) + 1.) * (gam1(b) + 1.) / z;

            if(log_p) /* FIXME ? -- improve quite a bit for c ~= 1 */
                ans += log(c * (b / apb));
            else
                ans *=  c * (b / apb);

            } else { /*     ------    a0 < 1 < b0 < 8     ------ */

                u = gamln1(a0);
                m = (int)(b0 - 1.);
                if (m >= 1) {
                    c = 1.;
                    for (i = 1; i <= m; ++i) {
                        b0 += -1.;
                        c *= b0 / (a0 + b0);
                    }
                    u += log(c);
                }

                z = a * log(x) - u;
                b0 += -1.; // => b0 in (0, 7)
                apb = a0 + b0;
                if (apb > 1.) {
                    u = a0 + b0 - 1.;
                    t = (gam1(u) + 1.) / apb;
                } else {
                    t = gam1(apb) + 1.;
                }

                if(log_p) /* FIXME? potential for improving log(t) */
                    ans = z + log(a0 / a) + log1p(gam1(b0)) - log(t);
                else
                    ans = exp(z) * (a0 / a) * (gam1(b0) + 1.) / t;
            }

        } else { /*         ------  a0 < 1 < 8 <= b0  ------ */

            u = gamln1(a0) + algdiv(a0, b0);
            z = a * log(x) - u;

            if(log_p)
                ans = z + log(a0 / a);
            else
                ans = a0 / a * exp(z);
        }
    }
    if (ans == R_D__0 || (!log_p && a <= eps * 0.1)) {
        return ans;
    }

/* ----------------------------------------------------------------------- */
/*               COMPUTE THE SERIES */
/* ----------------------------------------------------------------------- */
    double tol = eps / a,
    n = 0.,
    sum = 0., w;
    c = 1.;
    do { // sum is alternating as long as n < b (<==> 1 - b/n < 0)
        n += 1.;
        c *= (0.5 - b / n + 0.5) * x;
        w = c / (a + n);
        sum += w;
    } while (n < 1e7 && fabs(w) > tol);
    if(log_p) {
        if (a*sum > -1.)
            ans += log1p(a * sum);
        else
            ans = ML_NEGINF;
    } else if (a*sum > -1.) {
        ans *= (a * sum + 1.);
    } else { // underflow to
        ans = 0.;
    }
    return ans;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movsd %xmm0, -0x10(%rbp)
movsd %xmm1, -0x18(%rbp)
movsd %xmm2, -0x20(%rbp)
movsd %xmm3, -0x28(%rbp)
movl %edi, -0x2c(%rbp)
movsd -0x20(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x22f47
jp 0x22f47
movl -0x2c(%rbp), %eax
movsd 0xf873(%rip), %xmm0     # 0x32780
xorps %xmm1, %xmm1
movsd %xmm1, -0xa8(%rbp)
cmpl $0x0, %eax
movsd %xmm0, -0xa0(%rbp)
jne 0x22f35
movsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0xa0(%rbp)
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x2378a
movsd -0x10(%rbp), %xmm1
movsd -0x18(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x22f66
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
jmp 0x22f73
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0xb0(%rbp)
movsd -0xb0(%rbp), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
movsd 0xe66b(%rip), %xmm1     # 0x315f8
ucomisd %xmm1, %xmm0
jb 0x2305b
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
movsd -0x20(%rbp), %xmm0
callq 0x2250
movsd %xmm0, -0xc0(%rbp)
movsd -0x10(%rbp), %xmm0
movsd -0x18(%rbp), %xmm1
callq 0x260f0
movsd -0xc0(%rbp), %xmm2
movaps %xmm0, %xmm1
movsd -0xb8(%rbp), %xmm0
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x23032
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0xd0(%rbp)
movsd -0x10(%rbp), %xmm0
callq 0x2250
movaps %xmm0, %xmm1
movsd -0xd0(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0xc8(%rbp)
jmp 0x23049
movsd -0x60(%rbp), %xmm0
callq 0x2560
divsd -0x10(%rbp), %xmm0
movsd %xmm0, -0xc8(%rbp)
movsd -0xc8(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x23560
movsd -0x10(%rbp), %xmm0
ucomisd -0x18(%rbp), %xmm0
jb 0x23076
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0xd8(%rbp)
jmp 0x23083
movsd -0x18(%rbp), %xmm0
movsd %xmm0, -0xd8(%rbp)
movsd -0xd8(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd 0xf7d8(%rip), %xmm0     # 0x32870
ucomisd -0x70(%rbp), %xmm0
jbe 0x23474
movsd 0xe54d(%rip), %xmm0     # 0x315f8
ucomisd -0x70(%rbp), %xmm0
jb 0x23231
cmpl $0x0, -0x2c(%rbp)
je 0x230e9
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0xe0(%rbp)
movsd -0x20(%rbp), %xmm0
callq 0x2250
movaps %xmm0, %xmm1
movsd -0xe0(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x2311e
movsd -0x20(%rbp), %xmm0
movsd -0x10(%rbp), %xmm1
callq 0x2140
movsd %xmm0, -0x40(%rbp)
movsd -0x40(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x2311c
jp 0x2311c
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x2378a
jmp 0x2311e
movsd -0x10(%rbp), %xmm0
addsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
movsd 0xe4be(%rip), %xmm1     # 0x315f8
ucomisd %xmm1, %xmm0
jbe 0x2317d
movsd -0x10(%rbp), %xmm0
addsd -0x18(%rbp), %xmm0
movsd 0xe4a6(%rip), %xmm1     # 0x315f8
subsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
callq 0x26e70
movsd 0xe48b(%rip), %xmm1     # 0x315f8
addsd %xmm1, %xmm0
divsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
jmp 0x23198
movsd -0x78(%rbp), %xmm0
callq 0x26e70
movsd 0xe469(%rip), %xmm1     # 0x315f8
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x10(%rbp), %xmm0
callq 0x26e70
movsd 0xe44e(%rip), %xmm1     # 0x315f8
addsd %xmm1, %xmm0
movsd %xmm0, -0xe8(%rbp)
movsd -0x18(%rbp), %xmm0
callq 0x26e70
movaps %xmm0, %xmm1
movsd -0xe8(%rbp), %xmm0
movsd 0xe425(%rip), %xmm2     # 0x315f8
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
divsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x2320f
movsd -0x48(%rbp), %xmm0
movsd -0x18(%rbp), %xmm1
divsd -0x78(%rbp), %xmm1
mulsd %xmm1, %xmm0
callq 0x2250
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x2322c
movsd -0x48(%rbp), %xmm0
movsd -0x18(%rbp), %xmm1
divsd -0x78(%rbp), %xmm1
mulsd %xmm1, %xmm0
mulsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x2346f
movsd -0x68(%rbp), %xmm0
callq 0x268c0
movsd %xmm0, -0x58(%rbp)
movsd -0x70(%rbp), %xmm0
movsd 0xe3ab(%rip), %xmm1     # 0x315f8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x34(%rbp)
cmpl $0x1, -0x34(%rbp)
jl 0x232c8
movsd 0xe392(%rip), %xmm0     # 0x315f8
movsd %xmm0, -0x48(%rbp)
movl $0x1, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x34(%rbp), %eax
jg 0x232b4
movsd 0xf5f6(%rip), %xmm0     # 0x32878
addsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x70(%rbp), %xmm0
movsd -0x68(%rbp), %xmm1
addsd -0x70(%rbp), %xmm1
divsd %xmm1, %xmm0
mulsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x23272
movsd -0x48(%rbp), %xmm0
callq 0x2250
addsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0xf0(%rbp)
movsd -0x20(%rbp), %xmm0
callq 0x2250
movaps %xmm0, %xmm2
movsd -0xf0(%rbp), %xmm0
movsd -0x58(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0xf55d(%rip), %xmm0     # 0x32878
addsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movsd -0x68(%rbp), %xmm0
addsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
movsd 0xe2b7(%rip), %xmm1     # 0x315f8
ucomisd %xmm1, %xmm0
jbe 0x23384
movsd -0x68(%rbp), %xmm0
addsd -0x70(%rbp), %xmm0
movsd 0xe29f(%rip), %xmm1     # 0x315f8
subsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
callq 0x26e70
movsd 0xe284(%rip), %xmm1     # 0x315f8
addsd %xmm1, %xmm0
divsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
jmp 0x2339f
movsd -0x78(%rbp), %xmm0
callq 0x26e70
movsd 0xe262(%rip), %xmm1     # 0x315f8
addsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x2341e
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x108(%rbp)
movsd -0x68(%rbp), %xmm0
divsd -0x10(%rbp), %xmm0
callq 0x2250
movaps %xmm0, %xmm1
movsd -0x108(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x100(%rbp)
movsd -0x70(%rbp), %xmm0
callq 0x26e70
callq 0x2230
movaps %xmm0, %xmm1
movsd -0x100(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0xf8(%rbp)
movsd -0x50(%rbp), %xmm0
callq 0x2250
movaps %xmm0, %xmm1
movsd -0xf8(%rbp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x2346d
movsd -0x60(%rbp), %xmm0
callq 0x2560
movsd -0x68(%rbp), %xmm1
divsd -0x10(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x110(%rbp)
movsd -0x70(%rbp), %xmm0
callq 0x26e70
movaps %xmm0, %xmm1
movsd -0x110(%rbp), %xmm0
movsd 0xe19d(%rip), %xmm2     # 0x315f8
addsd %xmm2, %xmm1
mulsd %xmm1, %xmm0
divsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x2346f
jmp 0x2355e
movsd -0x68(%rbp), %xmm0
callq 0x268c0
movsd %xmm0, -0x120(%rbp)
movsd -0x68(%rbp), %xmm0
movsd -0x70(%rbp), %xmm1
callq 0x26b40
movaps %xmm0, %xmm1
movsd -0x120(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x118(%rbp)
movsd -0x20(%rbp), %xmm0
callq 0x2250
movaps %xmm0, %xmm2
movsd -0x118(%rbp), %xmm0
movsd -0x58(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x2352c
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x128(%rbp)
movsd -0x68(%rbp), %xmm0
divsd -0x10(%rbp), %xmm0
callq 0x2250
movaps %xmm0, %xmm1
movsd -0x128(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x2355c
movsd -0x68(%rbp), %xmm0
divsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x130(%rbp)
movsd -0x60(%rbp), %xmm0
callq 0x2560
movaps %xmm0, %xmm1
movsd -0x130(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x2355e
jmp 0x23560
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x148(%rbp)
movl -0x2c(%rbp), %eax
movsd 0xf208(%rip), %xmm0     # 0x32780
xorps %xmm1, %xmm1
movsd %xmm1, -0x140(%rbp)
cmpl $0x0, %eax
movsd %xmm0, -0x138(%rbp)
jne 0x235a0
movsd -0x140(%rbp), %xmm0
movsd %xmm0, -0x138(%rbp)
movsd -0x148(%rbp), %xmm0
movsd -0x138(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jne 0x235ba
jp 0x235ba
jmp 0x235d8
cmpl $0x0, -0x2c(%rbp)
jne 0x235e7
movsd -0x10(%rbp), %xmm1
movsd 0xe03b(%rip), %xmm0     # 0x31608
mulsd -0x28(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jb 0x235e7
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x2378a
movsd -0x28(%rbp), %xmm0
divsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x88(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x90(%rbp)
movsd 0xdfe4(%rip), %xmm0     # 0x315f8
movsd %xmm0, -0x48(%rbp)
movsd 0xdfd7(%rip), %xmm0     # 0x315f8
addsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x88(%rbp)
movsd -0x18(%rbp), %xmm1
divsd -0x88(%rbp), %xmm1
movsd 0xdfba(%rip), %xmm0     # 0x31600
subsd %xmm1, %xmm0
movsd 0xdfae(%rip), %xmm1     # 0x31600
addsd %xmm1, %xmm0
mulsd -0x20(%rbp), %xmm0
mulsd -0x48(%rbp), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
movsd -0x10(%rbp), %xmm1
addsd -0x88(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x98(%rbp)
movsd -0x98(%rbp), %xmm0
addsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x90(%rbp)
xorl %eax, %eax
movsd 0xf1db(%rip), %xmm0     # 0x32880
ucomisd -0x88(%rbp), %xmm0
movb %al, -0x149(%rbp)
jbe 0x236d6
movsd -0x98(%rbp), %xmm0
movaps 0xf42c(%rip), %xmm1     # 0x32af0
pand %xmm1, %xmm0
ucomisd -0x80(%rbp), %xmm0
seta %al
movb %al, -0x149(%rbp)
movb -0x149(%rbp), %al
testb $0x1, %al
jne 0x23619
cmpl $0x0, -0x2c(%rbp)
je 0x23732
movsd -0x10(%rbp), %xmm0
mulsd -0x90(%rbp), %xmm0
movsd 0xf179(%rip), %xmm1     # 0x32878
ucomisd %xmm1, %xmm0
jbe 0x23723
movsd -0x10(%rbp), %xmm0
mulsd -0x90(%rbp), %xmm0
callq 0x2230
addsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x23730
movsd 0xf055(%rip), %xmm0     # 0x32780
movsd %xmm0, -0x40(%rbp)
jmp 0x23780
movsd -0x10(%rbp), %xmm0
mulsd -0x90(%rbp), %xmm0
movsd 0xf131(%rip), %xmm1     # 0x32878
ucomisd %xmm1, %xmm0
jbe 0x23776
movsd -0x10(%rbp), %xmm0
movsd -0x90(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd 0xde92(%rip), %xmm1     # 0x315f8
addsd %xmm1, %xmm0
mulsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x2377e
xorps %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
jmp 0x23780
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
movsd -0x8(%rbp), %xmm0
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopl (%rax,%rax)