// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/probaln.c
// Function: probaln_glocal
int probaln_glocal(const uint8_t *ref, int l_ref, const uint8_t *query,
                   int l_query, const uint8_t *iqual, const probaln_par_t *c,
                   int *state, uint8_t *q)
{
    double *f = NULL, *b = NULL, *s = NULL, m[9], sI, sM, bI, bM;
    float *qual = NULL;
    int bw, bw2, i, k, is_backward = 1, Pr;

    if ( l_ref<0 || l_query<0 || l_query >= INT_MAX - 2) {
        errno = EINVAL;
        return INT_MIN;
    }
    if (l_ref==0 || l_query==0)
        return 0;  // Is this actually invalid??

    /*** initialization ***/
    is_backward = state && q? 1 : 0;
    bw = l_ref > l_query? l_ref : l_query;
    if (bw > c->bw) bw = c->bw;
    if (bw < abs(l_ref - l_query)) bw = abs(l_ref - l_query);
    bw2 = bw * 2 + 1;
    size_t i_dim = bw2 < l_ref ? (size_t) bw2*3+6 : (size_t) l_ref*3+6;

    // allocate the forward and backward matrices f[][] and b[][]
    // and the scaling array s[]
    // Ideally these callocs would be mallocs + initialisation of
    // the few bits needed.
    if (SIZE_MAX / (l_query+1) / i_dim < sizeof(double)) {
        errno = ENOMEM; // Allocation would fail
        return INT_MIN;
    }
    f = calloc((l_query+1)*i_dim, sizeof(double));
    if (!f) goto fail;
    if (is_backward) {
        b = calloc((l_query+1)*i_dim, sizeof(double));
        if (!b) goto fail;
    }

    // s[] is the scaling factor to avoid underflow
    s = malloc((l_query+2) * sizeof(double));
    if (!s) goto fail;

    // initialize qual
    qual = malloc(l_query * sizeof(float));
    if (!qual) goto fail;
    if (g_qual2prob[0] == 0)
        for (i = 0; i < 256; ++i)
            g_qual2prob[i] = pow(10, -i/10.);
    qual[0] = 0.0; // Should be unused
    for (i = 0; i < l_query; ++i)
        qual[i] = g_qual2prob[iqual? iqual[i] : 30];

    // initialize transition probability
    // the value here seems not to affect results; FIXME: need proof
    sM = sI = 1. / (2 * l_query + 2);
    m[0*3+0] = (1 - c->d - c->d) * (1 - sM);
    m[0*3+1] = m[0*3+2] = c->d * (1 - sM);
    m[1*3+0] = (1 - c->e) * (1 - sI);
    m[1*3+1] = c->e * (1 - sI);
    m[1*3+2] = 0.;
    m[2*3+0] = 1 - c->e;
    m[2*3+1] = 0.;
    m[2*3+2] = c->e;
    bM = (1 - c->d) / l_ref; // (bM+bI)*l_ref==1
    bI = c->d / l_ref;

    // f[] and b[] are 2-d arrays of three scores, with rows along the
    // query and columns across the band.  The first query base and
    // first band position appear at index 1 allowing edge conditions
    // to be stored in index 0.  Hence the loops below appear to use
    // 1-based indexing instead of 0-based as you'd normally expect in C,
    // and the sequences are accessed using query[i - 1] and ref[k - 1].

    /*** forward ***/
    // f[0]
    set_u(k, bw, 0, 0);
    f[0*i_dim+k] = s[0] = 1.;
    { // f[1]
        double *fi = &f[1*i_dim], sum;
        int beg = 1, end = l_ref < bw + 1? l_ref : bw + 1;
        for (k = beg, sum = 0.; k <= end; ++k) {
            int u;
            double e = (ref[k - 1] > 3 || query[0] > 3)? 1. : ref[k - 1] == query[0]? 1. - qual[0] : qual[0] * EM;
            set_u(u, bw, 1, k);
            fi[u+0] = e * bM; fi[u+1] = EI * bI;
            sum += fi[u] + fi[u+1];
        }
        s[1] = sum;
    }
    // f[2..l_query]
    for (i = 2; i <= l_query; ++i) {
        double *fi = &f[i*i_dim], *fi1 = &f[(i-1)*i_dim], sum, qli = qual[i-1];
        int beg = 1, end = l_ref, x;
        uint8_t qyi = query[i - 1];
        x = i - bw; beg = beg > x? beg : x; // band start
        x = i + bw; end = end < x? end : x; // band end

        // NB end-beg is almost always 14 (99.9% of the time)
        // Hence not a large volume to parallelise.
        //
        // Maybe stripe in diagonal doing 14 lines together?
        //
        // Consider rotation? 150x14 vs 14x150 so inner loop
        // takes longer.

        double E[] = {
            qli * EM, // 00
            1. - qli, // 01
            1.,       // 10
            1.,       // 11
        };
        double M = 1./s[i-1];

        // Note this code has the original version listed here (albeit
        // with improved formatting), but we do not compile using
        // -DPROBALN_ORIG.  The purpose of this code is to act as an
        // easier(?) to understand version of the heavily optimised
        // version following it and as an easy validation path in case
        // of any differences in results.
#ifdef PROBALN_ORIG
        for (k = beg, sum = 0.; k <= end; ++k) {
            int u, v11, v01, v10;
            double e;
            e = E[(ref[k - 1] > 3 || qyi > 3)*2 + (ref[k - 1] == qyi)];
            set_u(u, bw, i, k);
            set_u(v11, bw, i-1, k-1);
            set_u(v10, bw, i-1, k);
            set_u(v01, bw, i, k-1);
            fi[u+0] = e * (m[0] * M*fi1[v11+0] + m[3] * M*fi1[v11+1] + m[6] * M*fi1[v11+2]);
            fi[u+1] = EI * (m[1] * M*fi1[v10+0] + m[4] * M*fi1[v10+1]);
            fi[u+2] = m[2] * fi[v01+0] + m[8] * fi[v01+2];
            sum += fi[u] + fi[u+1] + fi[u+2];
        }
#else
        // We use EI*(M*m[1]*? + M*m[4]*?) a lot.  So factor it out here.
        double xm[5];
        xm[0] =    M*m[0];
        xm[1] =    M*m[3];
        xm[2] =    M*m[6];
        xm[3] = EI*M*m[1];
        xm[4] = EI*M*m[4];

        {
            int u, v11;
            set_u(u,   bw, i,   beg);
            set_u(v11, bw, i-1, beg-1);
            // Rather than recompute k->{u,v01,v10,v11} each loop
            // we just increment the pointers.
            double *xi = &fi[u];
            double *yi = &fi1[v11];
            // Derived from xi[0,2] in previous loop iter.
            double  l_x0 = m[2]*xi[0];
            double  l_x2 = m[8]*xi[2];
            for (k = beg, sum = 0.; k <= end; ++k, xi+=3, yi+=3) {
                int cond = (ref[k-1] > 3 || qyi > 3)*2 + (ref[k-1] == qyi);

                double z0 = xm[0]*yi[0];
                double z1 = xm[1]*yi[1];
                double z2 = xm[2]*yi[2];
                double z3 = xm[3]*yi[3];
                double z4 = xm[4]*yi[4];

                xi[0] = E[cond] * (z0+z1+z2);
                xi[1] = z3 + z4;
                xi[2] = l_x0 + l_x2;
                sum  += xi[0] + xi[1] + xi[2];

                l_x0 = m[2]*xi[0];
                l_x2 = m[8]*xi[2];
            }
        }
#endif
        s[i] = sum;
    }

    { // f[l_query+1]
        double sum;
        double M = 1./s[l_query];
        // Note that this goes from 1 to l_ref inclusive, but as the
        // alignment is banded not all of the values will have been
        // calculated (the rest are taken as 0), so the summation
        // actually goes over the values set in the last iteration of
        // the previous loop (when i = l_query).  For some reason lost to
        // time this is done by looking for valid values of 'u' instead of
        // working out 'beg' and 'end'.

        // From HTSlib 1.8 to 1.17, the endpoint was incorrectly set
        // to i_dim - 3.  When l_query <= bandwidth, this caused the last
        // column to be missed, and if l_ref == l_query then a match at the end
        // could incorrectly be reported as an insertion.  See #1605.

        for (k = 1, sum = 0.; k <= l_ref; ++k) {
            int u;
            set_u(u, bw, l_query, k);
            if (u < 3 || u >= i_dim) continue;
            sum += M*f[l_query*i_dim + u+0] * sM + M*f[l_query*i_dim + u+1] * sI;
        }
        s[l_query+1] = sum; // the last scaling factor
    }
    { // compute likelihood
        double p = 1., Pr1 = 0.;
        for (i = 0; i <= l_query + 1; ++i) {
            p *= s[i];
            if (p < 1e-100) Pr1 += -4.343 * log(p), p = 1.;
        }
        Pr1 += -4.343 * log(p * l_ref * l_query);
        Pr = (int)(Pr1 + .499);
        if (!is_backward) { // skip backward and MAP
            free(f); free(s); free(qual);
            return Pr;
        }
    }
    /*** backward ***/
    // b[l_query] (b[l_query+1][0]=1 and thus \tilde{b}[][]=1/s[l_query+1]; this is where s[l_query+1] comes from)
    for (k = 1; k <= l_ref; ++k) {
        int u;
        double *bi = &b[l_query*i_dim];
        set_u(u, bw, l_query, k);
        if (u < 3 || u >= i_dim) continue;
        bi[u+0] = sM / s[l_query] / s[l_query+1]; bi[u+1] = sI / s[l_query] / s[l_query+1];
    }
    // b[l_query-1..1]
    for (i = l_query - 1; i >= 1; --i) {
        int beg = 1, end = l_ref, x;
        double *bi = &b[i*i_dim], *bi1 = &b[(i+1)*i_dim], y = (i > 1), qli1 = qual[i];
        uint8_t qyi1 = query[i];
        x = i - bw; beg = beg > x? beg : x;
        x = i + bw; end = end < x? end : x;
        double E[] = {
            qli1 * EM, //000
            1. - qli1, //001
            1.,        //010
            1.,        //011
            //0,0,0,0    //1xx
        };

#ifdef PROBALN_ORIG
        for (k = end; k >= beg; --k) {
            int u, v11, v01, v10;
            double e;
            set_u(u, bw, i, k);
            set_u(v11, bw, i+1, k+1);
            set_u(v10, bw, i+1, k);
            set_u(v01, bw, i, k+1);
            e = (k>=l_ref)?0 :E[(ref[k] > 3 || qyi1 > 3)*2 + (ref[k] == qyi1)] * bi1[v11];
            bi[u+0] = e * m[0] + EI * m[1] * bi1[v10+1] + m[2] * bi[v01+2]; // bi1[v11] has been foled into e.
            bi[u+1] = e * m[3] + EI * m[4] * bi1[v10+1];
            bi[u+2] = (e * m[6] + m[8] * bi[v01+2]) * y;
//          fprintf(stderr, "B (%d,%d;%d): %lg,%lg,%lg\n", i, k, u, bi[u], bi[u+1], bi[u+2]); // DEBUG
        }
        // rescale
        int _beg, _end;
        set_u(_beg, bw, i, beg); set_u(_end, bw, i, end); _end += 2;
        for (k = _beg, y = 1./s[i]; k <= _end; ++k) bi[k] *= y;
#else
        {
            int u, v10;
            set_u(u,   bw, i,   end);
            set_u(v10, bw, i+1, end);
            // Rather than recompute k->{u,v01,v10,v11} each loop
            // we just increment the pointers.
            double *xi = &bi[u];
            double *yi = &bi1[v10];
            // NB xi[5] is equiv to v01+2.
            double xi_5 = xi[5];
            // Manual loop invariant removal
            double e1 = EI*m[1];
            double e4 = EI*m[4];
            // Do renorm too in the same pass.
            double n = 1./s[i];
            for (k = end; k >= beg; --k, xi -= 3, yi -= 3) {
                double e = (k>=l_ref)
                    ? 0
                    : E[(ref[k]>3 || qyi1>3)*2 + (ref[k] == qyi1)] * yi[3];

                xi[1] =  e * m[3] +   e4 * yi[1];
                xi[0] =  e * m[0] +   e1 * yi[1]  + m[2] * xi_5;
                xi[2] = (e * m[6] + m[8] * xi_5) * y;
                // bi[u+2] from this iter becomes bi[v01+2] in next iter
                xi_5 = xi[2];

                // rescale
                xi[1] *= n;
                xi[0] *= n;
                xi[2] *= n;
            }
        }
#endif
    }
    { // b[0]
        int beg = 1, end = l_ref < bw + 1? l_ref : bw + 1;
        double sum = 0.;
        for (k = end; k >= beg; --k) {
            int u;
            double e = (ref[k - 1] > 3 || query[0] > 3)? 1. : ref[k - 1] == query[0]? 1. - qual[0] : qual[0] * EM;
            set_u(u, bw, 1, k);
            if (u < 3 || u >= i_dim) continue;
            sum += e * b[1*i_dim + u+0] * bM + EI * b[1*i_dim + u+1] * bI;
        }
        set_u(k, bw, 0, 0);
        b[0*i_dim + k] = sum / s[0]; // if everything works as is expected, b[0][k] == 1.0
    }
    /*** MAP ***/
    for (i = 1; i <= l_query; ++i) {
        double sum = 0., *fi = &f[i*i_dim], *bi = &b[i*i_dim], max = 0.;
        int beg = 1, end = l_ref, x, max_k = -1;
        x = i - bw; beg = beg > x? beg : x;
        x = i + bw; end = end < x? end : x;
        double M = 1./s[i];
#ifdef PROBALN_ORIG
        for (k = beg; k <= end; ++k) {
            int u;
            double z;
            set_u(u, bw, i, k);
            z = M*fi[u+0] * bi[u+0];
            if (z > max) max = z, max_k = (k-1)<<2 | 0;
            sum += z;
            z = M*fi[u+1] * bi[u+1];
            if (z > max) max = z, max_k = (k-1)<<2 | 1;
            sum += z;
        }
#else
        {
            int u;
            set_u(u, bw, i, beg);
            for (k = beg; k <= end; ++k, u+=3) {
                double z1, z2;
                z1 = M*fi[u+0] * bi[u+0];
                z2 = M*fi[u+1] * bi[u+1];
                int which = z2 > z1; // strictly z2 >= z1 matches old code
                double zm = which ? z2 : z1;
                if (zm > max) {
                    max   = zm;
                    max_k = (k-1)<<2 | which;
                }
                sum += z1 + z2;
            }
        }
#endif
        max /= sum; sum *= s[i]; // if everything works as is expected, sum == 1.0
        if (state) state[i-1] = max_k;
        if (q) k = (int)(-4.343 * log(1. - max) + .499), q[i-1] = k > 100? 99 : k;
#ifdef PROBALN_MAIN
        k = 0;
        set_u(k, bw, 0, 0);
        fprintf(stderr, "(%.10lg,%.10lg) (%d,%d:%c,%c:%d) %lg\n", b[0][k], sum, i-1, max_k>>2,
                "ACGT"[query[i - 1]], "ACGT"[ref[(max_k>>2)]], max_k&3, max); // DEBUG
#endif
    }

    /*** free ***/
    free(f); free(b); free(s); free(qual);
    return Pr;

 fail:
    free(f); free(b); free(s); free(qual);
    return INT_MIN;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movl %esi, %ebx
movl %ecx, %eax
orl %esi, %eax
setns %al
cmpl $0x7ffffffd, %ecx       # imm = 0x7FFFFFFD
setl %sil
testb %al, %sil
jne 0x87653
callq 0x4050
movl $0x16, (%rax)
movl $0x80000000, %eax       # imm = 0x80000000
jmp 0x87669
movq %rdi, %r12
testl %ebx, %ebx
sete %dil
testl %ecx, %ecx
sete %sil
xorl %eax, %eax
orb %dil, %sil
je 0x8767b
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r9, %r15
movq %r8, %r14
movq %rdx, 0x78(%rsp)
cmpq $0x0, 0x160(%rsp)
setne %bpl
cmpq $0x0, 0x168(%rsp)
setne %r10b
movl %ebx, %eax
subl %ecx, %eax
movl %ecx, %edi
cmovgl %ebx, %edi
movl 0x8(%r9), %edx
cmpl %edx, %edi
cmovgel %edx, %edi
movl %eax, %esi
negl %esi
cmovsl %eax, %esi
cmpl %esi, %edi
cmovgl %edi, %esi
leal 0x1(,%rsi,2), %r8d
cmpl %ebx, %r8d
cmovgel %ebx, %r8d
leaq (%r8,%r8,2), %r13
addq $0x6, %r13
leal 0x1(%rcx), %edi
movq $-0x1, %rax
xorl %edx, %edx
divq %rdi
xorl %edx, %edx
divq %r13
cmpq $0x7, %rax
ja 0x876ff
callq 0x4050
movl $0xc, (%rax)
jmp 0x8764c
movb %r10b, 0xa0(%rsp)
movq %r8, 0x90(%rsp)
movq %rcx, 0x8(%rsp)
movq %rsi, 0x28(%rsp)
movq %r13, 0x40(%rsp)
movq %rdi, 0x70(%rsp)
imulq %rdi, %r13
movl $0x8, %esi
movq %r13, %rdi
callq 0x4300
testq %rax, %rax
je 0x87771
movq %rax, 0x10(%rsp)
andb 0xa0(%rsp), %bpl
movb %bpl, 0x3(%rsp)
je 0x8777b
movl $0x8, %esi
movq %r13, %rdi
callq 0x4300
movq %rax, %rbp
testq %rax, %rax
movq 0x8(%rsp), %rax
jne 0x87782
xorl %r13d, %r13d
xorl %ebp, %ebp
jmp 0x879e4
xorl %r13d, %r13d
xorl %ebp, %ebp
jmp 0x879e9
xorl %ebp, %ebp
movq 0x8(%rsp), %rax
leal 0x2(%rax), %ecx
movq %rcx, 0x68(%rsp)
leaq (,%rcx,8), %rdi
callq 0x4680
testq %rax, %rax
je 0x879e1
movq %rax, %r13
movl 0x8(%rsp), %eax
movq %rax, 0x20(%rsp)
leaq (,%rax,4), %rdi
callq 0x4680
testq %rax, %rax
je 0x879e4
movq %rax, 0x48(%rsp)
movq %rbp, 0x38(%rsp)
movq %r13, 0x50(%rsp)
movl %ebx, 0x4(%rsp)
movss 0x2a723(%rip), %xmm0    # 0xb1f00
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
leaq 0x2a716(%rip), %r13     # 0xb1f00
jne 0x87824
jp 0x87824
xorl %ebx, %ebx
movq %r13, %rbp
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
movsd 0xf8ae(%rip), %xmm0     # 0x970b0
divsd %xmm0, %xmm1
callq 0x48c0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, (%rbp)
decq %rbx
addq $0x4, %rbp
cmpq $-0x100, %rbx
jne 0x877f3
movq 0x48(%rsp), %r10
movl $0x0, (%r10)
movq 0x8(%rsp), %r11
testl %r11d, %r11d
movl 0x4(%rsp), %edx
movq 0x40(%rsp), %rsi
movq 0x78(%rsp), %rbx
movq 0x20(%rsp), %rdi
jle 0x87875
xorl %eax, %eax
testq %r14, %r14
je 0x8785b
movzbl (%r14,%rax), %ecx
jmp 0x87860
movl $0x1e, %ecx
movss (%r13,%rcx,4), %xmm0
movss %xmm0, (%r10,%rax,4)
incq %rax
cmpq %rax, %rdi
jne 0x8784f
leal 0x2(,%r11,2), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd 0xaa64(%rip), %xmm0     # 0x922f0
movapd %xmm0, %xmm6
divsd %xmm1, %xmm6
movss (%r15), %xmm1
movss 0x4(%r15), %xmm2
movss 0x168f9(%rip), %xmm3    # 0x9e1a0
movaps %xmm3, %xmm4
subss %xmm1, %xmm4
movaps %xmm4, %xmm5
subss %xmm1, %xmm5
cvtss2sd %xmm5, %xmm8
movapd %xmm0, %xmm9
movsd %xmm6, 0x88(%rsp)
subsd %xmm6, %xmm9
cvtss2sd %xmm1, %xmm10
subss %xmm2, %xmm3
cvtss2sd %xmm3, %xmm12
cvtss2sd %xmm2, %xmm11
xorps %xmm2, %xmm2
cvtsi2ss %edx, %xmm2
divss %xmm2, %xmm4
xorps %xmm6, %xmm6
cvtss2sd %xmm4, %xmm6
divss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm7
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq 0x50(%rsp), %r13
movq %rax, (%r13)
movq 0x10(%rsp), %rcx
movq %rax, 0x18(%rcx)
movq 0x28(%rsp), %rdi
leal 0x1(%rdi), %r8d
cmpl %edx, %r8d
cmovgel %edx, %r8d
testl %edx, %edx
movq %r8, 0xd8(%rsp)
jle 0x87a06
leaq (%rcx,%rsi,8), %rax
movl $0x1, %ecx
movl $0x1, %esi
subl %edi, %esi
xorl %edx, %edx
testl %esi, %esi
cmovlel %edx, %esi
movsd 0xea43(%rip), %xmm1     # 0x96398
mulsd %xmm7, %xmm1
cmpl $0x2, %r8d
cmovgel %r8d, %ecx
leal (%rsi,%rsi,2), %edi
movl $0x7, %esi
subl %edi, %esi
xorps %xmm5, %xmm5
movsd 0x1681a(%rip), %xmm2    # 0x9e190
movq 0x70(%rsp), %r9
movb (%r12,%rdx), %dil
movapd %xmm0, %xmm3
cmpb $0x3, %dil
ja 0x879b5
movb (%rbx), %r8b
movapd %xmm0, %xmm3
cmpb $0x3, %r8b
ja 0x879b5
xorps %xmm4, %xmm4
cvtss2sd (%r10), %xmm4
cmpb %r8b, %dil
jne 0x879ad
movapd %xmm0, %xmm3
subsd %xmm4, %xmm3
jmp 0x879b5
mulsd %xmm2, %xmm4
movapd %xmm4, %xmm3
leal -0x1(%rsi), %edi
mulsd %xmm6, %xmm3
movslq %edi, %rdi
movsd %xmm3, (%rax,%rdi,8)
movslq %esi, %rsi
movsd %xmm1, (%rax,%rsi,8)
addsd %xmm1, %xmm3
addsd %xmm3, %xmm5
addl $0x3, %esi
incq %rdx
cmpq %rdx, %rcx
jne 0x8797b
jmp 0x87a0e
xorl %r13d, %r13d
movq 0x10(%rsp), %rax
movq %rax, %rdi
callq 0x45c0
movq %rbp, %rdi
callq 0x45c0
movq %r13, %rdi
callq 0x45c0
jmp 0x8764c
xorps %xmm5, %xmm5
movq 0x70(%rsp), %r9
movsd %xmm7, 0xe0(%rsp)
movsd %xmm6, 0xe8(%rsp)
mulsd %xmm9, %xmm8
movsd %xmm8, 0x98(%rsp)
mulsd %xmm9, %xmm10
movapd %xmm10, 0x100(%rsp)
movapd %xmm9, %xmm0
movaps %xmm12, 0xf0(%rsp)
mulsd %xmm12, %xmm0
movapd %xmm0, 0x110(%rsp)
movaps %xmm11, 0xa0(%rsp)
mulsd %xmm11, %xmm9
movsd %xmm9, 0x60(%rsp)
movsd %xmm5, 0x8(%r13)
cmpl $0x2, %r11d
jl 0x87d49
movl $0x2, %eax
movq 0x28(%rsp), %rsi
subl %esi, %eax
movapd 0x110(%rsp), %xmm0
unpcklpd 0xf0(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0]
movq 0x90(%rsp), %rdi
leaq (,%rdi,8), %rcx
leaq (%rcx,%rcx,2), %r8
leaq (%rcx,%rcx,2), %rdx
addq $0x30, %rdx
leaq (%rdi,%rdi,2), %rdi
shlq $0x4, %rdi
movq 0x10(%rsp), %rcx
addq %rcx, %rdi
movq %rdi, 0x18(%rsp)
addq %rcx, %r8
movq %r8, 0x30(%rsp)
movl $0x1, %edi
subl %esi, %edi
movl $0x2, %r8d
movsd 0x166a5(%rip), %xmm1    # 0x9e190
movsd 0xa7fd(%rip), %xmm2     # 0x922f0
movaps 0xe716(%rip), %xmm3     # 0x96210
movsd 0xe896(%rip), %xmm4     # 0x96398
xorl %r10d, %r10d
movapd 0xa0(%rsp), %xmm15
cmpl $0x2, %eax
movl $0x1, %ebx
cmovgel %eax, %ebx
testl %eax, %eax
movl $0x0, %r14d
cmovgl %eax, %r14d
testl %edi, %edi
movl $0x0, %r9d
cmovgl %edi, %r9d
movq 0x48(%rsp), %rcx
xorps %xmm6, %xmm6
cvtss2sd -0x4(%rcx,%r8,4), %xmm6
movq 0x78(%rsp), %rcx
movb -0x1(%rcx,%r8), %r11b
movl %r8d, %r13d
movq 0x28(%rsp), %rsi
subl %esi, %r13d
cmpl $0x2, %r13d
movl $0x1, %ecx
cmovgel %r13d, %ecx
leal (%rsi,%r8), %ebp
movl 0x4(%rsp), %esi
cmpl %esi, %ebp
cmovgel %esi, %ebp
movapd %xmm2, %xmm7
subsd %xmm6, %xmm7
mulsd %xmm1, %xmm6
movsd %xmm6, 0xb0(%rsp)
movsd %xmm7, 0xb8(%rsp)
movaps %xmm3, 0xc0(%rsp)
xorpd %xmm9, %xmm9
cmpl %ebp, %ecx
jg 0x87d20
leaq -0x1(%rbx), %r15
leal (%rbx,%rbx,2), %esi
leal (%r14,%r14,2), %r14d
movl %esi, %ebx
subl %r14d, %ebx
addl $0x3, %ebx
movslq %ebx, %rbx
movq 0x18(%rsp), %r14
leaq (%r14,%rbx,8), %r14
leal (%r9,%r9,2), %r9d
subl %r9d, %esi
movslq %esi, %rsi
movq 0x30(%rsp), %r9
leaq (%r9,%rsi,8), %r9
movapd %xmm2, %xmm6
divsd %xmm5, %xmm6
movsd 0x98(%rsp), %xmm5
mulsd %xmm6, %xmm5
movapd %xmm6, %xmm7
unpcklpd %xmm6, %xmm7            # xmm7 = xmm7[0],xmm6[0]
mulpd %xmm0, %xmm7
mulsd %xmm4, %xmm6
movsd 0x60(%rsp), %xmm8
mulsd %xmm6, %xmm8
movapd 0x100(%rsp), %xmm9
mulsd %xmm9, %xmm6
movq 0x40(%rsp), %rsi
imulq %r8, %rsi
movq 0x10(%rsp), %rbx
leaq (%rbx,%rsi,8), %rsi
testl %r13d, %r13d
movl $0x0, %ebx
cmovlel %ebx, %r13d
subl %r13d, %ecx
leal (%rcx,%rcx,2), %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
movsd (%rsi,%rcx,8), %xmm10
movsd 0x10(%rsi,%rcx,8), %xmm11
movl %ebp, %r13d
unpcklpd %xmm9, %xmm8            # xmm8 = xmm8[0],xmm9[0]
xorpd %xmm9, %xmm9
cmpb $0x4, %r11b
setae %cl
movb (%r12,%r15), %sil
cmpb $0x4, %sil
setae %bl
orb %cl, %bl
xorl %ecx, %ecx
cmpb %r11b, %sil
sete %cl
movzbl %bl, %esi
movsd 0x30(%r9,%r10), %xmm13
mulsd %xmm5, %xmm13
movupd 0x38(%r9,%r10), %xmm12
mulpd %xmm7, %xmm12
shll $0x4, %esi
leal (%rsi,%rcx,8), %ecx
addsd %xmm12, %xmm13
unpckhpd %xmm12, %xmm12          # xmm12 = xmm12[1,1]
addsd %xmm13, %xmm12
mulsd 0xb0(%rsp,%rcx), %xmm12
movsd 0x48(%r9,%r10), %xmm13
movsd 0x50(%r9,%r10), %xmm14
unpcklpd %xmm10, %xmm14          # xmm14 = xmm14[0],xmm10[0]
mulpd %xmm8, %xmm14
movsd %xmm12, 0x60(%r14,%r10)
movapd %xmm6, %xmm10
unpcklpd %xmm11, %xmm10          # xmm10 = xmm10[0],xmm11[0]
unpcklpd %xmm15, %xmm13          # xmm13 = xmm13[0],xmm15[0]
mulpd %xmm10, %xmm13
addpd %xmm14, %xmm13
movupd %xmm13, 0x68(%r14,%r10)
movapd %xmm12, %xmm10
addsd %xmm13, %xmm12
unpckhpd %xmm13, %xmm13          # xmm13 = xmm13[1,1]
movapd %xmm13, %xmm11
addsd %xmm12, %xmm13
addsd %xmm13, %xmm9
incq %r15
addq $0x18, %r14
addq $0x18, %r9
cmpq %r13, %r15
jb 0x87c59
movq 0x50(%rsp), %r13
movsd %xmm9, (%r13,%r8,8)
incq %r8
incl %eax
addq %rdx, %r10
incl %edi
movapd %xmm9, %xmm5
movq 0x70(%rsp), %r9
cmpq %r9, %r8
jne 0x87b0f
movq 0x20(%rsp), %rax
movsd (%r13,%rax,8), %xmm0
movsd %xmm0, 0x80(%rsp)
movsd 0xa58a(%rip), %xmm0     # 0x922f0
xorpd %xmm1, %xmm1
movsd %xmm1, 0x30(%rsp)
movsd %xmm1, 0x18(%rsp)
movl 0x4(%rsp), %ecx
testl %ecx, %ecx
movq 0x28(%rsp), %r14
movq 0x40(%rsp), %r15
movq 0x38(%rsp), %rbp
movq 0x8(%rsp), %rdi
movsd 0x88(%rsp), %xmm4
jle 0x87e27
movapd %xmm0, %xmm1
divsd 0x80(%rsp), %xmm1
movl %edi, %eax
subl %r14d, %eax
xorl %edx, %edx
testl %eax, %eax
cmovgl %eax, %edx
movq %r15, %rax
imulq 0x20(%rsp), %rax
movq 0x10(%rsp), %rsi
leaq (%rsi,%rax,8), %rax
movl %ecx, %ecx
leal (%rdx,%rdx,2), %esi
movl $0x3, %edx
subl %esi, %edx
xorpd %xmm2, %xmm2
movsd %xmm2, 0x18(%rsp)
cmpl $0x7ffffffc, %edx       # imm = 0x7FFFFFFC
ja 0x87e1f
leal 0x3(%rdx), %esi
cmpq %rsi, %r15
jbe 0x87e1f
movsd (%rax,%rsi,8), %xmm2
mulsd %xmm1, %xmm2
movsd 0x8(%rax,%rsi,8), %xmm3
mulsd %xmm1, %xmm3
mulsd %xmm4, %xmm3
mulsd %xmm4, %xmm2
addsd %xmm3, %xmm2
movsd 0x18(%rsp), %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x18(%rsp)
addl $0x3, %edx
decq %rcx
jne 0x87de0
movsd 0x18(%rsp), %xmm1
movsd %xmm1, (%r13,%r9,8)
cmpl $-0x1, %edi
jl 0x87e9e
xorpd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0xa4a5(%rip), %xmm0     # 0x922f0
xorl %ebx, %ebx
movsd 0x16343(%rip), %xmm1    # 0x9e198
mulsd (%r13,%rbx,8), %xmm0
ucomisd %xmm0, %xmm1
jbe 0x87e94
callq 0x4390
movq 0x8(%rsp), %rdi
mulsd 0xa71c(%rip), %xmm0     # 0x92590
movsd 0x30(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x30(%rsp)
movsd 0x1630c(%rip), %xmm1    # 0x9e198
movsd 0xa45c(%rip), %xmm0     # 0x922f0
incq %rbx
cmpq %rbx, 0x68(%rsp)
jne 0x87e55
movl 0x4(%rsp), %ebx
xorps %xmm1, %xmm1
cvtsi2sd %ebx, %xmm1
mulsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %edi, %xmm0
mulsd %xmm1, %xmm0
callq 0x4390
mulsd 0xa6cb(%rip), %xmm0     # 0x92590
addsd 0x30(%rsp), %xmm0
addsd 0xa6cd(%rip), %xmm0     # 0x925a0
cvttsd2si %xmm0, %eax
movl %eax, 0x5c(%rsp)
cmpb $0x0, 0x3(%rsp)
je 0x88366
testl %ebx, %ebx
movq 0x8(%rsp), %rdi
movsd 0x98(%rsp), %xmm12
movsd 0x60(%rsp), %xmm13
movapd 0x100(%rsp), %xmm14
movapd 0xf0(%rsp), %xmm15
movsd 0x88(%rsp), %xmm0
jle 0x87f7f
movq %r15, %rax
imulq 0x20(%rsp), %rax
leaq (,%rax,8), %rax
addq %rbp, %rax
movl %edi, %ecx
subl %r14d, %ecx
xorl %edx, %edx
testl %ecx, %ecx
cmovgl %ecx, %edx
movl %ebx, %ecx
divsd 0x80(%rsp), %xmm0
divsd 0x18(%rsp), %xmm0
leal (%rdx,%rdx,2), %esi
movl $0x7, %edx
subl %esi, %edx
leal -0x4(%rdx), %esi
cmpl $0x7ffffffc, %esi       # imm = 0x7FFFFFFC
ja 0x87f77
leal -0x1(%rdx), %esi
cmpq %rsi, %r15
jbe 0x87f77
movsd %xmm0, (%rax,%rsi,8)
movl %edx, %esi
movsd %xmm0, (%rax,%rsi,8)
addl $0x3, %edx
decq %rcx
jne 0x87f58
cmpl $0x2, %edi
movq 0x20(%rsp), %r11
jl 0x8826c
movsd 0xe403(%rip), %xmm1     # 0x96398
movapd %xmm14, %xmm0
mulsd %xmm1, %xmm0
mulsd %xmm1, %xmm13
movq 0x28(%rsp), %rdx
movq 0x8(%rsp), %rsi
leal -0x1(%rdx,%rsi), %eax
cltq
movslq %ebx, %rbp
movq 0x40(%rsp), %rdi
movq %rdi, %rcx
imulq %r11, %rcx
movq 0x38(%rsp), %r8
leaq (%r8,%rcx,8), %rcx
addq $0x18, %rcx
movq %rcx, 0x18(%rsp)
subl %edx, %esi
movq 0x90(%rsp), %rcx
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
movq $-0x30, %rdx
subq %rcx, %rdx
movq %rdx, 0x30(%rsp)
leaq -0x1(%r11), %rcx
imulq %rdi, %rcx
leaq (%r8,%rcx,8), %rcx
movq %rcx, 0x60(%rsp)
leal -0x1(%rsi), %r9d
movsd 0xa2de(%rip), %xmm1     # 0x922f0
movsd 0x16176(%rip), %xmm2    # 0x9e190
movaps 0xe1ef(%rip), %xmm3     # 0x96210
xorl %r13d, %r13d
cmpq %rbp, %rax
movq %rbp, %r10
cmovlq %rax, %r10
cmpl %eax, %ebx
movl %eax, %edi
cmovll %ebx, %edi
testl %esi, %esi
movl $0x0, %r8d
cmovgl %esi, %r8d
testl %r9d, %r9d
movl $0x0, %edx
cmovgl %r9d, %edx
movapd %xmm1, %xmm4
movq %r11, 0x20(%rsp)
cmpq $0x2, %r11
jne 0x88060
xorpd %xmm4, %xmm4
movq 0x20(%rsp), %r15
leaq -0x1(%r15), %r14
movq 0x48(%rsp), %rcx
xorps %xmm5, %xmm5
cvtss2sd -0x4(%rcx,%r15,4), %xmm5
movl %r14d, %r11d
movq 0x28(%rsp), %rbx
subl %ebx, %r11d
cmpl $0x2, %r11d
movl $0x1, %ecx
cmovgel %r11d, %ecx
movq %r14, 0x68(%rsp)
addl %r14d, %ebx
movl 0x4(%rsp), %r14d
cmpl %r14d, %ebx
cmovgel %r14d, %ebx
movq 0x78(%rsp), %r14
movb -0x1(%r14,%r15), %r14b
movapd %xmm1, %xmm6
subsd %xmm5, %xmm6
mulsd %xmm2, %xmm5
movsd %xmm5, 0xb0(%rsp)
movsd %xmm6, 0xb8(%rsp)
movaps %xmm3, 0xc0(%rsp)
cmpl %ecx, %ebx
jl 0x8824a
leal (%rdi,%rdi,2), %edi
addl $0x3, %edi
leal (%r8,%r8,2), %r8d
movl %edi, %r15d
subl %r8d, %r15d
incq %r10
leal (%rdx,%rdx,2), %edx
subl %edx, %edi
movq 0x40(%rsp), %rdx
imulq 0x68(%rsp), %rdx
testl %r11d, %r11d
movl $0x0, %r8d
cmovlel %r8d, %r11d
subl %r11d, %ebx
movq 0x38(%rsp), %r8
leaq (%r8,%rdx,8), %rdx
leal (%rbx,%rbx,2), %r8d
addl $0x3, %r8d
movslq %r8d, %r8
movsd 0x28(%rdx,%r8,8), %xmm7
movslq %r15d, %rdx
movq 0x18(%rsp), %r8
leaq (%r8,%rdx,8), %rdx
movslq %edi, %rdi
movq 0x60(%rsp), %r8
leaq (%r8,%rdi,8), %r8
movapd %xmm1, %xmm5
movq 0x50(%rsp), %rdi
movq 0x20(%rsp), %r11
divsd -0x8(%rdi,%r11,8), %xmm5
movl %ecx, %edi
movapd %xmm5, %xmm6
unpcklpd %xmm5, %xmm6            # xmm6 = xmm6[0],xmm5[0]
movq %r13, %r11
leaq -0x1(%r10), %rcx
xorpd %xmm8, %xmm8
cmpq %rbp, %rcx
jge 0x881ad
cmpb $0x4, %r14b
setae %bl
movb -0x1(%r12,%r10), %r10b
cmpb $0x4, %r10b
setae %r15b
orb %bl, %r15b
xorl %ebx, %ebx
cmpb %r14b, %r10b
sete %bl
movzbl %r15b, %r10d
shll $0x4, %r10d
leal (%r10,%rbx,8), %r10d
movsd 0xb0(%rsp,%r10), %xmm8
mulsd (%rdx,%r11), %xmm8
movsd -0x10(%rdx,%r11), %xmm10
mulsd %xmm13, %xmm10
movapd %xmm14, %xmm11
mulsd %xmm7, %xmm11
mulsd 0xa0(%rsp), %xmm7
movapd %xmm8, %xmm9
mulsd %xmm15, %xmm9
addsd %xmm7, %xmm9
mulsd %xmm4, %xmm9
movapd %xmm8, %xmm7
mulsd 0x110(%rsp), %xmm7
addsd %xmm10, %xmm7
movsd %xmm7, 0x8(%r8,%r11)
movsd -0x10(%rdx,%r11), %xmm10
mulsd %xmm0, %xmm10
mulsd %xmm12, %xmm8
addsd %xmm10, %xmm8
addsd %xmm11, %xmm8
unpcklpd %xmm7, %xmm8            # xmm8 = xmm8[0],xmm7[0]
mulpd %xmm6, %xmm8
movupd %xmm8, (%r8,%r11)
movapd %xmm5, %xmm7
mulsd %xmm9, %xmm7
movsd %xmm7, 0x10(%r8,%r11)
addq $-0x18, %r11
movq %rcx, %r10
movapd %xmm9, %xmm7
cmpq %rdi, %rcx
jg 0x88164
decq %rax
decl %esi
addq 0x30(%rsp), %r13
decl %r9d
cmpq $0x2, 0x20(%rsp)
movq 0x68(%rsp), %r11
movl 0x4(%rsp), %ebx
jg 0x88024
testl %ebx, %ebx
jle 0x88378
movl $0x1, %eax
subl 0x28(%rsp), %eax
xorl %edx, %edx
testl %eax, %eax
cmovgl %eax, %edx
movq 0xd8(%rsp), %rcx
movl %ecx, %esi
movl %ecx, %eax
incl %eax
leal (%rcx,%rcx,2), %ecx
leal (%rdx,%rdx,2), %edx
subl %edx, %ecx
addl $0x3, %ecx
leaq (%rsi,%r12), %rdx
decq %rdx
xorpd %xmm0, %xmm0
movsd 0xa040(%rip), %xmm1     # 0x922f0
movsd 0xe0e0(%rip), %xmm2     # 0x96398
movsd 0x15ed0(%rip), %xmm3    # 0x9e190
movq 0x168(%rsp), %r13
movq 0x40(%rsp), %r8
movq 0x38(%rsp), %r9
movq 0x48(%rsp), %r10
movq 0x8(%rsp), %r11
movq 0x78(%rsp), %r14
movsd 0xe8(%rsp), %xmm6
movsd 0xe0(%rsp), %xmm7
movb (%rdx), %sil
movapd %xmm1, %xmm4
cmpb $0x3, %sil
ja 0x8832c
movb (%r14), %dil
movapd %xmm1, %xmm4
cmpb $0x3, %dil
ja 0x8832c
xorps %xmm5, %xmm5
cvtss2sd (%r10), %xmm5
cmpb %dil, %sil
jne 0x88324
movapd %xmm1, %xmm4
subsd %xmm5, %xmm4
jmp 0x8832c
mulsd %xmm3, %xmm5
movapd %xmm5, %xmm4
movl %ecx, %esi
cmpq %rsi, %r8
jbe 0x88357
addq %r8, %rsi
mulsd (%r9,%rsi,8), %xmm4
movsd 0x8(%r9,%rsi,8), %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm7, %xmm5
mulsd %xmm6, %xmm4
addsd %xmm5, %xmm4
addsd %xmm4, %xmm0
decl %eax
addl $-0x3, %ecx
decq %rdx
cmpl $0x1, %eax
jg 0x882f3
jmp 0x8838e
movq 0x10(%rsp), %rdi
callq 0x45c0
movq %r13, %rdi
jmp 0x88529
xorpd %xmm0, %xmm0
movq 0x168(%rsp), %r13
movq 0x38(%rsp), %r9
movq 0x8(%rsp), %r11
movq 0x50(%rsp), %rax
divsd (%rax), %xmm0
movsd %xmm0, 0x18(%r9)
testl %r11d, %r11d
jle 0x88510
movl $0x1, %ebp
movl $0x1, %r14d
subl 0x28(%rsp), %r14d
movl $0x1, %r15d
movl $0x63, %r12d
cmpl $0x2, %r14d
movl $0x1, %edi
cmovgel %r14d, %edi
testl %r14d, %r14d
movl $0x0, %esi
cmovgl %r14d, %esi
movl %r15d, %ecx
movq 0x28(%rsp), %rax
subl %eax, %ecx
cmpl $0x2, %ecx
cmovll %ebp, %ecx
addl %r15d, %eax
cmpl %ebx, %eax
cmovgel %ebx, %eax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movsd 0x9f00(%rip), %xmm1     # 0x92300
cmpl %eax, %ecx
jg 0x884c1
leal (%rdi,%rdi,2), %ecx
leal (%rsi,%rsi,2), %edx
subl %edx, %ecx
addl $0x3, %ecx
movl %edi, %esi
decl %esi
leal -0x4(,%rdi,4), %edi
movq 0x40(%rsp), %rdx
imulq %r15, %rdx
movq 0x10(%rsp), %r8
leaq (%r8,%rdx,8), %r8
movsd 0x9eb8(%rip), %xmm0     # 0x922f0
movq 0x50(%rsp), %r9
divsd (%r9,%r15,8), %xmm0
movq 0x38(%rsp), %r9
leaq (%r9,%rdx,8), %r9
xorpd %xmm1, %xmm1
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorpd %xmm2, %xmm2
movslq %ecx, %rcx
movsd (%r8,%rcx,8), %xmm3
mulsd %xmm0, %xmm3
mulsd (%r9,%rcx,8), %xmm3
leal 0x1(%rcx), %r10d
movslq %r10d, %r10
movsd (%r8,%r10,8), %xmm4
mulsd %xmm0, %xmm4
mulsd (%r9,%r10,8), %xmm4
xorl %r10d, %r10d
ucomisd %xmm3, %xmm4
movapd %xmm1, %xmm5
seta %r10b
movapd %xmm4, %xmm1
maxsd %xmm3, %xmm1
addl %edi, %r10d
ucomisd %xmm5, %xmm1
cmoval %r10d, %edx
maxsd %xmm5, %xmm1
addsd %xmm3, %xmm4
addsd %xmm4, %xmm2
addl $0x3, %ecx
incl %esi
addl $0x4, %edi
cmpl %eax, %esi
jl 0x88459
divsd %xmm2, %xmm1
movq 0x160(%rsp), %rax
movl %edx, -0x4(%rax,%r15,4)
movsd 0x9e1a(%rip), %xmm0     # 0x922f0
subsd %xmm1, %xmm0
callq 0x4390
mulsd 0xa0a9(%rip), %xmm0     # 0x92590
addsd 0xa0b1(%rip), %xmm0     # 0x925a0
cvttsd2si %xmm0, %eax
cmpl $0x65, %eax
cmovgel %r12d, %eax
movb %al, -0x1(%r13,%r15)
incq %r15
incl %r14d
cmpq 0x70(%rsp), %r15
jne 0x883c2
movq 0x10(%rsp), %rdi
callq 0x45c0
movq 0x38(%rsp), %rdi
callq 0x45c0
movq 0x50(%rsp), %rdi
callq 0x45c0
movq 0x48(%rsp), %rdi
callq 0x45c0
movl 0x5c(%rsp), %eax
jmp 0x87669
nopl (%rax)