// File: /workspace/github_c_makefile_star2_O3/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 $0x98, %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 0x7a4f(%rip), %xmm4     # 0x23b78
ucomisd %xmm5, %xmm4
movapd %xmm1, 0x10(%rsp)
movapd %xmm0, 0x40(%rsp)
jbe 0x1c171
movsd 0x78ad(%rip), %xmm0     # 0x239f0
ucomisd %xmm2, %xmm0
movapd %xmm5, 0x20(%rsp)
jae 0x1c1c8
ucomisd 0x7899(%rip), %xmm3     # 0x239f0
movapd %xmm3, 0x30(%rsp)
jbe 0x1c3ba
movapd %xmm2, %xmm0
callq 0x2240
jmp 0x1c3cb
ucomisd %xmm1, %xmm0
movapd %xmm0, %xmm6
addsd %xmm1, %xmm6
movapd %xmm3, 0x30(%rsp)
movapd %xmm2, 0x50(%rsp)
jbe 0x1c1f4
movapd %xmm1, %xmm5
divsd %xmm0, %xmm5
movsd 0x64c5(%rip), %xmm4     # 0x22660
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 0x1c237
movapd %xmm2, %xmm0
movapd %xmm2, 0x50(%rsp)
callq 0x2240
movsd %xmm0, (%rsp)
movapd 0x50(%rsp), %xmm0
xorpd 0x7c06(%rip), %xmm0     # 0x23df0
callq 0x1c860
jmp 0x1c3db
movapd %xmm0, %xmm3
divsd %xmm1, %xmm3
movsd 0x645c(%rip), %xmm4     # 0x22660
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, 0x80(%rsp)
movapd %xmm5, %xmm0
callq 0x2220
movsd %xmm0, 0x68(%rsp)
movapd 0x7b99(%rip), %xmm0     # 0x23df0
xorpd (%rsp), %xmm0
divsd 0x40(%rsp), %xmm0
movapd 0x7b76(%rip), %xmm1     # 0x23de0
andpd %xmm0, %xmm1
ucomisd 0x791a(%rip), %xmm1     # 0x23b90
jbe 0x1c2ac
movapd %xmm0, 0x20(%rsp)
movapd 0x80(%rsp), %xmm1
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
movapd 0x50(%rsp), %xmm0
divsd %xmm1, %xmm0
callq 0x2240
movapd 0x20(%rsp), %xmm1
subsd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
jmp 0x1c2b7
callq 0x1d23b
movapd %xmm0, 0x20(%rsp)
movapd (%rsp), %xmm1
divsd 0x10(%rsp), %xmm1
movapd 0x7b16(%rip), %xmm0     # 0x23de0
andpd %xmm1, %xmm0
ucomisd 0x78ba(%rip), %xmm0     # 0x23b90
movapd 0x30(%rsp), %xmm0
jbe 0x1c2f9
divsd 0x70(%rsp), %xmm0
movapd %xmm1, (%rsp)
callq 0x2240
movapd (%rsp), %xmm1
subsd %xmm0, %xmm1
jmp 0x1c306
movapd %xmm1, %xmm0
callq 0x1d23b
movapd %xmm0, %xmm1
mulsd 0x10(%rsp), %xmm1
movapd 0x20(%rsp), %xmm0
mulsd 0x40(%rsp), %xmm0
addsd %xmm1, %xmm0
xorpd 0x7acc(%rip), %xmm0     # 0x23df0
movl %ebp, %edi
movl %ebx, %esi
callq 0x1cd40
movapd %xmm0, %xmm3
testl %ebx, %ebx
je 0x1c388
movapd 0x10(%rsp), %xmm0
movsd %xmm3, (%rsp)
callq 0x2240
subsd 0x68(%rsp), %xmm0
mulsd 0x5ec5(%rip), %xmm0     # 0x22218
addsd 0x7925(%rip), %xmm0     # 0x23c80
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movapd 0x40(%rsp), %xmm0
movapd 0x10(%rsp), %xmm1
callq 0x1d360
movsd (%rsp), %xmm2
subsd %xmm0, %xmm2
jmp 0x1c5ef
movapd 0x80(%rsp), %xmm0
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
movapd 0x10(%rsp), %xmm2
mulsd %xmm2, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1c5a4
movapd %xmm2, %xmm1
sqrtsd %xmm0, %xmm0
jmp 0x1c5b9
movapd 0x7a2e(%rip), %xmm0     # 0x23df0
xorpd %xmm3, %xmm0
callq 0x1c860
movsd %xmm0, (%rsp)
movapd 0x30(%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 0x20(%rsp), %xmm0
ucomisd 0x625a(%rip), %xmm0     # 0x22660
jae 0x1c518
movapd %xmm1, %xmm5
cmplesd %xmm3, %xmm5
movapd %xmm5, %xmm2
andpd %xmm3, %xmm2
andnpd %xmm1, %xmm5
orpd %xmm2, %xmm5
ucomisd 0x774b(%rip), %xmm5     # 0x23b78
movapd %xmm5, 0x30(%rsp)
jae 0x1c545
movsd 0x621f(%rip), %xmm1     # 0x22660
ucomisd %xmm5, %xmm1
jae 0x1c5fd
movsd %xmm4, (%rsp)
callq 0x1cdd4
movsd %xmm0, 0x10(%rsp)
movsd 0x7505(%rip), %xmm0     # 0x23968
movapd 0x30(%rsp), %xmm4
addsd %xmm4, %xmm0
cvttsd2si %xmm0, %eax
testl %eax, %eax
jle 0x1c4d0
movsd 0x74eb(%rip), %xmm5     # 0x23968
movapd 0x20(%rsp), %xmm3
movsd 0x61d5(%rip), %xmm0     # 0x22660
addsd %xmm5, %xmm4
movapd %xmm3, %xmm1
addsd %xmm4, %xmm1
movapd %xmm4, %xmm2
divsd %xmm1, %xmm2
mulsd %xmm2, %xmm0
decl %eax
jne 0x1c48b
movapd %xmm4, 0x30(%rsp)
callq 0x2240
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movapd 0x30(%rsp), %xmm0
addsd 0x7498(%rip), %xmm0     # 0x23968
movapd 0x20(%rsp), %xmm1
movsd %xmm0, 0x40(%rsp)
addsd %xmm0, %xmm1
ucomisd 0x6178(%rip), %xmm1     # 0x22660
jbe 0x1c694
movsd 0x7472(%rip), %xmm0     # 0x23968
addsd %xmm1, %xmm0
movapd %xmm1, 0x30(%rsp)
callq 0x1d093
addsd 0x6153(%rip), %xmm0     # 0x22660
divsd 0x30(%rsp), %xmm0
jmp 0x1c6a5
movapd %xmm3, %xmm0
movsd %xmm4, (%rsp)
callq 0x1c8e0
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movl %ebp, %edi
movapd %xmm1, %xmm0
movl %ebx, %esi
addq $0x98, %rsp
popq %rbx
popq %rbp
jmp 0x1cd40
movsd %xmm4, (%rsp)
callq 0x1cdd4
movsd %xmm0, 0x10(%rsp)
movapd 0x20(%rsp), %xmm0
movaps 0x30(%rsp), %xmm1
callq 0x1cebd
movapd %xmm0, %xmm1
addsd 0x10(%rsp), %xmm1
testl %ebx, %ebx
je 0x1c673
movapd 0x20(%rsp), %xmm0
movsd %xmm1, 0x10(%rsp)
callq 0x2240
movsd (%rsp), %xmm1
subsd 0x10(%rsp), %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %ebp, %xmm2
addsd %xmm1, %xmm2
addsd %xmm0, %xmm2
jmp 0x1c5ef
movsd %xmm3, (%rsp)
callq 0x24f0
movsd (%rsp), %xmm3
movapd 0x10(%rsp), %xmm1
movapd 0x40(%rsp), %xmm2
mulsd 0x75d9(%rip), %xmm0     # 0x23ba0
mulsd %xmm0, %xmm3
movsd %xmm3, (%rsp)
movapd %xmm2, %xmm0
callq 0x1d360
xorpd 0x780f(%rip), %xmm0     # 0x23df0
callq 0x2550
movapd %xmm0, %xmm2
mulsd (%rsp), %xmm2
movapd %xmm2, %xmm0
addq $0x98, %rsp
popq %rbx
popq %rbp
retq
movl %ebp, %edi
movapd %xmm4, %xmm0
movl %ebx, %esi
callq 0x1cd40
movapd %xmm0, %xmm2
xorpd %xmm0, %xmm0
testl %ebx, %ebx
je 0x1c61e
movsd 0x7292(%rip), %xmm0     # 0x238b0
ucomisd %xmm0, %xmm2
movapd 0x10(%rsp), %xmm0
movapd 0x40(%rsp), %xmm1
jne 0x1c632
jnp 0x1c5ef
movsd %xmm2, (%rsp)
addsd %xmm0, %xmm1
ucomisd 0x601d(%rip), %xmm1     # 0x22660
jbe 0x1c756
movsd 0x7317(%rip), %xmm0     # 0x23968
addsd %xmm1, %xmm0
movapd %xmm1, 0x50(%rsp)
callq 0x1d093
addsd 0x5ff8(%rip), %xmm0     # 0x22660
divsd 0x50(%rsp), %xmm0
jmp 0x1c767
movsd (%rsp), %xmm0
subsd %xmm1, %xmm0
movl %ebp, %edi
xorl %esi, %esi
callq 0x1cd40
movapd 0x20(%rsp), %xmm2
mulsd %xmm0, %xmm2
jmp 0x1c5ef
movapd %xmm1, %xmm0
callq 0x1d093
addsd 0x5fbb(%rip), %xmm0     # 0x22660
movsd %xmm0, 0x30(%rsp)
movsd (%rsp), %xmm2
subsd 0x10(%rsp), %xmm2
testl %ebx, %ebx
movapd 0x20(%rsp), %xmm1
je 0x1c711
movapd %xmm1, %xmm0
movsd %xmm2, (%rsp)
callq 0x2240
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
movsd (%rsp), %xmm2
addsd %xmm1, %xmm2
addsd %xmm0, %xmm2
movsd %xmm2, (%rsp)
movsd 0x40(%rsp), %xmm0
callq 0x1d093
callq 0x2220
addsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
movsd 0x30(%rsp), %xmm0
callq 0x2240
jmp 0x1c37a
movl %ebp, %edi
movapd %xmm2, %xmm0
xorl %esi, %esi
callq 0x1cd40
movapd 0x20(%rsp), %xmm1
mulsd %xmm0, %xmm1
movapd %xmm1, 0x20(%rsp)
movsd 0x40(%rsp), %xmm0
callq 0x1d093
movapd %xmm0, %xmm2
addsd 0x5f1b(%rip), %xmm2     # 0x22660
mulsd 0x20(%rsp), %xmm2
divsd 0x30(%rsp), %xmm2
jmp 0x1c5ef
movapd %xmm1, %xmm0
callq 0x1d093
addsd 0x5ef9(%rip), %xmm0     # 0x22660
movapd %xmm0, 0x50(%rsp)
movaps 0x40(%rsp), %xmm0
callq 0x1d093
movsd %xmm0, 0x40(%rsp)
movapd 0x10(%rsp), %xmm0
callq 0x1d093
movapd %xmm0, %xmm3
testl %ebx, %ebx
je 0x1c80e
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 0x20(%rsp), %xmm0
callq 0x2240
movsd (%rsp), %xmm1
addsd %xmm0, %xmm1
addsd 0x10(%rsp), %xmm1
movsd %xmm1, (%rsp)
movapd 0x20(%rsp), %xmm0
divsd 0x30(%rsp), %xmm0
callq 0x2220
jmp 0x1c37a
movsd 0x5e4a(%rip), %xmm1     # 0x22660
movsd 0x40(%rsp), %xmm0
addsd %xmm1, %xmm0
addsd %xmm1, %xmm3
mulsd %xmm0, %xmm3
movapd 0x20(%rsp), %xmm0
unpcklpd %xmm0, %xmm3            # xmm3 = xmm3[0],xmm0[0]
movapd 0x50(%rsp), %xmm2
unpcklpd 0x30(%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 0x1c5ef