// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/htscodecs/htscodecs/arith_dynamic.c
// Function: arith_compress_to
unsigned char *arith_compress_to(unsigned char *in,  unsigned int in_size,
                                 unsigned char *out, unsigned int *out_size,
                                 int order) {
    unsigned int c_meta_len;
    uint8_t *rle = NULL, *packed = NULL;

    if (in_size > INT_MAX || (out && *out_size == 0)) {
        *out_size = 0;
        return NULL;
    }

    if (!out) {
        *out_size = arith_compress_bound(in_size, order);
        if (!(out = malloc(*out_size))) {
            *out_size = 0;
            return NULL;
        }
    }
    unsigned char *out_end = out + *out_size;

    if (in_size <= 20)
        order &= ~X_STRIPE;

    if (order & X_CAT) {
        out[0] = X_CAT;
        c_meta_len = 1 + var_put_u32(&out[1], out_end, in_size);
        if (c_meta_len + in_size > *out_size) {
            *out_size = 0;
            return NULL;
        }
        memcpy(out+c_meta_len, in, in_size);
        *out_size = in_size+c_meta_len;
    }

    if (order & X_STRIPE) {
        int N = (order>>8) & 0xff;
        if (N == 0) N = 4; // default for compatibility with old tests

        if (N > in_size)
            N = in_size;

        unsigned char *transposed = malloc(in_size);
        unsigned int part_len[256];
        unsigned int idx[256];
        if (!transposed) {
            *out_size = 0;
            return NULL;
        }

        int i, j, x;
        for (i = 0; i < N; i++) {
            part_len[i] = in_size / N + ((in_size % N) > i);
            idx[i] = i ? idx[i-1] + part_len[i-1] : 0; // cumulative index
        }

        for (i = x = 0; i < in_size-N; i += N, x++) {
            for (j = 0; j < N; j++)
                transposed[idx[j]+x] = in[i+j];
        }
        for (; i < in_size; i += N, x++) {
            for (j = 0; i+j < in_size; j++)
                transposed[idx[j]+x] = in[i+j];
        }

        unsigned int olen2;
        unsigned char *out2, *out2_start;
        c_meta_len = 1;
        *out = order & ~X_NOSZ;
        c_meta_len += var_put_u32(out+c_meta_len, out_end, in_size);
        if (c_meta_len >= *out_size) {
            free(transposed);
            *out_size = 0;
            return NULL;
        }

        out[c_meta_len++] = N;

        out2_start = out2 = out+7+5*N; // shares a buffer with c_meta
        for (i = 0; i < N; i++) {
            // Brute force try all methods.
            // FIXME: optimise this bit.  Maybe learn over time?
            int j, best_j = 0, best_sz = INT_MAX;
            uint8_t *r;

            // Works OK with read names. The first byte is the most important,
            // as it has most variability (little-endian).  After that it's
            // often quite predictable.
            //
            // Do we gain in any other context in CRAM? Aux tags maybe?
            int m[][4] = {{3, 1,64,0},
                          {2, 1,0},
                          {2, 1,128},
                          {2, 1,128}};

//          int m[][6] = {{4, 1,64,2,0},  //test of adding in an order-2 codec
//                        {3, 1,2,0},
//                        {3, 1,2,128},
//                        {3, 1,2,128}};

// Other possibilities for methods to try.
//          int m[][10] = {{8, 1,128,129,64,65,192,193,4,0},
//                         {8, 1,128,129,64,65,192,193,4,0},
//                         {8, 1,128,129,64,65,192,193,4,0},
//                         {8, 1,128,129,64,65,192,193,4,0}};

//          int m[][9] = {{5, 1,128,64,65,0},
//                        {5, 1,128,64,65,0},
//                        {5, 1,128,64,65,0},
//                        {5, 1,128,64,65,0}};

//          int m[][6] = {{4, 0,1,128,64},
//                        {5, 0,1,128,65,193},
//                        {3, 0,1,128},
//                        {3, 0,1,128}};

//          int m[][6] = {{4, 1,128,64,0},
//                        {4, 1,128,65,0},
//                        {2, 128,0},
//                        {2, 128,0}};

//          int m[][6] = {{2, 64,0},
//                        {1, 0},
//                        {1, 128},
//                        {1, 128}};

//          int m[][6] = {{1, 0},
//                        {2, 128,0},
//                        {1, 128},
//                        {1, 128}};

            for (j = 1; j <= m[MIN(i,3)][0]; j++) {
                if (out2 - out > *out_size)
                    continue; // an error, but caught in best_sz check later

                olen2 = *out_size - (out2 - out);
                //fprintf(stderr, "order=%d m=%d\n", order&3, m[MIN(i,4)][j]);
                if ((order&3) == 0 && (m[MIN(i,3)][j]&1))
                    continue;

                r = arith_compress_to(transposed+idx[i], part_len[i],
                                      out2, &olen2, m[MIN(i,3)][j] | X_NOSZ);
                if (r && olen2 && best_sz > olen2) {
                    best_sz = olen2;
                    best_j = j;
                }
            }

            if (best_sz == INT_MAX) {
                free(transposed);
                *out_size = 0;
                return NULL;
            }
            if (best_j != j-1) {
                olen2 = *out_size - (out2 - out);
                r = arith_compress_to(transposed+idx[i], part_len[i],
                                      out2, &olen2,
                                      m[MIN(i,3)][best_j] | X_NOSZ);
                if (!r) {
                    free(transposed);
                    *out_size = 0;
                    return NULL;
                }
            }
            out2 += olen2;
            c_meta_len += var_put_u32(out+c_meta_len, out_end, olen2);
        }
        memmove(out+c_meta_len, out2_start, out2-out2_start);
        free(transposed);
        *out_size = c_meta_len + out2-out2_start;
        return out;
    }

    int do_pack = order & X_PACK;
    int do_rle  = order & X_RLE;
    int no_size = order & X_NOSZ;
    int do_ext  = order & X_EXT;

    out[0] = order;
    c_meta_len = 1;

    if (!no_size)
        c_meta_len += var_put_u32(&out[1], out_end, in_size);

    order &= 0x3;

    // Format is compressed meta-data, compressed data.
    // Meta-data can be empty, pack, rle lengths, or pack + rle lengths.
    // Data is either the original data, bit-packed packed, rle literals or
    // packed + rle literals.

    if (do_pack && in_size) {
        // PACK 2, 4 or 8 symbols into one byte.
        int pmeta_len;
        uint64_t packed_len;
        if (c_meta_len + 256 > *out_size) {
            *out_size = 0;
            return NULL;
        }
        packed = hts_pack(in, in_size, out+c_meta_len, &pmeta_len, &packed_len);
        if (!packed) {
            out[0] &= ~X_PACK;
            do_pack = 0;
            free(packed);
            packed = NULL;
        } else {
            in = packed;
            in_size = packed_len;
            c_meta_len += pmeta_len;

            // Could derive this rather than storing verbatim.
            // Orig size * 8/nbits (+1 if not multiple of 8/n)
            int sz = var_put_u32(out+c_meta_len, out_end, in_size);
            c_meta_len += sz;
            *out_size -= sz;
        }
    } else if (do_pack) {
        out[0] &= ~X_PACK;
    }

    if (do_rle && !in_size) {
        out[0] &= ~X_RLE;
    }

    *out_size -= c_meta_len;
    if (order && in_size < 8) {
        out[0] &= ~3;
        order  &= ~3;
    }

    if (do_ext) {
        // Use an external compression library instead.
        // For now, bzip2
#ifdef HAVE_LIBBZ2
        if (BZ_OK != BZ2_bzBuffToBuffCompress((char *)out+c_meta_len, out_size,
                                              (char *)in, in_size, 9, 0, 30))
            *out_size = in_size; // Didn't fit with bz2; force X_CAT below instead
#else
        fprintf(stderr, "Htscodecs has been compiled without libbz2 support\n");
        free(out);
        *out_size = 0;
        return NULL;
#endif

//      // lzma doesn't help generally, at least not for the name tokeniser
//      size_t lzma_size = 0;
//      lzma_easy_buffer_encode(9, LZMA_CHECK_CRC32, NULL,
//                              in, in_size, out+c_meta_len, &lzma_size,
//                              *out_size);
//      *out_size = lzma_size;

    } else {
        uint8_t *r;
        if (do_rle) {
            if (order == 0)
                r=arith_compress_O0_RLE(in, in_size, out+c_meta_len, out_size);
            else
                r=arith_compress_O1_RLE(in, in_size, out+c_meta_len, out_size);
        } else {
            //if (order == 2)
            //  arith_compress_O2(in, in_size, out+c_meta_len, out_size);
            //else
            if (order == 1)
                r=arith_compress_O1(in, in_size, out+c_meta_len, out_size);
            else
                r=arith_compress_O0(in, in_size, out+c_meta_len, out_size);
        }

        if (!r) {
            free(rle);
            free(packed);
            *out_size = 0;
            return NULL;
        }
    }

    if (*out_size >= in_size) {
        out[0] &= ~(3|X_EXT); // no entropy encoding, but keep e.g. PACK
        out[0] |= X_CAT | no_size;

        if (out + c_meta_len + in_size > out_end) {
            free(rle);
            free(packed);
            *out_size = 0;
            return NULL;
        }
        memcpy(out+c_meta_len, in, in_size);
        *out_size = in_size;
    }

    free(rle);
    free(packed);

    *out_size += c_meta_len;

    return out;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x878, %rsp            # imm = 0x878
movq %rcx, %r9
testl %esi, %esi
js 0x5ad75
movl %r8d, %ebp
movq %rdx, %r14
movl %esi, %r15d
movq %rdi, %r12
testq %rdx, %rdx
movq %r9, 0x10(%rsp)
je 0x5abbd
cmpl $0x0, (%r9)
jne 0x5abe6
jmp 0x5ad75
movl %r15d, %edi
movl %ebp, %esi
callq 0x5aaf0
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
movl %eax, %edi
callq 0x4680
movq 0x10(%rsp), %r9
movq %rax, %r14
testq %rax, %rax
je 0x5ad75
movl (%r9), %ebx
movl %ebp, %eax
andl $-0x9, %eax
cmpl $0x15, %r15d
cmovael %ebp, %eax
testb $0x20, %al
movq %rbx, 0x48(%rsp)
movl %eax, 0x20(%rsp)
je 0x5adb5
movb $0x20, (%r14)
cmpl $0x5, %ebx
ja 0x5ac8d
movq $-0x1, %rsi
xorl %ecx, %ecx
movl %r15d, %edx
movl %r15d, %eax
shrl $0x7, %eax
incq %rsi
addq $0x7, %rcx
cmpl $0x7f, %edx
movl %eax, %edx
ja 0x5ac1e
leaq (,%rbx,8), %rdx
subq %rbx, %rdx
addq $-0x7, %rdx
movl $0x1, %eax
cmpq %rcx, %rdx
jl 0x5ad6c
addq $-0x7, %rcx
cmpq $0x4, %rsi
movl $0x4, %edx
cmovbq %rsi, %rdx
incq %rdx
xorl %eax, %eax
movl %r15d, %esi
shrl %cl, %esi
xorl %edi, %edi
testl %ecx, %ecx
setne %dil
andl $0x7f, %esi
shll $0x7, %edi
orl %esi, %edi
movb %dil, 0x1(%r14,%rax)
incq %rax
addl $-0x7, %ecx
cmpl %eax, %edx
jne 0x5ac62
incl %eax
jmp 0x5ad6c
cmpl $0x7f, %r15d
ja 0x5aca1
movb %r15b, 0x1(%r14)
movl $0x2, %eax
jmp 0x5ad6c
movl %r15d, %eax
cmpl $0x3fff, %r15d          # imm = 0x3FFF
ja 0x5acc9
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x2(%r14)
movl $0x3, %eax
jmp 0x5ad6c
cmpl $0x1fffff, %r15d        # imm = 0x1FFFFF
ja 0x5acf7
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x3(%r14)
movl $0x4, %eax
jmp 0x5ad6c
cmpl $0xfffffff, %r15d       # imm = 0xFFFFFFF
ja 0x5ad31
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r15d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x4(%r14)
movl $0x5, %eax
jmp 0x5ad6c
shrl $0x1c, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r15d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r15d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x4(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x5(%r14)
movl $0x6, %eax
leal (%rax,%r15), %ebx
cmpl (%r9), %ebx
jbe 0x5ad94
movl $0x0, (%r9)
xorl %r14d, %r14d
movq %r14, %rax
addq $0x878, %rsp            # imm = 0x878
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
addq %r14, %rdi
movl %r15d, %edx
movq %r12, %rsi
callq 0x43c0
movq 0x10(%rsp), %r9
movl %ebx, (%r9)
movq 0x48(%rsp), %rbx
movl 0x20(%rsp), %eax
testb $0x8, %al
jne 0x5ae5a
movl %eax, %ecx
movb %al, (%r14)
movl $0x1, %r13d
andl $0x10, %ecx
movl %ecx, 0x30(%rsp)
jne 0x5b5b1
cmpl $0x5, %ebx
ja 0x5b01d
movq $-0x1, %rdx
xorl %ecx, %ecx
movl %r15d, %esi
movl %r15d, %eax
shrl $0x7, %eax
incq %rdx
addq $0x7, %rcx
cmpl $0x7f, %esi
movl %eax, %esi
ja 0x5aded
leaq (,%rbx,8), %rax
subq %rbx, %rax
addq $-0x7, %rax
cmpq %rcx, %rax
jl 0x5b5b1
addq $-0x7, %rcx
cmpq $0x4, %rdx
movl $0x4, %eax
cmovbq %rdx, %rax
incq %rax
xorl %r13d, %r13d
movl %r15d, %edx
shrl %cl, %edx
xorl %esi, %esi
testl %ecx, %ecx
setne %sil
andl $0x7f, %edx
shll $0x7, %esi
orl %edx, %esi
movb %sil, 0x1(%r14,%r13)
incq %r13
addl $-0x7, %ecx
cmpl %r13d, %eax
jne 0x5ae2d
incl %r13d
jmp 0x5b5b1
movzbl %ah, %eax
testl %eax, %eax
movl $0x4, %ebx
cmovnel %eax, %ebx
cmpl %r15d, %ebx
movl %r15d, %eax
cmovbl %ebx, %eax
movq %rax, 0x38(%rsp)
movl %r15d, %ebp
movq %rbp, %rdi
callq 0x4680
testq %rax, %rax
je 0x5b8d3
movq %rax, %r13
testl %r15d, %r15d
movq 0x10(%rsp), %r10
je 0x5aeda
movl %r15d, %eax
xorl %edx, %edx
movq 0x38(%rsp), %rsi
divl %esi
xorl %ecx, %ecx
cmpl $0x1, %esi
adcl $0x0, %esi
cmpq %rdx, %rcx
movl %eax, %edi
adcl $0x0, %edi
movl %edi, 0x470(%rsp,%rcx,4)
movl $0x0, %edi
testq %rcx, %rcx
je 0x5aece
movl 0x46c(%rsp,%rcx,4), %edi
addl 0x6c(%rsp,%rcx,4), %edi
movl %edi, 0x70(%rsp,%rcx,4)
incq %rcx
cmpq %rcx, %rsi
jne 0x5aeaa
xorl %ecx, %ecx
movl $0x0, %eax
cmpl %r15d, %ebx
jae 0x5af2d
movl %r15d, %edx
movq 0x38(%rsp), %rsi
subl %esi, %edx
cmpl $0x1, %esi
adcl $0x0, %esi
movl %ebx, %edi
xorl %ecx, %ecx
movq %r12, %r8
xorl %eax, %eax
xorl %r9d, %r9d
movb (%r8,%r9), %r10b
movl 0x70(%rsp,%r9,4), %r11d
addl %eax, %r11d
movb %r10b, (%r13,%r11)
incq %r9
cmpq %r9, %rsi
jne 0x5af02
addq %rdi, %rcx
incl %eax
addq %rdi, %r8
cmpq %rdx, %rcx
jb 0x5aeff
movq 0x10(%rsp), %r10
cmpl %r15d, %ecx
jae 0x5af6b
movl %ecx, %ecx
cmpl %r15d, %ebx
cmovael %r15d, %ebx
addq %rcx, %r12
xorl %edx, %edx
movb (%r12,%rdx), %sil
movl 0x70(%rsp,%rdx,4), %edi
addl %eax, %edi
movb %sil, (%r13,%rdi)
leaq (%rcx,%rdx), %rsi
incq %rsi
incq %rdx
cmpq %rbp, %rsi
jb 0x5af40
addq %rbx, %rcx
incl %eax
addq %rbx, %r12
cmpq %rbp, %rcx
jb 0x5af3e
movl 0x20(%rsp), %eax
andb $-0x11, %al
movb %al, (%r14)
movq 0x48(%rsp), %rbx
cmpl $0x5, %ebx
ja 0x5b003
movq $-0x1, %rdx
xorl %ecx, %ecx
movl %r15d, %esi
movl %r15d, %eax
movq 0x38(%rsp), %rbp
shrl $0x7, %eax
incq %rdx
addq $0x7, %rcx
cmpl $0x7f, %esi
movl %eax, %esi
ja 0x5af96
leaq (,%rbx,8), %rax
subq %rbx, %rax
addq $-0x7, %rax
xorl %r12d, %r12d
cmpq %rcx, %rax
jl 0x5b1a1
addq $-0x7, %rcx
cmpq $0x4, %rdx
movl $0x4, %eax
cmovbq %rdx, %rax
incq %rax
xorl %r12d, %r12d
movl %r15d, %edx
shrl %cl, %edx
xorl %esi, %esi
testl %ecx, %ecx
setne %sil
andl $0x7f, %edx
shll $0x7, %esi
orl %edx, %esi
movb %sil, 0x1(%r14,%r12)
incq %r12
addl $-0x7, %ecx
cmpl %r12d, %eax
jne 0x5afd9
jmp 0x5b1a1
cmpl $0x7f, %r15d
movq 0x38(%rsp), %rbp
ja 0x5b032
movb %r15b, 0x1(%r14)
movl $0x1, %r12d
jmp 0x5b1a1
cmpl $0x7f, %r15d
ja 0x5b05b
movb %r15b, 0x1(%r14)
movl $0x2, %r13d
jmp 0x5b5b1
movl %r15d, %eax
cmpl $0x3fff, %r15d          # imm = 0x3FFF
ja 0x5b084
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x2(%r14)
movl $0x2, %r12d
jmp 0x5b1a1
movl %r15d, %eax
cmpl $0x3fff, %r15d          # imm = 0x3FFF
ja 0x5b0b6
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x2(%r14)
movl $0x3, %r13d
jmp 0x5b5b1
cmpl $0x1fffff, %r15d        # imm = 0x1FFFFF
ja 0x5b0e8
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x3(%r14)
movl $0x3, %r12d
jmp 0x5b1a1
cmpl $0x1fffff, %r15d        # imm = 0x1FFFFF
ja 0x5b123
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x3(%r14)
movl $0x4, %r13d
jmp 0x5b5b1
cmpl $0xfffffff, %r15d       # imm = 0xFFFFFFF
ja 0x5b165
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r15d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x4(%r14)
movl $0x4, %r12d
jmp 0x5b1a1
cmpl $0xfffffff, %r15d       # imm = 0xFFFFFFF
ja 0x5b575
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r15d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x4(%r14)
movl $0x5, %r13d
jmp 0x5b5b1
shrl $0x1c, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r15d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r15d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x4(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x5(%r14)
movl $0x5, %r12d
leal 0x1(%r12), %eax
cmpl (%r10), %eax
jae 0x5b52e
addl $0x2, %r12d
movl %eax, %eax
movb %bpl, (%r14,%rax)
leal (%rbp,%rbp,4), %eax
addq %r14, %rax
addq $0x7, %rax
testl %r15d, %r15d
movq %rax, 0x50(%rsp)
je 0x5b53e
cmpl $0x1, %ebp
adcl $0x0, %ebp
xorl %r11d, %r11d
movq %rax, %r15
movq %r14, 0x58(%rsp)
movq %rbp, 0x38(%rsp)
movq %r12, 0x68(%rsp)
cmpq $0x3, %r11
movl $0x3, %eax
cmovbq %r11, %rax
cmpl $0x3, %r11d
movl $0x3, %ecx
cmovbl %r11d, %ecx
movq %rcx, 0x60(%rsp)
shll $0x4, %ecx
leaq 0x4361a(%rip), %rdx     # 0x9e830
movl (%rcx,%rdx), %r12d
testl %r12d, %r12d
movq %r11, 0x30(%rsp)
movq %r15, 0x28(%rsp)
jle 0x5b2ef
shll $0x4, %eax
leaq (%rax,%rdx), %rbx
addq $0x4, %rbx
movq %r14, %rax
movq %r15, %r14
subq %rax, %r14
xorl %r15d, %r15d
movl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movl $0x0, 0x44(%rsp)
movl 0x20(%rsp), %ecx
movl (%r10), %eax
cmpq %rax, %r14
jg 0x5b2c9
subl %r14d, %eax
movl %eax, 0x1c(%rsp)
testb $0x3, %cl
jne 0x5b270
testb $0x1, (%rbx,%r15,4)
jne 0x5b2c9
movl 0x70(%rsp,%r11,4), %edi
addq %r13, %rdi
movl 0x470(%rsp,%r11,4), %esi
movl (%rbx,%r15,4), %r8d
orl $0x10, %r8d
movq 0x28(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
callq 0x5ab80
testq %rax, %rax
setne %cl
movl 0x1c(%rsp), %eax
testl %eax, %eax
setne %dl
andb %cl, %dl
cmpl %eax, %ebp
seta %cl
testb %cl, %dl
je 0x5b2bb
leal 0x1(%r15), %ecx
movl %ecx, 0x44(%rsp)
movl %eax, %ebp
movq 0x10(%rsp), %r10
movl 0x20(%rsp), %ecx
movq 0x30(%rsp), %r11
incq %r15
cmpq %r15, %r12
jne 0x5b255
cmpl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
sete %al
movq 0x58(%rsp), %r14
movq 0x48(%rsp), %rbx
movq 0x38(%rsp), %rbp
movl 0x44(%rsp), %ecx
jmp 0x5b2f6
movb $0x1, %al
xorl %r15d, %r15d
xorl %ecx, %ecx
testb %al, %al
movq 0x68(%rsp), %r12
je 0x5b324
movq %r13, %rdi
callq 0x45c0
movq 0x30(%rsp), %r11
movq 0x10(%rsp), %r10
movl $0x0, (%r10)
xorl %eax, %eax
movq 0x28(%rsp), %r15
jmp 0x5b518
cmpl %r15d, %ecx
movq 0x28(%rsp), %r15
je 0x5b389
movl %r14d, %eax
subl %r15d, %eax
addl (%r10), %eax
movl %eax, 0x1c(%rsp)
movl 0x70(%rsp,%r11,4), %edi
addq %r13, %rdi
movl 0x470(%rsp,%r11,4), %esi
movslq %ecx, %rax
movq 0x60(%rsp), %rdx
shlq $0x4, %rdx
leaq 0x434d2(%rip), %rcx     # 0x9e830
addq %rcx, %rdx
movl (%rdx,%rax,4), %r8d
orl $0x10, %r8d
movq %r15, %rdx
leaq 0x1c(%rsp), %rcx
callq 0x5ab80
movq 0x30(%rsp), %r11
movq 0x10(%rsp), %r10
testq %rax, %rax
je 0x5b45d
movl 0x1c(%rsp), %eax
movl %r12d, %ecx
leaq (%r14,%rcx), %rdx
movq %rbx, %rdi
subq %rcx, %rdi
cmpq $0x4, %rdi
jg 0x5b429
xorl %r10d, %r10d
xorl %r8d, %r8d
movl %eax, %r11d
movl %eax, %r9d
movq %r8, %rcx
movq %r10, %rsi
shrl $0x7, %r9d
addq $0x7, %r8
incq %r10
cmpl $0x7f, %r11d
movl %r9d, %r11d
ja 0x5b3b0
leaq (,%rdi,8), %r9
subq %rdi, %r9
xorl %edi, %edi
cmpq %r8, %r9
movq 0x10(%rsp), %r10
movq 0x30(%rsp), %r11
jl 0x5b510
cmpq $0x4, %rsi
movl $0x4, %edi
cmovaeq %rdi, %rsi
incq %rsi
xorl %edi, %edi
movl %eax, %r8d
shrl %cl, %r8d
xorl %r9d, %r9d
testl %ecx, %ecx
setne %r9b
andl $0x7f, %r8d
shll $0x7, %r9d
orl %r8d, %r9d
movb %r9b, (%rdx,%rdi)
incq %rdi
addl $-0x7, %ecx
cmpl %edi, %esi
jne 0x5b3fc
jmp 0x5b510
cmpl $0x7f, %eax
ja 0x5b43a
movb %al, (%rdx)
movl $0x1, %edi
jmp 0x5b510
movl %eax, %ecx
cmpl $0x3fff, %eax           # imm = 0x3FFF
ja 0x5b47d
shrl $0x7, %ecx
orb $-0x80, %cl
movb %cl, (%rdx)
movl %eax, %ecx
andb $0x7f, %cl
movb %cl, 0x1(%rdx)
movl $0x2, %edi
jmp 0x5b510
movq %r13, %rdi
callq 0x45c0
movq 0x30(%rsp), %r11
movq 0x10(%rsp), %r10
movl $0x0, (%r10)
xorl %eax, %eax
jmp 0x5b518
cmpl $0x1fffff, %eax         # imm = 0x1FFFFF
ja 0x5b4a6
shrl $0xe, %ecx
orb $-0x80, %cl
movb %cl, (%rdx)
movl %eax, %ecx
shrl $0x7, %ecx
orb $-0x80, %cl
movb %cl, 0x1(%rdx)
movl %eax, %ecx
andb $0x7f, %cl
movb %cl, 0x2(%rdx)
movl $0x3, %edi
jmp 0x5b510
cmpl $0xfffffff, %eax        # imm = 0xFFFFFFF
ja 0x5b4da
shrl $0x15, %ecx
orb $-0x80, %cl
movb %cl, (%rdx)
movl %eax, %ecx
shrl $0xe, %ecx
orb $-0x80, %cl
movb %cl, 0x1(%rdx)
movl %eax, %ecx
shrl $0x7, %ecx
orb $-0x80, %cl
movb %cl, 0x2(%rdx)
movl %eax, %ecx
andb $0x7f, %cl
movb %cl, 0x3(%rdx)
movl $0x4, %edi
jmp 0x5b510
shrl $0x1c, %ecx
orb $-0x80, %cl
movb %cl, (%rdx)
movl %eax, %ecx
shrl $0x15, %ecx
orb $-0x80, %cl
movb %cl, 0x1(%rdx)
movl %eax, %ecx
shrl $0xe, %ecx
orb $-0x80, %cl
movb %cl, 0x2(%rdx)
movl %eax, %ecx
shrl $0x7, %ecx
orb $-0x80, %cl
movb %cl, 0x3(%rdx)
movl %eax, %ecx
andb $0x7f, %cl
movb %cl, 0x4(%rdx)
movl $0x5, %edi
addq %rax, %r15
addl %edi, %r12d
movb $0x1, %al
testb %al, %al
je 0x5ad7c
incq %r11
cmpq %rbp, %r11
jne 0x5b1e8
jmp 0x5b541
movq %r13, %rdi
callq 0x45c0
xorl %r15d, %r15d
xorl %r14d, %r14d
jmp 0x5b568
movq %rax, %r15
movl %r12d, %edi
addq %r14, %rdi
movq %r15, %rdx
movq 0x50(%rsp), %rbx
subq %rbx, %rdx
movq %rbx, %rsi
callq 0x4830
movq %r13, %rdi
callq 0x45c0
addl %r12d, %r15d
subl %ebx, %r15d
movq 0x10(%rsp), %rax
movl %r15d, (%rax)
jmp 0x5ad7f
shrl $0x1c, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r15d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r15d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x4(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x5(%r14)
movl $0x6, %r13d
movl 0x20(%rsp), %edx
testb %dl, %dl
setns %al
testl %r15d, %r15d
sete %cl
orb %al, %cl
jne 0x5b5e4
leal 0x100(%r13), %edx
movl (%r9), %ebp
cmpl %ebp, %edx
jbe 0x5b5f5
movl $0x0, (%r9)
xorl %eax, %eax
movl 0x20(%rsp), %ecx
jmp 0x5b7cd
testb %dl, %dl
movl %edx, %ecx
jns 0x5b5ee
andb $0x7f, (%r14)
xorl %eax, %eax
jmp 0x5b7d5
movl %edx, 0x28(%rsp)
movl %r15d, %esi
movl %r13d, %edx
addq %r14, %rdx
leaq 0x70(%rsp), %rcx
leaq 0x470(%rsp), %r8
movq %r12, %rdi
callq 0x63eb0
testq %rax, %rax
je 0x5b6bf
movq 0x470(%rsp), %r15
addl 0x70(%rsp), %r13d
leaq (%r14,%r13), %r10
movq %rbx, %rdx
subq %r13, %rdx
cmpq $0x4, %rdx
jg 0x5b6cf
movq $-0x1, %rdi
xorl %ecx, %ecx
movl %r15d, %r8d
movl %r15d, %esi
movq 0x10(%rsp), %r9
shrl $0x7, %esi
incq %rdi
addq $0x7, %rcx
cmpl $0x7f, %r8d
movl %esi, %r8d
ja 0x5b655
leaq (,%rdx,8), %rsi
subq %rdx, %rsi
xorl %edx, %edx
cmpq %rcx, %rsi
jl 0x5b7bc
addq $-0x7, %rcx
cmpq $0x4, %rdi
movl $0x4, %esi
cmovbq %rdi, %rsi
incq %rsi
xorl %edx, %edx
movl %r15d, %edi
shrl %cl, %edi
xorl %r8d, %r8d
testl %ecx, %ecx
setne %r8b
andl $0x7f, %edi
shll $0x7, %r8d
orl %edi, %r8d
movb %r8b, (%r10,%rdx)
incq %rdx
addl $-0x7, %ecx
cmpl %edx, %esi
jne 0x5b694
jmp 0x5b7bc
andb $0x7f, (%r14)
xorl %eax, %eax
movq 0x10(%rsp), %r9
jmp 0x5b7c5
cmpl $0x7f, %r15d
movq 0x10(%rsp), %r9
ja 0x5b6e7
movb %r15b, (%r10)
movl $0x1, %edx
jmp 0x5b7bc
movl %r15d, %ecx
cmpl $0x3fff, %r15d          # imm = 0x3FFF
ja 0x5b710
shrl $0x7, %ecx
orb $-0x80, %cl
movb %cl, (%r10)
movl %r15d, %ecx
andb $0x7f, %cl
movb %cl, 0x1(%r10)
movl $0x2, %edx
jmp 0x5b7bc
cmpl $0x1fffff, %r15d        # imm = 0x1FFFFF
ja 0x5b740
shrl $0xe, %ecx
orb $-0x80, %cl
movb %cl, (%r10)
movl %r15d, %ecx
shrl $0x7, %ecx
orb $-0x80, %cl
movb %cl, 0x1(%r10)
movl %r15d, %ecx
andb $0x7f, %cl
movb %cl, 0x2(%r10)
movl $0x3, %edx
jmp 0x5b7bc
cmpl $0xfffffff, %r15d       # imm = 0xFFFFFFF
ja 0x5b77d
shrl $0x15, %ecx
orb $-0x80, %cl
movb %cl, (%r10)
movl %r15d, %ecx
shrl $0xe, %ecx
orb $-0x80, %cl
movb %cl, 0x1(%r10)
movl %r15d, %ecx
shrl $0x7, %ecx
orb $-0x80, %cl
movb %cl, 0x2(%r10)
movl %r15d, %ecx
andb $0x7f, %cl
movb %cl, 0x3(%r10)
movl $0x4, %edx
jmp 0x5b7bc
shrl $0x1c, %ecx
orb $-0x80, %cl
movb %cl, (%r10)
movl %r15d, %ecx
shrl $0x15, %ecx
orb $-0x80, %cl
movb %cl, 0x1(%r10)
movl %r15d, %ecx
shrl $0xe, %ecx
orb $-0x80, %cl
movb %cl, 0x2(%r10)
movl %r15d, %ecx
shrl $0x7, %ecx
orb $-0x80, %cl
movb %cl, 0x3(%r10)
movl %r15d, %ecx
andb $0x7f, %cl
movb %cl, 0x4(%r10)
movl $0x5, %edx
addl %edx, %r13d
subl %edx, (%r9)
movq %rax, %r12
movl 0x20(%rsp), %ecx
movl 0x28(%rsp), %edx
cmpl %ebp, %edx
ja 0x5ad7c
movl %ecx, %esi
andl $0x3, %esi
testb $0x40, %cl
je 0x5b7e8
testl %r15d, %r15d
jne 0x5b7e8
andb $-0x41, (%r14)
subl %r13d, (%r9)
testl %esi, %esi
je 0x5b7fb
cmpl $0x7, %r15d
ja 0x5b7fb
andb $-0x4, (%r14)
xorl %esi, %esi
movl %r13d, %ebp
leaq (%r14,%rbp), %rdx
testb $0x4, %cl
jne 0x5b826
testb $0x40, %cl
movq %rax, 0x20(%rsp)
movq %r12, %rdi
jne 0x5b86b
cmpl $0x1, %esi
jne 0x5b87c
movl %r15d, %esi
movq %r9, %rcx
callq 0x5ca9f
jmp 0x5b894
movl $0x1e, (%rsp)
movq %rdx, %rdi
movq %r9, %rsi
movq %r12, %rdx
movl %r15d, %ecx
movl $0x9, %r8d
xorl %r9d, %r9d
movq %rbp, 0x28(%rsp)
movq %rbx, %rbp
movq %rax, %rbx
callq 0x4280
movq %rbx, %r8
movq %rbp, %rbx
movq 0x28(%rsp), %rbp
movq 0x10(%rsp), %rcx
testl %eax, %eax
je 0x5b8a3
movl %r15d, (%rcx)
jmp 0x5b8a3
testl %esi, %esi
je 0x5b889
movl %r15d, %esi
movq %r9, %rcx
callq 0x5c19c
jmp 0x5b894
movl %r15d, %esi
movq %r9, %rcx
callq 0x5ceaf
jmp 0x5b894
movl %r15d, %esi
movq %r9, %rcx
callq 0x5b925
testq %rax, %rax
movq 0x10(%rsp), %rcx
movq 0x20(%rsp), %r8
je 0x5b90f
cmpl %r15d, (%rcx)
jb 0x5b8fc
addq %r14, %rbx
movb (%r14), %al
andb $-0x28, %al
movl 0x30(%rsp), %ecx
orb %al, %cl
orb $0x20, %cl
movb %cl, (%r14)
addq %r14, %rbp
movl %r15d, %edx
leaq (%rdx,%rbp), %rax
cmpq %rbx, %rax
jbe 0x5b8e3
movq %r8, %rdi
callq 0x45c0
movq 0x10(%rsp), %rax
movl $0x0, (%rax)
jmp 0x5ad7c
movq %rbp, %rdi
movq %r12, %rsi
movq %r8, %rbx
callq 0x43c0
movq %rbx, %r8
movq 0x10(%rsp), %rcx
movl %r15d, (%rcx)
movq %r8, %rdi
movq %rcx, %rbx
callq 0x45c0
addl %r13d, (%rbx)
jmp 0x5ad7f
movq %r8, %rdi
movq %rcx, %rbx
callq 0x45c0
movl $0x0, (%rbx)
jmp 0x5ad7c