// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rsi, %r12
movq %rdi, %r14
movl (%rdi), %r13d
xorl %eax, %eax
testl %r13d, %r13d
movl $0x0, %ecx
cmovgl %r13d, %ecx
movq %rcx, 0x10(%rsp)
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
cmpq %rax, 0x10(%rsp)
je 0xa0c0
movq 0x50(%r14), %rcx
movq %rdx, (%rcx,%rax,8)
incq %rax
jmp 0xa0ac
movsd 0x30(%r12), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xa92b
movsd 0x1f8b(%rip), %xmm3     # 0xc068
ucomisd %xmm0, %xmm3
jb 0xa92b
movl 0x28(%r12), %edx
testl %edx, %edx
setg %al
cmpl %r13d, %edx
setl %cl
testb %cl, %al
je 0xa157
movq %r13, 0x40(%rsp)
movq %rdx, %r15
movslq 0x8(%r14), %rbx
movslq 0x4(%r14), %rbp
leaq (,%rdx,4), %rdi
movq %rdi, 0x60(%rsp)
callq 0x11a0
movq %rax, %r13
movq %r15, (%rsp)
movslq %r15d, %rdi
movq %rbp, 0x18(%rsp)
imulq %rbp, %rdi
movq %rdi, 0x8(%rsp)
shlq $0x2, %rdi
callq 0x11a0
movq %rax, %r15
xorl %eax, %eax
cmpq %rax, (%rsp)
je 0xa21a
movl %eax, (%r13,%rax,4)
incq %rax
jmp 0xa143
pushq $0x1
popq %rax
cmpl $0x2, %r13d
pushq $0x1
popq %rcx
cmovgel %r13d, %ecx
decl %ecx
xorl %edx, %edx
cmpq %rcx, %rdx
je 0xa243
movq %rax, %rsi
cmpl %esi, %r13d
jle 0xa20f
movl 0x4(%r14), %edi
xorl %r8d, %r8d
testl %edi, %edi
movl $0x0, %r9d
cmovgl %edi, %r9d
movl %esi, %r10d
imull %edi, %r10d
movslq %r10d, %r10
movl %edx, %r11d
imull %edi, %r11d
movslq %r11d, %r11
subq $0x1, %r9
jb 0xa1c9
movq 0x20(%r14), %rbx
movl (%rbx,%r11,4), %ebp
xorl %r15d, %r15d
cmpl (%rbx,%r10,4), %ebp
sete %r15b
addl %r15d, %r8d
incq %r10
incq %r11
jmp 0xa1a5
cvtsi2sd %r8d, %xmm0
movapd %xmm3, %xmm1
subsd 0x30(%r12), %xmm1
cvtsi2sd %edi, %xmm2
mulsd %xmm1, %xmm2
ucomisd %xmm2, %xmm0
jb 0xa207
movq 0x50(%r14), %rdi
movsd (%rdi,%rdx,8), %xmm0
addsd %xmm3, %xmm0
movsd %xmm0, (%rdi,%rdx,8)
movsd (%rdi,%rsi,8), %xmm0
addsd %xmm3, %xmm0
movsd %xmm0, (%rdi,%rsi,8)
incq %rsi
jmp 0xa175
incq %rdx
incq %rax
jmp 0xa169
movq %r12, 0x68(%rsp)
movq (%rsp), %r12
cmpl %r12d, 0x40(%rsp)
jle 0xa252
callq 0x148d
xorl %edx, %edx
divq %r12
cmpl %edx, (%rsp)
jle 0xa23e
movl %r12d, (%r13,%rdx,4)
incq %r12
jmp 0xa223
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
jmp 0xa901
xorl %eax, %eax
movq 0x18(%rsp), %rcx
testl %ecx, %ecx
movl $0x0, %ebp
cmovgl %ecx, %ebp
leaq (,%rcx,4), %r12
movq %r15, %rcx
cmpq (%rsp), %rax
je 0xa2a3
xorl %edx, %edx
cmpq %rdx, %rbp
je 0xa29b
movslq (%r13,%rax,4), %rsi
movslq 0x4(%r14), %rdi
imulq %rsi, %rdi
shlq $0x2, %rdi
addq 0x20(%r14), %rdi
movl (%rdi,%rdx,4), %esi
movl %esi, (%rcx,%rdx,4)
incq %rdx
jmp 0xa276
incq %rax
addq %r12, %rcx
jmp 0xa26e
movq %r13, %rdi
callq 0x1050
movq 0x40(%rsp), %rax
leaq (,%rax,4), %rdi
movq %rdi, 0x70(%rsp)
callq 0x11a0
movq %rax, 0x28(%rsp)
movq 0x8(%rsp), %rax
imull %ebx, %eax
movq %rax, 0x8(%rsp)
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x11a0
movq %rax, %r13
movq 0x60(%rsp), %rdi
callq 0x11a0
movq %rax, 0x50(%rsp)
xorl %eax, %eax
movq 0x28(%rsp), %rcx
cmpq %rax, 0x10(%rsp)
je 0xa309
andl $0x0, (%rcx,%rax,4)
incq %rax
jmp 0xa2f9
movq 0x5ce8(%rip), %rax      # 0xfff8
movq (%rax), %rcx
leaq 0x2586(%rip), %rdi      # 0xc8a0
pushq $0xa
popq %rsi
pushq $0x1
popq %rdx
callq 0x1200
xorl %ecx, %ecx
movq 0x8(%rsp), %rax
testl %eax, %eax
cmovlel %ecx, %eax
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rax
imull %ebx, %eax
movl %eax, 0x48(%rsp)
movq 0x5caf(%rip), %rax      # 0xfff8
movq (%rax), %rsi
cmpl $0xa, %ecx
je 0xa562
movq %rcx, 0x20(%rsp)
pushq $0x2e
popq %rdi
callq 0x1130
xorl %eax, %eax
movsd 0x1cfc(%rip), %xmm3     # 0xc068
cmpq %rax, (%rsp)
je 0xa380
movq 0x50(%rsp), %rcx
andl $0x0, (%rcx,%rax,4)
incq %rax
jmp 0xa36c
xorl %eax, %eax
cmpq 0x10(%rsp), %rax
je 0xa46c
movq 0x28(%rsp), %rcx
movl (%rcx,%rax,4), %ecx
movl %ecx, %edx
imull 0x18(%rsp), %edx
movslq %edx, %rdx
leaq (%r15,%rdx,4), %rsi
xorpd %xmm0, %xmm0
xorl %edi, %edi
movslq %eax, %rdx
cmpq %rdi, %rbp
je 0xa3dc
movslq 0x4(%r14), %r8
imulq %r8, %rdx
shlq $0x2, %rdx
addq 0x20(%r14), %rdx
movl (%rsi,%rdi,4), %r8d
movapd %xmm3, %xmm1
cmpl (%rdx,%rdi,4), %r8d
jne 0xa3d3
xorpd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %rdi
jmp 0xa3a9
movq %r15, %rdi
xorl %r8d, %r8d
movl %ecx, %esi
cmpq (%rsp), %r8
je 0xa439
xorpd %xmm1, %xmm1
xorl %r9d, %r9d
cmpq %r9, %rbp
je 0xa421
movslq 0x4(%r14), %r10
imulq %rdx, %r10
shlq $0x2, %r10
addq 0x20(%r14), %r10
movl (%rdi,%r9,4), %r11d
movapd %xmm3, %xmm2
cmpl (%r10,%r9,4), %r11d
jne 0xa418
xorpd %xmm2, %xmm2
addsd %xmm2, %xmm1
incq %r9
jmp 0xa3f1
ucomisd %xmm1, %xmm0
cmoval %r8d, %esi
minsd %xmm0, %xmm1
incq %r8
addq %r12, %rdi
movapd %xmm1, %xmm0
jmp 0xa3e4
cmpl %ecx, %esi
je 0xa445
movq 0x28(%rsp), %rcx
movl %esi, (%rcx,%rax,4)
movslq %esi, %rcx
movq 0x50(%rsp), %rdx
cvtsi2sdl (%rdx,%rcx,4), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xa464
cvttsd2si %xmm0, %edx
movq 0x50(%rsp), %rsi
movl %edx, (%rsi,%rcx,4)
incq %rax
jmp 0xa382
movq 0x20(%rsp), %rcx
cmpl $0x9, %ecx
jne 0xa47d
incl %ecx
jmp 0xa342
xorl %eax, %eax
cmpq %rax, 0x8(%rsp)
je 0xa491
andl $0x0, (%r13,%rax,4)
incq %rax
jmp 0xa47f
xorl %eax, %eax
cmpq 0x10(%rsp), %rax
je 0xa4e2
movslq %eax, %rcx
xorl %edx, %edx
cmpl %edx, %ebp
je 0xa4d8
movq 0x28(%rsp), %rsi
movl (%rsi,%rax,4), %esi
imull 0x18(%rsp), %esi
addl %edx, %esi
imull %ebx, %esi
movq 0x20(%r14), %rdi
movslq 0x4(%r14), %r8
imulq %rcx, %r8
addq %rdx, %r8
movslq (%rdi,%r8,4), %rdi
movslq %esi, %rsi
addq %rdi, %rsi
incl (%r13,%rsi,4)
incq %rdx
jmp 0xa49f
incq %rax
movq 0x20(%rsp), %rcx
jmp 0xa493
xorl %esi, %esi
xorl %eax, %eax
cmpl (%rsp), %eax
je 0xa476
movl %eax, 0x30(%rsp)
movl %eax, %edx
imull 0x18(%rsp), %edx
movl %esi, 0x38(%rsp)
xorl %edi, %edi
cmpq %rbp, %rdi
je 0xa54d
movslq %esi, %rax
leaq (,%rax,4), %r8
addq %r13, %r8
leal (%rdx,%rdi), %r9d
movl %r9d, %eax
imull %ebx, %eax
cltq
movl (%r13,%rax,4), %r11d
xorl %r10d, %r10d
pushq $0x1
popq %rax
cmpq %rbx, %rax
jge 0xa53f
movl (%r8,%rax,4), %ecx
cmpl %r11d, %ecx
cmovgl %eax, %r10d
cmovgl %ecx, %r11d
incq %rax
jmp 0xa526
movslq %r9d, %rax
movl %r10d, (%r15,%rax,4)
incq %rdi
addl %ebx, %esi
jmp 0xa4fc
movl 0x30(%rsp), %eax
incl %eax
movl 0x38(%rsp), %esi
addl 0x48(%rsp), %esi
movq 0x20(%rsp), %rcx
jmp 0xa4e6
pushq $0xa
popq %rdi
callq 0x1130
movq (%rsp), %rax
movl %eax, %ebx
imull %eax, %ebx
leaq (,%rbx,8), %rdi
callq 0x11a0
movq %rax, 0x58(%rsp)
xorl %eax, %eax
movq 0x58(%rsp), %rcx
cmpq %rax, %rbx
je 0xa59b
andq $0x0, (%rcx,%rax,8)
incq %rax
jmp 0xa58c
xorl %eax, %eax
movsd 0x1ac3(%rip), %xmm0     # 0xc068
movq %r15, %rcx
movq (%rsp), %r11
cmpq %r11, %rax
je 0xa606
movq 0x58(%rsp), %rdx
leaq (%rdx,%rax,8), %rdx
movq %r15, %rsi
xorl %edi, %edi
cmpq %r11, %rdi
je 0xa5fe
movq %rdi, %r8
imulq %r11, %r8
xorl %r9d, %r9d
cmpq %r9, %rbp
je 0xa5f6
movl (%rcx,%r9,4), %r10d
movapd %xmm0, %xmm1
cmpl (%rsi,%r9,4), %r10d
je 0xa5e5
xorpd %xmm1, %xmm1
addsd (%rdx,%r8,8), %xmm1
movsd %xmm1, (%rdx,%r8,8)
incq %r9
jmp 0xa5ce
incq %rdi
addq %r12, %rsi
jmp 0xa5bf
incq %rax
addq %r12, %rcx
jmp 0xa5ac
movq %r15, %rdi
callq 0x1050
movq %r13, %rdi
callq 0x1050
movq 0x60(%rsp), %rbx
movq %rbx, %rdi
callq 0x11a0
movq %rax, %r13
movq %rbx, %rdi
callq 0x11a0
movq %rax, 0x38(%rsp)
movq %rbx, %rdi
callq 0x11a0
movq %rax, 0x30(%rsp)
movq 0x70(%rsp), %rdi
callq 0x11a0
movq %rax, 0x48(%rsp)
movq 0x40(%rsp), %r15
movq %r15, %rdi
shlq $0x3, %rdi
callq 0x11a0
movq %rax, %rbx
imull 0x18(%rsp), %r15d
movslq %r15d, %rdi
shlq $0x2, %rdi
callq 0x11a0
movq %rax, 0x20(%rsp)
xorl %eax, %eax
movabsq $0x3ff0000000000000, %r10 # imm = 0x3FF0000000000000
cmpq %rax, (%rsp)
je 0xa697
andl $0x0, (%r13,%rax,4)
incq %rax
jmp 0xa686
movl (%r14), %ecx
xorl %eax, %eax
testl %ecx, %ecx
cmovlel %eax, %ecx
movq %rcx, 0x8(%rsp)
cmpq %rax, 0x8(%rsp)
je 0xa6c0
movq 0x28(%rsp), %rcx
movslq (%rcx,%rax,4), %rcx
incl (%r13,%rcx,4)
incq %rax
jmp 0xa6a6
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rax, (%rsp)
je 0xa6e4
movq 0x38(%rsp), %rdx
movl %ecx, (%rdx,%rax,4)
addl (%r13,%rax,4), %ecx
movq 0x30(%rsp), %rdx
movl %ecx, (%rdx,%rax,4)
incq %rax
jmp 0xa6c4
xorl %eax, %eax
xorl %ecx, %ecx
movq %r13, 0x40(%rsp)
cmpl (%rsp), %ecx
je 0xa755
xorl %edx, %edx
cmpq 0x8(%rsp), %rdx
je 0xa751
movq 0x28(%rsp), %rsi
cmpl %ecx, (%rsi,%rdx,4)
jne 0xa74c
movl %eax, %esi
imull 0x18(%rsp), %esi
movslq %esi, %rsi
movq 0x20(%rsp), %rdi
leaq (%rdi,%rsi,4), %rsi
movslq %edx, %rdi
xorl %r8d, %r8d
cmpq %r8, %rbp
je 0xa740
movslq 0x4(%r14), %r9
imulq %rdi, %r9
shlq $0x2, %r9
addq 0x20(%r14), %r9
movl (%r9,%r8,4), %r9d
movl %r9d, (%rsi,%r8,4)
incq %r8
jmp 0xa71e
cltq
movq 0x48(%rsp), %rsi
movl %edx, (%rsi,%rax,4)
incl %eax
incq %rdx
jmp 0xa6f4
incl %ecx
jmp 0xa6ed
movq 0x68(%rsp), %rax
movsd 0x30(%rax), %xmm2
movl 0x4(%r14), %eax
cvtsi2sd %eax, %xmm3
xorl %ecx, %ecx
cmpq %rcx, 0x10(%rsp)
je 0xa779
movq %r10, (%rbx,%rcx,8)
incq %rcx
jmp 0xa769
movsd 0x18e7(%rip), %xmm0     # 0xc068
movapd %xmm0, %xmm1
subsd %xmm2, %xmm1
mulsd %xmm3, %xmm1
movsd 0x1c93(%rip), %xmm2     # 0xc428
mulsd %xmm1, %xmm2
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
movq (%rsp), %rdx
cmpq %rdx, %rcx
je 0xa88b
movq %rcx, 0x18(%rsp)
imulq %rdx, %rcx
movq 0x58(%rsp), %rdx
leaq (%rdx,%rcx,8), %rcx
movq %rcx, 0x28(%rsp)
xorl %esi, %esi
cmpq (%rsp), %rsi
je 0xa87e
movq 0x28(%rsp), %rcx
movsd (%rcx,%rsi,8), %xmm3
ucomisd %xmm2, %xmm3
jae 0xa7e5
incq %rsi
jmp 0xa7c6
movq 0x38(%rsp), %rcx
movq 0x18(%rsp), %rdx
movslq (%rcx,%rdx,4), %rdi
movq 0x30(%rsp), %rcx
movslq (%rcx,%rdx,4), %r8
movq %r12, %r9
imulq %rdi, %r9
addq 0x20(%rsp), %r9
cmpq %r8, %rdi
jge 0xa7e0
movq 0x38(%rsp), %rcx
movslq (%rcx,%rsi,4), %r10
movq 0x30(%rsp), %rcx
movslq (%rcx,%rsi,4), %r11
movq %r12, %rbp
imulq %r10, %rbp
addq 0x20(%rsp), %rbp
cmpq %r11, %r10
jge 0xa876
cmpq %rdi, %r10
je 0xa86e
xorl %ecx, %ecx
xorl %edx, %edx
cmpq %rcx, %rax
je 0xa856
movl (%r9,%rcx,4), %r13d
xorl %r15d, %r15d
cmpl (%rbp,%rcx,4), %r13d
sete %r15b
addl %r15d, %edx
incq %rcx
jmp 0xa839
cvtsi2sd %edx, %xmm3
ucomisd %xmm1, %xmm3
jb 0xa86e
movsd (%rbx,%rdi,8), %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, (%rbx,%rdi,8)
incq %r10
addq %r12, %rbp
jmp 0xa82b
incq %rdi
addq %r12, %r9
jmp 0xa808
movq 0x18(%rsp), %rcx
incq %rcx
jmp 0xa7a0
xorl %eax, %eax
movq 0x68(%rsp), %r12
cmpq %rax, 0x10(%rsp)
je 0xa8b5
movsd (%rbx,%rax,8), %xmm0
movq 0x50(%r14), %rcx
movq 0x48(%rsp), %rdx
movslq (%rdx,%rax,4), %rdx
movsd %xmm0, (%rcx,%rdx,8)
incq %rax
jmp 0xa892
movq 0x40(%rsp), %rdi
callq 0x1050
movq 0x38(%rsp), %rdi
callq 0x1050
movq 0x30(%rsp), %rdi
callq 0x1050
movq 0x48(%rsp), %rdi
callq 0x1050
movq %rbx, %rdi
callq 0x1050
movq 0x50(%rsp), %rdi
callq 0x1050
movq 0x20(%rsp), %rdi
callq 0x1050
movsd 0x1767(%rip), %xmm3     # 0xc068
xorl %eax, %eax
cmpq %rax, 0x8(%rsp)
je 0xa921
movq 0x50(%r14), %rcx
movapd %xmm3, %xmm0
divsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%rcx,%rax,8)
incq %rax
jmp 0xa903
movq 0x8(%rsp), %rax
movq %rax, 0x10(%rsp)
xorl %eax, %eax
cmpq %rax, 0x10(%rsp)
je 0xa94e
movsd 0x38(%r12), %xmm0
movq 0x50(%r14), %rcx
mulsd (%rcx,%rax,8), %xmm0
movsd %xmm0, (%rcx,%rax,8)
incq %rax
jmp 0xa92d
andq $0x0, 0x48(%r14)
xorpd %xmm0, %xmm0
xorl %eax, %eax
cmpq %rax, 0x10(%rsp)
je 0xa974
movq 0x50(%r14), %rcx
addsd (%rcx,%rax,8), %xmm0
movsd %xmm0, 0x48(%r14)
incq %rax
jmp 0xa959
movsd 0x30(%r12), %xmm2
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm2
movq 0x566e(%rip), %rax      # 0xfff8
movq (%rax), %rdi
jb 0xa9cc
movsd 0x16d1(%rip), %xmm1     # 0xc068
ucomisd %xmm2, %xmm1
jb 0xa9cc
subsd %xmm2, %xmm1
mulsd 0x1ee7(%rip), %xmm1     # 0xc890
movsd 0x38(%r12), %xmm2
leaq 0x1ef4(%rip), %rsi      # 0xc8ab
movb $0x3, %al
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1170
leaq 0x1f2a(%rip), %rsi      # 0xc8fd
movb $0x1, %al
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1170