// File: /workspace/github_c_makefile_star2_O0/debbiemarkslab[P]plmc/src/weights.c
// Function: MSAReweightSequences
void MSAReweightSequences(alignment_t *ali, options_t *options) {
    /* Reweight seqeuences by their inverse neighborhood size. Each sequence's
       weight is the inverse of the number of neighboring sequences with less
       than THETA percent divergence
    */
    for (int i = 0; i < ali->nSeqs; i++) ali->weights[i] = 1.0;

    /* Only apply reweighting if theta is on [0,1] */
    if (options->theta >= 0 && options->theta <= 1) {
        /* The neighborhood size of each sequence is the number of sequences
           in the alignment within theta percent divergence */

        if (options->fastWeights > 0 && options->fastWeights < ali->nSeqs) {
            /* Cluster the sequences with k-consensus */
            int nClusters = options->fastWeights;
            int nIterations = 10;
            int nSeqs = ali->nSeqs;
            int nCodes = ali->nCodes;
            int nSites = ali->nSites;

#define COUNTS(i,j,a) counts[i * nSites * nCodes + j * nCodes + a]
#define CONSENSUS(i,j) consensus[i * nSites + j]
#define ALI(i,j) aliPermute[i * nSites + j]

            /* Pick initial clusters with Reservoir sampling */
            int *clusters = (int *) malloc(nClusters * sizeof(int));
            letter_t *consensus = (letter_t *) malloc(nClusters * nSites * sizeof(letter_t));
            for (int i = 0; i < nClusters; i++) clusters[i] = i;
            for (int i = nClusters; i < nSeqs; i++) {
                int ix = genrand_int32() % (i);
                if (ix < nClusters) clusters[ix] = i;
            }
            for (int i = 0; i < nClusters; i++)
                for (int j = 0; j < nSites; j++)
                    CONSENSUS(i,j) = seq(clusters[i], j);
            free(clusters);

            /* EM steps */
            int *assignment = (int *) malloc(nSeqs * sizeof(int));
            int *counts = (int *) malloc(nClusters * nSites * nCodes * sizeof(int));
            int *radii = (int *) malloc(nClusters * sizeof(int));
            for (int i = 0; i < nSeqs; i++) assignment[i] = 0;
            fprintf(stderr, "Clustering");
            for (int t = 0; t < nIterations; t++) {
                fprintf(stderr, ".");
                /* Step 1. Update the assignments */
                for (int i = 0; i < nClusters; i++) radii[i] = 0;
#pragma omp parallel for
                for (int s = 0; s < nSeqs; s++) {
                    int ixOld = assignment[s];
                    /* Current distance to current assignment */
                    numeric_t distance = 0;
                    for (int j = 0; j < nSites; j++)
                        distance += (CONSENSUS(ixOld, j) != seq(s, j));
                    /* Find closest */
                    int ixNew = ixOld;
                    for (int i = 0; i < nClusters; i++) {
                        numeric_t distanceI = 0;
                        for (int j = 0; j < nSites; j++)
                            distanceI += (CONSENSUS(i, j) != seq(s, j));
                        if (distanceI < distance) {
                            ixNew = i;
                            distance = distanceI;
                        }
                    }
                    if (ixNew != ixOld) assignment[s] = ixNew;
                    if (radii[ixNew] < distance) radii[ixNew] = distance;
                }
                /* --------------------------_DEBUG_--------------------------*/
                // for (int s = 0; s < nClusters; s++) {
                //     int size = 0;
                //     for (int i = 0; i < nSeqs; i++) size += (assignment[i] == s);
                //     fprintf(stderr, ">Cluster %d, %d members, radius %d\n", s, size, radii[s]);
                //     for (int i = 0; i < ali->nSites; i++)
                //         if (CONSENSUS(s,i) >= 0) {
                //             fprintf(stderr, "%c", ali->alphabet[CONSENSUS(s,i)]);
                //         } else {
                //             fprintf(stderr, " ");
                //         }
                //     fprintf(stderr, "\n");
                // }
                /* --------------------------^DEBUG^--------------------------*/

                /* Step 2. Update the consensus sequences */
                /* Update the counts */
                if (t < nIterations - 1) {
                    for (int i = 0; i < nClusters * nSites * nCodes; i++)
                        counts[i] = 0;
                    for (int s = 0; s < nSeqs; s++)
                        for (int j = 0; j < nSites; j++)
                            COUNTS(assignment[s], j, seq(s, j)) += 1;
#pragma omp parallel for
                    for (int i = 0; i < nClusters; i++)
                        for (int j = 0; j < nSites; j++) {
                            int topCode = 0;
                            int topCounts = COUNTS(i, j, 0);
                            for (int b = 1; b < nCodes; b++)
                                if (COUNTS(i, j, b) > topCounts) {
                                    topCode = b;
                                    topCounts = COUNTS(i, j, b);
                                }
                            CONSENSUS(i ,j) = topCode;
                        }
                }
            }
            fprintf(stderr, "\n");

            /* Profile-profile distances */
            numeric_t *clusterID = (numeric_t *) malloc(nClusters * nClusters * sizeof(numeric_t));
            for (int i = 0; i < nClusters * nClusters; i++) clusterID[i] = 0;
#pragma omp parallel for
            for (int pi = 0; pi < nClusters; pi++)
                for (int pj = 0; pj < nClusters; pj++)
                    for (int j = 0; j < nSites; j++)
                        clusterID[pi + pj * nClusters] +=
                                (CONSENSUS(pi,j) == CONSENSUS(pj,j));

            free(consensus);
            free(counts);

            /* Permute alignment */
            int *clusterSizes = (int *) malloc(nClusters * sizeof(int));
            int *clusterStart = (int *) malloc(nClusters * sizeof(int));
            int *clusterEnd = (int *) malloc(nClusters * sizeof(int));
            int *permuteMap = (int *) malloc(nSeqs * sizeof(int));
            numeric_t *weightsP = (numeric_t *) malloc(nSeqs * sizeof(numeric_t));
            letter_t *aliPermute = (letter_t *) malloc(nSeqs * nSites * sizeof(letter_t));
            for (int i = 0; i < nClusters; i++) clusterSizes[i] = 0;
            for (int s = 0; s < ali->nSeqs; s++)
                clusterSizes[assignment[s]] += 1;
            int ix = 0;
            for (int i = 0; i < nClusters; i++) {
                clusterStart[i] = ix;
                ix += clusterSizes[i];
                clusterEnd[i] = ix;
            }
            ix = 0;
            for (int i = 0; i < nClusters; i++)
                for (int s = 0; s < ali->nSeqs; s++)
                    if (assignment[s] == i) {
                        for (int j = 0; j < nSites; j++)
                            ALI(ix,j) = seq(s,j);
                        permuteMap[ix] = s;
                        ix++;
                    }

            /* ----------------------------_DEBUG_----------------------------*/
            // for (int s = 0; s < nSeqs; s++) {
            //     fprintf(stdout, ">Seq %d\n", s);
            //     for (int i = 0; i < ali->nSites; i++)
            //             fprintf(stdout, "%c", ali->alphabet[ALI(s,i)]);
            //     fprintf(stdout, "\n");
            // }
            /* ----------------------------^DEBUG^----------------------------*/

            /* Sequence weights */
            numeric_t cutoff = (numeric_t) ((1 - options->theta) * ali->nSites);
            for (int s = 0; s < nSeqs; s++) weightsP[s] = 1;
#pragma omp parallel for
            for (int ci = 0; ci < nClusters; ci++)
                for (int cj = 0; cj < nClusters; cj++)
                    if (clusterID[ci * nClusters + cj] >= 0.9 * cutoff)
                        for (int s = clusterStart[ci]; s < clusterEnd[ci]; s++)
                            for (int t = clusterStart[cj]; t < clusterEnd[cj]; t++)
                                if (s != t) {
                                    int id = 0;
                                    for (int n = 0; n < ali->nSites; n++)
                                        id += (ALI(s, n) == ALI(t, n));
                                    if (id >= cutoff) weightsP[s] += 1.0;
                                }
            for (int s = 0; s < nSeqs; s++)
                ali->weights[permuteMap[s]] = weightsP[s];

#undef COUNTS
#undef CONSENSUS
#undef ALI

            free(clusterSizes);
            free(clusterStart);
            free(clusterEnd);
            free(permuteMap);
            free(weightsP);
            free(radii);
            free(aliPermute);
        } else {
            /* Deterministic sequence weights */
#if defined(_OPENMP)
            /* Naive parallelization is faster ignoring symmetry */
            #pragma omp parallel for
            for (int s = 0; s < ali->nSeqs; s++)
                for (int t = 0; t < ali->nSeqs; t++)
                    if (s != t) {
                        int id = 0;
                        for (int n = 0; n < ali->nSites; n++)
                            id += (seq(s, n) == seq(t, n));
                        if (id >= ((1 - options->theta) * ali->nSites))
                            ali->weights[s] += 1.0;
                    }
#else
            /* For a single core, take advantage of symmetry */
            for (int s = 0; s < ali->nSeqs - 1; s++)
                for (int t = s + 1; t < ali->nSeqs; t++) {
                    int id = 0;
                    for (int n = 0; n < ali->nSites; n++)
                        id += (seq(s, n) == seq(t, n));
                    if (id >= ((1 - options->theta) * ali->nSites)) {
                        ali->weights[s] += 1.0;
                        ali->weights[t] += 1.0;
                    }
                }
#endif
        }

        /* Reweight sequences by the inverse of the neighborhood size */
        for (int i = 0; i < ali->nSeqs; i++)
            ali->weights[i] = 1.0 / ali->weights[i];
    }

    /* Scale sets the effective number of samples per neighborhood */
    for (int i = 0; i < ali->nSeqs; i++)
        ali->weights[i] *= options->scale;

    /* The effective number of sequences is then the sum of the weights */
    ali->nEff = 0;
    for (int i = 0; i < ali->nSeqs; i++) ali->nEff += ali->weights[i];

    if (options->theta >= 0 && options->theta <= 1) {
        fprintf(stderr,
                "Effective number of samples: %.1f\t(%.0f%% identical neighborhood = %.3f samples)\n",
                ali->nEff, 100 * (1 - options->theta), options->scale);
    } else {
        fprintf(stderr,
                "Theta not between 0 and 1, no sequence reweighting applied (N = %.2f)\n",
                ali->nEff);
    }
}

