// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/htscodecs/htscodecs/fqzcomp_qual.c
// Function: fqz_qual_stats
void fqz_qual_stats(fqz_slice *s,
                    unsigned char *in, size_t in_size,
                    fqz_param *pm,
                    uint32_t qhist[256],
                    int one_param) {
#define NP 32
    uint32_t qhistb[NP][256] = {{0}};  // both
    uint32_t qhist1[NP][256] = {{0}};  // READ1 only
    uint32_t qhist2[NP][256] = {{0}};  // READ2 only
    uint64_t t1[NP] = {0};             // Count for READ1
    uint64_t t2[NP] = {0};             // COUNT for READ2
    uint32_t avg[2560] = {0};          // Avg qual *and later* avg-to-selector map.

    int dir = 0;
    int last_len = 0;
    int do_dedup = 0;
    size_t rec;
    size_t i, j;
    int num_rec = 0;

    // See what info we've been given.
    // Do we have READ1 / READ2?
    // Do we have selector hidden in the top bits of flag?
    int max_sel = 0;
    int has_r2 = 0;
    for (rec = 0; rec < s->num_records; rec++) {
        if (one_param >= 0 && (s->flags[rec] >> 16) != one_param)
            continue;
        num_rec++;
        if (max_sel < (s->flags[rec] >> 16))
            max_sel = (s->flags[rec] >> 16);
        if (s->flags[rec] & FQZ_FREAD2)
            has_r2 = 1;
    }

    // Dedup detection and histogram stats gathering
    int *avg_qual = calloc((s->num_records+1), sizeof(int));
    if (!avg_qual)
        return;

    rec = i = j = 0;
    while (i < in_size) {
        if (one_param >= 0 && (s->flags[rec] >> 16) != one_param) {
            avg_qual[rec] = 0;
            i += s->len[rec++];
            continue;
        }
        if (rec < s->num_records) {
            j = s->len[rec];
            dir = s->flags[rec] & FQZ_FREAD2 ? 1 : 0;
            if (i > 0 && j == last_len
                && !memcmp(in+i-last_len, in+i, j))
                do_dedup++; // cache which records are dup?
        } else {
            j = in_size - i;
            dir = 0;
        }
        last_len = j;

        uint32_t (*qh)[256] = dir ? qhist2 : qhist1;
        uint64_t *th        = dir ? t2     : t1;

        uint32_t tot = 0;
        for (; i < in_size && j > 0; i++, j--) {
            tot += in[i];
            qhist[in[i]]++;
            qhistb[j & (NP-1)][in[i]]++;
            qh[j & (NP-1)][in[i]]++;
            th[j & (NP-1)]++;
        }
        tot = last_len ? (tot*10.0)/last_len+.5 : 0;

        avg_qual[rec] = tot;
        avg[MIN(2559, tot)]++;

        rec++;
    }
    pm->do_dedup = ((rec+1)/(do_dedup+1) < 500);

    last_len = 0;

    // Unique symbol count
    for (i = pm->max_sym = pm->nsym = 0; i < 256; i++) {
        if (qhist[i])
            pm->max_sym = i, pm->nsym++;
    }


    // Auto tune: does average quality helps us?
    if (pm->do_qa != 0) {
        // Histogram of average qual in avg[]
        // NB: we convert avg[] from count to selector index

        // Few symbols means high compression which means
        // selector bits become more significant fraction.
        // Reduce selector bits by skewing the distribution
        // to not be even binning.
        double qf0 = pm->nsym > 8 ? 0.2 : 0.05;
        double qf1 = pm->nsym > 8 ? 0.5 : 0.22;
        double qf2 = pm->nsym > 8 ? 0.8 : 0.60;

        int total = 0;
        i = 0;
        while (i < 2560) {
            total += avg[i];
            if (total > qf0 * num_rec) {
                //fprintf(stderr, "Q1=%d\n", (int)i);
                break;
            }
            avg[i++] = 0;
        }
        while (i < 2560) {
            total += avg[i];
            if (total > qf1 * num_rec) {
                //fprintf(stderr, "Q2=%d\n", (int)i);
                break;
            }
            avg[i++] = 1;
        }
        while (i < 2560) {
            total += avg[i];
            if (total > qf2 * num_rec) {
                //fprintf(stderr, "Q3=%d\n", (int)i);
                break;
            }
            avg[i++] = 2;
        }
        while (i < 2560)
            avg[i++] = 3;

        // Compute simple entropy of merged signal vs split signal.
        i = 0;
        rec = 0;

        int qbin4[4][NP][256] = {{{0}}};
        int qbin2[2][NP][256] = {{{0}}};
        int qbin1   [NP][256] = {{0}};
        int qcnt4[4][NP] = {{0}};
        int qcnt2[4][NP] = {{0}};
        int qcnt1   [NP] = {0};
        while (i < in_size) {
            if (one_param >= 0 && (s->flags[rec] >> 16) != one_param) {
                i += s->len[rec++];
                continue;
            }
            if ((rec & 7) && rec < s->num_records) {
                // subsample for speed
                i += s->len[rec++];
                continue;
            }
            if (rec < s->num_records)
                j = s->len[rec];
            else
                j = in_size - i;
            last_len = j;

            uint32_t tot = avg_qual[rec];
            int qb4 = avg[MIN(2559, tot)];
            int qb2 = qb4/2;

            for (; i < in_size && j > 0; i++, j--) {
                int x = j & (NP-1);
                qbin4[qb4][x][in[i]]++;  qcnt4[qb4][x]++;
                qbin2[qb2][x][in[i]]++;  qcnt2[qb2][x]++;
                qbin1     [x][in[i]]++;  qcnt1     [x]++;
            }
            rec++;
        }

        double e1 = 0, e2 = 0, e4 = 0;
        for (j = 0; j < NP; j++) {
            for (i = 0; i < 256; i++) {
                if (qbin1   [j][i]) e1 += qbin1   [j][i] * fast_log(qbin1   [j][i] / (double)qcnt1   [j]);
                if (qbin2[0][j][i]) e2 += qbin2[0][j][i] * fast_log(qbin2[0][j][i] / (double)qcnt2[0][j]);
                if (qbin2[1][j][i]) e2 += qbin2[1][j][i] * fast_log(qbin2[1][j][i] / (double)qcnt2[1][j]);
                if (qbin4[0][j][i]) e4 += qbin4[0][j][i] * fast_log(qbin4[0][j][i] / (double)qcnt4[0][j]);
                if (qbin4[1][j][i]) e4 += qbin4[1][j][i] * fast_log(qbin4[1][j][i] / (double)qcnt4[1][j]);
                if (qbin4[2][j][i]) e4 += qbin4[2][j][i] * fast_log(qbin4[2][j][i] / (double)qcnt4[2][j]);
                if (qbin4[3][j][i]) e4 += qbin4[3][j][i] * fast_log(qbin4[3][j][i] / (double)qcnt4[3][j]);
            }
        }
        e1 /= -log(2)/8;
        e2 /= -log(2)/8;
        e4 /= -log(2)/8;
        //fprintf(stderr, "E1=%f E2=%f E4=%f %f\n", e1, e2+s->num_records/8, e4+s->num_records/4, (e4+s->num_records/4)/(e2+s->num_records/8));

        // Note by using the selector we're robbing bits from elsewhere in
        // the context, which may reduce compression better.
        // We don't know how much by, so this is basically a guess!
        // For now we just say need 5% saving here.
        double qm = pm->do_qa > 0 ? 1 : 0.98;
        if ((pm->do_qa == -1 || pm->do_qa >= 4) &&
            e4 + s->num_records/4 < e2*qm + s->num_records/8 &&
            e4 + s->num_records/4 < e1*qm) {
            //fprintf(stderr, "do q4\n");
            for (i = 0; i < s->num_records; i++) {
                //fprintf(stderr, "%d -> %d -> %d, %d\n", (int)i, avg_qual[i], avg[MIN(2559, avg_qual[i])], s->flags[i]>>16);
                s->flags[i] |= avg[MIN(2559, avg_qual[i])] <<16;
            }
            pm->do_sel = 1;
            max_sel = 3;
        } else if ((pm->do_qa == -1 || pm->do_qa >= 2) && e2 + s->num_records/8 < e1*qm) {
            //fprintf(stderr, "do q2\n");
            for (i = 0; i < s->num_records; i++)
                s->flags[i] |= (avg[MIN(2559, avg_qual[i])]>>1) <<16;
            pm->do_sel = 1;
            max_sel = 1;
        }

        if (pm->do_qa == -1) {
            // assume qual, pos, delta in that order.
            if (pm->pbits > 0 && pm->dbits > 0) {
                // 1 from pos/delta
                pm->sloc = pm->dloc-1;
                pm->pbits--;
                pm->dbits--;
                pm->dloc++;
            } else if (pm->dbits >= 2) {
                // 2 from delta
                pm->sloc = pm->dloc;
                pm->dbits -= 2;
                pm->dloc += 2;
            } else if (pm->qbits >= 2) {
                pm->qbits -= 2;
                pm->ploc -= 2;
                pm->sloc = 16-2 - pm->do_r2;
                if (pm->qbits == 6 && pm->qshift == 5)
                    pm->qbits--;
            }
            pm->do_qa = 4;
        }
    }

    // Auto tune: does splitting up READ1 and READ2 help us?
    if (has_r2 || pm->do_r2) { // FIXME: && but debug for now
        double e1 = 0, e2 = 0; // entropy sum

        for (j = 0; j < NP; j++) {
            if (!t1[j] || !t2[j]) continue;
            for (i = 0; i < 256; i++) {
                if (!qhistb[j][i]) continue;
                e1 -= (qhistb[j][i])*log(qhistb[j][i] / (double)(t1[j]+t2[j]));
                if (qhist1[j][i])
                    e2 -= qhist1[j][i] * log(qhist1[j][i] / (double)t1[j]);
                if (qhist2[j][i])
                    e2 -= qhist2[j][i] * log(qhist2[j][i] / (double)t2[j]);
            }
        }
        e1 /= log(2)*8; // bytes
        e2 /= log(2)*8;

        //fprintf(stderr, "read1/2 entropy merge %f split %f\n", e1, e2);

        // Note by using the selector we're robbing bits from elsewhere in
        // the context, which may reduce compression better.
        // We don't know how much by, so this is basically a guess!
        // For now we just say need 5% saving here.
        double qm = pm->do_r2 > 0 ? 1 : 0.95;
        if (e2 + (8+s->num_records/8) < e1*qm) {
            for (rec = 0; rec < s->num_records; rec++) {
                if (one_param >= 0 && (s->flags[rec] >> 16) != one_param)
                    continue;
                int sel = s->flags[rec] >> 16;
                s->flags[rec] =  (s->flags[rec] & 0xffff)
                    | ((s->flags[rec] & FQZ_FREAD2)
                       ? ((sel*2)+1) << 16
                       : ((sel*2)+0) << 16);
                if (max_sel < (s->flags[rec]>>16))
                    max_sel = (s->flags[rec]>>16);
            }
        }
    }

    // We provided explicit selector data or auto-tuned it
    if (max_sel > 0) {
        pm->do_sel = 1;
        pm->max_sel = max_sel;
    }

    free(avg_qual);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x52f08, %rsp          # imm = 0x52F08
movl %r9d, %ebx
movq %r8, 0x20(%rsp)
movq %rcx, (%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, 0x28(%rsp)
movq %rdi, %r14
leaq 0xaf00(%rsp), %r15
xorl %ebp, %ebp
movl $0x8000, %edx           # imm = 0x8000
movq %r15, %rdi
xorl %esi, %esi
callq 0x4260
leaq 0x2af00(%rsp), %r12
movl $0x8000, %edx           # imm = 0x8000
movq %r12, %rdi
xorl %esi, %esi
callq 0x4260
leaq 0x22f00(%rsp), %r13
movl $0x8000, %edx           # imm = 0x8000
movq %r13, %rdi
xorl %esi, %esi
callq 0x4260
leaq 0x400(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x4260
leaq 0x300(%rsp), %rdi
movl $0x100, %edx            # imm = 0x100
xorl %esi, %esi
callq 0x4260
leaq 0x700(%rsp), %rdi
movl $0x2800, %edx           # imm = 0x2800
xorl %esi, %esi
callq 0x4260
movslq (%r14), %rax
testq %rax, %rax
je 0x5c10b
movq 0x10(%r14), %rcx
xorl %edx, %edx
movl $0x1, %esi
xorl %edi, %edi
xorl %ebp, %ebp
xorl %r8d, %r8d
movl (%rcx,%rdx,4), %r9d
movl %r9d, %r10d
shrl $0x10, %r10d
testl %ebx, %ebx
js 0x5c0df
cmpl %ebx, %r10d
jne 0x5c0ef
incl %edi
cmpl %r10d, %ebp
cmovbel %r10d, %ebp
testb %r9b, %r9b
cmovsl %esi, %r8d
incq %rdx
cmpq %rdx, %rax
jne 0x5c0cb
cvtsi2sd %edi, %xmm0
movsd %xmm0, 0x38(%rsp)
testl %r8d, %r8d
sete 0x48(%rsp)
jmp 0x5c11a
xorpd %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
movb $0x1, 0x48(%rsp)
incl %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x4300
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x5c353
movq %r14, 0x18(%rsp)
movl %ebp, 0x14(%rsp)
xorl %ebp, %ebp
movq 0x8(%rsp), %r9
testq %r9, %r9
je 0x5c36a
xorl %eax, %eax
movsd 0x3877e(%rip), %xmm2    # 0x948d8
movsd 0x36ebe(%rip), %xmm3    # 0x93020
movl $0x9ff, %r11d           # imm = 0x9FF
xorl %r8d, %r8d
xorl %r10d, %r10d
xorl %r14d, %r14d
movq %r10, %rcx
movq %r14, %rdx
testl %ebx, %ebx
js 0x5c1b6
movq 0x18(%rsp), %rdi
movq 0x10(%rdi), %rsi
movzwl 0x2(%rsi,%rcx,4), %esi
cmpl %ebx, %esi
je 0x5c1b0
movq 0x30(%rsp), %rsi
movl $0x0, (%rsi,%rcx,4)
movq 0x8(%rdi), %rsi
movl (%rsi,%rcx,4), %esi
incq %rcx
addq %rsi, %rdx
cmpq %r9, %rdx
jb 0x5c177
jmp 0x5c365
movq %rcx, %r10
movq %rdx, %r14
movq 0x18(%rsp), %rdx
movslq (%rdx), %rcx
cmpq %rcx, %r10
jae 0x5c24a
movq 0x8(%rdx), %rcx
movq 0x10(%rdx), %rdx
movl (%rcx,%r10,4), %esi
movl (%rdx,%r10,4), %ecx
shrl $0x7, %ecx
andl $0x1, %ecx
testq %r14, %r14
je 0x5c254
cltq
cmpq %rsi, %rax
jne 0x5c254
movq 0x28(%rsp), %rax
movq %rsi, %rdx
leaq (%rax,%r14), %rsi
movq %rsi, %rdi
movq %rdx, 0x40(%rsp)
subq %rdx, %rdi
movl %r8d, 0x60(%rsp)
movq %r10, 0x50(%rsp)
movl %ecx, 0x70(%rsp)
callq 0x44d0
movl 0x70(%rsp), %ecx
movl $0x9ff, %r11d           # imm = 0x9FF
movsd 0x36dfb(%rip), %xmm3    # 0x93020
movsd 0x386ab(%rip), %xmm2    # 0x948d8
movq 0x50(%rsp), %r10
movl 0x60(%rsp), %r8d
movq 0x8(%rsp), %r9
cmpl $0x1, %eax
adcl $0x0, %r8d
movq 0x40(%rsp), %rax
jmp 0x5c257
movq %r9, %rax
subq %r14, %rax
xorl %ecx, %ecx
jmp 0x5c257
movq %rsi, %rax
testl %ecx, %ecx
movq %r13, %rcx
cmoveq %r12, %rcx
leaq 0x300(%rsp), %rdx
leaq 0x400(%rsp), %rsi
cmoveq %rsi, %rdx
xorpd %xmm0, %xmm0
cmpq %r14, %r9
jbe 0x5c315
testq %rax, %rax
je 0x5c315
movq %r10, 0x50(%rsp)
movl %r8d, 0x60(%rsp)
xorl %esi, %esi
movq %rax, %rdi
movq 0x28(%rsp), %r10
movzbl (%r10,%r14), %r8d
movq 0x20(%rsp), %r9
incl (%r9,%r8,4)
movl %edi, %r9d
andl $0x1f, %r9d
movzbl (%r10,%r14), %r10d
incq (%rdx,%r9,8)
shll $0x2, %r10d
shll $0xa, %r9d
leaq (%rsp,%r9), %r11
addq $0xaf00, %r11           # imm = 0xAF00
incl (%r10,%r11)
addq %rcx, %r9
incl (%r10,%r9)
movq 0x8(%rsp), %r9
addl %r8d, %esi
incq %r14
cmpq %r9, %r14
jae 0x5c2f7
leaq -0x1(%rdi), %r8
cmpq $0x1, %rdi
movq %r8, %rdi
jne 0x5c299
movl %esi, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
mulsd %xmm2, %xmm0
movl 0x60(%rsp), %r8d
movq 0x50(%rsp), %r10
movl $0x9ff, %r11d           # imm = 0x9FF
testl %eax, %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
addsd %xmm3, %xmm0
cvttsd2si %xmm0, %rcx
cmovel %eax, %ecx
movq 0x30(%rsp), %rdx
movl %ecx, (%rdx,%r10,4)
cmpl %r11d, %ecx
cmovael %r11d, %ecx
incl 0x700(%rsp,%rcx,4)
incq %r10
cmpq %r9, %r14
jb 0x5c171
jmp 0x5c370
addq $0x52f08, %rsp          # imm = 0x52F08
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, %r10
jmp 0x5c370
xorl %r8d, %r8d
xorl %r10d, %r10d
incq %r10
incl %r8d
movslq %r8d, %rcx
movq %r10, %rax
xorl %edx, %edx
divq %rcx
xorl %ecx, %ecx
cmpq $0x1f4, %rax            # imm = 0x1F4
setb %cl
movq (%rsp), %rax
movl %ecx, 0xc(%rax)
movq %rax, %rcx
movq $0x0, 0x3c(%rax)
xorl %eax, %eax
movl 0x14(%rsp), %r14d
movq 0x20(%rsp), %rdx
cmpl $0x0, (%rdx,%rax,4)
je 0x5c3b8
movl %eax, 0x3c(%rcx)
incl %ebp
movl %ebp, 0x40(%rcx)
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x5c3aa
movl 0x1c60(%rcx), %eax
testl %eax, %eax
movl %ebx, 0x40(%rsp)
je 0x5c442
movl %eax, 0x20(%rsp)
xorl %eax, %eax
cmpl $0x9, %ebp
setge %al
shll $0x3, %eax
leaq 0x3f6d9(%rip), %rcx     # 0x9bac0
movsd (%rax,%rcx), %xmm1
leaq 0x3f6dd(%rip), %rcx     # 0x9bad0
movsd (%rax,%rcx), %xmm0
leaq 0x3f6e1(%rip), %rcx     # 0x9bae0
movsd (%rax,%rcx), %xmm2
mulsd 0x38(%rsp), %xmm2
xorl %ecx, %ecx
leaq 0x70c(%rsp), %rax
xorl %edx, %edx
addl -0xc(%rax), %edx
xorps %xmm3, %xmm3
cvtsi2sd %edx, %xmm3
ucomisd %xmm2, %xmm3
ja 0x5c44c
incq %rcx
movl $0x0, -0xc(%rax)
addq $0x4, %rax
cmpq $0xa00, %rcx            # imm = 0xA00
jne 0x5c416
jmp 0x5c5e2
movq 0x30(%rsp), %rdi
jmp 0x5cc3f
cmpq $0x9ff, %rcx            # imm = 0x9FF
ja 0x5c5e2
mulsd 0x38(%rsp), %xmm1
addl -0xc(%rax), %edx
xorps %xmm2, %xmm2
cvtsi2sd %edx, %xmm2
ucomisd %xmm1, %xmm2
ja 0x5c48b
incq %rcx
movl $0x1, -0xc(%rax)
addq $0x4, %rax
cmpq $0xa00, %rcx            # imm = 0xA00
jne 0x5c45f
jmp 0x5c5e2
cmpq $0x9ff, %rcx            # imm = 0x9FF
ja 0x5c5e2
mulsd 0x38(%rsp), %xmm0
xorl %esi, %esi
addl 0x700(%rsp,%rcx,4), %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
ucomisd %xmm0, %xmm1
ja 0x5c4d4
movl $0x2, 0x700(%rsp,%rcx,4)
incq %rcx
addq $-0x4, %rsi
cmpq $0xa00, %rcx            # imm = 0xA00
jne 0x5c4a0
jmp 0x5c5e2
cmpq $0x9ff, %rcx            # imm = 0x9FF
ja 0x5c5e2
subq %rsi, %rax
movl $0xa03, %edx            # imm = 0xA03
subq %rcx, %rdx
movl $0x9ff, %esi            # imm = 0x9FF
subq %rcx, %rsi
movq %rsi, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
andq $-0x4, %rdx
xorl %ecx, %ecx
movdqa 0x38364(%rip), %xmm1    # 0x94870
movdqa 0x3836c(%rip), %xmm2    # 0x94880
movdqa 0x38374(%rip), %xmm3    # 0x94890
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movq %rcx, %xmm5
pshufd $0x44, %xmm5, %xmm5     # xmm5 = xmm5[0,1,0,1]
movdqa %xmm5, %xmm6
por %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %esi
notl %esi
testb $0x1, %sil
je 0x5c56e
movl $0x3, -0xc(%rax)
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0x5c584
movl $0x3, -0x8(%rax)
por %xmm1, %xmm5
pxor %xmm3, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
pxor %xmm4, %xmm5
pextrw $0x0, %xmm5, %esi
testb $0x1, %sil
je 0x5c5c0
movl $0x3, -0x4(%rax)
pextrw $0x4, %xmm5, %esi
testb $0x1, %sil
je 0x5c5d1
movl $0x3, (%rax)
addq $0x4, %rcx
addq $0x10, %rax
cmpq %rcx, %rdx
jne 0x5c524
leaq 0x32f00(%rsp), %rdi
movl $0x20000, %edx          # imm = 0x20000
xorl %esi, %esi
callq 0x4260
leaq 0x12f00(%rsp), %rdi
movl $0x10000, %edx          # imm = 0x10000
xorl %esi, %esi
callq 0x4260
leaq 0x2f00(%rsp), %rbp
movl $0x8000, %edx           # imm = 0x8000
movq %rbp, %rdi
xorl %esi, %esi
callq 0x4260
leaq 0x100(%rsp), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x4260
leaq 0x500(%rsp), %rdi
movl $0x200, %edx            # imm = 0x200
xorl %esi, %esi
callq 0x4260
xorpd %xmm0, %xmm0
movapd %xmm0, 0xf0(%rsp)
movapd %xmm0, 0xe0(%rsp)
movapd %xmm0, 0xd0(%rsp)
movapd %xmm0, 0xc0(%rsp)
movapd %xmm0, 0xb0(%rsp)
movapd %xmm0, 0xa0(%rsp)
movapd %xmm0, 0x90(%rsp)
movapd %xmm0, 0x80(%rsp)
movq 0x8(%rsp), %r9
testq %r9, %r9
je 0x5c7e8
xorl %eax, %eax
xorl %edx, %edx
testl %ebx, %ebx
movq 0x18(%rsp), %rcx
js 0x5c6bd
movq 0x10(%rcx), %rsi
movzwl 0x2(%rsi,%rax,4), %esi
cmpl %ebx, %esi
jne 0x5c6d2
testb $0x7, %al
setne %dil
movslq (%rcx), %rsi
cmpq %rsi, %rax
setb %r8b
testb %r8b, %dil
je 0x5c6f7
movq 0x8(%rcx), %rsi
movl (%rsi,%rax,4), %esi
addq %rsi, %rdx
incq %rax
movq 0x8(%rsp), %r9
cmpq %r9, %rdx
movl 0x40(%rsp), %ebx
movl 0x14(%rsp), %r14d
jb 0x5c6a7
jmp 0x5c7e8
cmpq %rsi, %rax
jae 0x5c705
movq 0x8(%rcx), %rsi
movl (%rsi,%rax,4), %esi
jmp 0x5c70b
movq %r9, %rsi
subq %rdx, %rsi
cmpq %rdx, %r9
movq 0x30(%rsp), %rcx
jbe 0x5c6dc
testq %rsi, %rsi
je 0x5c6dc
movl (%rcx,%rax,4), %edi
movl $0x9ff, %ecx            # imm = 0x9FF
cmpl %ecx, %edi
cmovael %ecx, %edi
movslq 0x700(%rsp,%rdi,4), %r8
movl %r8d, %edi
shrl $0x1f, %edi
addl %r8d, %edi
sarl %edi
movslq %edi, %r10
movq %r8, %rdi
shlq $0xf, %rdi
addq %rsp, %rdi
addq $0x32f00, %rdi          # imm = 0x32F00
shlq $0x7, %r8
addq %rsp, %r8
addq $0x100, %r8             # imm = 0x100
movq %r10, %r9
shlq $0xf, %r9
addq %rsp, %r9
addq $0x12f00, %r9           # imm = 0x12F00
shlq $0x7, %r10
addq %rsp, %r10
addq $0x500, %r10            # imm = 0x500
movl %esi, %r11d
andl $0x1f, %r11d
movq 0x28(%rsp), %rcx
movzbl (%rcx,%rdx), %r14d
movl %r11d, %ecx
shll $0xa, %ecx
leaq (%rdi,%rcx), %rbx
shll $0x2, %r14d
incl (%r14,%rbx)
shll $0x2, %r11d
incl (%r11,%r8)
leaq (%r9,%rcx), %rbx
incl (%r14,%rbx)
incl (%r11,%r10)
addq %rsp, %rcx
addq $0x2f00, %rcx           # imm = 0x2F00
incl (%r14,%rcx)
incl 0x80(%rsp,%r11)
incq %rdx
cmpq 0x8(%rsp), %rdx
jae 0x5c6dc
leaq -0x1(%rsi), %rcx
cmpq $0x1, %rsi
movq %rcx, %rsi
jne 0x5c77b
jmp 0x5c6dc
movabsq $-0x3fef127e83d16f12, %rax # imm = 0xC010ED817C2E90EE
leaq 0x1af00(%rsp), %rcx
xorpd %xmm1, %xmm1
leaq 0x4af00(%rsp), %rdx
xorl %esi, %esi
movl $0x400, %r10d           # imm = 0x400
movsd 0x3f27a(%rip), %xmm2    # 0x9ba90
xorpd %xmm0, %xmm0
xorpd %xmm3, %xmm3
movq 0x30(%rsp), %rdi
xorl %r8d, %r8d
movl (%rbp,%r8,4), %r9d
testl %r9d, %r9d
je 0x5c868
xorps %xmm4, %xmm4
cvtsi2sd %r9d, %xmm4
xorps %xmm5, %xmm5
cvtsi2sdl 0x80(%rsp,%rsi,4), %xmm5
movapd %xmm4, %xmm6
divsd %xmm5, %xmm6
movq %xmm6, %r9
addq %rax, %r9
xorps %xmm5, %xmm5
cvtsi2sd %r9, %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm3
movl -0x8000(%rcx,%r8,4), %r9d
testl %r9d, %r9d
je 0x5c8ad
xorps %xmm4, %xmm4
cvtsi2sd %r9d, %xmm4
xorps %xmm5, %xmm5
cvtsi2sdl 0x500(%rsp,%rsi,4), %xmm5
movapd %xmm4, %xmm6
divsd %xmm5, %xmm6
movq %xmm6, %r9
addq %rax, %r9
xorps %xmm5, %xmm5
cvtsi2sd %r9, %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm0
movl (%rcx,%r8,4), %r9d
testl %r9d, %r9d
je 0x5c8ee
xorps %xmm4, %xmm4
cvtsi2sd %r9d, %xmm4
xorps %xmm5, %xmm5
cvtsi2sdl 0x580(%rsp,%rsi,4), %xmm5
movapd %xmm4, %xmm6
divsd %xmm5, %xmm6
movq %xmm6, %r9
addq %rax, %r9
xorps %xmm5, %xmm5
cvtsi2sd %r9, %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm0
movl -0x18000(%rdx,%r8,4), %r9d
testl %r9d, %r9d
je 0x5c933
xorps %xmm4, %xmm4
cvtsi2sd %r9d, %xmm4
xorps %xmm5, %xmm5
cvtsi2sdl 0x100(%rsp,%rsi,4), %xmm5
movapd %xmm4, %xmm6
divsd %xmm5, %xmm6
movq %xmm6, %r9
addq %rax, %r9
xorps %xmm5, %xmm5
cvtsi2sd %r9, %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm1
movl -0x10000(%rdx,%r8,4), %r9d
testl %r9d, %r9d
je 0x5c978
xorps %xmm4, %xmm4
cvtsi2sd %r9d, %xmm4
xorps %xmm5, %xmm5
cvtsi2sdl 0x180(%rsp,%rsi,4), %xmm5
movapd %xmm4, %xmm6
divsd %xmm5, %xmm6
movq %xmm6, %r9
addq %rax, %r9
xorps %xmm5, %xmm5
cvtsi2sd %r9, %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm1
movl -0x8000(%rdx,%r8,4), %r9d
testl %r9d, %r9d
je 0x5c9bd
xorps %xmm4, %xmm4
cvtsi2sd %r9d, %xmm4
xorps %xmm5, %xmm5
cvtsi2sdl 0x200(%rsp,%rsi,4), %xmm5
movapd %xmm4, %xmm6
divsd %xmm5, %xmm6
movq %xmm6, %r9
addq %rax, %r9
xorps %xmm5, %xmm5
cvtsi2sd %r9, %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm1
movl (%rdx,%r8,4), %r9d
testl %r9d, %r9d
je 0x5c9fe
xorps %xmm4, %xmm4
cvtsi2sd %r9d, %xmm4
xorps %xmm5, %xmm5
cvtsi2sdl 0x280(%rsp,%rsi,4), %xmm5
movapd %xmm4, %xmm6
divsd %xmm5, %xmm6
movq %xmm6, %r9
addq %rax, %r9
xorps %xmm5, %xmm5
cvtsi2sd %r9, %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm1
incq %r8
cmpq $0x100, %r8             # imm = 0x100
jne 0x5c826
incq %rsi
addq %r10, %rbp
addq %r10, %rcx
addq %r10, %rdx
cmpq $0x20, %rsi
jne 0x5c823
unpcklpd %xmm3, %xmm0            # xmm0 = xmm0[0],xmm3[0]
divpd 0x3f0c0(%rip), %xmm0    # 0x9baf0
xorl %eax, %eax
movl 0x20(%rsp), %esi
testl %esi, %esi
setg %al
leaq 0x3f0be(%rip), %rcx     # 0x9bb00
movsd (%rcx,%rax,8), %xmm2
cmpl $-0x1, %esi
setne %al
cmpl $0x4, %esi
setl %cl
testb %cl, %al
jne 0x5caf7
divsd 0x3f035(%rip), %xmm1    # 0x9ba98
movq 0x18(%rsp), %rax
movl (%rax), %eax
leal 0x3(%rax), %ecx
leal 0x7(%rax), %edx
testl %eax, %eax
cmovnsl %eax, %ecx
cmovnsl %eax, %edx
sarl $0x2, %ecx
xorps %xmm3, %xmm3
cvtsi2sd %ecx, %xmm3
addsd %xmm1, %xmm3
sarl $0x3, %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
movapd %xmm0, %xmm4
mulsd %xmm2, %xmm4
addsd %xmm1, %xmm4
ucomisd %xmm3, %xmm4
jbe 0x5caf7
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
mulsd %xmm2, %xmm1
ucomisd %xmm3, %xmm1
jbe 0x5caf7
movl $0x3, %r14d
testl %eax, %eax
je 0x5cb76
movq 0x18(%rsp), %r8
movq 0x10(%r8), %rax
xorl %ecx, %ecx
movl $0x9ff, %edx            # imm = 0x9FF
movl (%rdi,%rcx,4), %esi
cmpl %edx, %esi
cmovgel %edx, %esi
movslq %esi, %rsi
movl 0x700(%rsp,%rsi,4), %esi
shll $0x10, %esi
orl %esi, (%rax,%rcx,4)
incq %rcx
movslq (%r8), %rsi
cmpq %rsi, %rcx
jb 0x5cad2
jmp 0x5cb76
cmpl $-0x1, %esi
setne %al
cmpl $0x2, %esi
setl %cl
testb %cl, %al
jne 0x5cb83
movq 0x18(%rsp), %rax
movl (%rax), %eax
leal 0x7(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x3, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
addsd %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
mulsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
movq (%rsp), %rcx
jbe 0x5cb87
movl $0x1, %r14d
testl %eax, %eax
je 0x5cb7a
movq 0x18(%rsp), %r8
movq 0x10(%r8), %rax
xorl %ecx, %ecx
movl $0x9ff, %edx            # imm = 0x9FF
movl (%rdi,%rcx,4), %esi
cmpl %edx, %esi
cmovgel %edx, %esi
movslq %esi, %rsi
movl 0x700(%rsp,%rsi,4), %esi
andl $-0x2, %esi
shll $0xf, %esi
orl %esi, (%rax,%rcx,4)
incq %rcx
movslq (%r8), %rsi
cmpq %rsi, %rcx
jb 0x5cb50
movq (%rsp), %rcx
movl $0x1, 0x8(%rcx)
jmp 0x5cb87
movq (%rsp), %rcx
cmpl $-0x1, 0x1c60(%rcx)
jne 0x5cc3a
movq %rcx, %rax
movl 0x24(%rcx), %ecx
movl 0x2c(%rax), %eax
testl %ecx, %ecx
je 0x5cbcb
testl %eax, %eax
je 0x5cbeb
movq (%rsp), %r8
movl 0x30(%r8), %edx
leal -0x1(%rdx), %esi
movl %esi, 0x38(%r8)
decl %ecx
movl %ecx, 0x24(%r8)
movq %r8, %rcx
decl %eax
movl %eax, 0x2c(%r8)
incl %edx
movl %edx, 0x30(%r8)
jmp 0x5cc30
cmpl $0x2, %eax
jb 0x5cbeb
movq (%rsp), %rdx
movl 0x30(%rdx), %ecx
movl %ecx, 0x38(%rdx)
addl $-0x2, %eax
movl %eax, 0x2c(%rdx)
addl $0x2, %ecx
movl %ecx, 0x30(%rdx)
movq %rdx, %rcx
jmp 0x5cc30
movq (%rsp), %rcx
movl 0x1c(%rcx), %eax
cmpl $0x2, %eax
jb 0x5cc30
addl $-0x2, %eax
movl %eax, 0x1c(%rcx)
addl $-0x2, 0x28(%rcx)
movl $0xe, %ecx
movq (%rsp), %rdx
subl 0x1c5c(%rdx), %ecx
movq (%rsp), %rdx
movl %ecx, 0x38(%rdx)
movq (%rsp), %rcx
cmpl $0x6, %eax
jne 0x5cc30
cmpl $0x5, 0x1c48(%rcx)
jne 0x5cc30
movl $0x5, 0x1c(%rcx)
movl $0x4, 0x1c60(%rcx)
movl %r14d, 0x14(%rsp)
cmpb $0x0, 0x48(%rsp)
je 0x5cc53
cmpl $0x0, 0x1c5c(%rcx)
je 0x5ceb5
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
xorl %ebx, %ebx
movl $0x400, %r14d           # imm = 0x400
movsd %xmm0, 0x28(%rsp)
movq 0x400(%rsp,%rbx,8), %rcx
testq %rcx, %rcx
je 0x5cdd4
movq 0x300(%rsp,%rbx,8), %rax
testq %rax, %rax
je 0x5cdd4
leaq (%rax,%rcx), %rdx
movq %rdx, %xmm0
movq 0x38b12(%rip), %xmm1    # 0x957b0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x38b16(%rip), %xmm2    # 0x957c0
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movapd %xmm3, 0x60(%rsp)
movq %rcx, %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movapd %xmm3, 0x50(%rsp)
movq %rax, %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movapd %xmm1, 0x70(%rsp)
xorl %ebp, %ebp
movl (%r15,%rbp,4), %eax
testl %eax, %eax
je 0x5cdc4
movl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x20(%rsp)
divsd 0x60(%rsp), %xmm0
callq 0x4390
movl (%r12,%rbp,4), %eax
testl %eax, %eax
je 0x5cd70
movl %eax, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
movsd %xmm1, 0x38(%rsp)
movsd %xmm0, 0x48(%rsp)
movapd %xmm1, %xmm0
divsd 0x50(%rsp), %xmm0
callq 0x4390
mulsd 0x38(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x48(%rsp), %xmm0
movsd %xmm1, 0x8(%rsp)
movsd 0x20(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd 0x28(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rsp)
movl (%r13,%rbp,4), %eax
testl %eax, %eax
je 0x5cdc4
movl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x20(%rsp)
divsd 0x70(%rsp), %xmm0
callq 0x4390
mulsd 0x20(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
incq %rbp
cmpq $0x100, %rbp            # imm = 0x100
jne 0x5cd00
incq %rbx
addq %r14, %r15
addq %r14, %r12
addq %r14, %r13
cmpq $0x20, %rbx
jne 0x5cc6b
movsd 0x3ecae(%rip), %xmm0    # 0x9baa0
movsd 0x28(%rsp), %xmm2
divsd %xmm0, %xmm2
xorl %ecx, %ecx
movq (%rsp), %rax
cmpl $0x0, 0x1c5c(%rax)
setg %cl
movq 0x18(%rsp), %r10
movl (%r10), %eax
leal 0x7(%rax), %edx
testl %eax, %eax
cmovnsl %eax, %edx
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
sete %sil
sarl $0x3, %edx
addl $0x8, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
addsd %xmm1, %xmm0
leaq 0x3ecce(%rip), %rdx     # 0x9bb10
mulsd (%rdx,%rcx,8), %xmm2
ucomisd %xmm0, %xmm2
setbe %cl
orb %sil, %cl
movl 0x14(%rsp), %r9d
movq 0x30(%rsp), %rdi
jne 0x5ceba
movq 0x10(%r10), %rcx
xorl %edx, %edx
movl 0x40(%rsp), %r8d
movl (%rcx,%rdx,4), %esi
testl %r8d, %r8d
js 0x5ce7c
movl %esi, %r11d
shrl $0x10, %r11d
cmpl %r8d, %r11d
jne 0x5cea8
movzwl %si, %eax
movl %esi, %r11d
andl $0xffff0000, %r11d      # imm = 0xFFFF0000
shll $0x9, %esi
andl $0x10000, %esi          # imm = 0x10000
leal (%rsi,%r11,2), %esi
orl %esi, %eax
movl %eax, (%rcx,%rdx,4)
shrl $0x10, %esi
cmpl %esi, %r9d
cmovbel %esi, %r9d
movl (%r10), %eax
incq %rdx
movslq %eax, %rsi
cmpq %rsi, %rdx
jb 0x5ce68
jmp 0x5ceba
movl 0x14(%rsp), %r9d
testl %r9d, %r9d
jle 0x5cece
movq (%rsp), %rax
movl $0x1, 0x8(%rax)
movl %r9d, 0x44(%rax)
addq $0x52f08, %rsp          # imm = 0x52F08
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x45c0