// File: /workspace/github_c_makefile_star2_O2/c-zhou[P]yahs/binomlite.c
// Function: brcmp1
static double brcmp1(int mu, double a, double b, double x, double y, int give_log)
{
/* -----------------------------------------------------------------------
 *          Evaluation of    exp(mu) * x^a * y^b / beta(a,b)
 * ----------------------------------------------------------------------- */

    static double const__ = .398942280401433; /* == 1/sqrt(2*pi); */
    /* R has  M_1_SQRT_2PI */

    /* Local variables */
    double c, t, u, v, z, a0, b0, apb;

    a0 = fmin2(a,b);
    if (a0 < 8.) {
    double lnx, lny;
    if (x <= .375) {
        lnx = log(x);
        lny = alnrel(-x);
    } else if (y > .375) {
        // L11:
        lnx = log(x);
        lny = log(y);
    } else {
        lnx = alnrel(-y);
        lny = log(y);
    }

    // L20:
    z = a * lnx + b * lny;
    if (a0 >= 1.) {
        z -= betaln(a, b);
        return esum(mu, z, give_log);
    }
    // else :
    /* ----------------------------------------------------------------------- */
    /*              PROCEDURE FOR A < 1 OR B < 1 */
    /* ----------------------------------------------------------------------- */
    // L30:
    b0 = fmax2(a,b);
    if (b0 >= 8.) {
    /* L80:                  ALGORITHM FOR b0 >= 8 */
        u = gamln1(a0) + algdiv(a0, b0);
        return give_log
        ? log(a0) + esum(mu, z - u, 1)
        :     a0  * esum(mu, z - u, 0);

    } else if (b0 <= 1.) {
        //                   a0 < 1, b0 <= 1
        double ans = esum(mu, z, give_log);
        if (ans == (give_log ? ML_NEGINF : 0.))
        return ans;

        apb = a + b;
        if (apb > 1.) {
        // L40:
        u = a + b - 1.;
        z = (gam1(u) + 1.) / apb;
        } else {
        z = gam1(apb) + 1.;
        }
        // L50:
        c = give_log
        ? log1p(gam1(a)) + log1p(gam1(b)) - log(z)
        : (gam1(a) + 1.) * (gam1(b) + 1.) / z;
        return give_log
        ? ans + log(a0) + c - log1p(a0 / b0)
        : ans * (a0 * c) / (a0 / b0 + 1.);
    }
    // else:               algorithm for    a0 < 1 < b0 < 8
    // L60:
    u = gamln1(a0);
    int i, n = (int)(b0 - 1.);
    if (n >= 1) {
        c = 1.;
        for (i = 1; i <= n; ++i) {
        b0 += -1.;
        c *= b0 / (a0 + b0);
        /* L61: */
        }
        u += log(c); // TODO?: log(c) = log( prod(...) ) =  sum( log(...) )
    }
    // L70:
    z -= u;
    b0 += -1.;
    apb = a0 + b0;
    if (apb > 1.) {
        // L71:
        t = (gam1(apb - 1.) + 1.) / apb;
    } else {
        t = gam1(apb) + 1.;
    }
    // L72:
    return give_log
        ? log(a0)+ esum(mu, z, 1) + log1p(gam1(b0)) - log(t) // TODO? log(t) = log1p(..)
        :     a0 * esum(mu, z, 0) * (gam1(b0) + 1.) / t;

    } else {

/* ----------------------------------------------------------------------- */
/*              PROCEDURE FOR A >= 8 AND B >= 8 */
/* ----------------------------------------------------------------------- */
    // L100:
    double h, x0, y0, lambda;
    if (a > b) {
        // L101:
        h = b / a;
        x0 = 1. / (h + 1.);// => lx0 := log(x0) = 0 - log1p(h)
        y0 = h / (h + 1.);
        lambda = (a + b) * y - b;
    } else {
        h = a / b;
        x0 = h / (h + 1.);  // => lx0 := log(x0) = - log1p(1/h)
        y0 = 1. / (h + 1.);
        lambda = a - (a + b) * x;
    }
    double lx0 = -log1p(b/a); // in both cases

    // L110:
    double e = -lambda / a;
    if (fabs(e) > 0.6) {
        // L111:
        u = e - log(x / x0);
    } else {
        u = rlog1(e);
    }

    // L120:
    e = lambda / b;
    if (fabs(e) > 0.6) {
        // L121:
        v = e - log(y / y0);
    } else {
        v = rlog1(e);
    }

    // L130:
    z = esum(mu, -(a * u + b * v), give_log);
    return give_log
        ? log(const__)+ (log(b) + lx0)/2. + z      - bcorr(a, b)
        :     const__ * sqrt(b * x0)      * z * exp(-bcorr(a, b));
    }

}

