// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/htscodecs/htscodecs/rANS_static32x16pr_avx512.c
// Function: rans_compress_O1_32x16_avx512
unsigned char *rans_compress_O1_32x16_avx512(unsigned char *in,
                                             unsigned int in_size,
                                             unsigned char *out,
                                             unsigned int *out_size) {
    unsigned char *cp, *out_end, *out_free = NULL;
    unsigned int tab_size;
    uint32_t bound = rans_compress_bound_4x16(in_size,1)-20;
    int z;
    RansState ransN[32] __attribute__((aligned(64)));

    if (in_size < 32) // force O0 instead
        return NULL;

    if (!out) {
        *out_size = bound;
        out = malloc(*out_size);
    }
    if (!out || bound > *out_size)
        return NULL;

    if (((size_t)out)&1)
        bound--;
    out_end = out + bound;

    RansEncSymbol (*syms)[256] = htscodecs_tls_alloc(256 * (sizeof(*syms)));
    if (!syms) {
        free(out_free);
        return NULL;
    }

    cp = out;
    int shift = encode_freq1(in, in_size, 32, syms, &cp);
    if (shift < 0) {
        free(out_free);
        htscodecs_tls_free(syms);
        return NULL;
    }
    tab_size = cp - out;

    for (z = 0; z < 32; z++)
      RansEncInit(&ransN[z]);

    uint8_t* ptr = out_end;

    int iN[32] __attribute__((aligned(64)));
    int isz4 = in_size/32;
    for (z = 0; z < 32; z++)
        iN[z] = (z+1)*isz4-2;

    uint32_t lN[32] __attribute__((aligned(64)));
    for (z = 0; z < 32; z++)
        lN[z] = in[iN[z]+1];

    // Deal with the remainder
    z = 32-1;
    lN[z] = in[in_size-1];
    for (iN[z] = in_size-2; iN[z] > 32*isz4-2; iN[z]--) {
        unsigned char c = in[iN[z]];
        RansEncPutSymbol(&ransN[z], &ptr, &syms[c][lN[z]]);
        lN[z] = c;
    }

    LOAD512(Rv, ransN);

    uint16_t *ptr16 = (uint16_t *)ptr;
    LOAD512(iN, iN);
    LOAD512(last, lN);

    __m512i c1 = _mm512_i32gather_epi32x1(iN1, in);
    __m512i c2 = _mm512_i32gather_epi32x1(iN2, in);

    // We cache the next 64-bytes locally and transpose.
    // This means we can load 32 ints from t32[x] with load instructions
    // instead of gathers.  The copy, transpose and expand is easier done
    // in scalar code.
#define BATCH 64
    uint8_t t32[BATCH][32] __attribute__((aligned(64)));
    int next_batch;
    if (iN[0] > BATCH) {
        int i, j;
        for (i = 0; i < BATCH; i++)
            // memcpy(c[i], &in[iN[i]-32], 32); fast mode
            for (j = 0; j < 32; j++)
                t32[BATCH-1-i][j] = in[iN[j]-1-i];
        next_batch = BATCH;
    } else {
        next_batch = -1;
    }

    for (; iN[0] >= 0; iN[0]--) {
        // Note, consider doing the same approach for the AVX2 encoder.
        // Maybe we can also get gather working well there?
        // Gather here is still a major latency bottleneck, consuming
        // around 40% of CPU cycles overall.

        // FIXME: maybe we need to cope with in[31] read over-flow
        // on loop cycles 0, 1, 2 where gather reads 32-bits instead of
        // 8 bits.  Use set instead there on c2?

        // index into syms[0][0] array, used for x_max, rcp_freq, and bias
        __m512i vidx1 = _mm512_slli_epi32(c1, 8);
        __m512i vidx2 = _mm512_slli_epi32(c2, 8);
        vidx1 = _mm512_add_epi32(vidx1, last1);
        vidx2 = _mm512_add_epi32(vidx2, last2);
        vidx1 = _mm512_slli_epi32(vidx1, 2);
        vidx2 = _mm512_slli_epi32(vidx2, 2);

        // ------------------------------------------------------------
        //      for (z = NX-1; z >= 0; z--) {
        //          if (ransN[z] >= x_max[z]) {
        //              *--ptr16 = ransN[z] & 0xffff;
        //              ransN[z] >>= 16;
        //          }
        //      }

#define SET512x(a,x) \
        __m512i a##1 = _mm512_i32gather_epi32x(vidx1, &syms[0][0].x, 4); \
        __m512i a##2 = _mm512_i32gather_epi32x(vidx2, &syms[0][0].x, 4)

        // Start of next loop, moved here to remove latency.
        // last[z] = c[z]
        // iN[z]--
        // c[z] = in[iN[z]]
        last1 = c1;
        last2 = c2;
        iN1 = _mm512_sub_epi32(iN1, _mm512_set1_epi32(1));
        iN2 = _mm512_sub_epi32(iN2, _mm512_set1_epi32(1));

        // Code below is equivalent to this:
        // c1 = _mm512_i32gather_epi32(iN1, in, 1);
        // c2 = _mm512_i32gather_epi32(iN2, in, 1);

        // Better when we have a power of 2
        if (next_batch >= 0) {
            if (--next_batch < 0 && iN[0] > BATCH) {
                // Load 32 BATCH blocks of data.
                // Executed once every BATCH cycles
                int i, j;
                uint8_t c[32][BATCH];
                iN[0] += BATCH;
                for (j = 0; j < 32; j++) {
                    iN[j] -= BATCH;
                    memcpy(c[j], &in[iN[j]-BATCH], BATCH);
                }
                // transpose matrix from 32xBATCH to BATCHx32
                for (j = 0; j < 32; j++) {
                    for (i = 0; i < BATCH; i+=16) {
                        int z;
                        for (z = 0; z < 16; z++)
                            t32[i+z][j] = c[j][i+z];
                    }
                }
                next_batch = BATCH-1;
            }
            if (next_batch >= 0) {
                // Copy from our of our pre-loaded BATCHx32 tables
                // Executed every cycles
                __m128i c1_ = _mm_load_si128((__m128i *)&t32[next_batch][0]);
                __m128i c2_ = _mm_load_si128((__m128i *)&t32[next_batch][16]);
                c1 = _mm512_cvtepu8_epi32(c1_);
                c2 = _mm512_cvtepu8_epi32(c2_);
            }
        }

        if (next_batch < 0 && iN[0]) {
            // no pre-loaded data as within BATCHx32 of input end
            c1 = _mm512_i32gather_epi32x1(iN1, in);
            c2 = _mm512_i32gather_epi32x1(iN2, in);

            // Speeds up clang, even though not needed any more.
            // Harmless to leave here.
            c1 = _mm512_and_si512(c1, _mm512_set1_epi32(0xff));
            c2 = _mm512_and_si512(c2, _mm512_set1_epi32(0xff));
        }
        // End of "equivalent to" code block

        SET512x(xmax, x_max); // high latency

        uint16_t gt_mask1 = _mm512_cmpgt_epi32_mask(Rv1, xmax1);
        int pc1 = _mm_popcnt_u32(gt_mask1);
        __m512i Rp1 = _mm512_and_si512(Rv1, _mm512_set1_epi32(0xffff));
        __m512i Rp2 = _mm512_and_si512(Rv2, _mm512_set1_epi32(0xffff));
        uint16_t gt_mask2 = _mm512_cmpgt_epi32_mask(Rv2, xmax2);
        SET512x(SDv, cmpl_freq); // good
        int pc2 = _mm_popcnt_u32(gt_mask2);

        Rp1 = _mm512_maskz_compress_epi32(gt_mask1, Rp1);
        Rp2 = _mm512_maskz_compress_epi32(gt_mask2, Rp2);

        _mm512_mask_cvtepi32_storeu_epi16(ptr16-pc2, (1<<pc2)-1, Rp2);
        ptr16 -= pc2;
        _mm512_mask_cvtepi32_storeu_epi16(ptr16-pc1, (1<<pc1)-1, Rp1);
        ptr16 -= pc1;

        Rv1 = _mm512_mask_srli_epi32(Rv1, gt_mask1, Rv1, 16);
        Rv2 = _mm512_mask_srli_epi32(Rv2, gt_mask2, Rv2, 16);

        // ------------------------------------------------------------
        // uint32_t q = (uint32_t) (((uint64_t)ransN[z] * rcp_freq[z])
        //                          >> rcp_shift[z]);
        // ransN[z] = ransN[z] + bias[z] + q * cmpl_freq[z];
        SET512x(rfv, rcp_freq); // good-ish

        __m512i rf1_hm = _mm512_mul_epu32(_mm512_srli_epi64(Rv1, 32),
                                          _mm512_srli_epi64(rfv1, 32));
        __m512i rf2_hm = _mm512_mul_epu32(_mm512_srli_epi64(Rv2, 32),
                                          _mm512_srli_epi64(rfv2, 32));
        __m512i rf1_lm = _mm512_srli_epi64(_mm512_mul_epu32(Rv1, rfv1), 32);
        __m512i rf2_lm = _mm512_srli_epi64(_mm512_mul_epu32(Rv2, rfv2), 32);

        const __m512i top32 = _mm512_set1_epi64((uint64_t)0xffffffff00000000);
        rf1_hm = _mm512_and_epi32(rf1_hm, top32);
        rf2_hm = _mm512_and_epi32(rf2_hm, top32);
        rfv1 = _mm512_or_epi32(rf1_lm, rf1_hm);
        rfv2 = _mm512_or_epi32(rf2_lm, rf2_hm);

        SET512x(biasv, bias); // good
        __m512i shiftv1 = _mm512_srli_epi32(SDv1, 16);
        __m512i shiftv2 = _mm512_srli_epi32(SDv2, 16);

        shiftv1 = _mm512_sub_epi32(shiftv1, _mm512_set1_epi32(32));
        shiftv2 = _mm512_sub_epi32(shiftv2, _mm512_set1_epi32(32));

        __m512i qv1 = _mm512_srlv_epi32(rfv1, shiftv1);
        __m512i qv2 = _mm512_srlv_epi32(rfv2, shiftv2);

        const __m512i bot16 = _mm512_set1_epi32(0xffff);
        qv1 = _mm512_mullo_epi32(qv1, _mm512_and_si512(SDv1, bot16));
        qv2 = _mm512_mullo_epi32(qv2, _mm512_and_si512(SDv2, bot16));

        qv1 = _mm512_add_epi32(qv1, biasv1);
        Rv1 = _mm512_add_epi32(Rv1, qv1);

        qv2 = _mm512_add_epi32(qv2, biasv2);
        Rv2 = _mm512_add_epi32(Rv2, qv2);
    }

    STORE512(Rv, ransN);
    STORE512(last, lN);

    ptr = (uint8_t *)ptr16;

    for (z = 32-1; z>=0; z--)
        RansEncPutSymbol(&ransN[z], &ptr, &syms[0][lN[z]]);

    for (z = 32-1; z >= 0; z--)
        RansEncFlush(&ransN[z], &ptr);

    // Finalise block size and return it
    *out_size = (out_end - ptr) + tab_size;

//    cp = out;
//    *cp++ = (in_size>> 0) & 0xff;
//    *cp++ = (in_size>> 8) & 0xff;
//    *cp++ = (in_size>>16) & 0xff;
//    *cp++ = (in_size>>24) & 0xff;

    memmove(out + tab_size, ptr, out_end-ptr);

    htscodecs_tls_free(syms);
    return out;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
andq $-0x40, %rsp
subq $0x15c0, %rsp           # imm = 0x15C0
movq %rcx, %r14
movq %rdx, %r15
movl %esi, %r12d
movq %rdi, %rbx
pushq $0x1
popq %rsi
movl %r12d, %edi
callq 0x4edbc
movq %r12, 0x100(%rsp)
cmpl $0x20, %r12d
jb 0x57d63
movq %rbx, 0x18(%rsp)
leal -0x14(%rax), %ebx
testq %r15, %r15
je 0x57702
cmpl (%r14), %ebx
jbe 0x5771e
jmp 0x57d63
movl %ebx, (%r14)
movl %ebx, %edi
movq %rax, %r12
callq 0x4680
movq %rax, %r15
movq %r12, %rax
testq %r15, %r15
je 0x57d63
addl $-0x15, %eax
testb $0x1, %r15b
cmovel %ebx, %eax
movq %rax, 0x48(%rsp)
movl $0x100000, %edi         # imm = 0x100000
callq 0x6412c
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x57d63
movl $0x100, %edi            # imm = 0x100
movl $0x400, %esi            # imm = 0x400
callq 0x6426c
testq %rax, %rax
je 0x57d59
movq %rax, %r13
leaq 0x580(%rsp), %rdi
movl $0x420, %edx            # imm = 0x420
xorl %esi, %esi
callq 0x4260
movq 0x100(%rsp), %rcx
movl %ecx, %r10d
shrl $0x5, %r10d
movl %ecx, %ebx
movq 0x18(%rsp), %rax
addq %rax, %rbx
pushq $-0x1
popq %r12
cmpl $0x7a120, %ecx          # imm = 0x7A120
movq %r15, 0x28(%rsp)
movq %r14, 0x60(%rsp)
movq %r10, 0x240(%rsp)
jbe 0x578e3
movl $0x100, %edi            # imm = 0x100
movl $0x40c, %esi            # imm = 0x40C
callq 0x6426c
testq %rax, %rax
je 0x57cfd
leaq -0x8(%rbx), %rdx
xorl %esi, %esi
movq 0x18(%rsp), %rcx
cmpq %rdx, %rcx
jae 0x5787c
movzbl (%rcx), %r8d
movzbl 0x1(%rcx), %r9d
movzbl 0x2(%rcx), %r10d
movzbl 0x3(%rcx), %edi
movzbl %sil, %esi
shll $0xa, %esi
addq %r13, %rsi
incl (%rsi,%r8,4)
imulq $0x40c, %r8, %rsi       # imm = 0x40C
addq %rax, %rsi
incl (%rsi,%r9,4)
shll $0xa, %r9d
addq %r13, %r9
incl (%r9,%r10,4)
imulq $0x40c, %r10, %rsi      # imm = 0x40C
addq %rax, %rsi
incl (%rsi,%rdi,4)
movzbl 0x4(%rcx), %r8d
movzbl 0x5(%rcx), %r9d
movzbl 0x6(%rcx), %r10d
movzbl 0x7(%rcx), %esi
shll $0xa, %edi
addq %r13, %rdi
incl (%rdi,%r8,4)
imulq $0x40c, %r8, %rdi       # imm = 0x40C
addq %rax, %rdi
incl (%rdi,%r9,4)
addq $0x8, %rcx
shll $0xa, %r9d
addq %r13, %r9
incl (%r9,%r10,4)
imulq $0x40c, %r10, %rdi      # imm = 0x40C
addq %rax, %rdi
incl (%rdi,%rsi,4)
jmp 0x577d2
movzbl (%rcx), %esi
incq %rcx
shll $0xa, %edx
addq %r13, %rdx
incl (%rdx,%rsi,4)
movzbl %sil, %edx
cmpq %rbx, %rcx
jb 0x5786d
incl 0x580(%rsp,%rdx,4)
xorl %ecx, %ecx
movq %rax, %rdx
movq %r13, %rsi
movq 0x18(%rsp), %rbx
cmpq $0x100, %rcx            # imm = 0x100
je 0x579cb
xorl %edi, %edi
xorl %r8d, %r8d
cmpq $0x100, %rdi            # imm = 0x100
je 0x578c8
movl (%rsi,%rdi,4), %r9d
addl (%rdx,%rdi,4), %r9d
movl %r9d, (%rsi,%rdi,4)
addl %r9d, %r8d
incq %rdi
jmp 0x578ab
addl %r8d, 0x580(%rsp,%rcx,4)
incq %rcx
addq $0x400, %rsi            # imm = 0x400
addq $0x40c, %rdx            # imm = 0x40C
jmp 0x57899
leaq -0x8(%rbx), %rcx
xorl %edx, %edx
cmpq %rcx, %rax
jae 0x57982
movzbl (%rax), %r8d
movzbl 0x1(%rax), %r9d
movzbl 0x2(%rax), %edi
movzbl 0x3(%rax), %esi
movzbl %dl, %edx
shll $0xa, %edx
addq %r13, %rdx
incl (%rdx,%r8,4)
shll $0xa, %r8d
addq %r13, %r8
incl (%r8,%r9,4)
shll $0xa, %r9d
addq %r13, %r9
incl (%r9,%rdi,4)
shll $0xa, %edi
addq %r13, %rdi
incl (%rdi,%rsi,4)
movzbl 0x4(%rax), %r8d
movzbl 0x5(%rax), %r9d
movzbl 0x6(%rax), %edi
movzbl 0x7(%rax), %edx
shll $0xa, %esi
addq %r13, %rsi
incl (%rsi,%r8,4)
shll $0xa, %r8d
addq %r13, %r8
incl (%r8,%r9,4)
addq $0x8, %rax
shll $0xa, %r9d
addq %r13, %r9
incl (%r9,%rdi,4)
shll $0xa, %edi
addq %r13, %rdi
incl (%rdi,%rdx,4)
jmp 0x578e9
movzbl (%rax), %edx
incq %rax
shll $0xa, %ecx
addq %r13, %rcx
incl (%rcx,%rdx,4)
movzbl %dl, %ecx
cmpq %rbx, %rax
jb 0x57973
incl 0x580(%rsp,%rcx,4)
xorl %eax, %eax
movq %r13, %rcx
movq 0x18(%rsp), %rbx
cmpq $0x100, %rax            # imm = 0x100
je 0x579db
xorl %edx, %edx
xorl %esi, %esi
cmpq $0x100, %rdx            # imm = 0x100
je 0x579b8
addl (%rcx,%rdx,4), %esi
incq %rdx
jmp 0x579a7
addl %esi, 0x580(%rsp,%rax,4)
incq %rax
addq $0x400, %rcx            # imm = 0x400
jmp 0x5799b
movq %rax, %rdi
callq 0x64291
movq 0x240(%rsp), %r10
movl %r10d, %eax
leaq (%rbx,%rax), %rcx
pushq $0x1f
popq %rdx
subq $0x1, %rdx
jb 0x579f8
movzbl (%rcx), %esi
incl (%r13,%rsi,4)
addq %rax, %rcx
jmp 0x579e5
leaq 0x580(%rsp), %rbx
movl (%rbx), %r14d
addl $0x1f, %r14d
pushq $0x1
popq %r12
movl %r12d, (%rbx)
leaq 0x1(%r15), %rdi
movb $0x0, (%r15)
movq %rdi, 0x180(%rsp)
movq %rbx, %rsi
callq 0x5962c
cltq
addq %r15, %rax
incq %rax
movq %rax, 0x20(%rsp)
movl %r14d, (%rbx)
leaq 0xd80(%rsp), %r15
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
callq 0x4260
movq %rbx, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x4fa19
movl %eax, %ecx
shll %cl, %r12d
movl %r12d, 0x280(%rsp)
xorl %r12d, %r12d
movq 0x30(%rsp), %rax
movq %r13, %r14
movq %r13, 0x1c0(%rsp)
movl %ecx, 0x140(%rsp)
cmpq $0x100, %r12            # imm = 0x100
je 0x57c10
movl 0x580(%rsp,%r12,4), %esi
testl %esi, %esi
je 0x57bfb
movq %rax, 0xc0(%rsp)
movl 0xd80(%rsp,%r12,4), %eax
movl $0x400, %edi            # imm = 0x400
cmpl %edi, %eax
movl $0x400, %r15d           # imm = 0x400
cmovbl %eax, %r15d
cmpl $0xa, %ecx
cmovnel %eax, %r15d
movq %r12, %rbx
shlq $0xa, %rbx
addq %r13, %rbx
movq %rbx, %rdi
movl %r15d, %edx
callq 0x56e66
testl %eax, %eax
movq 0x18(%rsp), %rax
js 0x57ce3
movq %r12, 0x80(%rsp)
movl %r15d, 0x580(%rsp,%r12,4)
xorl %r13d, %r13d
movq 0x20(%rsp), %r12
movq %r12, %r15
xorl %eax, %eax
cmpq $0x100, %r13            # imm = 0x100
je 0x57b59
cmpl $0x0, 0x580(%rsp,%r13,4)
je 0x57b54
movl (%r14,%r13,4), %esi
testl %esi, %esi
je 0x57b4b
testl %eax, %eax
je 0x57b3a
decl %eax
cltq
subq %rax, %r15
movb %al, (%r15)
incq %r15
movl (%r14,%r13,4), %esi
movq %r15, %rdi
callq 0x596aa
movl %eax, %eax
addq %rax, %r15
xorl %eax, %eax
jmp 0x57b54
incl %eax
movb $0x0, (%r15)
incq %r15
incq %r13
jmp 0x57b09
testl %eax, %eax
je 0x57b6a
decl %eax
cltq
subq %rax, %r15
movb %al, (%r15)
incq %r15
subl %r12d, %r15d
shlq $0x20, %r15
movq 0x80(%rsp), %r12
movl 0x580(%rsp,%r12,4), %esi
movq %rbx, %rdi
movl 0x280(%rsp), %ebx
movl %ebx, %edx
callq 0x5767d
movl %ebx, 0x580(%rsp,%r12,4)
xorl %ebx, %ebx
movq 0xc0(%rsp), %r12
xorl %r13d, %r13d
cmpq $0x100, %rbx            # imm = 0x100
je 0x57bd3
movl (%r14,%rbx,4), %edx
movq %r12, %rdi
movl %r13d, %esi
movl 0x140(%rsp), %ecx
callq 0x56f89
addl (%r14,%rbx,4), %r13d
incq %rbx
addq $0x10, %r12
jmp 0x57ba7
sarq $0x20, %r15
addq %r15, 0x20(%rsp)
movq 0x1c0(%rsp), %r13
movl 0x140(%rsp), %ecx
movq 0x80(%rsp), %r12
movq 0xc0(%rsp), %rax
incq %r12
addq $0x400, %r14            # imm = 0x400
addq $0x1000, %rax           # imm = 0x1000
jmp 0x57a85
movl %ecx, %eax
shlb $0x4, %al
movq 0x28(%rsp), %r15
movb %al, (%r15)
movq 0x20(%rsp), %rax
movq %rax, %rbx
subq %r15, %rbx
cmpq $0x3e9, %rbx            # imm = 0x3E9
jl 0x57cf6
movl %eax, %r12d
movq 0x180(%rsp), %rdi
subl %edi, %r12d
leaq 0x380(%rsp), %rcx
movl %r12d, %esi
xorl %edx, %edx
callq 0x4ee61
movq %rax, %r15
testq %rax, %rax
je 0x57d09
movl 0x380(%rsp), %ecx
leal 0x6(%rcx), %eax
cmpq %rax, %rbx
movq 0x18(%rsp), %rbx
jbe 0x57d0e
movq 0x28(%rsp), %rax
orb $0x1, (%rax)
movq 0x180(%rsp), %rdi
movl %r12d, %esi
movq %rcx, %r12
movq %rcx, 0xc0(%rsp)
callq 0x596aa
movl %eax, %edi
addq 0x180(%rsp), %rdi
movq %rdi, 0x80(%rsp)
movl %r12d, %esi
callq 0x596aa
movl %eax, %r12d
addq 0x80(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
movq 0xc0(%rsp), %rdx
callq 0x43c0
addq 0xc0(%rsp), %r12
movq %r12, 0x20(%rsp)
jmp 0x57d0e
movq %rax, %rbx
movq 0x28(%rsp), %r15
movq %r15, 0x20(%rsp)
pushq $-0x1
popq %r12
jmp 0x57d23
movq 0x18(%rsp), %rbx
jmp 0x57d1b
movq %r15, 0x20(%rsp)
movq 0x18(%rsp), %rbx
jmp 0x57d23
movq 0x18(%rsp), %rbx
movq %r15, %rdi
callq 0x45c0
movq 0x28(%rsp), %r15
movl 0x140(%rsp), %r12d
movq %r13, %rdi
callq 0x64291
testl %r12d, %r12d
js 0x57d59
movq 0x48(%rsp), %rax
leaq (%r15,%rax), %rcx
xorl %eax, %eax
movq 0x240(%rsp), %rdx
cmpq $0x20, %rax
je 0x57d78
movl $0x8000, 0x380(%rsp,%rax,4) # imm = 0x8000
incq %rax
jmp 0x57d43
movq 0x30(%rsp), %rdi
callq 0x64291
xorl %r15d, %r15d
movq %r15, %rax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, 0x58(%rsp)
movq %rcx, 0x38(%rsp)
leal -0x2(%rdx), %eax
xorl %ecx, %ecx
cmpq $0x20, %rcx
je 0x57d9b
movl %eax, 0x2c0(%rsp,%rcx,4)
incq %rcx
addl %edx, %eax
jmp 0x57d87
xorl %eax, %eax
cmpq $0x20, %rax
je 0x57dbc
movslq 0x2c0(%rsp,%rax,4), %rcx
movzbl 0x1(%rbx,%rcx), %ecx
movl %ecx, 0x480(%rsp,%rax,4)
incq %rax
jmp 0x57d9d
movq 0x100(%rsp), %r13
leal -0x1(%r13), %eax
movb (%rbx,%rax), %r12b
leal -0x2(%r13), %r15d
andl $-0x20, %r13d
addl $-0x2, %r13d
leaq 0x3fc(%rsp), %rbx
leaq 0x38(%rsp), %r14
movzbl %r12b, %edx
cmpl %r13d, %r15d
jle 0x57e1c
movl %r15d, %eax
movq 0x18(%rsp), %rcx
movzbl (%rcx,%rax), %r12d
movl %r12d, %eax
shll $0xc, %eax
shll $0x4, %edx
addq 0x30(%rsp), %rdx
addq %rax, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x57080
decl %r15d
jmp 0x57de5
movl %r15d, 0x33c(%rsp)
movl %edx, 0x4fc(%rsp)
vmovaps 0x380(%rsp), %zmm0
vmovaps %zmm0, 0xc0(%rsp)
vmovaps 0x3c0(%rsp), %zmm0
vmovaps %zmm0, 0x140(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x40(%rsp)
vmovaps 0x2c0(%rsp), %zmm0
vmovaps 0x300(%rsp), %zmm1
vmovaps %zmm1, 0x1c0(%rsp)
vmovaps 0x480(%rsp), %zmm1
vmovaps %zmm1, 0x100(%rsp)
vmovdqa64 0x4c0(%rsp), %zmm1
vmovdqa64 %zmm1, 0x80(%rsp)
movl 0x2c0(%rsp), %r12d
vmovaps %zmm0, 0x280(%rsp)
movq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x5852d
vmovaps %zmm0, 0x340(%rsp)
vmovdqa64 0x1c0(%rsp), %zmm0
movq %rbx, %rdi
callq 0x5852d
pushq $-0x1
popq %r13
cmpl $0x41, %r12d
jl 0x57f0e
leaq 0xd60(%rsp), %rax
xorl %ecx, %ecx
pushq $0x40
popq %r13
cmpq $0x40, %rcx
je 0x57f0e
movl %ecx, %edx
notl %edx
xorl %esi, %esi
cmpq $0x20, %rsi
je 0x57f05
movl 0x2c0(%rsp,%rsi,4), %edi
addl %edx, %edi
movslq %edi, %rdi
movb (%rbx,%rdi), %dil
movb %dil, (%rax,%rsi)
incq %rsi
jmp 0x57ee6
incq %rcx
addq $-0x20, %rax
jmp 0x57eda
movq 0x20(%rsp), %rax
subq 0x28(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq -0x80(%rbx), %r14
movq 0x30(%rsp), %rax
leaq 0xc(%rax), %rcx
movq %rcx, 0x78(%rsp)
leaq 0x4(%rax), %rcx
movq %rcx, 0x70(%rsp)
addq $0x8, %rax
movq %rax, 0x68(%rsp)
vmovdqa64 0x80(%rsp), %zmm4
vmovdqa64 0x100(%rsp), %zmm5
vmovdqa64 0x340(%rsp), %zmm2
testl %r12d, %r12d
js 0x5844c
vmovdqa64 %zmm0, %zmm3
vmovdqa64 0x280(%rsp), %zmm0
vpternlogd $0xff, %zmm1, %zmm1, %zmm1
vpaddd %zmm1, %zmm0, %zmm0
vmovdqa64 %zmm0, 0x280(%rsp)
vmovdqa64 0x1c0(%rsp), %zmm0
vpaddd %zmm1, %zmm0, %zmm0
vmovdqa64 %zmm0, 0x1c0(%rsp)
testl %r13d, %r13d
vmovdqa64 %zmm2, 0x240(%rsp)
vmovdqa64 %zmm3, 0x180(%rsp)
js 0x58006
jne 0x57ffc
cmpl $0x41, %r12d
jb 0x57ffc
addl $0x40, %r12d
movl %r12d, 0x2c0(%rsp)
leaq 0x2c0(%rsp), %rax
xorl %ecx, %ecx
cmpq $0x200, %rcx            # imm = 0x200
je 0x5809c
movslq (%rax), %rdx
leal -0x40(%rdx), %esi
movl %esi, (%rax)
vmovdqu64 (%r14,%rdx), %zmm0
vmovdqu64 %zmm0, 0xd80(%rsp,%rcx,4)
addq $0x10, %rcx
addq $0x4, %rax
jmp 0x57fce
subl $0x1, %r13d
jae 0x58100
pushq $-0x1
popq %r15
movl %r15d, %r13d
vmovdqa64 %zmm3, %zmm0
vmovdqa64 %zmm2, %zmm6
testl %r12d, %r12d
je 0x5811b
vmovaps 0x280(%rsp), %zmm0
movq 0x18(%rsp), %r12
movq %r12, %rdi
vmovdqa64 %zmm4, 0x80(%rsp)
vmovdqa64 %zmm5, 0x100(%rsp)
callq 0x5852d
vmovaps %zmm0, 0x340(%rsp)
vmovdqa64 0x1c0(%rsp), %zmm0
movq %r12, %rdi
callq 0x5852d
vmovdqa64 0x100(%rsp), %zmm5
vmovdqa64 0x80(%rsp), %zmm4
vmovdqa64 0x180(%rsp), %zmm3
vmovdqa64 0x240(%rsp), %zmm2
vpbroadcastd 0x25c3f(%rip), %zmm1 # 0x7dcc8
vpandq 0x340(%rsp), %zmm1, %zmm6
vpandq %zmm1, %zmm0, %zmm0
movl %r15d, %r13d
jmp 0x5811b
leaq 0x580(%rsp), %rax
leaq 0xd80(%rsp), %rcx
xorl %edx, %edx
cmpq $0x20, %rdx
je 0x580fc
movq %rax, %rsi
movq %rcx, %rdi
xorl %r8d, %r8d
cmpq $0x3f, %r8
ja 0x580f0
movq %rsi, %r9
xorl %r10d, %r10d
cmpq $0x10, %r10
je 0x580df
movb (%rdi,%r10), %r11b
movb %r11b, (%r9)
incq %r10
addq $0x20, %r9
jmp 0x580c9
addq $0x10, %r8
addq $0x10, %rdi
addq $0x200, %rsi            # imm = 0x200
jmp 0x580bd
incq %rdx
addq $0x40, %rcx
incq %rax
jmp 0x580ae
pushq $0x3f
popq %r13
movl %r13d, %eax
shlq $0x5, %rax
vpmovzxbd 0x580(%rsp,%rax), %zmm6
vpmovzxbd 0x590(%rsp,%rax), %zmm0
pushq $-0x1
popq %r15
vmovdqa64 %zmm0, 0x540(%rsp)
vmovdqa64 %zmm6, 0x340(%rsp)
vpslld $0xa, %zmm2, %zmm0
vpslld $0x2, %zmm5, %zmm1
vpaddd %zmm0, %zmm1, %zmm2
vmovdqa64 %zmm2, 0x100(%rsp)
vpslld $0xa, %zmm3, %zmm0
vpslld $0x2, %zmm4, %zmm1
vpaddd %zmm0, %zmm1, %zmm0
vmovdqa64 %zmm0, 0x80(%rsp)
vmovdqa64 %zmm2, %zmm0
movq 0x30(%rsp), %r12
movq %r12, %rdi
callq 0x570b9
vmovdqa64 %zmm0, 0x440(%rsp)
vmovdqa64 0x80(%rsp), %zmm0
movq %r12, %rdi
callq 0x570b9
vmovdqa64 0x440(%rsp), %zmm1
vpcmpltd 0xc0(%rsp), %zmm1, %k1
kmovw %k1, 0x200(%rsp)
kmovw %k1, %eax
popcntl %eax, %r12d
vpcmpltd 0x140(%rsp), %zmm0, %k1
kmovw %k1, 0x400(%rsp)
vmovaps 0x100(%rsp), %zmm0
movq 0x78(%rsp), %rbx
movq %rbx, %rdi
callq 0x570b9
vmovaps %zmm0, 0x440(%rsp)
vmovaps 0x80(%rsp), %zmm0
movq %rbx, %rdi
callq 0x570b9
vmovaps %zmm0, 0x500(%rsp)
kmovw 0x400(%rsp), %k2
kmovw %k2, %eax
popcntl %eax, %ecx
vpbroadcastd 0x29b4d(%rip), %zmm1 # 0x81d60
vmovdqa64 0xc0(%rsp), %zmm2
vpandq %zmm1, %zmm2, %zmm0
kmovw 0x200(%rsp), %k3
vpcompressd %zmm0, %zmm0 {%k3} {z}
vmovdqa64 0x140(%rsp), %zmm3
vpandq %zmm1, %zmm3, %zmm1
vpcompressd %zmm1, %zmm1 {%k2} {z}
leal (%rcx,%rcx), %eax
movq 0x40(%rsp), %rdx
subq %rax, %rdx
movl %r15d, %eax
shll %cl, %eax
notl %eax
kmovw %eax, %k1
vpmovdw %zmm1, (%rdx) {%k1}
movl %r12d, %ecx
shll %cl, %r15d
leal (%r12,%r12), %ecx
subq %rcx, %rdx
notl %r15d
kmovw %r15d, %k1
movq %rdx, 0x40(%rsp)
vpmovdw %zmm0, (%rdx) {%k1}
vpsrld $0x10, %zmm2, %zmm2 {%k3}
vmovdqa64 %zmm2, 0xc0(%rsp)
vpsrld $0x10, %zmm3, %zmm3 {%k2}
vmovdqa64 %zmm3, 0x140(%rsp)
vmovaps 0x100(%rsp), %zmm0
movq 0x70(%rsp), %rbx
movq %rbx, %rdi
callq 0x570b9
vmovaps %zmm0, 0x200(%rsp)
vmovdqa64 0x80(%rsp), %zmm0
movq %rbx, %rdi
callq 0x570b9
vmovdqa64 0xc0(%rsp), %zmm4
vpsrlq $0x20, %zmm4, %zmm1
vmovdqa64 0x200(%rsp), %zmm6
vpsrlq $0x20, %zmm6, %zmm2
vpmuludq %zmm1, %zmm2, %zmm1
vmovdqa64 0x140(%rsp), %zmm5
vpsrlq $0x20, %zmm5, %zmm2
vpsrlq $0x20, %zmm0, %zmm3
vpmuludq %zmm2, %zmm3, %zmm2
vpmuludq %zmm4, %zmm6, %zmm3
vpsrlq $0x20, %zmm3, %zmm3
vpmuludq %zmm5, %zmm0, %zmm0
vpsrlq $0x20, %zmm0, %zmm0
movw $0xaaaa, %ax            # imm = 0xAAAA
kmovw %eax, %k1
vpord %zmm1, %zmm3, %zmm3 {%k1}
vmovdqa64 %zmm3, 0x200(%rsp)
vpord %zmm2, %zmm0, %zmm0 {%k1}
vmovdqa64 %zmm0, 0x400(%rsp)
vmovaps 0x100(%rsp), %zmm0
movq 0x68(%rsp), %rbx
movq %rbx, %rdi
callq 0x570b9
vmovaps %zmm0, 0x100(%rsp)
vmovdqa64 0x80(%rsp), %zmm0
movq %rbx, %rdi
callq 0x570b9
vmovdqa64 0x440(%rsp), %zmm4
vpsrld $0x10, %zmm4, %zmm1
vmovdqa64 0x500(%rsp), %zmm5
vpsrld $0x10, %zmm5, %zmm2
vpbroadcastd 0x25922(%rip), %zmm3 # 0x7dcc0
vpaddd %zmm3, %zmm1, %zmm1
vmovdqa64 0x200(%rsp), %zmm6
vpsrlvd %zmm1, %zmm6, %zmm1
vpaddd %zmm3, %zmm2, %zmm2
vmovdqa64 0x400(%rsp), %zmm3
vpsrlvd %zmm2, %zmm3, %zmm2
vpbroadcastd 0x29990(%rip), %zmm6 # 0x81d60
vpandq %zmm6, %zmm4, %zmm3
vpmulld %zmm3, %zmm1, %zmm1
vpandq %zmm6, %zmm5, %zmm3
vpmulld %zmm3, %zmm2, %zmm2
vmovdqa64 0x100(%rsp), %zmm3
vpaddd 0xc0(%rsp), %zmm3, %zmm3
vpaddd %zmm1, %zmm3, %zmm1
vmovdqa64 %zmm1, 0xc0(%rsp)
vpaddd 0x140(%rsp), %zmm0, %zmm0
vpaddd %zmm2, %zmm0, %zmm0
vmovdqa64 %zmm0, 0x140(%rsp)
vmovdqa64 0x540(%rsp), %zmm0
movl 0x2c0(%rsp), %r12d
decl %r12d
movl %r12d, 0x2c0(%rsp)
vmovdqa64 0x180(%rsp), %zmm4
vmovdqa64 0x240(%rsp), %zmm5
jmp 0x57f51
vmovaps 0xc0(%rsp), %zmm0
vmovaps %zmm0, 0x380(%rsp)
vmovdqa64 0x140(%rsp), %zmm0
vmovdqa64 %zmm0, 0x3c0(%rsp)
vmovdqa64 %zmm5, 0x480(%rsp)
vmovdqa64 %zmm4, 0x4c0(%rsp)
leaq 0x38(%rsp), %rbx
movq 0x40(%rsp), %rax
movq %rax, (%rbx)
pushq $0x1f
popq %r14
movq 0x28(%rsp), %r15
movq 0x30(%rsp), %r12
testl %r14d, %r14d
js 0x584c8
movl %r14d, %eax
leaq (%rsp,%rax,4), %rdi
addq $0x380, %rdi            # imm = 0x380
movl 0x480(%rsp,%rax,4), %edx
shlq $0x4, %rdx
addq %r12, %rdx
movq %rbx, %rsi
vzeroupper
callq 0x57080
decl %r14d
jmp 0x58497
pushq $0x1f
popq %rcx
movq 0x38(%rsp), %rsi
xorl %eax, %eax
movq 0x60(%rsp), %r8
movq 0x20(%rsp), %r9
testl %ecx, %ecx
js 0x584f5
movl %ecx, %edx
movl 0x380(%rsp,%rdx,4), %edx
movl %edx, -0x4(%rsi,%rax)
decl %ecx
addq $-0x4, %rax
jmp 0x584dc
movq 0x58(%rsp), %rdx
subq %rsi, %rdx
subq %rax, %rdx
movl 0x50(%rsp), %edi
addl 0x48(%rsp), %r9d
subl %esi, %r9d
subl %eax, %r9d
movl %r9d, (%r8)
addq %r15, %rdi
addq %rax, %rsi
vzeroupper
callq 0x4830
movq %r12, %rdi
callq 0x64291
jmp 0x57d66