// File: /workspace/github_c_makefile_star2_O2/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, %r12
movq %rcx, 0x40(%rsp)
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %r13
leaq 0xaf00(%rsp), %rdi
movl $0x8000, %edx           # imm = 0x8000
xorl %esi, %esi
callq 0x4260
leaq 0x12f00(%rsp), %rdi
movl $0x8000, %edx           # imm = 0x8000
xorl %esi, %esi
callq 0x4260
leaq 0x2f00(%rsp), %rdi
movl $0x8000, %edx           # imm = 0x8000
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), %rbp
movl $0x2800, %edx           # imm = 0x2800
movq %rbp, %rdi
xorl %esi, %esi
callq 0x4260
xorl %r8d, %r8d
movq %r13, 0x18(%rsp)
movslq (%r13), %rax
pushq $0x1
popq %r9
xorl %edi, %edi
xorl %r10d, %r10d
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x4b638
movq 0x18(%rsp), %rdx
movq 0x10(%rdx), %rdx
movl (%rdx,%rcx,4), %edx
movl %edx, %esi
shrl $0x10, %esi
testl %ebx, %ebx
js 0x4b625
cmpl %ebx, %esi
jne 0x4b633
incl %r10d
cmpl %esi, %edi
cmovbel %esi, %edi
testb %dl, %dl
cmovsl %r9d, %r8d
incq %rcx
jmp 0x4b607
movl %r10d, 0x48(%rsp)
movl %r9d, 0x38(%rsp)
movq %r8, 0x30(%rsp)
movl %edi, 0x10(%rsp)
incl %eax
movslq %eax, %rdi
pushq $0x4
popq %rsi
callq 0x4300
movq %rax, 0x20(%rsp)
testq %rax, %rax
leaq 0x12f00(%rsp), %r13
je 0x4be20
movl %ebx, 0x14(%rsp)
xorl %ebx, %ebx
movsd 0x2b21c(%rip), %xmm2    # 0x76898
movsd 0x2999c(%rip), %xmm3    # 0x75020
xorl %r9d, %r9d
movl $0x0, 0x28(%rsp)
xorl %ecx, %ecx
movq %rbx, %rdx
movq %r9, %rax
cmpq %r15, %rdx
jae 0x4b821
movl 0x14(%rsp), %edi
testl %edi, %edi
js 0x4b6d8
movq 0x18(%rsp), %r8
movq 0x10(%r8), %rsi
movzwl 0x2(%rsi,%rax,4), %esi
cmpl %edi, %esi
je 0x4b6d2
movq 0x20(%rsp), %rsi
andl $0x0, (%rsi,%rax,4)
movq 0x8(%r8), %rsi
movl (%rsi,%rax,4), %esi
incq %rax
addq %rsi, %rdx
jmp 0x4b697
movq %rdx, %rbx
movq %rax, %r9
movq 0x18(%rsp), %rdx
movslq (%rdx), %rax
cmpq %rax, %r9
movq %r9, 0x8(%rsp)
jae 0x4b74c
movq 0x8(%rdx), %rax
movq 0x10(%rdx), %rsi
movl (%rax,%r9,4), %edx
movl (%rsi,%r9,4), %r8d
shrl $0x7, %r8d
andl $0x1, %r8d
testq %rbx, %rbx
je 0x4b757
movslq %ecx, %rax
cmpq %rdx, %rax
jne 0x4b757
leaq (%r14,%rbx), %rsi
movq %rsi, %rdi
subq %rdx, %rdi
movl %r8d, 0x60(%rsp)
movq %rdx, 0x50(%rsp)
callq 0x44d0
movl 0x60(%rsp), %r8d
movsd 0x298eb(%rip), %xmm3    # 0x75020
movsd 0x2b15b(%rip), %xmm2    # 0x76898
cmpl $0x1, %eax
adcl $0x0, 0x28(%rsp)
movq 0x50(%rsp), %rcx
jmp 0x4b75a
movq %r15, %rcx
subq %rbx, %rcx
xorl %r8d, %r8d
jmp 0x4b75a
movq %rdx, %rcx
testl %r8d, %r8d
leaq 0x2f00(%rsp), %rdx
cmoveq %r13, %rdx
leaq 0x300(%rsp), %rsi
leaq 0x400(%rsp), %rax
cmoveq %rax, %rsi
xorl %eax, %eax
movq %rcx, %r8
movq %rcx, %rdi
addq $-0x1, %rdi
setb %r9b
cmpq %r15, %rbx
jae 0x4b7d6
testb %r9b, %r9b
je 0x4b7d6
movzbl (%r14,%rbx), %r9d
incl (%r12,%r9,4)
andl $0x1f, %r8d
movzbl (%r14,%rbx), %r10d
incq (%rsi,%r8,8)
shll $0x2, %r10d
shll $0xa, %r8d
leaq (%rsp,%r8), %r11
addq $0xaf00, %r11           # imm = 0xAF00
incl (%r10,%r11)
addq %rdx, %r8
incl (%r10,%r8)
addl %r9d, %eax
incq %rbx
movq %rdi, %r8
jmp 0x4b785
testl %ecx, %ecx
je 0x4b7f8
movl %eax, %eax
cvtsi2sd %rax, %xmm0
mulsd %xmm2, %xmm0
cvtsi2sd %ecx, %xmm1
divsd %xmm1, %xmm0
addsd %xmm3, %xmm0
cvttsd2si %xmm0, %rax
jmp 0x4b7fa
xorl %eax, %eax
movq 0x8(%rsp), %r9
movq 0x20(%rsp), %rdx
movl %eax, (%rdx,%r9,4)
movl $0x9ff, %edx            # imm = 0x9FF
cmpl %edx, %eax
cmovael %edx, %eax
incl 0x700(%rsp,%rax,4)
incq %r9
jmp 0x4b691
incq %rax
movl 0x28(%rsp), %ecx
incl %ecx
movslq %ecx, %rsi
xorl %ecx, %ecx
xorl %edx, %edx
divq %rsi
xorl %edx, %edx
cmpq $0x1f4, %rax            # imm = 0x1F4
setb %dl
movq 0x40(%rsp), %r10
movl %edx, 0xc(%r10)
andq $0x0, 0x3c(%r10)
xorl %eax, %eax
cmpq $0x100, %rax            # imm = 0x100
je 0x4b86d
cmpl $0x0, (%r12,%rax,4)
je 0x4b868
movl %eax, 0x3c(%r10)
incl %ecx
movl %ecx, 0x40(%r10)
incq %rax
jmp 0x4b84f
movl 0x1c60(%r10), %edx
testl %edx, %edx
je 0x4bea9
xorl %eax, %eax
cmpl $0x9, %ecx
setge %al
shll $0x3, %eax
leaq 0x31fd2(%rip), %rcx     # 0x7d860
movsd (%rax,%rcx), %xmm2
leaq 0x31fd6(%rip), %rcx     # 0x7d870
movsd (%rax,%rcx), %xmm0
cvtsi2sdl 0x48(%rsp), %xmm1
leaq 0x31fd4(%rip), %rcx     # 0x7d880
movsd (%rax,%rcx), %xmm3
mulsd %xmm1, %xmm3
xorl %ecx, %ecx
xorl %eax, %eax
movq 0x18(%rsp), %r12
cmpq $0xa00, %rax            # imm = 0xA00
je 0x4b8e0
addl (%rbp), %ecx
cvtsi2sd %ecx, %xmm4
ucomisd %xmm3, %xmm4
ja 0x4b8e0
incq %rax
andl $0x0, (%rbp)
addq $0x4, %rbp
jmp 0x4b8be
mulsd %xmm1, %xmm2
cmpq $0xa00, %rax            # imm = 0xA00
je 0x4b909
addl (%rbp), %ecx
cvtsi2sd %ecx, %xmm3
ucomisd %xmm2, %xmm3
ja 0x4b909
incq %rax
movl $0x1, (%rbp)
addq $0x4, %rbp
jmp 0x4b8e4
mulsd %xmm1, %xmm0
cmpq $0xa00, %rax            # imm = 0xA00
jae 0x4b940
addl (%rbp), %ecx
cvtsi2sd %ecx, %xmm1
ucomisd %xmm0, %xmm1
ja 0x4b940
incq %rax
movl $0x2, (%rbp)
addq $0x4, %rbp
jmp 0x4b90d
incq %rax
movl $0x3, (%rbp)
addq $0x4, %rbp
cmpq $0x9ff, %rax            # imm = 0x9FF
jbe 0x4b932
movl %edx, 0x8(%rsp)
leaq 0x32f00(%rsp), %rdi
xorl %ebx, %ebx
movl $0x20000, %edx          # imm = 0x20000
xorl %esi, %esi
callq 0x4260
leaq 0x22f00(%rsp), %rdi
movl $0x10000, %edx          # imm = 0x10000
xorl %esi, %esi
callq 0x4260
leaq 0x1af00(%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)
movl $0x9ff, %esi            # imm = 0x9FF
xorl %r8d, %r8d
movq %r15, %r13
subq %rbx, %r13
jbe 0x4bb32
cmpl $0x0, 0x14(%rsp)
js 0x4ba2d
movq 0x10(%r12), %rax
movzwl 0x2(%rax,%r8,4), %eax
cmpl 0x14(%rsp), %eax
jne 0x4ba42
testb $0x7, %r8b
setne %cl
movslq (%r12), %rax
cmpq %rax, %r8
setb %dl
testb %dl, %cl
je 0x4ba53
movq 0x8(%r12), %rax
movl (%rax,%r8,4), %eax
addq %rax, %rbx
jmp 0x4bb2a
cmpq %rax, %r8
jae 0x4ba61
movq 0x8(%r12), %rax
movl (%rax,%r8,4), %r13d
movq 0x20(%rsp), %rax
movl (%rax,%r8,4), %eax
cmpl %esi, %eax
cmovael %esi, %eax
movslq 0x700(%rsp,%rax,4), %rcx
movl %ecx, %eax
cltd
pushq $0x2
popq %rdi
idivl %edi
movslq %eax, %r10
movq %rcx, %rax
shlq $0xf, %rax
addq %rsp, %rax
addq $0x32f00, %rax          # imm = 0x32F00
shlq $0x7, %rcx
addq %rsp, %rcx
addq $0x100, %rcx            # imm = 0x100
movq %r10, %rdx
shlq $0xf, %rdx
addq %rsp, %rdx
addq $0x22f00, %rdx          # imm = 0x22F00
shlq $0x7, %r10
addq %rsp, %r10
addq $0x500, %r10            # imm = 0x500
movq %r13, %r11
addq $-0x1, %r11
setb %r12b
cmpq %r15, %rbx
jae 0x4bb25
testb %r12b, %r12b
je 0x4bb25
andl $0x1f, %r13d
movzbl (%r14,%rbx), %r12d
movl %r13d, %r9d
shll $0xa, %r9d
leaq (%rax,%r9), %rdi
shll $0x2, %r12d
incl (%r12,%rdi)
shll $0x2, %r13d
incl (%r13,%rcx)
leaq (%rdx,%r9), %rdi
incl (%r12,%rdi)
incl (%r13,%r10)
leaq (%rsp,%r9), %rdi
addq $0x1af00, %rdi          # imm = 0x1AF00
incl (%r12,%rdi)
incl 0x80(%rsp,%r13)
incq %rbx
movq %r11, %r13
jmp 0x4bac2
movq 0x18(%rsp), %r12
incq %r8
jmp 0x4ba09
movabsq $-0x3fef127e83d16f12, %rax # imm = 0xC010ED817C2E90EE
leaq 0x2af00(%rsp), %rcx
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
leaq 0x4af00(%rsp), %rdx
xorl %esi, %esi
movl $0x400, %edi            # imm = 0x400
movsd 0x31d7d(%rip), %xmm2    # 0x7d8e0
movq 0x40(%rsp), %r10
leaq 0xaf00(%rsp), %r15
leaq 0x12f00(%rsp), %r13
cmpq $0x20, %rsi
je 0x4bd50
xorl %r8d, %r8d
cmpq $0x100, %r8             # imm = 0x100
je 0x4bd3f
movl (%rbp,%r8,4), %r9d
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
testl %r9d, %r9d
je 0x4bbd3
cvtsi2sd %r9d, %xmm4
cvtsi2sdl 0x80(%rsp,%rsi,4), %xmm5
movapd %xmm4, %xmm6
divsd %xmm5, %xmm6
movq %xmm6, %r9
addq %rax, %r9
cvtsi2sd %r9, %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm3
movl -0x8000(%rcx,%r8,4), %r9d
testl %r9d, %r9d
je 0x4bc0f
cvtsi2sd %r9d, %xmm4
cvtsi2sdl 0x500(%rsp,%rsi,4), %xmm5
movapd %xmm4, %xmm6
divsd %xmm5, %xmm6
movq %xmm6, %r9
addq %rax, %r9
cvtsi2sd %r9, %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm0
movl (%rcx,%r8,4), %r9d
testl %r9d, %r9d
je 0x4bc47
cvtsi2sd %r9d, %xmm4
cvtsi2sdl 0x580(%rsp,%rsi,4), %xmm5
movapd %xmm4, %xmm6
divsd %xmm5, %xmm6
movq %xmm6, %r9
addq %rax, %r9
cvtsi2sd %r9, %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm0
movl -0x18000(%rdx,%r8,4), %r9d
testl %r9d, %r9d
je 0x4bc83
cvtsi2sd %r9d, %xmm4
cvtsi2sdl 0x100(%rsp,%rsi,4), %xmm5
movapd %xmm4, %xmm6
divsd %xmm5, %xmm6
movq %xmm6, %r9
addq %rax, %r9
cvtsi2sd %r9, %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm1
movl -0x10000(%rdx,%r8,4), %r9d
testl %r9d, %r9d
je 0x4bcbf
cvtsi2sd %r9d, %xmm4
cvtsi2sdl 0x180(%rsp,%rsi,4), %xmm5
movapd %xmm4, %xmm6
divsd %xmm5, %xmm6
movq %xmm6, %r9
addq %rax, %r9
cvtsi2sd %r9, %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm1
movl -0x8000(%rdx,%r8,4), %r9d
testl %r9d, %r9d
je 0x4bcfb
cvtsi2sd %r9d, %xmm4
cvtsi2sdl 0x200(%rsp,%rsi,4), %xmm5
movapd %xmm4, %xmm6
divsd %xmm5, %xmm6
movq %xmm6, %r9
addq %rax, %r9
cvtsi2sd %r9, %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm1
movl (%rdx,%r8,4), %r9d
testl %r9d, %r9d
je 0x4bd33
cvtsi2sd %r9d, %xmm4
cvtsi2sdl 0x280(%rsp,%rsi,4), %xmm5
movapd %xmm4, %xmm6
divsd %xmm5, %xmm6
movq %xmm6, %r9
addq %rax, %r9
cvtsi2sd %r9, %xmm5
mulsd %xmm2, %xmm5
mulsd %xmm4, %xmm5
addsd %xmm5, %xmm1
incq %r8
unpcklpd %xmm3, %xmm0            # xmm0 = xmm0[0],xmm3[0]
jmp 0x4bb85
incq %rsi
addq %rdi, %rdx
addq %rdi, %rcx
addq %rdi, %rbp
jmp 0x4bb78
divpd 0x31b38(%rip), %xmm0    # 0x7d890
xorl %eax, %eax
movl 0x8(%rsp), %edi
testl %edi, %edi
setg %al
leaq 0x31b36(%rip), %rcx     # 0x7d8a0
movsd (%rcx,%rax,8), %xmm2
cmpl $-0x1, %edi
setne %al
cmpl $0x4, %edi
setl %cl
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
testb %cl, %al
jne 0x4be32
divsd 0x31b55(%rip), %xmm1    # 0x7d8e8
movl (%r12), %ecx
pushq $0x4
popq %rsi
movl %ecx, %eax
cltd
idivl %esi
cvtsi2sd %eax, %xmm4
addsd %xmm1, %xmm4
movl %ecx, %eax
cltd
pushq $0x8
popq %rsi
idivl %esi
cvtsi2sd %eax, %xmm1
movapd %xmm0, %xmm5
mulsd %xmm2, %xmm5
addsd %xmm1, %xmm5
ucomisd %xmm4, %xmm5
jbe 0x4be32
movapd %xmm2, %xmm1
mulsd %xmm3, %xmm1
ucomisd %xmm4, %xmm1
jbe 0x4be32
xorl %eax, %eax
pushq $0x3
popq %rdx
movl %edx, 0x38(%rsp)
movl $0x9ff, %edx            # imm = 0x9FF
leaq 0x2f00(%rsp), %rbp
movslq %ecx, %rcx
cmpq %rcx, %rax
jae 0x4bec3
movq 0x20(%rsp), %rcx
movl (%rcx,%rax,4), %ecx
cmpl %edx, %ecx
cmovgel %edx, %ecx
movslq %ecx, %rcx
movl 0x700(%rsp,%rcx,4), %ecx
shll $0x10, %ecx
movq 0x10(%r12), %rsi
orl %ecx, (%rsi,%rax,4)
incq %rax
movl (%r12), %ecx
jmp 0x4bde9
addq $0x52f08, %rsp          # imm = 0x52F08
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $-0x1, %edi
setne %al
cmpl $0x2, %edi
setl %cl
testb %cl, %al
leaq 0x2f00(%rsp), %rbp
jne 0x4bed3
movl (%r12), %ecx
movl %ecx, %eax
cltd
pushq $0x8
popq %rsi
idivl %esi
cvtsi2sd %eax, %xmm1
addsd %xmm1, %xmm0
mulsd %xmm2, %xmm3
ucomisd %xmm0, %xmm3
jbe 0x4bed3
xorl %eax, %eax
movl $0x9ff, %edx            # imm = 0x9FF
movslq %ecx, %rcx
cmpq %rcx, %rax
jae 0x4bec3
movq 0x20(%rsp), %rcx
movl (%rcx,%rax,4), %ecx
cmpl %edx, %ecx
cmovgel %edx, %ecx
movslq %ecx, %rcx
movl 0x700(%rsp,%rcx,4), %ecx
andl $-0x2, %ecx
shll $0xf, %ecx
movq 0x10(%r12), %rsi
orl %ecx, (%rsi,%rax,4)
incq %rax
movl (%r12), %ecx
jmp 0x4be73
movq 0x18(%rsp), %r12
leaq 0xaf00(%rsp), %r15
leaq 0x2f00(%rsp), %rbp
jmp 0x4bf72
movl $0x1, 0x8(%r10)
movl 0x38(%rsp), %eax
movl %eax, 0x10(%rsp)
cmpl $-0x1, 0x1c60(%r10)
jne 0x4bf72
movl 0x24(%r10), %ecx
movl 0x2c(%r10), %eax
testl %ecx, %ecx
je 0x4bf10
testl %eax, %eax
je 0x4bf2d
movl 0x30(%r10), %edx
leal -0x1(%rdx), %esi
movl %esi, 0x38(%r10)
decl %ecx
movl %ecx, 0x24(%r10)
decl %eax
movl %eax, 0x2c(%r10)
incl %edx
movl %edx, 0x30(%r10)
jmp 0x4bf67
cmpl $0x2, %eax
jb 0x4bf2d
movl 0x30(%r10), %ecx
movl %ecx, 0x38(%r10)
addl $-0x2, %eax
movl %eax, 0x2c(%r10)
addl $0x2, %ecx
movl %ecx, 0x30(%r10)
jmp 0x4bf67
movl 0x1c(%r10), %eax
cmpl $0x2, %eax
jb 0x4bf67
addl $-0x2, %eax
movl %eax, 0x1c(%r10)
addl $-0x2, 0x28(%r10)
pushq $0xe
popq %rcx
subl 0x1c5c(%r10), %ecx
movl %ecx, 0x38(%r10)
cmpl $0x6, %eax
jne 0x4bf67
cmpl $0x5, 0x1c48(%r10)
jne 0x4bf67
movl $0x5, 0x1c(%r10)
movl $0x4, 0x1c60(%r10)
cmpl $0x0, 0x30(%rsp)
jne 0x4bf87
cmpl $0x0, 0x1c5c(%r10)
je 0x4c1d8
xorpd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
xorl %ebx, %ebx
movl $0x400, %r14d           # imm = 0x400
movsd %xmm0, 0x8(%rsp)
cmpq $0x20, %rbx
je 0x4c126
movq 0x400(%rsp,%rbx,8), %rcx
testq %rcx, %rcx
je 0x4c115
movq 0x300(%rsp,%rbx,8), %rax
testq %rax, %rax
je 0x4c115
leaq (%rax,%rcx), %rdx
movq %rdx, %xmm0
movq 0x2b784(%rip), %xmm1    # 0x77760
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x2b788(%rip), %xmm2    # 0x77770
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 %r12d, %r12d
cmpq $0x100, %r12            # imm = 0x100
je 0x4c110
movl (%r15,%r12,4), %eax
testl %eax, %eax
je 0x4c108
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x28(%rsp)
divsd 0x60(%rsp), %xmm0
callq 0x4390
movl (%r13,%r12,4), %eax
testl %eax, %eax
je 0x4c0b7
movl %eax, %eax
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 0x28(%rsp), %xmm1
mulsd %xmm0, %xmm1
movsd 0x30(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
movl (%rbp,%r12,4), %eax
testl %eax, %eax
je 0x4c108
movl %eax, %eax
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x28(%rsp)
divsd 0x70(%rsp), %xmm0
callq 0x4390
mulsd 0x28(%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
incq %r12
jmp 0x4c03f
movq 0x18(%rsp), %r12
incq %rbx
addq %r14, %rbp
addq %r14, %r13
addq %r14, %r15
jmp 0x4bf9f
movsd 0x317c2(%rip), %xmm0    # 0x7d8f0
movsd 0x30(%rsp), %xmm1
divsd %xmm0, %xmm1
xorl %esi, %esi
movq 0x40(%rsp), %r10
cmpl $0x0, 0x1c5c(%r10)
movsd 0x8(%rsp), %xmm2
divsd %xmm0, %xmm2
setg %sil
movl (%r12), %ecx
movl %ecx, %eax
cltd
pushq $0x8
popq %rdi
idivl %edi
addl $0x8, %eax
cvtsi2sd %eax, %xmm0
addsd %xmm2, %xmm0
leaq 0x3173d(%rip), %rax     # 0x7d8b0
mulsd (%rax,%rsi,8), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x4c1d8
xorl %eax, %eax
movl 0x14(%rsp), %r8d
movl 0x10(%rsp), %r9d
movslq %ecx, %rdx
cmpq %rdx, %rax
jae 0x4c1dd
movq 0x10(%r12), %rdx
movl (%rdx,%rax,4), %esi
testl %r8d, %r8d
js 0x4c1a9
movl %esi, %edi
shrl $0x10, %edi
cmpl %r8d, %edi
jne 0x4c1d3
movzwl %si, %ecx
movl %esi, %edi
andl $0xffff0000, %edi       # imm = 0xFFFF0000
shll $0x9, %esi
andl $0x10000, %esi          # imm = 0x10000
leal (%rsi,%rdi,2), %esi
orl %esi, %ecx
movl %ecx, (%rdx,%rax,4)
shrl $0x10, %esi
cmpl %esi, %r9d
cmovbel %esi, %r9d
movl (%r12), %ecx
incq %rax
jmp 0x4c18a
movl 0x10(%rsp), %r9d
testl %r9d, %r9d
jle 0x4c1ee
movl $0x1, 0x8(%r10)
movl %r9d, 0x44(%r10)
movq 0x20(%rsp), %rdi
addq $0x52f08, %rsp          # imm = 0x52F08
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x45c0