// File: /workspace/github_c_makefile_star2_O3/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 $0x88, %rsp
movq %rdi, %r12
movl (%rdi), %ebp
testl %ebp, %ebp
jle 0xb4f7
movq 0x50(%r12), %rax
leal 0x1(%rbp), %ecx
leaq -0x1(%rbp), %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
shrl %ecx
shlq $0x4, %rcx
pmovsxbq 0x248d(%rip), %xmm1     # 0xd920
xorl %edx, %edx
movdqa 0x1c13(%rip), %xmm2     # 0xd0b0
pxor %xmm2, %xmm0
movabsq $0x3ff0000000000000, %r8 # imm = 0x3FF0000000000000
pcmpeqd %xmm3, %xmm3
pmovsxbq 0x246a(%rip), %xmm4     # 0xd922
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
pcmpgtq %xmm0, %xmm5
movd %xmm5, %edi
notl %edi
testb $0x1, %dil
je 0xb4d5
movq %r8, (%rax,%rdx)
pxor %xmm3, %xmm5
pextrb $0x8, %xmm5, %edi
testb $0x1, %dil
je 0xb4ea
movq %r8, 0x8(%rax,%rdx)
paddq %xmm4, %xmm1
addq $0x10, %rdx
cmpq %rdx, %rcx
jne 0xb4b8
movsd 0x30(%rsi), %xmm0
pxor %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0xbf2c
movsd 0x1b56(%rip), %xmm3     # 0xd068
ucomisd %xmm0, %xmm3
jb 0xbf2c
movl 0x28(%rsi), %edx
testl %edx, %edx
setg %al
cmpl %ebp, %edx
setl %cl
testb %cl, %al
movq %rsi, 0x78(%rsp)
movq %r12, 0x48(%rsp)
movq %rbp, 0x60(%rsp)
je 0xbe0d
movl 0x8(%r12), %r15d
movslq 0x4(%r12), %rbx
movl %ebx, %r13d
leaq (,%rdx,4), %rdi
movq %rdi, 0x38(%rsp)
movq %rdx, 0x8(%rsp)
callq 0x11b0
movq %rax, %r14
movq %rbx, 0x28(%rsp)
imull 0x8(%rsp), %ebx
movq %rbx, 0x30(%rsp)
movslq %ebx, %rdi
shlq $0x2, %rdi
callq 0x11b0
movq 0x8(%rsp), %rbx
movq %rax, 0x10(%rsp)
leal 0x3(%rbx), %eax
andl $-0x4, %eax
leaq -0x1(%rbx), %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
pmovsxbq 0x237b(%rip), %xmm1     # 0xd924
pmovsxbq 0x236e(%rip), %xmm2     # 0xd920
xorl %ecx, %ecx
pxor 0x1af4(%rip), %xmm0     # 0xd0b0
pcmpeqd %xmm3, %xmm3
pmovsxbq 0x235d(%rip), %xmm4     # 0xd926
movdqa %xmm2, %xmm5
pxor 0x1adb(%rip), %xmm5     # 0xd0b0
pcmpgtq %xmm0, %xmm5
movd %xmm5, %edx
notl %edx
testb $0x1, %dl
je 0xb5e9
movl %ecx, (%r14,%rcx,4)
pxor %xmm3, %xmm5
pextrb $0x8, %xmm5, %edx
testb $0x1, %dl
je 0xb600
leal 0x1(%rcx), %edx
movl %edx, 0x4(%r14,%rcx,4)
movdqa %xmm1, %xmm5
pxor 0x1aa4(%rip), %xmm5     # 0xd0b0
pcmpgtq %xmm0, %xmm5
pxor %xmm3, %xmm5
pextrb $0x0, %xmm5, %edx
testb $0x1, %dl
je 0xb628
leal 0x2(%rcx), %edx
movl %edx, 0x8(%r14,%rcx,4)
pextrb $0x8, %xmm5, %edx
testb $0x1, %dl
je 0xb63b
leal 0x3(%rcx), %edx
movl %edx, 0xc(%r14,%rcx,4)
addq $0x4, %rcx
paddq %xmm4, %xmm2
paddq %xmm4, %xmm1
cmpq %rcx, %rax
jne 0xb5c9
callq 0x2623
xorl %edx, %edx
divq %rbx
cmpl %edx, 0x8(%rsp)
jle 0xb664
movl %ebx, (%r14,%rdx,4)
incq %rbx
cmpl %ebx, %ebp
jg 0xb650
movq %r14, 0x18(%rsp)
leaq (,%r13,4), %rax
movq %rax, 0x40(%rsp)
xorl %r14d, %r14d
xorl %ebx, %ebx
movq 0x8(%rsp), %rax
testl %r13d, %r13d
jle 0xb6c2
movl %r14d, %eax
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,4), %rdi
movq 0x18(%rsp), %rax
movslq (%rax,%rbx,4), %rax
movslq 0x4(%r12), %rsi
imulq %rax, %rsi
shlq $0x2, %rsi
addq 0x20(%r12), %rsi
movq 0x40(%rsp), %rdx
callq 0x11a0
movq 0x8(%rsp), %rax
incq %rbx
addl 0x28(%rsp), %r14d
cmpq %rbx, %rax
jne 0xb687
movq 0x18(%rsp), %rdi
callq 0x1050
leaq (,%rbp,4), %rsi
movl $0x1, %edi
movq %rsi, 0x70(%rsp)
callq 0x1160
movq %rax, 0x50(%rsp)
movq 0x30(%rsp), %r14
imull %r15d, %r14d
movslq %r14d, %rdi
shlq $0x2, %rdi
callq 0x11b0
movq %rax, %rbx
movq 0x38(%rsp), %rdi
callq 0x11b0
movq %rax, 0x68(%rsp)
movq 0x58d5(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x2207(%rip), %rdi      # 0xd934
movl $0xa, %esi
movl $0x1, %edx
callq 0x1210
movq %r14, 0x30(%rsp)
leaq (,%r14,4), %rax
movq %rax, 0x58(%rsp)
movq 0x28(%rsp), %rax
leaq (,%rax,4), %r14
movl %r13d, %eax
imull %r15d, %eax
movl %eax, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x5882(%rip), %rax      # 0x10ff8
movq (%rax), %rsi
movl $0x2e, %edi
callq 0x1140
movq 0x68(%rsp), %rdi
xorl %esi, %esi
movq 0x38(%rsp), %rdx
callq 0x1110
xorl %eax, %eax
movsd 0x18ca(%rip), %xmm3     # 0xd068
movq 0x50(%rsp), %rdi
movl (%rdi,%rax,4), %ecx
movslq %eax, %rdx
cmpl $0x0, 0x28(%rsp)
jle 0xb7fb
movl %ecx, %edi
imull %r13d, %edi
movslq 0x4(%r12), %rsi
movslq %edi, %rdi
movq 0x10(%rsp), %r8
leaq (%r8,%rdi,4), %rdi
imulq %rdx, %rsi
shlq $0x2, %rsi
addq 0x20(%r12), %rsi
pxor %xmm0, %xmm0
xorl %r8d, %r8d
movl (%rdi,%r8,4), %r9d
movapd %xmm3, %xmm1
cmpl (%rsi,%r8,4), %r9d
jne 0xb7ed
xorpd %xmm1, %xmm1
addsd %xmm1, %xmm0
incq %r8
cmpq %r8, %r13
jne 0xb7db
jmp 0xb7ff
pxor %xmm0, %xmm0
movq 0x10(%rsp), %rdi
xorl %r8d, %r8d
movl %ecx, %esi
testl %r13d, %r13d
jle 0xb847
movslq 0x4(%r12), %r9
imulq %rdx, %r9
shlq $0x2, %r9
addq 0x20(%r12), %r9
xorpd %xmm1, %xmm1
xorl %r10d, %r10d
movl (%rdi,%r10,4), %r11d
movapd %xmm3, %xmm2
cmpl (%r9,%r10,4), %r11d
jne 0xb839
xorpd %xmm2, %xmm2
addsd %xmm2, %xmm1
incq %r10
cmpq %r10, %r13
jne 0xb827
jmp 0xb84b
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
minsd %xmm0, %xmm1
cmoval %r8d, %esi
incq %r8
addq %r14, %rdi
movapd %xmm1, %xmm0
cmpq 0x8(%rsp), %r8
jne 0xb809
cmpl %ecx, %esi
movq 0x50(%rsp), %rdi
je 0xb874
movl %esi, (%rdi,%rax,4)
movslq %esi, %rcx
movq 0x68(%rsp), %rdx
xorps %xmm0, %xmm0
cvtsi2sdl (%rdx,%rcx,4), %xmm0
ucomisd %xmm0, %xmm1
jbe 0xb896
cvttsd2si %xmm1, %edx
movq 0x68(%rsp), %rsi
movl %edx, (%rsi,%rcx,4)
incq %rax
cmpq %rbp, %rax
jne 0xb7a3
cmpl $0x9, 0x20(%rsp)
je 0xb9a8
cmpl $0x0, 0x30(%rsp)
jle 0xb8c3
movq %rbx, %rdi
xorl %esi, %esi
movq 0x58(%rsp), %rdx
callq 0x1110
xorl %eax, %eax
movq 0x50(%rsp), %r8
testl %r13d, %r13d
jle 0xb905
movslq 0x4(%r12), %rdx
movslq %eax, %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq 0x20(%r12), %rcx
movl (%r8,%rax,4), %edx
imull 0x18(%rsp), %edx
xorl %esi, %esi
movl (%rcx,%rsi,4), %edi
addl %edx, %edi
movslq %edi, %rdi
incl (%rbx,%rdi,4)
incq %rsi
addl %r15d, %edx
cmpq %rsi, %r13
jne 0xb8ef
incq %rax
cmpq %rbp, %rax
jne 0xb8ca
xorl %eax, %eax
xorl %ecx, %ecx
cmpl $0x0, 0x28(%rsp)
jle 0xb97b
movq %rcx, %rdx
imulq %r13, %rdx
movl %eax, %esi
xorl %edi, %edi
leaq (%rdi,%rdx), %r8
xorl %r9d, %r9d
cmpl $0x2, %r15d
jl 0xb964
movslq %esi, %r9
leaq (%rbx,%r9,4), %r10
movl %r8d, %r9d
imull %r15d, %r9d
movslq %r9d, %r9
movl (%rbx,%r9,4), %r11d
xorl %r9d, %r9d
movl $0x1, %ebp
movl (%r10,%rbp,4), %r12d
cmpl %r11d, %r12d
cmovgl %ebp, %r9d
cmovgl %r12d, %r11d
incq %rbp
cmpq %rbp, %r15
jne 0xb94d
movslq %r8d, %r8
movq 0x10(%rsp), %r10
movl %r9d, (%r10,%r8,4)
incq %rdi
addl %r15d, %esi
cmpq %r13, %rdi
jne 0xb923
incq %rcx
addl 0x18(%rsp), %eax
cmpq 0x8(%rsp), %rcx
jne 0xb911
movq 0x20(%rsp), %rax
incl %eax
movq %rax, 0x20(%rsp)
cmpl $0xa, %eax
movq 0x48(%rsp), %r12
movq 0x60(%rsp), %rbp
jne 0xb76f
movq 0x5649(%rip), %rax      # 0x10ff8
movq (%rax), %rsi
movl $0xa, %edi
callq 0x1140
movq 0x8(%rsp), %rax
movl %eax, %r15d
imull %eax, %r15d
leaq (,%r15,8), %rdi
callq 0x11b0
cmpq $0x1, %r15
adcq $0x0, %r15
shlq $0x3, %r15
movq %r15, %rdx
xorl %r15d, %r15d
movq %rax, 0x80(%rsp)
movq %rax, %rdi
xorl %esi, %esi
callq 0x1110
movq 0x8(%rsp), %r11
movsd 0x1662(%rip), %xmm0     # 0xd068
xorl %eax, %eax
movl %r15d, %ecx
movq 0x10(%rsp), %rsi
leaq (%rsi,%rcx,4), %rcx
movq 0x80(%rsp), %rdx
leaq (%rdx,%rax,8), %rdx
xorl %edi, %edi
testl %r13d, %r13d
jle 0xba5b
movq %rdi, %r8
imulq %r11, %r8
movsd (%rdx,%r8,8), %xmm1
xorl %r9d, %r9d
movl (%rcx,%r9,4), %r10d
movapd %xmm0, %xmm2
cmpl (%rsi,%r9,4), %r10d
je 0xba49
xorpd %xmm2, %xmm2
addsd %xmm2, %xmm1
incq %r9
cmpq %r9, %r13
jne 0xba37
movsd %xmm1, (%rdx,%r8,8)
incq %rdi
addq 0x40(%rsp), %rsi
cmpq %r11, %rdi
jne 0xba22
incq %rax
addl %r13d, %r15d
cmpq %r11, %rax
jne 0xba08
movq 0x10(%rsp), %rdi
callq 0x1050
movq %rbx, %rdi
callq 0x1050
movl $0x1, %edi
movq 0x38(%rsp), %rbx
movq %rbx, %rsi
callq 0x1160
movq %rax, %r15
movq %rbx, %rdi
callq 0x11b0
movq %rax, 0x18(%rsp)
movq %rbx, %rdi
movq %r15, %rbx
callq 0x11b0
movq %rax, 0x20(%rsp)
movq 0x70(%rsp), %rdi
callq 0x11b0
movq %rax, 0x30(%rsp)
leaq (,%rbp,8), %rdi
callq 0x11b0
movq %rax, %r15
movq 0x28(%rsp), %rax
imull %ebp, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x11b0
movq %rax, 0x38(%rsp)
movl (%r12), %esi
testl %esi, %esi
movq 0x50(%rsp), %rdx
jle 0xbb0d
xorl %eax, %eax
movslq (%rdx,%rax,4), %rcx
incl (%rbx,%rcx,4)
incq %rax
cmpq %rax, %rsi
jne 0xbafe
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x8(%rsp), %r8
movq 0x18(%rsp), %rdi
movq 0x20(%rsp), %r9
movl %ecx, (%rdi,%rax,4)
addl (%rbx,%rax,4), %ecx
movl %ecx, (%r9,%rax,4)
incq %rax
cmpq %rax, %r8
jne 0xbb20
movq %rbx, 0x70(%rsp)
xorl %r12d, %r12d
xorl %ebx, %ebx
movq %rsi, 0x58(%rsp)
movq 0x30(%rsp), %rax
testl %esi, %esi
jle 0xbbae
xorl %ebp, %ebp
cmpl %r12d, (%rdx,%rbp,4)
jne 0xbba6
testl %r13d, %r13d
jle 0xbb9e
movq 0x48(%rsp), %rcx
movslq 0x4(%rcx), %rax
movslq %ebp, %rsi
imulq %rax, %rsi
movl %ebx, %eax
imull %r13d, %eax
cltq
movq 0x38(%rsp), %rdx
leaq (%rdx,%rax,4), %rdi
shlq $0x2, %rsi
addq 0x20(%rcx), %rsi
movq 0x40(%rsp), %rdx
callq 0x11a0
movq 0x30(%rsp), %rax
movq 0x58(%rsp), %rsi
movq 0x50(%rsp), %rdx
movq 0x8(%rsp), %r8
movslq %ebx, %rbx
movl %ebp, (%rax,%rbx,4)
incl %ebx
incq %rbp
cmpq %rbp, %rsi
jne 0xbb4c
incl %r12d
cmpl %r8d, %r12d
jne 0xbb46
movsd 0x14aa(%rip), %xmm0     # 0xd068
movapd %xmm0, %xmm2
movq 0x78(%rsp), %rax
subsd 0x30(%rax), %xmm2
movq 0x48(%rsp), %rax
movl 0x4(%rax), %eax
cvtsi2sd %eax, %xmm1
mulsd %xmm2, %xmm1
movq 0x60(%rsp), %rdx
leaq 0x1(%rdx), %rcx
andq $-0x2, %rcx
decq %rdx
movq %rdx, %xmm2
pshufd $0x44, %xmm2, %xmm2     # xmm2 = xmm2[0,1,0,1]
pmovsxbq 0x1d21(%rip), %xmm3     # 0xd920
xorl %edx, %edx
pxor 0x14a7(%rip), %xmm2     # 0xd0b0
movabsq $0x3ff0000000000000, %rsi # imm = 0x3FF0000000000000
pcmpeqd %xmm4, %xmm4
pmovsxbq 0x1d02(%rip), %xmm5     # 0xd922
movdqa %xmm3, %xmm6
pxor 0x1484(%rip), %xmm6     # 0xd0b0
pcmpgtq %xmm2, %xmm6
movd %xmm6, %edi
notl %edi
testb $0x1, %dil
je 0xbc41
movq %rsi, (%r15,%rdx,8)
pxor %xmm4, %xmm6
pextrb $0x8, %xmm6, %edi
testb $0x1, %dil
je 0xbc56
movq %rsi, 0x8(%r15,%rdx,8)
addq $0x2, %rdx
paddq %xmm5, %xmm3
cmpq %rdx, %rcx
jne 0xbc20
movsd 0x1835(%rip), %xmm2     # 0xd4a0
mulsd %xmm1, %xmm2
xorl %ecx, %ecx
movq %rcx, 0x28(%rsp)
imulq %r8, %rcx
movq 0x80(%rsp), %rdx
leaq (%rdx,%rcx,8), %rcx
movq %rcx, 0x40(%rsp)
xorl %edx, %edx
movq 0x40(%rsp), %rcx
movq %rdx, 0x10(%rsp)
movsd (%rcx,%rdx,8), %xmm3
ucomisd %xmm2, %xmm3
jb 0xbd60
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rdx
movslq (%rcx,%rdx,4), %rdi
movq 0x20(%rsp), %rcx
movslq (%rcx,%rdx,4), %r8
cmpl %r8d, %edi
jge 0xbd60
movq 0x18(%rsp), %rcx
movq 0x10(%rsp), %rdx
movslq (%rcx,%rdx,4), %r9
movq 0x20(%rsp), %rcx
movslq (%rcx,%rdx,4), %r10
movq %r14, %r11
imulq %r9, %r11
movq 0x38(%rsp), %rcx
addq %rcx, %r11
movq %r14, %r13
imulq %rdi, %r13
addq %rcx, %r13
movq %r11, %rbx
movq %r9, %rbp
cmpl %r10d, %r9d
jge 0xbd55
cmpq %rdi, %rbp
je 0xbd4a
testl %eax, %eax
jle 0xbd30
xorl %edx, %edx
xorl %ecx, %ecx
movl (%r13,%rdx,4), %r12d
xorl %esi, %esi
cmpl (%rbx,%rdx,4), %r12d
sete %sil
addl %esi, %ecx
incq %rdx
cmpq %rdx, %rax
jne 0xbd0e
xorps %xmm3, %xmm3
cvtsi2sd %ecx, %xmm3
jmp 0xbd34
xorpd %xmm3, %xmm3
ucomisd %xmm1, %xmm3
jb 0xbd4a
movsd (%r15,%rdi,8), %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, (%r15,%rdi,8)
incq %rbp
addq %r14, %rbx
cmpq %r10, %rbp
jne 0xbd01
incq %rdi
addq %r14, %r13
cmpq %r8, %rdi
jne 0xbcf6
movq 0x10(%rsp), %rdx
incq %rdx
movq 0x8(%rsp), %r8
cmpq %r8, %rdx
jne 0xbc8d
movq 0x28(%rsp), %rcx
incq %rcx
cmpq %r8, %rcx
jne 0xbc71
movq 0x48(%rsp), %r12
movq 0x50(%r12), %rax
xorl %ecx, %ecx
movq 0x60(%rsp), %rsi
movq 0x30(%rsp), %rbx
movsd (%r15,%rcx,8), %xmm0
movslq (%rbx,%rcx,4), %rdx
movsd %xmm0, (%rax,%rdx,8)
incq %rcx
cmpq %rcx, %rsi
jne 0xbd9d
movq 0x70(%rsp), %rdi
callq 0x1050
movq 0x18(%rsp), %rdi
callq 0x1050
movq 0x20(%rsp), %rdi
callq 0x1050
movq %rbx, %rdi
callq 0x1050
movq %r15, %rdi
callq 0x1050
movq 0x68(%rsp), %rdi
callq 0x1050
movq 0x38(%rsp), %rdi
callq 0x1050
movq 0x78(%rsp), %rsi
movsd 0x1265(%rip), %xmm3     # 0xd068
movq 0x58(%rsp), %rbp
jmp 0xbf09
cmpl $0x2, %ebp
jl 0xbf09
leal -0x1(%rbp), %eax
movq %rax, 0x40(%rsp)
movl 0x4(%r12), %ecx
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
leaq (,%rcx,4), %rdx
movl $0x1, %edi
xorl %eax, %eax
movq %rdx, %r8
xorl %r10d, %r10d
movq %rax, 0x8(%rsp)
movl %eax, %r11d
shlq $0x2, %r11
leaq 0x1(%r10), %rax
movq %rax, 0x10(%rsp)
movq %r8, %rbx
movq %rdi, %r14
testl %ecx, %ecx
jle 0xbea1
movq 0x20(%r12), %r15
leaq (%r15,%r11), %r12
addq %rbx, %r15
xorl %r13d, %r13d
xorl %ebp, %ebp
movl (%r12,%r13,4), %eax
xorl %r9d, %r9d
cmpl (%r15,%r13,4), %eax
sete %r9b
addl %r9d, %ebp
incq %r13
cmpq %r13, %rcx
jne 0xbe6f
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
movq 0x78(%rsp), %rsi
movq 0x48(%rsp), %r12
movq 0x60(%rsp), %rbp
jmp 0xbea5
xorpd %xmm1, %xmm1
movapd %xmm3, %xmm2
subsd 0x30(%rsi), %xmm2
mulsd %xmm0, %xmm2
ucomisd %xmm2, %xmm1
jb 0xbedd
movq 0x50(%r12), %rax
movsd (%rax,%r10,8), %xmm1
addsd %xmm3, %xmm1
movsd %xmm1, (%rax,%r10,8)
movsd (%rax,%r14,8), %xmm1
addsd %xmm3, %xmm1
movsd %xmm1, (%rax,%r14,8)
incq %r14
addq %rdx, %rbx
cmpq %rbp, %r14
jne 0xbe5a
incq %rdi
movq 0x8(%rsp), %rax
addl %ecx, %eax
addq %rdx, %r8
movq 0x10(%rsp), %r10
cmpq 0x40(%rsp), %r10
jne 0xbe3f
testl %ebp, %ebp
jle 0xbf7e
movq 0x50(%r12), %rax
movl %ebp, %ecx
xorl %edx, %edx
movapd %xmm3, %xmm0
divsd (%rax,%rdx,8), %xmm0
movsd %xmm0, (%rax,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0xbf16
testl %ebp, %ebp
jle 0xbf7e
movq 0x50(%r12), %rcx
movl %ebp, %eax
xorl %edx, %edx
movsd 0x38(%rsi), %xmm0
mulsd (%rcx,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0xbf39
movq $0x0, 0x48(%r12)
xorpd %xmm0, %xmm0
testl %ebp, %ebp
jle 0xbf8b
movq 0x50(%r12), %rcx
xorl %edx, %edx
addsd (%rcx,%rdx,8), %xmm0
movsd %xmm0, 0x48(%r12)
incq %rdx
cmpq %rdx, %rax
jne 0xbf68
jmp 0xbf8b
movq $0x0, 0x48(%r12)
xorpd %xmm0, %xmm0
movsd 0x30(%rsi), %xmm2
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm2
movq 0x5059(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
jb 0xbfe2
movsd 0x10bc(%rip), %xmm1     # 0xd068
ucomisd %xmm2, %xmm1
jb 0xbfe2
subsd %xmm2, %xmm1
mulsd 0x195a(%rip), %xmm1     # 0xd918
movsd 0x38(%rsi), %xmm2
leaq 0x1975(%rip), %rsi      # 0xd93f
movb $0x3, %al
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1180
leaq 0x19a8(%rip), %rsi      # 0xd991
movb $0x1, %al
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1180