// Assembly:
subq $0x178, %rsp            # imm = 0x178
movq %rdi, 0x170(%rsp)
movq %rsi, 0x168(%rsp)
movl $0x0, 0x164(%rsp)
movl 0x164(%rsp), %eax
movq 0x170(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x16a59
movq 0x170(%rsp), %rax
movq 0x50(%rax), %rax
movslq 0x164(%rsp), %rcx
movsd 0x260f(%rip), %xmm0     # 0x19050
movsd %xmm0, (%rax,%rcx,8)
movl 0x164(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x164(%rsp)
jmp 0x16a12
movq 0x168(%rsp), %rax
movsd 0x30(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x17c9e
movq 0x168(%rsp), %rax
movsd 0x25cd(%rip), %xmm0     # 0x19050
ucomisd 0x30(%rax), %xmm0
jb 0x17c9e
movq 0x168(%rsp), %rax
cmpl $0x0, 0x28(%rax)
jle 0x17ad7
movq 0x168(%rsp), %rax
movl 0x28(%rax), %eax
movq 0x170(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x17ad7
movq 0x168(%rsp), %rax
movl 0x28(%rax), %eax
movl %eax, 0x160(%rsp)
movl $0xa, 0x15c(%rsp)
movq 0x170(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x158(%rsp)
movq 0x170(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0x154(%rsp)
movq 0x170(%rsp), %rax
movl 0x4(%rax), %eax
movl %eax, 0x150(%rsp)
movslq 0x160(%rsp), %rdi
shlq $0x2, %rdi
callq 0x1170
movq %rax, 0x148(%rsp)
movl 0x160(%rsp), %eax
imull 0x150(%rsp), %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x1170
movq %rax, 0x140(%rsp)
movl $0x0, 0x13c(%rsp)
movl 0x13c(%rsp), %eax
cmpl 0x160(%rsp), %eax
jge 0x16b91
movl 0x13c(%rsp), %edx
movq 0x148(%rsp), %rax
movslq 0x13c(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x13c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x13c(%rsp)
jmp 0x16b54
movl 0x160(%rsp), %eax
movl %eax, 0x138(%rsp)
movl 0x138(%rsp), %eax
cmpl 0x158(%rsp), %eax
jge 0x16c09
callq 0x1640
movslq 0x138(%rsp), %rcx
xorl %edx, %edx
divq %rcx
movl %edx, %eax
movl %eax, 0x134(%rsp)
movl 0x134(%rsp), %eax
cmpl 0x160(%rsp), %eax
jge 0x16bf4
movl 0x138(%rsp), %edx
movq 0x148(%rsp), %rax
movslq 0x134(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x16bf6
movl 0x138(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x138(%rsp)
jmp 0x16b9f
movl $0x0, 0x130(%rsp)
movl 0x130(%rsp), %eax
cmpl 0x160(%rsp), %eax
jge 0x16ccf
movl $0x0, 0x12c(%rsp)
movl 0x12c(%rsp), %eax
cmpl 0x150(%rsp), %eax
jge 0x16cb7
movq 0x170(%rsp), %rax
movq 0x20(%rax), %rax
movl 0x12c(%rsp), %ecx
movq 0x148(%rsp), %rdx
movslq 0x130(%rsp), %rsi
movl (%rdx,%rsi,4), %edx
movq 0x170(%rsp), %rsi
imull 0x4(%rsi), %edx
addl %edx, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq 0x140(%rsp), %rax
movl 0x130(%rsp), %ecx
imull 0x150(%rsp), %ecx
addl 0x12c(%rsp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x12c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x12c(%rsp)
jmp 0x16c33
jmp 0x16cb9
movl 0x130(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x130(%rsp)
jmp 0x16c14
movq 0x148(%rsp), %rdi
callq 0x1030
movslq 0x158(%rsp), %rdi
shlq $0x2, %rdi
callq 0x1170
movq %rax, 0x120(%rsp)
movl 0x160(%rsp), %eax
imull 0x150(%rsp), %eax
imull 0x154(%rsp), %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x1170
movq %rax, 0x118(%rsp)
movslq 0x160(%rsp), %rdi
shlq $0x2, %rdi
callq 0x1170
movq %rax, 0x110(%rsp)
movl $0x0, 0x10c(%rsp)
movl 0x10c(%rsp), %eax
cmpl 0x158(%rsp), %eax
jge 0x16d7e
movq 0x120(%rsp), %rax
movslq 0x10c(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movl 0x10c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10c(%rsp)
jmp 0x16d44
movq 0x5273(%rip), %rax      # 0x1bff8
movq (%rax), %rdi
leaq 0x2a36(%rip), %rsi      # 0x197c5
movb $0x0, %al
callq 0x1140
movl $0x0, 0x108(%rsp)
movl 0x108(%rsp), %eax
cmpl 0x15c(%rsp), %eax
jge 0x173ca
movq 0x523c(%rip), %rax      # 0x1bff8
movq (%rax), %rdi
leaq 0x2a0a(%rip), %rsi      # 0x197d0
movb $0x0, %al
callq 0x1140
movl $0x0, 0x104(%rsp)
movl 0x104(%rsp), %eax
cmpl 0x160(%rsp), %eax
jge 0x16e12
movq 0x110(%rsp), %rax
movslq 0x104(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movl 0x104(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x104(%rsp)
jmp 0x16dd8
movl $0x0, 0x100(%rsp)
movl 0x100(%rsp), %eax
cmpl 0x158(%rsp), %eax
jge 0x170ac
movq 0x120(%rsp), %rax
movslq 0x100(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0xfc(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0xf0(%rsp)
movl $0x0, 0xec(%rsp)
movl 0xec(%rsp), %eax
cmpl 0x150(%rsp), %eax
jge 0x16efc
movq 0x140(%rsp), %rax
movl 0xfc(%rsp), %ecx
imull 0x150(%rsp), %ecx
addl 0xec(%rsp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq 0x170(%rsp), %rcx
movq 0x20(%rcx), %rcx
movl 0xec(%rsp), %edx
movl 0x100(%rsp), %esi
movq 0x170(%rsp), %rdi
imull 0x4(%rdi), %esi
addl %esi, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
cvtsi2sd %eax, %xmm0
addsd 0xf0(%rsp), %xmm0
movsd %xmm0, 0xf0(%rsp)
movl 0xec(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xec(%rsp)
jmp 0x16e62
movl 0xfc(%rsp), %eax
movl %eax, 0xe8(%rsp)
movl $0x0, 0xe4(%rsp)
movl 0xe4(%rsp), %eax
cmpl 0x160(%rsp), %eax
jge 0x1702a
xorps %xmm0, %xmm0
movsd %xmm0, 0xd8(%rsp)
movl $0x0, 0xd4(%rsp)
movl 0xd4(%rsp), %eax
cmpl 0x150(%rsp), %eax
jge 0x16fda
movq 0x140(%rsp), %rax
movl 0xe4(%rsp), %ecx
imull 0x150(%rsp), %ecx
addl 0xd4(%rsp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq 0x170(%rsp), %rcx
movq 0x20(%rcx), %rcx
movl 0xd4(%rsp), %edx
movl 0x100(%rsp), %esi
movq 0x170(%rsp), %rdi
imull 0x4(%rdi), %esi
addl %esi, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
setne %al
andb $0x1, %al
movzbl %al, %eax
cvtsi2sd %eax, %xmm0
addsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0xd8(%rsp)
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0x16f40
movsd 0xd8(%rsp), %xmm1
movsd 0xf0(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x17012
movl 0xe4(%rsp), %eax
movl %eax, 0xe8(%rsp)
movsd 0xd8(%rsp), %xmm0
movsd %xmm0, 0xf0(%rsp)
jmp 0x17014
movl 0xe4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xe4(%rsp)
jmp 0x16f15
movl 0xe8(%rsp), %eax
cmpl 0xfc(%rsp), %eax
je 0x17054
movl 0xe8(%rsp), %edx
movq 0x120(%rsp), %rax
movslq 0x100(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x110(%rsp), %rax
movslq 0xe8(%rsp), %rcx
cvtsi2sdl (%rax,%rcx,4), %xmm1
movsd 0xf0(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x17094
cvttsd2si 0xf0(%rsp), %edx
movq 0x110(%rsp), %rax
movslq 0xe8(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x17096
movl 0x100(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x100(%rsp)
jmp 0x16e1d
movl 0x108(%rsp), %eax
movl 0x15c(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x173b2
movl $0x0, 0xd0(%rsp)
movl 0xd0(%rsp), %eax
movl 0x160(%rsp), %ecx
imull 0x150(%rsp), %ecx
imull 0x154(%rsp), %ecx
cmpl %ecx, %eax
jge 0x1711c
movq 0x118(%rsp), %rax
movslq 0xd0(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movl 0xd0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd0(%rsp)
jmp 0x170d0
movl $0x0, 0xcc(%rsp)
movl 0xcc(%rsp), %eax
cmpl 0x158(%rsp), %eax
jge 0x171ff
movl $0x0, 0xc8(%rsp)
movl 0xc8(%rsp), %eax
cmpl 0x150(%rsp), %eax
jge 0x171e7
movq 0x118(%rsp), %rax
movq 0x120(%rsp), %rcx
movslq 0xcc(%rsp), %rdx
movl (%rcx,%rdx,4), %ecx
imull 0x150(%rsp), %ecx
imull 0x154(%rsp), %ecx
movl 0xc8(%rsp), %edx
imull 0x154(%rsp), %edx
addl %edx, %ecx
movq 0x170(%rsp), %rdx
movq 0x20(%rdx), %rdx
movl 0xc8(%rsp), %esi
movl 0xcc(%rsp), %edi
movq 0x170(%rsp), %r8
imull 0x4(%r8), %edi
addl %edi, %esi
movslq %esi, %rsi
addl (%rdx,%rsi,4), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl 0xc8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc8(%rsp)
jmp 0x17146
jmp 0x171e9
movl 0xcc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xcc(%rsp)
jmp 0x17127
movl $0x0, 0xc4(%rsp)
movl 0xc4(%rsp), %eax
cmpl 0x160(%rsp), %eax
jge 0x173b0
movl $0x0, 0xc0(%rsp)
movl 0xc0(%rsp), %eax
cmpl 0x150(%rsp), %eax
jge 0x17398
movl $0x0, 0xbc(%rsp)
movq 0x118(%rsp), %rax
movl 0xc4(%rsp), %ecx
imull 0x150(%rsp), %ecx
imull 0x154(%rsp), %ecx
movl 0xc0(%rsp), %edx
imull 0x154(%rsp), %edx
addl %edx, %ecx
addl $0x0, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0xb8(%rsp)
movl $0x1, 0xb4(%rsp)
movl 0xb4(%rsp), %eax
cmpl 0x154(%rsp), %eax
jge 0x17357
movq 0x118(%rsp), %rax
movl 0xc4(%rsp), %ecx
imull 0x150(%rsp), %ecx
imull 0x154(%rsp), %ecx
movl 0xc0(%rsp), %edx
imull 0x154(%rsp), %edx
addl %edx, %ecx
addl 0xb4(%rsp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
cmpl 0xb8(%rsp), %eax
jle 0x1733f
movl 0xb4(%rsp), %eax
movl %eax, 0xbc(%rsp)
movq 0x118(%rsp), %rax
movl 0xc4(%rsp), %ecx
imull 0x150(%rsp), %ecx
imull 0x154(%rsp), %ecx
movl 0xc0(%rsp), %edx
imull 0x154(%rsp), %edx
addl %edx, %ecx
addl 0xb4(%rsp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0xb8(%rsp)
jmp 0x17341
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
jmp 0x17293
movl 0xbc(%rsp), %edx
movq 0x140(%rsp), %rax
movl 0xc4(%rsp), %ecx
imull 0x150(%rsp), %ecx
addl 0xc0(%rsp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0xc0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc0(%rsp)
jmp 0x17229
jmp 0x1739a
movl 0xc4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc4(%rsp)
jmp 0x1720a
jmp 0x173b2
jmp 0x173b4
movl 0x108(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x108(%rsp)
jmp 0x16da1
movq 0x4c27(%rip), %rax      # 0x1bff8
movq (%rax), %rdi
leaq 0x2cd8(%rip), %rsi      # 0x1a0b3
movb $0x0, %al
callq 0x1140
movl 0x160(%rsp), %eax
imull 0x160(%rsp), %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x1170
movq %rax, 0xa8(%rsp)
movl $0x0, 0xa4(%rsp)
movl 0xa4(%rsp), %eax
movl 0x160(%rsp), %ecx
imull 0x160(%rsp), %ecx
cmpl %ecx, %eax
jge 0x17455
movq 0xa8(%rsp), %rax
movslq 0xa4(%rsp), %rcx
xorps %xmm0, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl 0xa4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa4(%rsp)
jmp 0x17410
movl $0x0, 0xa0(%rsp)
movl 0xa0(%rsp), %eax
cmpl 0x160(%rsp), %eax
jge 0x17579
movl $0x0, 0x9c(%rsp)
movl 0x9c(%rsp), %eax
cmpl 0x160(%rsp), %eax
jge 0x17561
movl $0x0, 0x98(%rsp)
movl 0x98(%rsp), %eax
cmpl 0x150(%rsp), %eax
jge 0x17549
movq 0x140(%rsp), %rax
movl 0xa0(%rsp), %ecx
imull 0x150(%rsp), %ecx
addl 0x98(%rsp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq 0x140(%rsp), %rcx
movl 0x9c(%rsp), %edx
imull 0x150(%rsp), %edx
addl 0x98(%rsp), %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
cvtsi2sd %eax, %xmm0
movq 0xa8(%rsp), %rax
movl 0xa0(%rsp), %ecx
movl 0x9c(%rsp), %edx
imull 0x160(%rsp), %edx
addl %edx, %ecx
movslq %ecx, %rcx
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl 0x98(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x98(%rsp)
jmp 0x1749e
jmp 0x1754b
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x1747f
jmp 0x17563
movl 0xa0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa0(%rsp)
jmp 0x17460
movq 0x140(%rsp), %rdi
callq 0x1030
movq 0x118(%rsp), %rdi
callq 0x1030
movslq 0x160(%rsp), %rdi
shlq $0x2, %rdi
callq 0x1170
movq %rax, 0x90(%rsp)
movslq 0x160(%rsp), %rdi
shlq $0x2, %rdi
callq 0x1170
movq %rax, 0x88(%rsp)
movslq 0x160(%rsp), %rdi
shlq $0x2, %rdi
callq 0x1170
movq %rax, 0x80(%rsp)
movslq 0x158(%rsp), %rdi
shlq $0x2, %rdi
callq 0x1170
movq %rax, 0x78(%rsp)
movslq 0x158(%rsp), %rdi
shlq $0x3, %rdi
callq 0x1170
movq %rax, 0x70(%rsp)
movl 0x158(%rsp), %eax
imull 0x150(%rsp), %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x1170
movq %rax, 0x68(%rsp)
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
cmpl 0x160(%rsp), %eax
jge 0x17660
movq 0x90(%rsp), %rax
movslq 0x64(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x17632
movl $0x0, 0x60(%rsp)
movl 0x60(%rsp), %eax
movq 0x170(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x176a7
movq 0x90(%rsp), %rax
movq 0x120(%rsp), %rcx
movslq 0x60(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0x17668
movl $0x0, 0x5c(%rsp)
movl $0x0, 0x58(%rsp)
movl 0x58(%rsp), %eax
cmpl 0x160(%rsp), %eax
jge 0x17711
movl 0x5c(%rsp), %edx
movq 0x88(%rsp), %rax
movslq 0x58(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x90(%rsp), %rax
movslq 0x58(%rsp), %rcx
movl (%rax,%rcx,4), %eax
addl 0x5c(%rsp), %eax
movl %eax, 0x5c(%rsp)
movl 0x5c(%rsp), %edx
movq 0x80(%rsp), %rax
movslq 0x58(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x176b7
movl $0x0, 0x5c(%rsp)
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
cmpl 0x160(%rsp), %eax
jge 0x1780d
movl $0x0, 0x50(%rsp)
movl 0x50(%rsp), %eax
movq 0x170(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x177fb
movq 0x120(%rsp), %rax
movslq 0x50(%rsp), %rcx
movl (%rax,%rcx,4), %eax
cmpl 0x54(%rsp), %eax
jne 0x177e9
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x150(%rsp), %eax
jge 0x177cd
movq 0x170(%rsp), %rax
movq 0x20(%rax), %rax
movl 0x4c(%rsp), %ecx
movl 0x50(%rsp), %edx
movq 0x170(%rsp), %rsi
imull 0x4(%rsi), %edx
addl %edx, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq 0x68(%rsp), %rax
movl 0x5c(%rsp), %ecx
imull 0x150(%rsp), %ecx
addl 0x4c(%rsp), %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x17770
movl 0x50(%rsp), %edx
movq 0x78(%rsp), %rax
movslq 0x5c(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
jmp 0x177eb
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x1773a
jmp 0x177fd
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x17721
movq 0x168(%rsp), %rax
movsd 0x1833(%rip), %xmm0     # 0x19050
subsd 0x30(%rax), %xmm0
movq 0x170(%rsp), %rax
cvtsi2sdl 0x4(%rax), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, 0x40(%rsp)
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0x158(%rsp), %eax
jge 0x17872
movq 0x70(%rsp), %rax
movslq 0x3c(%rsp), %rcx
movsd 0x17f0(%rip), %xmm0     # 0x19050
movsd %xmm0, (%rax,%rcx,8)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x17841
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x160(%rsp), %eax
jge 0x17a30
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
cmpl 0x160(%rsp), %eax
jge 0x17a1e
movq 0xa8(%rsp), %rax
movl 0x38(%rsp), %ecx
imull 0x160(%rsp), %ecx
addl 0x34(%rsp), %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movsd 0x1b0c(%rip), %xmm1     # 0x193d8
mulsd 0x40(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jb 0x17a0c
movq 0x88(%rsp), %rax
movslq 0x38(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x30(%rsp)
movl 0x30(%rsp), %eax
movq 0x80(%rsp), %rcx
movslq 0x38(%rsp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x17a0a
movq 0x88(%rsp), %rax
movslq 0x34(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movq 0x80(%rsp), %rcx
movslq 0x34(%rsp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x179f8
movl 0x30(%rsp), %eax
cmpl 0x2c(%rsp), %eax
je 0x179e6
movl $0x0, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
movq 0x170(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x179ba
movq 0x68(%rsp), %rax
movl 0x30(%rsp), %ecx
imull 0x150(%rsp), %ecx
addl 0x24(%rsp), %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq 0x68(%rsp), %rcx
movl 0x2c(%rsp), %edx
imull 0x150(%rsp), %edx
addl 0x24(%rsp), %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
addl 0x28(%rsp), %eax
movl %eax, 0x28(%rsp)
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x17956
cvtsi2sdl 0x28(%rsp), %xmm0
ucomisd 0x40(%rsp), %xmm0
jb 0x179e4
movq 0x70(%rsp), %rax
movslq 0x30(%rsp), %rcx
movsd 0x1676(%rip), %xmm0     # 0x19050
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x179e6
jmp 0x179e8
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x1791e
jmp 0x179fa
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x178f0
jmp 0x17a0c
jmp 0x17a0e
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x17893
jmp 0x17a20
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x1787a
movl $0x0, 0x20(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x158(%rsp), %eax
jge 0x17a80
movq 0x70(%rsp), %rax
movslq 0x20(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x170(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x78(%rsp), %rcx
movslq 0x20(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x17a38
movq 0x90(%rsp), %rdi
callq 0x1030
movq 0x88(%rsp), %rdi
callq 0x1030
movq 0x80(%rsp), %rdi
callq 0x1030
movq 0x78(%rsp), %rdi
callq 0x1030
movq 0x70(%rsp), %rdi
callq 0x1030
movq 0x110(%rsp), %rdi
callq 0x1030
movq 0x68(%rsp), %rdi
callq 0x1030
jmp 0x17c43
movl $0x0, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movq 0x170(%rsp), %rcx
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x17c41
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
movl 0x18(%rsp), %eax
movq 0x170(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x17c2f
movl $0x0, 0x14(%rsp)
movl $0x0, 0x10(%rsp)
movl 0x10(%rsp), %eax
movq 0x170(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x17ba5
movq 0x170(%rsp), %rax
movq 0x20(%rax), %rax
movl 0x10(%rsp), %ecx
movl 0x1c(%rsp), %edx
movq 0x170(%rsp), %rsi
imull 0x4(%rsi), %edx
addl %edx, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq 0x170(%rsp), %rcx
movq 0x20(%rcx), %rcx
movl 0x10(%rsp), %edx
movl 0x18(%rsp), %esi
movq 0x170(%rsp), %rdi
imull 0x4(%rdi), %esi
addl %esi, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
addl 0x14(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x10(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
jmp 0x17b27
cvtsi2sdl 0x14(%rsp), %xmm0
movq 0x168(%rsp), %rax
movsd 0x1495(%rip), %xmm1     # 0x19050
subsd 0x30(%rax), %xmm1
movq 0x170(%rsp), %rax
cvtsi2sdl 0x4(%rax), %xmm2
mulsd %xmm2, %xmm1
ucomisd %xmm1, %xmm0
jb 0x17c1d
movq 0x170(%rsp), %rax
movq 0x50(%rax), %rax
movslq 0x1c(%rsp), %rcx
movsd 0x1460(%rip), %xmm0     # 0x19050
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq 0x170(%rsp), %rax
movq 0x50(%rax), %rax
movslq 0x18(%rsp), %rcx
movsd 0x143d(%rip), %xmm0     # 0x19050
addsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x17c1f
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x17b03
jmp 0x17c31
movl 0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
jmp 0x17adf
jmp 0x17c43
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
movq 0x170(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x17c9c
movq 0x170(%rsp), %rax
movq 0x50(%rax), %rax
movslq 0xc(%rsp), %rcx
movsd 0x13dc(%rip), %xmm0     # 0x19050
divsd (%rax,%rcx,8), %xmm0
movq 0x170(%rsp), %rax
movq 0x50(%rax), %rax
movslq 0xc(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x17c4b
jmp 0x17c9e
movl $0x0, 0x8(%rsp)
movl 0x8(%rsp), %eax
movq 0x170(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x17ceb
movq 0x168(%rsp), %rax
movsd 0x38(%rax), %xmm0
movq 0x170(%rsp), %rax
movq 0x50(%rax), %rax
movslq 0x8(%rsp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
movl 0x8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
jmp 0x17ca6
movq 0x170(%rsp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x48(%rax)
movl $0x0, 0x4(%rsp)
movl 0x4(%rsp), %eax
movq 0x170(%rsp), %rcx
cmpl (%rcx), %eax
jge 0x17d48
movq 0x170(%rsp), %rax
movq 0x50(%rax), %rax
movslq 0x4(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq 0x170(%rsp), %rax
addsd 0x48(%rax), %xmm0
movsd %xmm0, 0x48(%rax)
movl 0x4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4(%rsp)
jmp 0x17d03
movq 0x168(%rsp), %rax
movsd 0x30(%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x17dca
movq 0x168(%rsp), %rax
movsd 0x12e2(%rip), %xmm0     # 0x19050
ucomisd 0x30(%rax), %xmm0
jb 0x17dca
movq 0x427c(%rip), %rax      # 0x1bff8
movq (%rax), %rdi
movq 0x170(%rsp), %rax
movsd 0x48(%rax), %xmm0
movq 0x168(%rsp), %rax
movsd 0x12b4(%rip), %xmm2     # 0x19050
subsd 0x30(%rax), %xmm2
movsd 0x135f(%rip), %xmm1     # 0x19108
mulsd %xmm2, %xmm1
movq 0x168(%rsp), %rax
movsd 0x38(%rax), %xmm2
leaq 0x1a11(%rip), %rsi      # 0x197d2
movb $0x3, %al
callq 0x1140
jmp 0x17def
movq 0x4227(%rip), %rax      # 0x1bff8
movq (%rax), %rdi
movq 0x170(%rsp), %rax
movsd 0x48(%rax), %xmm0
leaq 0x1a3c(%rip), %rsi      # 0x19824
movb $0x1, %al
callq 0x1140
addq $0x178, %rsp            # imm = 0x178
retq
nopw (%rax,%rax)