// File: /workspace/github_c_makefile_star2_O3/c-zhou[P]yahs/binomlite.c
// Function: basym
static double basym(double a, double b, double lambda, double eps, int log_p)
{
/* ----------------------------------------------------------------------- */
/*     ASYMPTOTIC EXPANSION FOR I_x(A,B) FOR LARGE A AND B. */
/*     LAMBDA = (A + B)*Y - B  AND EPS IS THE TOLERANCE USED. */
/*     IT IS ASSUMED THAT LAMBDA IS NONNEGATIVE AND THAT */
/*     A AND B ARE GREATER THAN OR EQUAL TO 15. */
/* ----------------------------------------------------------------------- */


/* ------------------------ */
/*     ****** NUM IS THE MAXIMUM VALUE THAT N CAN TAKE IN THE DO LOOP */
/*            ENDING AT STATEMENT 50. IT IS REQUIRED THAT NUM BE EVEN. */
#define num_IT 20
/*            THE ARRAYS A0, B0, C, D HAVE DIMENSION NUM + 1. */

    static double const e0 = 1.12837916709551;/* e0 == 2/sqrt(pi) */
    static double const e1 = .353553390593274;/* e1 == 2^(-3/2)   */
    static double const ln_e0 = 0.120782237635245; /* == ln(e0) */

    double a0[num_IT + 1], b0[num_IT + 1], c[num_IT + 1], d[num_IT + 1];

    double f = a * rlog1(-lambda/a) + b * rlog1(lambda/b), t;
    if(log_p)
    t = -f;
    else {
    t = exp(-f);
    if (t == 0.) {
        return 0; /* once underflow, always underflow .. */
    }
    }
    double z0 = sqrt(f),
    z = z0 / e1 * 0.5,
    z2 = f + f,
    h, r0, r1, w0;

    if (a < b) {
    h = a / b;
    r0 = 1. / (h + 1.);
    r1 = (b - a) / b;
    w0 = 1. / sqrt(a * (h + 1.));
    } else {
    h = b / a;
    r0 = 1. / (h + 1.);
    r1 = (b - a) / a;
    w0 = 1. / sqrt(b * (h + 1.));
    }

    a0[0] = r1 * .66666666666666663;
    c[0] = a0[0] * -0.5;
    d[0] = -c[0];
    double j0 = 0.5 / e0 * erfc1(1, z0),
    j1 = e1,
    sum = j0 + d[0] * w0 * j1;

    double s = 1.,
    h2 = h * h,
    hn = 1.,
    w = w0,
    znm1 = z,
    zn = z2;
    int n;
    for (n = 2; n <= num_IT; n += 2) {
    hn *= h2;
    a0[n - 1] = r0 * 2. * (h * hn + 1.) / (n + 2.);
    int np1 = n + 1;
    s += hn;
    a0[np1 - 1] = r1 * 2. * s / (n + 3.);
    
    int i, j, m;
    for (i = n; i <= np1; ++i) {
        double r = (i + 1.) * -0.5;
        b0[0] = r * a0[0];
        for (m = 2; m <= i; ++m) {
        double bsum = 0.;
        for (j = 1; j <= m-1; ++j) {
            int mmj = m - j;
            bsum += (j * r - mmj) * a0[j - 1] * b0[mmj - 1];
        }
        b0[m - 1] = r * a0[m - 1] + bsum / m;
        }
        c[i - 1] = b0[i - 1] / (i + 1.);

        double dsum = 0.;
        for (j = 1; j <= i-1; ++j) {
        dsum += d[i - j - 1] * c[j - 1];
        }
        d[i - 1] = -(dsum + c[i - 1]);
    }

    j0 = e1 * znm1 + (n - 1.) * j0;
    j1 = e1 * zn + n * j1;
    znm1 = z2 * znm1;
    zn = z2 * zn;
    w *= w0;
    double t0 = d[n - 1] * w * j0;
    w *= w0;
    double t1 = d[np1 - 1] * w * j1;
    sum += t0 + t1;
    if (fabs(t0) + fabs(t1) <= eps * sum) {
        break;
    }
    }

    if(log_p)
    return ln_e0 + t - bcorr(a, b) + log(sum);
    else {
    double u = exp(-bcorr(a, b));
    return e0 * t * u * sum;
    }

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x358, %rsp            # imm = 0x358
movl %edi, %ebx
movapd %xmm2, 0x10(%rsp)
movsd %xmm1, 0x8(%rsp)
movapd %xmm0, %xmm1
movsd %xmm0, 0x30(%rsp)
movapd %xmm2, %xmm0
xorpd 0x9d39(%rip), %xmm0     # 0x23df0
divsd %xmm1, %xmm0
callq 0x1d23b
movapd %xmm0, 0x20(%rsp)
movapd 0x10(%rsp), %xmm0
divsd 0x8(%rsp), %xmm0
callq 0x1d23b
movapd 0x20(%rsp), %xmm1
mulsd 0x8(%rsp), %xmm0
mulsd 0x30(%rsp), %xmm1
addsd %xmm0, %xmm1
movapd 0x9cfb(%rip), %xmm0     # 0x23df0
xorpd %xmm1, %xmm0
testl %ebx, %ebx
je 0x1a5da
xorpd %xmm6, %xmm6
ucomisd %xmm6, %xmm1
movapd %xmm0, 0x40(%rsp)
jb 0x1a117
sqrtsd %xmm1, %xmm5
jmp 0x1a134
movapd %xmm1, %xmm0
movapd %xmm1, 0x20(%rsp)
callq 0x24f0
xorpd %xmm6, %xmm6
movapd 0x20(%rsp), %xmm1
movapd %xmm0, %xmm5
movapd %xmm5, %xmm0
divsd 0x9a08(%rip), %xmm0     # 0x23b48
mulsd 0x80d0(%rip), %xmm0     # 0x22218
movapd %xmm0, 0x90(%rsp)
addsd %xmm1, %xmm1
movapd %xmm1, 0x20(%rsp)
movsd 0x8(%rsp), %xmm2
movapd %xmm2, %xmm7
movsd 0x30(%rsp), %xmm3
subsd %xmm3, %xmm7
movapd %xmm2, %xmm0
divsd %xmm3, %xmm0
movapd %xmm3, %xmm1
divsd %xmm2, %xmm1
movapd %xmm3, %xmm4
cmpltsd %xmm2, %xmm4
andpd %xmm4, %xmm1
andnpd %xmm0, %xmm4
orpd %xmm1, %xmm4
movapd %xmm2, %xmm1
maxsd %xmm3, %xmm1
movapd %xmm3, %xmm0
movapd %xmm4, 0x70(%rsp)
addsd 0x84b2(%rip), %xmm4     # 0x22660
minsd %xmm2, %xmm0
mulsd %xmm4, %xmm0
ucomisd %xmm6, %xmm0
movl %ebx, 0x3c(%rsp)
jb 0x1a1c6
sqrtsd %xmm0, %xmm0
jmp 0x1a201
movsd %xmm5, 0x10(%rsp)
movapd %xmm7, 0x50(%rsp)
movapd %xmm1, 0x60(%rsp)
movapd %xmm4, 0x80(%rsp)
callq 0x24f0
movapd 0x80(%rsp), %xmm4
movapd 0x60(%rsp), %xmm1
movapd 0x50(%rsp), %xmm7
movsd 0x10(%rsp), %xmm5
movapd 0x9c67(%rip), %xmm2     # 0x23e70
unpcklpd %xmm7, %xmm2            # xmm2 = xmm2[0],xmm7[0]
unpcklpd %xmm1, %xmm4            # xmm4 = xmm4[0],xmm1[0]
divpd %xmm4, %xmm2
movapd %xmm2, 0x50(%rsp)
movsd 0x843d(%rip), %xmm1     # 0x22660
divsd %xmm0, %xmm1
movsd %xmm1, 0x60(%rsp)
unpckhpd %xmm2, %xmm2            # xmm2 = xmm2[1,1]
mulsd 0x9917(%rip), %xmm2     # 0x23b50
movsd %xmm2, 0xa0(%rsp)
mulsd 0x966e(%rip), %xmm2     # 0x238b8
movapd %xmm2, 0x10(%rsp)
leaq 0x2b0(%rsp), %r14
movsd %xmm2, (%r14)
movapd 0x9b8b(%rip), %xmm0     # 0x23df0
xorpd %xmm2, %xmm0
movlpd %xmm0, 0x150(%rsp)
movapd %xmm5, %xmm0
callq 0x1d6ee
mulsd 0x98d5(%rip), %xmm0     # 0x23b58
movsd 0x60(%rsp), %xmm10
movapd 0x10(%rsp), %xmm1
mulsd %xmm10, %xmm1
mulsd 0x98ab(%rip), %xmm1     # 0x23b48
movapd %xmm1, %xmm2
movapd %xmm0, %xmm1
subsd %xmm2, %xmm1
movapd %xmm1, 0x10(%rsp)
movapd 0x70(%rsp), %xmm1
mulsd %xmm1, %xmm1
movapd 0x50(%rsp), %xmm2
addpd %xmm2, %xmm2
movapd %xmm2, 0x50(%rsp)
movapd 0x20(%rsp), %xmm6
movapd 0x90(%rsp), %xmm7
unpcklpd %xmm6, %xmm7            # xmm7 = xmm7[0],xmm6[0]
shufpd $0x2, 0x9b9b(%rip), %xmm0 # xmm0 = xmm0[0],mem[1]
unpcklpd %xmm6, %xmm6            # xmm6 = xmm6[0,0]
movl $0x3, %eax
movl $0x2, %esi
movl $0x4, %ecx
xorl %edx, %edx
movsd 0x95b6(%rip), %xmm3     # 0x238b8
movapd 0x9ae6(%rip), %xmm4     # 0x23df0
movsd 0x834d(%rip), %xmm9     # 0x22660
movapd %xmm9, %xmm8
movapd %xmm10, %xmm2
cmpq $0x14, %rsi
ja 0x1a587
mulsd %xmm1, %xmm9
movapd 0x70(%rsp), %xmm11
mulsd %xmm9, %xmm11
addsd 0x831f(%rip), %xmm11    # 0x22660
leaq 0x2(%rsi), %rdi
leaq -0x1(%rsi), %r8
movq %r8, 0x20(%rsp)
addsd %xmm9, %xmm8
leal 0x3(%rsi), %r9d
unpcklpd %xmm8, %xmm11           # xmm11 = xmm11[0],xmm8[0]
mulpd 0x50(%rsp), %xmm11
movd %r9d, %xmm12
movd %edi, %xmm13
punpcklqdq %xmm12, %xmm13  # xmm13 = xmm13[0],xmm12[0]
movdqa 0x9b16(%rip), %xmm5     # 0x23e90
por %xmm5, %xmm13
subpd %xmm5, %xmm13
divpd %xmm13, %xmm11
movupd %xmm11, 0x98(%rsp,%rsi,8)
movsd 0xa0(%rsp), %xmm11
movq %rdx, %r9
movq %rsi, %r11
movq %rax, %r10
leaq 0x1(%r11), %r15
movl %r15d, %ebx
xorps %xmm12, %xmm12
cvtsi2sd %rbx, %xmm12
movapd %xmm12, %xmm13
mulsd %xmm3, %xmm13
movapd %xmm13, %xmm14
mulsd %xmm11, %xmm14
movsd %xmm14, 0x200(%rsp)
movl $0x2, %r12d
movl $0x1, %r13d
xorpd %xmm14, %xmm14
xorl %ebx, %ebx
movq %r13, %rbp
leaq 0x1(%rbx), %r8
xorps %xmm15, %xmm15
cvtsi2sd %r8d, %xmm15
xorps %xmm5, %xmm5
cvtsi2sd %ebp, %xmm5
mulsd %xmm13, %xmm15
subsd %xmm5, %xmm15
mulsd 0xa0(%rsp,%rbx,8), %xmm15
mulsd 0x1f8(%rsp,%rbp,8), %xmm15
addsd %xmm15, %xmm14
movq %r8, %rbx
decq %rbp
jne 0x1a3ea
xorps %xmm5, %xmm5
cvtsi2sd %r12d, %xmm5
divsd %xmm5, %xmm14
movsd 0x98(%rsp,%r12,8), %xmm5
mulsd %xmm13, %xmm5
addsd %xmm14, %xmm5
movsd %xmm5, 0x1f8(%rsp,%r12,8)
incq %r12
incq %r13
cmpq %r10, %r12
jne 0x1a3e0
movsd 0x1f8(%rsp,%r11,8), %xmm13
divsd %xmm12, %xmm13
movsd %xmm13, 0x2a8(%rsp,%r11,8)
xorpd %xmm12, %xmm12
movq %r14, %rbx
movq %r9, %r12
movsd 0x150(%rsp,%r12,8), %xmm5
mulsd (%rbx), %xmm5
addsd %xmm5, %xmm12
addq $0x8, %rbx
addq $-0x1, %r12
jb 0x1a483
addsd %xmm12, %xmm13
xorpd %xmm4, %xmm13
movlpd %xmm13, 0x148(%rsp,%r11,8)
incq %r10
incq %r9
movq %r15, %r11
cmpq %rcx, %r15
jne 0x1a3a6
xorps %xmm5, %xmm5
cvtsi2sd %esi, %xmm5
xorps %xmm11, %xmm11
cvtsi2sdl 0x20(%rsp), %xmm11
unpcklpd %xmm5, %xmm11           # xmm11 = xmm11[0],xmm5[0]
mulpd %xmm11, %xmm0
movapd %xmm6, %xmm11
mulpd %xmm7, %xmm11
mulpd 0x99ac(%rip), %xmm7     # 0x23ea0
addpd %xmm7, %xmm0
movapd %xmm2, %xmm12
mulsd %xmm2, %xmm10
mulsd %xmm10, %xmm12
movupd 0x148(%rsp,%rsi,8), %xmm5
unpcklpd %xmm12, %xmm10          # xmm10 = xmm10[0],xmm12[0]
mulpd %xmm5, %xmm10
mulpd %xmm0, %xmm10
movapd %xmm10, %xmm5
unpckhpd %xmm10, %xmm5           # xmm5 = xmm5[1],xmm10[1]
addsd %xmm10, %xmm5
movapd 0x10(%rsp), %xmm13
addsd %xmm5, %xmm13
andpd 0x989d(%rip), %xmm10    # 0x23de0
pshufd $0xee, %xmm10, %xmm5    # xmm5 = xmm10[2,3,2,3]
addsd %xmm10, %xmm5
movapd %xmm13, 0x10(%rsp)
movapd %xmm13, %xmm10
mulsd 0x95fd(%rip), %xmm10    # 0x23b60
addq $0x2, %rax
addq $0x2, %rcx
addq $0x2, %rdx
ucomisd %xmm5, %xmm10
movq %rdi, %rsi
movapd %xmm12, %xmm10
movapd %xmm11, %xmm7
jb 0x1a31d
cmpl $0x0, 0x3c(%rsp)
je 0x1a5fc
movapd 0x40(%rsp), %xmm0
addsd 0x95cc(%rip), %xmm0     # 0x23b68
movapd %xmm0, 0x40(%rsp)
movsd 0x30(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x1d360
movapd 0x40(%rsp), %xmm1
subsd %xmm0, %xmm1
movapd %xmm1, 0x40(%rsp)
movapd 0x10(%rsp), %xmm0
callq 0x2240
movapd %xmm0, %xmm2
addsd 0x40(%rsp), %xmm2
jmp 0x1a636
movapd %xmm1, 0x20(%rsp)
callq 0x2550
xorpd %xmm2, %xmm2
ucomisd %xmm2, %xmm0
jne 0x1a5f1
jnp 0x1a636
movapd 0x20(%rsp), %xmm1
jmp 0x1a101
movsd 0x30(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x1d360
xorpd 0x97db(%rip), %xmm0     # 0x23df0
callq 0x2550
movapd 0x40(%rsp), %xmm1
mulsd 0x9548(%rip), %xmm1     # 0x23b70
mulsd %xmm0, %xmm1
movapd 0x10(%rsp), %xmm2
mulsd %xmm1, %xmm2
movapd %xmm2, %xmm0
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq