// File: /workspace/github_c_makefile_star2_O1/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, %ebp
movq %r8, 0x10(%rsp)
movq %rcx, 0x38(%rsp)
movq %rdx, (%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %rbx
leaq 0xaf00(%rsp), %r15
xorl %r14d, %r14d
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
movq %rbx, 0x28(%rsp)
movslq (%rbx), %rax
testq %rax, %rax
je 0x5eb39
xorl %ecx, %ecx
movl $0x1, %edx
xorl %esi, %esi
xorl %r14d, %r14d
xorl %edi, %edi
testl %ebp, %ebp
js 0x5eafd
movq 0x28(%rsp), %r8
movq 0x10(%r8), %r8
movzwl 0x2(%r8,%rcx,4), %r8d
cmpl %ebp, %r8d
jne 0x5eb20
incl %esi
movq 0x28(%rsp), %r8
movq 0x10(%r8), %r8
movl (%r8,%rcx,4), %r8d
movl %r8d, %r9d
shrl $0x10, %r9d
cmpl %r9d, %r14d
cmovbel %r9d, %r14d
testb %r8b, %r8b
cmovsl %edx, %edi
incq %rcx
cmpq %rcx, %rax
jne 0x5eae5
cvtsi2sd %esi, %xmm0
movsd %xmm0, 0x30(%rsp)
testl %edi, %edi
sete %bl
jmp 0x5eb45
xorpd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
movb $0x1, %bl
incl %eax
movslq %eax, %rdi
movl $0x4, %esi
callq 0x4300
testq %rax, %rax
je 0x5ed77
movq %rax, %rdi
movb %bl, 0x48(%rsp)
movl %r14d, 0xc(%rsp)
movq (%rsp), %r9
testq %r9, %r9
movq %rax, 0x20(%rsp)
je 0x5ed8e
xorl %eax, %eax
movsd 0x38d13(%rip), %xmm2    # 0x97898
movsd 0x37493(%rip), %xmm3    # 0x96020
movl $0x9ff, %r11d           # imm = 0x9FF
xorl %r8d, %r8d
xorl %r10d, %r10d
xorl %r14d, %r14d
movq 0x28(%rsp), %rbx
movq %r10, %rcx
movq %r14, %rdx
testl %ebp, %ebp
js 0x5ebdc
movq 0x10(%rbx), %rsi
movzwl 0x2(%rsi,%rcx,4), %esi
cmpl %ebp, %esi
je 0x5ebd6
movl $0x0, (%rdi,%rcx,4)
movq 0x8(%rbx), %rsi
movl (%rsi,%rcx,4), %esi
incq %rcx
addq %rsi, %rdx
cmpq %r9, %rdx
jb 0x5eba7
jmp 0x5ed89
movq %rcx, %r10
movq %rdx, %r14
movslq (%rbx), %rcx
cmpq %rcx, %r10
jae 0x5ec6f
movq 0x8(%rbx), %rcx
movq 0x10(%rbx), %rdx
movl (%rcx,%r10,4), %esi
movl (%rdx,%r10,4), %ecx
shrl $0x7, %ecx
andl $0x1, %ecx
testq %r14, %r14
je 0x5ec79
cltq
cmpq %rsi, %rax
jne 0x5ec79
movl %ecx, 0x70(%rsp)
movq 0x18(%rsp), %rcx
movq %rsi, %rdx
movq %rsi, 0x40(%rsp)
leaq (%rcx,%r14), %rsi
movq %rsi, %rdi
subq %rax, %rdi
movq %r8, 0x60(%rsp)
movq %r10, 0x50(%rsp)
callq 0x44d0
movl 0x70(%rsp), %ecx
movl $0x9ff, %r11d           # imm = 0x9FF
movsd 0x373da(%rip), %xmm3    # 0x96020
movsd 0x38c4a(%rip), %xmm2    # 0x97898
movq 0x50(%rsp), %r10
movq 0x60(%rsp), %r8
movq (%rsp), %r9
movq 0x20(%rsp), %rdi
cmpl $0x1, %eax
adcl $0x0, %r8d
movq 0x40(%rsp), %rax
jmp 0x5ec7c
movq %r9, %rax
subq %r14, %rax
xorl %ecx, %ecx
jmp 0x5ec7c
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 0x5ed3e
testq %rax, %rax
je 0x5ed3e
movq %r10, 0x50(%rsp)
movq %r8, 0x60(%rsp)
xorl %esi, %esi
movq %rax, %rdi
movq 0x18(%rsp), %r10
movzbl (%r10,%r14), %r8d
movq 0x10(%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 (%rsp), %r9
addl %r8d, %esi
incq %r14
cmpq %r9, %r14
jae 0x5ed1b
leaq -0x1(%rdi), %r8
cmpq $0x1, %rdi
movq %r8, %rdi
jne 0x5ecbe
movl %esi, %ecx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
mulsd %xmm2, %xmm0
movq 0x20(%rsp), %rdi
movq 0x60(%rsp), %r8
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
movl %ecx, (%rdi,%r10,4)
cmpl %r11d, %ecx
cmovael %r11d, %ecx
incl 0x700(%rsp,%rcx,4)
incq %r10
cmpq %r9, %r14
jb 0x5eba1
jmp 0x5ed99
addq $0x52f08, %rsp          # imm = 0x52F08
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, %r10
jmp 0x5ed99
xorl %r8d, %r8d
xorl %r10d, %r10d
movq 0x28(%rsp), %rbx
incq %r10
incl %r8d
movslq %r8d, %rsi
xorl %ecx, %ecx
movq %r10, %rax
xorl %edx, %edx
divq %rsi
xorl %edx, %edx
cmpq $0x1f4, %rax            # imm = 0x1F4
setb %dl
movq 0x38(%rsp), %rdi
movl %edx, 0xc(%rdi)
movq $0x0, 0x3c(%rdi)
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax,%rcx,4)
je 0x5edd8
movl %ecx, 0x3c(%rdi)
incl 0x40(%rdi)
incq %rcx
cmpq $0x100, %rcx            # imm = 0x100
jne 0x5edcc
movl 0x1c60(%rdi), %edx
testl %edx, %edx
movl %ebp, 0x40(%rsp)
je 0x5f47b
xorl %eax, %eax
cmpl $0x9, 0x40(%rdi)
setge %al
shll $0x3, %eax
leaq 0x3fa97(%rip), %rcx     # 0x9e8a0
movsd (%rax,%rcx), %xmm1
leaq 0x3fa9b(%rip), %rcx     # 0x9e8b0
movsd (%rax,%rcx), %xmm0
leaq 0x3fa9f(%rip), %rcx     # 0x9e8c0
movsd (%rax,%rcx), %xmm2
mulsd 0x30(%rsp), %xmm2
xorl %eax, %eax
xorl %ecx, %ecx
addl 0x700(%rsp,%rax,4), %ecx
xorps %xmm3, %xmm3
cvtsi2sd %ecx, %xmm3
ucomisd %xmm2, %xmm3
ja 0x5ee5f
movl $0x0, 0x700(%rsp,%rax,4)
incq %rax
cmpq $0xa00, %rax            # imm = 0xA00
jne 0x5ee30
movl $0xa00, %eax            # imm = 0xA00
cmpq $0x9ff, %rax            # imm = 0x9FF
ja 0x5ee9c
mulsd 0x30(%rsp), %xmm1
addl 0x700(%rsp,%rax,4), %ecx
xorps %xmm2, %xmm2
cvtsi2sd %ecx, %xmm2
ucomisd %xmm1, %xmm2
ja 0x5ee9c
movl $0x1, 0x700(%rsp,%rax,4)
incq %rax
cmpq $0xa00, %rax            # imm = 0xA00
jne 0x5ee6d
movl $0xa00, %eax            # imm = 0xA00
cmpq $0x9ff, %rax            # imm = 0x9FF
ja 0x5eed9
mulsd 0x30(%rsp), %xmm0
addl 0x700(%rsp,%rax,4), %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
ucomisd %xmm0, %xmm1
ja 0x5eed9
movl $0x2, 0x700(%rsp,%rax,4)
incq %rax
cmpq $0xa00, %rax            # imm = 0xA00
jne 0x5eeaa
movl $0xa00, %eax            # imm = 0xA00
movl %edx, 0x10(%rsp)
cmpq $0x9ff, %rax            # imm = 0x9FF
ja 0x5eefb
movl $0x3, 0x700(%rsp,%rax,4)
incq %rax
cmpq $0xa00, %rax            # imm = 0xA00
jne 0x5eee5
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), %r14
movl $0x8000, %edx           # imm = 0x8000
movq %r14, %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 (%rsp), %rdi
testq %rdi, %rdi
je 0x5f0ef
xorl %eax, %eax
xorl %edx, %edx
testl %ebp, %ebp
js 0x5efd0
movq 0x10(%rbx), %rsi
movzwl 0x2(%rsi,%rax,4), %esi
cmpl %ebp, %esi
jne 0x5efdc
testb $0x7, %al
je 0x5f000
movslq (%rbx), %rsi
cmpq %rsi, %rax
jae 0x5f000
movq 0x8(%rbx), %rsi
movl (%rsi,%rax,4), %esi
addq %rsi, %rdx
incq %rax
movq (%rsp), %rdi
cmpq %rdi, %rdx
movl 0x40(%rsp), %ebp
movq 0x28(%rsp), %rbx
jb 0x5efbf
jmp 0x5f0ef
movslq (%rbx), %rsi
cmpq %rsi, %rax
jae 0x5f011
movq 0x8(%rbx), %rsi
movl (%rsi,%rax,4), %esi
jmp 0x5f017
movq %rdi, %rsi
subq %rdx, %rsi
movq 0x20(%rsp), %rcx
cmpq %rdx, %rdi
jbe 0x5efe6
testq %rsi, %rsi
je 0x5efe6
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 0x18(%rsp), %rcx
movzbl (%rcx,%rdx), %ecx
movl %r11d, %ebp
shll $0xa, %ebp
leaq (%rdi,%rbp), %rbx
shll $0x2, %ecx
incl (%rcx,%rbx)
shll $0x2, %r11d
incl (%r11,%r8)
leaq (%r9,%rbp), %rbx
incl (%rcx,%rbx)
incl (%r11,%r10)
leaq (%rsp,%rbp), %rbx
addq $0x2f00, %rbx           # imm = 0x2F00
incl (%rcx,%rbx)
incl 0x80(%rsp,%r11)
incq %rdx
cmpq (%rsp), %rdx
jae 0x5efe6
leaq -0x1(%rsi), %rcx
cmpq $0x1, %rsi
movq %rcx, %rsi
jne 0x5f087
jmp 0x5efe6
movabsq $-0x3fef127e83d16f12, %rax # imm = 0xC010ED817C2E90EE
leaq 0x1af00(%rsp), %rcx
xorpd %xmm2, %xmm2
leaq 0x4af00(%rsp), %rdx
xorl %esi, %esi
movl $0x400, %edi            # imm = 0x400
movsd 0x3f754(%rip), %xmm3    # 0x9e870
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
movq 0x20(%rsp), %r10
xorl %r8d, %r8d
movl (%r14,%r8,4), %r9d
testl %r9d, %r9d
je 0x5f16d
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 %xmm3, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm1
movl -0x8000(%rcx,%r8,4), %r9d
testl %r9d, %r9d
je 0x5f1b2
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 %xmm3, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm0
movl (%rcx,%r8,4), %r9d
testl %r9d, %r9d
je 0x5f1f3
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 %xmm3, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm0
movl -0x18000(%rdx,%r8,4), %r9d
testl %r9d, %r9d
je 0x5f238
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 %xmm3, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm2
movl -0x10000(%rdx,%r8,4), %r9d
testl %r9d, %r9d
je 0x5f27d
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 %xmm3, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm2
movl -0x8000(%rdx,%r8,4), %r9d
testl %r9d, %r9d
je 0x5f2c2
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 %xmm3, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm2
movl (%rdx,%r8,4), %r9d
testl %r9d, %r9d
je 0x5f303
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 %xmm3, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm2
incq %r8
cmpq $0x100, %r8             # imm = 0x100
jne 0x5f12c
incq %rsi
addq %rdi, %r14
addq %rdi, %rcx
addq %rdi, %rdx
cmpq $0x20, %rsi
jne 0x5f129
movsd 0x3f547(%rip), %xmm3    # 0x9e878
divsd %xmm3, %xmm1
divsd %xmm3, %xmm0
xorl %eax, %eax
movl 0x10(%rsp), %esi
testl %esi, %esi
setg %al
leaq 0x3f585(%rip), %rcx     # 0x9e8d0
movsd (%rcx,%rax,8), %xmm3
cmpl $-0x1, %esi
setne %al
cmpl $0x4, %esi
setl %cl
testb %cl, %al
jne 0x5f3f9
divsd 0x3f50c(%rip), %xmm2    # 0x9e878
movl (%rbx), %eax
leal 0x3(%rax), %ecx
leal 0x7(%rax), %edx
testl %eax, %eax
cmovnsl %eax, %ecx
cmovnsl %eax, %edx
sarl $0x2, %ecx
xorps %xmm4, %xmm4
cvtsi2sd %ecx, %xmm4
addsd %xmm2, %xmm4
sarl $0x3, %edx
xorps %xmm2, %xmm2
cvtsi2sd %edx, %xmm2
movapd %xmm0, %xmm5
mulsd %xmm3, %xmm5
addsd %xmm2, %xmm5
ucomisd %xmm4, %xmm5
jbe 0x5f3f9
movapd %xmm3, %xmm2
mulsd %xmm1, %xmm2
ucomisd %xmm4, %xmm2
jbe 0x5f3f9
movl $0x3, %r8d
cmpl $0x0, (%rbx)
movq 0x38(%rsp), %rdi
je 0x5f472
movq 0x10(%rbx), %rax
xorl %ecx, %ecx
movl $0x9ff, %edx            # imm = 0x9FF
movl (%r10,%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 (%rbx), %rsi
cmpq %rsi, %rcx
jb 0x5f3d3
jmp 0x5f472
cmpl $-0x1, %esi
setne %al
cmpl $0x2, %esi
setl %cl
testb %cl, %al
movq 0x38(%rsp), %rdi
jne 0x5f485
movl (%rbx), %eax
leal 0x7(%rax), %ecx
testl %eax, %eax
cmovnsl %eax, %ecx
sarl $0x3, %ecx
xorps %xmm2, %xmm2
cvtsi2sd %ecx, %xmm2
addsd %xmm2, %xmm0
mulsd %xmm1, %xmm3
ucomisd %xmm0, %xmm3
movl 0xc(%rsp), %r8d
jbe 0x5f48a
movl $0x1, %r8d
cmpl $0x0, (%rbx)
je 0x5f472
movq 0x10(%rbx), %rax
xorl %ecx, %ecx
movl $0x9ff, %edx            # imm = 0x9FF
movl (%r10,%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 (%rbx), %rsi
cmpq %rsi, %rcx
jb 0x5f44b
movl $0x1, 0x8(%rdi)
jmp 0x5f48a
movb 0x48(%rsp), %r9b
jmp 0x5f524
movl 0xc(%rsp), %r8d
cmpl $-0x1, 0x1c60(%rdi)
movb 0x48(%rsp), %r9b
jne 0x5f51f
movl 0x24(%rdi), %eax
testl %eax, %eax
je 0x5f4c4
movl 0x2c(%rdi), %ecx
testl %ecx, %ecx
je 0x5f4c4
movl 0x30(%rdi), %edx
leal -0x1(%rdx), %esi
movl %esi, 0x38(%rdi)
decl %eax
movl %eax, 0x24(%rdi)
decl %ecx
movl %ecx, 0x2c(%rdi)
incl %edx
movl %edx, 0x30(%rdi)
jmp 0x5f515
movl 0x2c(%rdi), %eax
cmpl $0x2, %eax
jb 0x5f4e0
movl 0x30(%rdi), %ecx
movl %ecx, 0x38(%rdi)
addl $-0x2, %eax
movl %eax, 0x2c(%rdi)
addl $0x2, %ecx
movl %ecx, 0x30(%rdi)
jmp 0x5f515
movl 0x1c(%rdi), %eax
cmpl $0x2, %eax
jb 0x5f515
addl $-0x2, %eax
movl %eax, 0x1c(%rdi)
addl $-0x2, 0x28(%rdi)
movl $0xe, %ecx
subl 0x1c5c(%rdi), %ecx
movl %ecx, 0x38(%rdi)
cmpl $0x6, %eax
jne 0x5f515
cmpl $0x5, 0x1c48(%rdi)
jne 0x5f515
movl $0x5, 0x1c(%rdi)
movl $0x4, 0x1c60(%rdi)
movl %r8d, 0xc(%rsp)
testb %r9b, %r9b
je 0x5f536
cmpl $0x0, 0x1c5c(%rdi)
je 0x5f783
xorpd %xmm0, %xmm0
movsd %xmm0, (%rsp)
xorl %ebx, %ebx
movl $0x400, %r14d           # imm = 0x400
movsd %xmm0, 0x18(%rsp)
movq 0x400(%rsp,%rbx,8), %rcx
testq %rcx, %rcx
je 0x5f6b2
movq 0x300(%rsp,%rbx,8), %rax
testq %rax, %rax
je 0x5f6b2
leaq (%rax,%rcx), %rdx
movq %rdx, %xmm0
movq 0x39180(%rip), %xmm1    # 0x98700
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x39184(%rip), %xmm2    # 0x98710
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 0x5f6a2
movl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x10(%rsp)
divsd 0x60(%rsp), %xmm0
callq 0x4390
movl (%r12,%rbp,4), %eax
testl %eax, %eax
je 0x5f650
movl %eax, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
movsd %xmm1, 0x48(%rsp)
movsd %xmm0, 0x30(%rsp)
movapd %xmm1, %xmm0
divsd 0x50(%rsp), %xmm0
callq 0x4390
mulsd 0x48(%rsp), %xmm0
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movsd 0x30(%rsp), %xmm0
movsd %xmm1, (%rsp)
movsd 0x10(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd 0x18(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
movl (%r13,%rbp,4), %eax
testl %eax, %eax
je 0x5f6a2
movl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x10(%rsp)
divsd 0x70(%rsp), %xmm0
callq 0x4390
mulsd 0x10(%rsp), %xmm0
movsd (%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
incq %rbp
cmpq $0x100, %rbp            # imm = 0x100
jne 0x5f5e2
incq %rbx
addq %r14, %r15
addq %r14, %r12
addq %r14, %r13
cmpq $0x20, %rbx
movl 0x40(%rsp), %r8d
jne 0x5f54d
movsd 0x3f1ab(%rip), %xmm0    # 0x9e880
movsd 0x18(%rsp), %xmm2
divsd %xmm0, %xmm2
movsd (%rsp), %xmm1
divsd %xmm0, %xmm1
xorl %eax, %eax
movq 0x38(%rsp), %rdi
cmpl $0x0, 0x1c5c(%rdi)
setg %al
movq 0x28(%rsp), %r10
movl (%r10), %ecx
leal 0x7(%rcx), %edx
testl %ecx, %ecx
cmovnsl %ecx, %edx
sarl $0x3, %edx
addl $0x8, %edx
xorps %xmm0, %xmm0
cvtsi2sd %edx, %xmm0
addsd %xmm1, %xmm0
leaq 0x3f1bf(%rip), %rcx     # 0x9e8e0
mulsd (%rcx,%rax,8), %xmm2
ucomisd %xmm0, %xmm2
movl 0xc(%rsp), %r9d
jbe 0x5f788
cmpl $0x0, (%r10)
je 0x5f788
xorl %eax, %eax
testl %r8d, %r8d
js 0x5f74c
movq 0x10(%r10), %rcx
movzwl 0x2(%rcx,%rax,4), %ecx
cmpl %r8d, %ecx
jne 0x5f776
movq 0x10(%r10), %rcx
movl (%rcx,%rax,4), %edx
movl %edx, %esi
andl $0xffff0000, %esi       # imm = 0xFFFF0000
shll $0x9, %edx
andl $0x10000, %edx          # imm = 0x10000
leal (%rdx,%rsi,2), %edx
shrl $0x10, %edx
movw %dx, 0x2(%rcx,%rax,4)
cmpl %edx, %r9d
cmovbel %edx, %r9d
incq %rax
movslq (%r10), %rcx
cmpq %rcx, %rax
jb 0x5f739
jmp 0x5f788
movl 0xc(%rsp), %r9d
testl %r9d, %r9d
jle 0x5f798
movl $0x1, 0x8(%rdi)
movl %r9d, 0x44(%rdi)
movq 0x20(%rsp), %rdi
addq $0x52f08, %rsp          # imm = 0x52F08
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x45c0