// Assembly:
pushq %rbp
pushq %rbx
subq $0x88, %rsp
movl %esi, %ebx
movl %edi, %ebp
movapd %xmm0, %xmm5
cmplesd %xmm1, %xmm5
movapd %xmm5, %xmm4
andpd %xmm0, %xmm4
andnpd %xmm1, %xmm5
orpd %xmm4, %xmm5
movsd 0x8115(%rip), %xmm4     # 0x1f8b0
ucomisd %xmm5, %xmm4
movapd %xmm1, 0x10(%rsp)
movapd %xmm0, 0x40(%rsp)
jbe 0x177e3
movsd 0x811b(%rip), %xmm0     # 0x1f8d0
ucomisd %xmm2, %xmm0
movapd %xmm5, 0x30(%rsp)
jae 0x1783a
ucomisd 0x8107(%rip), %xmm3     # 0x1f8d0
movapd %xmm3, 0x20(%rsp)
jbe 0x17a27
movapd %xmm2, %xmm0
callq 0x2240
jmp 0x17a38
ucomisd %xmm1, %xmm0
movapd %xmm0, %xmm6
addsd %xmm1, %xmm6
movapd %xmm3, 0x20(%rsp)
movapd %xmm2, 0x50(%rsp)
jbe 0x17866
movapd %xmm1, %xmm5
divsd %xmm0, %xmm5
movsd 0x6e0b(%rip), %xmm4     # 0x1e618
movapd %xmm5, %xmm2
addsd %xmm4, %xmm2
divsd %xmm2, %xmm4
movapd %xmm5, %xmm7
divsd %xmm2, %xmm7
movapd %xmm7, 0x70(%rsp)
mulsd %xmm3, %xmm6
subsd %xmm1, %xmm6
movapd %xmm6, (%rsp)
unpcklpd %xmm4, %xmm5            # xmm5 = xmm5[0],xmm4[0]
jmp 0x178a9
movapd %xmm2, %xmm0
movapd %xmm2, 0x50(%rsp)
callq 0x2240
movsd %xmm0, (%rsp)
movapd 0x50(%rsp), %xmm0
xorpd 0x8474(%rip), %xmm0     # 0x1fcd0
callq 0x17ecb
jmp 0x17a48
movapd %xmm0, %xmm3
divsd %xmm1, %xmm3
movsd 0x6da2(%rip), %xmm4     # 0x1e618
movapd %xmm1, %xmm5
unpcklpd %xmm3, %xmm5            # xmm5 = xmm5[0],xmm3[0]
addsd %xmm4, %xmm3
divsd %xmm3, %xmm4
movapd %xmm4, 0x70(%rsp)
mulsd %xmm2, %xmm6
movapd %xmm0, %xmm1
subsd %xmm6, %xmm1
movapd %xmm0, %xmm2
unpcklpd %xmm3, %xmm2            # xmm2 = xmm2[0],xmm3[0]
divpd %xmm2, %xmm5
movapd %xmm1, (%rsp)
movapd %xmm5, 0x30(%rsp)
movapd %xmm5, %xmm0
callq 0x2220
movapd 0x30(%rsp), %xmm1
movsd %xmm0, 0x68(%rsp)
movapd 0x8404(%rip), %xmm2     # 0x1fcd0
xorpd (%rsp), %xmm2
divsd 0x40(%rsp), %xmm2
movapd 0x83e1(%rip), %xmm0     # 0x1fcc0
andpd %xmm2, %xmm0
ucomisd 0x7fcd(%rip), %xmm0     # 0x1f8b8
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
movapd %xmm1, 0x30(%rsp)
jbe 0x17918
movapd 0x50(%rsp), %xmm0
divsd %xmm1, %xmm0
movapd %xmm2, 0x50(%rsp)
callq 0x2240
movapd 0x50(%rsp), %xmm1
subsd %xmm0, %xmm1
jmp 0x17925
movapd %xmm2, %xmm0
callq 0x18895
movapd %xmm0, %xmm1
movapd %xmm1, 0x50(%rsp)
movapd (%rsp), %xmm1
divsd 0x10(%rsp), %xmm1
movapd 0x8382(%rip), %xmm0     # 0x1fcc0
andpd %xmm1, %xmm0
ucomisd 0x7f6e(%rip), %xmm0     # 0x1f8b8
movapd 0x20(%rsp), %xmm0
jbe 0x1796d
divsd 0x70(%rsp), %xmm0
movapd %xmm1, (%rsp)
callq 0x2240
movapd (%rsp), %xmm1
subsd %xmm0, %xmm1
jmp 0x1797a
movapd %xmm1, %xmm0
callq 0x18895
movapd %xmm0, %xmm1
mulsd 0x10(%rsp), %xmm1
movapd 0x50(%rsp), %xmm0
mulsd 0x40(%rsp), %xmm0
addsd %xmm1, %xmm0
xorpd 0x8338(%rip), %xmm0     # 0x1fcd0
movl %ebp, %edi
movl %ebx, %esi
callq 0x183a0
movapd %xmm0, %xmm3
testl %ebx, %ebx
je 0x179fc
movapd 0x10(%rsp), %xmm0
movsd %xmm3, (%rsp)
callq 0x2240
subsd 0x68(%rsp), %xmm0
mulsd 0x6819(%rip), %xmm0     # 0x1e1e0
addsd 0x8191(%rip), %xmm0     # 0x1fb60
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movapd 0x40(%rsp), %xmm0
movapd 0x10(%rsp), %xmm1
callq 0x189ba
movsd (%rsp), %xmm2
subsd %xmm0, %xmm2
jmp 0x17bf3
movapd 0x30(%rsp), %xmm0
movapd 0x10(%rsp), %xmm2
mulsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x17ba8
movapd %xmm2, %xmm1
sqrtsd %xmm0, %xmm0
jmp 0x17bbd
movapd 0x82a1(%rip), %xmm0     # 0x1fcd0
xorpd %xmm3, %xmm0
callq 0x17ecb
movsd %xmm0, (%rsp)
movapd 0x20(%rsp), %xmm0
callq 0x2240
movapd 0x10(%rsp), %xmm1
mulsd %xmm1, %xmm0
movapd 0x40(%rsp), %xmm3
movsd (%rsp), %xmm4
mulsd %xmm3, %xmm4
addsd %xmm0, %xmm4
movapd 0x30(%rsp), %xmm0
ucomisd 0x6ba5(%rip), %xmm0     # 0x1e618
jae 0x17b1f
movapd %xmm1, %xmm5
cmplesd %xmm3, %xmm5
movapd %xmm5, %xmm2
andpd %xmm3, %xmm2
andnpd %xmm1, %xmm5
orpd %xmm2, %xmm5
ucomisd 0x7e16(%rip), %xmm5     # 0x1f8b0
movapd %xmm5, 0x20(%rsp)
jae 0x17b4c
movsd 0x6b6a(%rip), %xmm1     # 0x1e618
ucomisd %xmm5, %xmm1
jae 0x17c01
movsd %xmm4, (%rsp)
callq 0x1842e
movsd %xmm0, 0x10(%rsp)
movsd 0x7ce0(%rip), %xmm0     # 0x1f7b0
movapd 0x20(%rsp), %xmm4
addsd %xmm4, %xmm0
cvttsd2si %xmm0, %eax
testl %eax, %eax
jle 0x17cc1
movsd 0x7cc2(%rip), %xmm5     # 0x1f7b0
movapd 0x30(%rsp), %xmm3
movsd 0x6b1c(%rip), %xmm0     # 0x1e618
subl $0x1, %eax
jb 0x17c98
addsd %xmm5, %xmm4
movapd %xmm3, %xmm1
addsd %xmm4, %xmm1
movapd %xmm4, %xmm2
divsd %xmm1, %xmm2
mulsd %xmm2, %xmm0
jmp 0x17afc
movapd %xmm3, %xmm0
movsd %xmm4, (%rsp)
callq 0x17f4b
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movl %ebp, %edi
movapd %xmm1, %xmm0
movl %ebx, %esi
addq $0x88, %rsp
popq %rbx
popq %rbp
jmp 0x183a0
movsd %xmm4, (%rsp)
callq 0x1842e
movsd %xmm0, 0x10(%rsp)
movapd 0x30(%rsp), %xmm0
movaps 0x20(%rsp), %xmm1
callq 0x18517
movapd %xmm0, %xmm1
addsd 0x10(%rsp), %xmm1
testl %ebx, %ebx
je 0x17c77
movapd 0x30(%rsp), %xmm0
movsd %xmm1, 0x10(%rsp)
callq 0x2240
movsd (%rsp), %xmm1
subsd 0x10(%rsp), %xmm1
cvtsi2sd %ebp, %xmm2
addsd %xmm1, %xmm2
addsd %xmm0, %xmm2
jmp 0x17bf3
movsd %xmm3, (%rsp)
callq 0x24f0
movsd (%rsp), %xmm3
movapd 0x10(%rsp), %xmm1
movapd 0x40(%rsp), %xmm2
mulsd 0x7cfd(%rip), %xmm0     # 0x1f8c8
mulsd %xmm0, %xmm3
movsd %xmm3, (%rsp)
movapd %xmm2, %xmm0
callq 0x189ba
xorpd 0x80eb(%rip), %xmm0     # 0x1fcd0
callq 0x2550
movapd %xmm0, %xmm2
mulsd (%rsp), %xmm2
movapd %xmm2, %xmm0
addq $0x88, %rsp
popq %rbx
popq %rbp
retq
movl %ebp, %edi
movapd %xmm4, %xmm0
movl %ebx, %esi
callq 0x183a0
movapd %xmm0, %xmm2
xorpd %xmm0, %xmm0
testl %ebx, %ebx
je 0x17c22
movsd 0x7b56(%rip), %xmm0     # 0x1f778
ucomisd %xmm0, %xmm2
movapd 0x10(%rsp), %xmm0
movapd 0x40(%rsp), %xmm1
jne 0x17c36
jnp 0x17bf3
movsd %xmm2, (%rsp)
addsd %xmm0, %xmm1
ucomisd 0x69d1(%rip), %xmm1     # 0x1e618
jbe 0x17dc1
movsd 0x7b5b(%rip), %xmm0     # 0x1f7b0
addsd %xmm1, %xmm0
movapd %xmm1, 0x50(%rsp)
callq 0x186ed
addsd 0x69ac(%rip), %xmm0     # 0x1e618
divsd 0x50(%rsp), %xmm0
jmp 0x17dd2
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0
movl %ebp, %edi
xorl %esi, %esi
callq 0x183a0
movapd 0x30(%rsp), %xmm2
mulsd %xmm0, %xmm2
jmp 0x17bf3
movapd %xmm4, 0x20(%rsp)
callq 0x2240
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movapd 0x20(%rsp), %xmm0
addsd 0x7aef(%rip), %xmm0     # 0x1f7b0
movapd 0x30(%rsp), %xmm1
movsd %xmm0, 0x40(%rsp)
addsd %xmm0, %xmm1
ucomisd 0x693f(%rip), %xmm1     # 0x1e618
jbe 0x17d02
movsd 0x7acd(%rip), %xmm0     # 0x1f7b0
addsd %xmm1, %xmm0
movapd %xmm1, 0x20(%rsp)
callq 0x186ed
addsd 0x691e(%rip), %xmm0     # 0x1e618
divsd 0x20(%rsp), %xmm0
jmp 0x17d13
movapd %xmm1, %xmm0
callq 0x186ed
addsd 0x6905(%rip), %xmm0     # 0x1e618
movsd %xmm0, 0x20(%rsp)
movsd (%rsp), %xmm2
subsd 0x10(%rsp), %xmm2
testl %ebx, %ebx
movapd 0x30(%rsp), %xmm1
je 0x17d7c
movapd %xmm1, %xmm0
movsd %xmm2, (%rsp)
callq 0x2240
cvtsi2sd %ebp, %xmm1
movsd (%rsp), %xmm2
addsd %xmm1, %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, (%rsp)
movsd 0x40(%rsp), %xmm0
callq 0x186ed
callq 0x2220
addsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
movsd 0x20(%rsp), %xmm0
callq 0x2240
jmp 0x179ee
movl %ebp, %edi
movapd %xmm2, %xmm0
xorl %esi, %esi
callq 0x183a0
movapd 0x30(%rsp), %xmm1
mulsd %xmm0, %xmm1
movapd %xmm1, 0x30(%rsp)
movsd 0x40(%rsp), %xmm0
callq 0x186ed
movapd %xmm0, %xmm2
addsd 0x6868(%rip), %xmm2     # 0x1e618
mulsd 0x30(%rsp), %xmm2
divsd 0x20(%rsp), %xmm2
jmp 0x17bf3
movapd %xmm1, %xmm0
callq 0x186ed
addsd 0x6846(%rip), %xmm0     # 0x1e618
movapd %xmm0, 0x50(%rsp)
movaps 0x40(%rsp), %xmm0
callq 0x186ed
movsd %xmm0, 0x40(%rsp)
movapd 0x10(%rsp), %xmm0
callq 0x186ed
movapd %xmm0, %xmm3
testl %ebx, %ebx
je 0x17e79
movsd 0x40(%rsp), %xmm0
movapd %xmm3, 0x40(%rsp)
callq 0x2220
movsd %xmm0, 0x10(%rsp)
movapd 0x40(%rsp), %xmm0
callq 0x2220
addsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movapd 0x50(%rsp), %xmm0
callq 0x2240
movsd 0x10(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movapd 0x30(%rsp), %xmm0
callq 0x2240
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
addsd 0x10(%rsp), %xmm1
movsd %xmm1, (%rsp)
movapd 0x30(%rsp), %xmm0
divsd 0x20(%rsp), %xmm0
callq 0x2220
jmp 0x179ee
movsd 0x6797(%rip), %xmm1     # 0x1e618
movsd 0x40(%rsp), %xmm0
addsd %xmm1, %xmm0
addsd %xmm1, %xmm3
mulsd %xmm0, %xmm3
movapd 0x30(%rsp), %xmm0
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
movapd 0x50(%rsp), %xmm2
unpcklpd 0x20(%rsp), %xmm2       # xmm2 = xmm2[0],mem[0]
divpd %xmm2, %xmm3
mulsd %xmm3, %xmm0
movsd (%rsp), %xmm2
mulsd %xmm0, %xmm2
unpckhpd %xmm3, %xmm3            # xmm3 = xmm3[1,1]
addsd %xmm1, %xmm3
divsd %xmm3, %xmm2
jmp 0x17bf3