// File: /workspace/github_c_makefile_star2_O3/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 $0x868, %rsp            # imm = 0x868
movq %rcx, %r9
testl %esi, %esi
js 0x58ada
movl %r8d, %ebp
movq %rdx, %r14
movl %esi, %r12d
movq %rdi, %r13
testq %rdx, %rdx
je 0x58121
movl (%r9), %r15d
movl %r15d, %r8d
testq %r15, %r15
jne 0x58156
jmp 0x58ada
movq %r12, %r14
movl %r12d, %edi
movl %ebp, %esi
movq %r9, %rbx
callq 0x58054
movl %eax, (%rbx)
movl %eax, %r12d
movl %eax, %r15d
movq %r15, %rdi
callq 0x4680
testq %rax, %rax
je 0x58d47
movq %rbx, %r9
movl %r12d, %r8d
movq %r14, %r12
movq %rax, %r14
movl %ebp, %eax
andl $-0x9, %eax
cmpl $0x15, %r12d
cmovael %ebp, %eax
testb $0x20, %al
movq %r9, 0x10(%rsp)
movl %eax, 0xc(%rsp)
je 0x58309
movb $0x20, (%r14)
cmpl $0x5, %r8d
ja 0x581fb
movq $-0x1, %rsi
xorl %ecx, %ecx
movl %r12d, %edx
movl %r12d, %eax
shrl $0x7, %eax
incq %rsi
addq $0x7, %rcx
cmpl $0x7f, %edx
movl %eax, %edx
ja 0x5818c
leaq (,%r15,8), %rdx
subq %r15, %rdx
addq $-0x7, %rdx
movl $0x1, %eax
cmpq %rcx, %rdx
jl 0x582da
addq $-0x7, %rcx
cmpq $0x4, %rsi
movl $0x4, %edx
cmovbq %rsi, %rdx
incq %rdx
xorl %eax, %eax
movl %r12d, %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 0x581d0
incl %eax
jmp 0x582da
cmpl $0x7f, %r12d
ja 0x5820f
movb %r12b, 0x1(%r14)
movl $0x2, %eax
jmp 0x582da
movl %r12d, %eax
cmpl $0x3fff, %r12d          # imm = 0x3FFF
ja 0x58237
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x2(%r14)
movl $0x3, %eax
jmp 0x582da
cmpl $0x1fffff, %r12d        # imm = 0x1FFFFF
ja 0x58265
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x3(%r14)
movl $0x4, %eax
jmp 0x582da
cmpl $0xfffffff, %r12d       # imm = 0xFFFFFFF
ja 0x5829f
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r12d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x4(%r14)
movl $0x5, %eax
jmp 0x582da
shrl $0x1c, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r12d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r12d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x4(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x5(%r14)
movl $0x6, %eax
leal (%rax,%r12), %ebx
cmpl (%r9), %ebx
ja 0x58ada
movl %eax, %edi
addq %r14, %rdi
movl %r12d, %edx
movq %r13, %rsi
movl %r8d, %ebp
callq 0x43c0
movl %ebp, %r8d
movl 0xc(%rsp), %eax
movq 0x10(%rsp), %r9
movl %ebx, (%r9)
movq %r15, 0x20(%rsp)
testb $0x8, %al
jne 0x583b5
movl %eax, %ebx
movb %al, (%r14)
movl $0x1, %r15d
andl $0x10, %ebx
jne 0x58abb
cmpl $0x5, %r8d
ja 0x58579
movq $-0x1, %rdx
xorl %ecx, %ecx
movl %r12d, %esi
movl %r12d, %eax
shrl $0x7, %eax
incq %rdx
addq $0x7, %rcx
cmpl $0x7f, %esi
movl %eax, %esi
ja 0x58343
movq 0x20(%rsp), %rsi
leaq (,%rsi,8), %rax
subq %rsi, %rax
addq $-0x7, %rax
cmpq %rcx, %rax
jl 0x58abb
addq $-0x7, %rcx
cmpq $0x4, %rdx
movl $0x4, %eax
cmovbq %rdx, %rax
incq %rax
xorl %r15d, %r15d
movl %r12d, %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,%r15)
incq %r15
addl $-0x7, %ecx
cmpl %r15d, %eax
jne 0x58388
incl %r15d
jmp 0x58abb
movl %r8d, 0x18(%rsp)
movq %r14, 0x38(%rsp)
movzbl %ah, %eax
testl %eax, %eax
movl $0x4, %r14d
cmovnel %eax, %r14d
cmpl %r12d, %r14d
movl %r12d, %ebx
cmovbl %r14d, %ebx
movl %r12d, %r15d
movq %r15, %rdi
callq 0x4680
testq %rax, %rax
je 0x58d06
movq %rax, %rbp
testl %r12d, %r12d
movq 0x10(%rsp), %r10
je 0x5843a
movl %r12d, %eax
xorl %edx, %edx
divl %ebx
xorl %ecx, %ecx
cmpl $0x1, %ebx
movl %ebx, %esi
adcl $0x0, %esi
cmpq %rdx, %rcx
movl %eax, %edi
adcl $0x0, %edi
movl %edi, 0x460(%rsp,%rcx,4)
movl $0x0, %edi
testq %rcx, %rcx
je 0x5842e
movl 0x45c(%rsp,%rcx,4), %edi
addl 0x5c(%rsp,%rcx,4), %edi
movl %edi, 0x60(%rsp,%rcx,4)
incq %rcx
cmpq %rcx, %rsi
jne 0x5840a
xorl %ecx, %ecx
movl $0x0, %eax
cmpl %r12d, %r14d
jae 0x5848b
movl %r12d, %edx
subl %ebx, %edx
cmpl $0x1, %ebx
movl %ebx, %esi
adcl $0x0, %esi
movl %r14d, %edi
xorl %ecx, %ecx
movq %r13, %r8
xorl %eax, %eax
xorl %r9d, %r9d
movb (%r8,%r9), %r10b
movl 0x60(%rsp,%r9,4), %r11d
addl %eax, %r11d
movb %r10b, (%rbp,%r11)
incq %r9
cmpq %r9, %rsi
jne 0x58460
addq %rdi, %rcx
incl %eax
addq %rdi, %r8
cmpq %rdx, %rcx
jb 0x5845d
movq 0x10(%rsp), %r10
cmpl %r12d, %ecx
jae 0x584ca
movl %ecx, %ecx
cmpl %r12d, %r14d
cmovael %r12d, %r14d
addq %rcx, %r13
xorl %edx, %edx
movb (%r13,%rdx), %sil
movl 0x60(%rsp,%rdx,4), %edi
addl %eax, %edi
movb %sil, (%rbp,%rdi)
leaq (%rcx,%rdx), %rsi
incq %rsi
incq %rdx
cmpq %r15, %rsi
jb 0x5849e
addq %r14, %rcx
incl %eax
addq %r14, %r13
cmpq %r15, %rcx
jb 0x5849c
movl 0xc(%rsp), %eax
andb $-0x11, %al
movq 0x38(%rsp), %r14
movb %al, (%r14)
cmpl $0x5, 0x18(%rsp)
ja 0x58564
movq $-0x1, %rdx
xorl %ecx, %ecx
movl %r12d, %esi
movl %r12d, %eax
movq 0x20(%rsp), %rdi
shrl $0x7, %eax
incq %rdx
addq $0x7, %rcx
cmpl $0x7f, %esi
movl %eax, %esi
ja 0x584f7
leaq (,%rdi,8), %rax
subq %rdi, %rax
addq $-0x7, %rax
xorl %r15d, %r15d
cmpq %rcx, %rax
jl 0x586fd
addq $-0x7, %rcx
cmpq $0x4, %rdx
movl $0x4, %eax
cmovbq %rdx, %rax
incq %rax
xorl %r15d, %r15d
movl %r12d, %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,%r15)
incq %r15
addl $-0x7, %ecx
cmpl %r15d, %eax
jne 0x5853a
jmp 0x586fd
cmpl $0x7f, %r12d
ja 0x5858e
movb %r12b, 0x1(%r14)
movl $0x1, %r15d
jmp 0x586fd
cmpl $0x7f, %r12d
ja 0x585b7
movb %r12b, 0x1(%r14)
movl $0x2, %r15d
jmp 0x58abb
movl %r12d, %eax
cmpl $0x3fff, %r12d          # imm = 0x3FFF
ja 0x585e0
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x2(%r14)
movl $0x2, %r15d
jmp 0x586fd
movl %r12d, %eax
cmpl $0x3fff, %r12d          # imm = 0x3FFF
ja 0x58612
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x2(%r14)
movl $0x3, %r15d
jmp 0x58abb
cmpl $0x1fffff, %r12d        # imm = 0x1FFFFF
ja 0x58644
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x3(%r14)
movl $0x3, %r15d
jmp 0x586fd
cmpl $0x1fffff, %r12d        # imm = 0x1FFFFF
ja 0x5867f
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x3(%r14)
movl $0x4, %r15d
jmp 0x58abb
cmpl $0xfffffff, %r12d       # imm = 0xFFFFFFF
ja 0x586c1
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r12d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x4(%r14)
movl $0x4, %r15d
jmp 0x586fd
cmpl $0xfffffff, %r12d       # imm = 0xFFFFFFF
ja 0x58a7f
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r12d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x4(%r14)
movl $0x5, %r15d
jmp 0x58abb
shrl $0x1c, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r12d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r12d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x4(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x5(%r14)
movl $0x5, %r15d
leal 0x1(%r15), %eax
cmpl (%r10), %eax
jae 0x58a3b
addl $0x2, %r15d
movl %eax, %eax
movb %bl, (%r14,%rax)
leal (%rbx,%rbx,4), %eax
addq %r14, %rax
addq $0x7, %rax
testl %r12d, %r12d
movq %rax, 0x48(%rsp)
je 0x58a4b
cmpl $0x1, %ebx
adcl $0x0, %ebx
xorl %r11d, %r11d
movq %rax, %r12
movq %rbx, 0x30(%rsp)
movq %r15, 0x58(%rsp)
movl %r11d, %eax
cmpq $0x3, %rax
movl $0x3, %ecx
cmovaeq %rcx, %rax
cmpl $0x3, %r11d
movl $0x3, %ecx
cmovbl %r11d, %ecx
movq %rcx, 0x50(%rsp)
shll $0x4, %ecx
leaq 0x432e2(%rip), %rdx     # 0x9ba50
movl (%rcx,%rdx), %ebx
testl %ebx, %ebx
jle 0x58a3b
shll $0x4, %eax
leaq 0x432cd(%rip), %rcx     # 0x9ba50
leaq (%rax,%rcx), %r13
addq $0x4, %r13
movq %r12, 0x40(%rsp)
subq %r14, %r12
xorl %r15d, %r15d
movl $0x7fffffff, 0x18(%rsp) # imm = 0x7FFFFFFF
movl $0x0, 0x2c(%rsp)
movl 0xc(%rsp), %ecx
movl (%r10), %eax
cmpq %rax, %r12
jg 0x58825
subl %r12d, %eax
movl (%r13,%r15,4), %r8d
movl %eax, 0x1c(%rsp)
testb $0x3, %cl
jne 0x587cb
movl %r8d, %eax
andl $0x1, %eax
jne 0x58825
movl 0x60(%rsp,%r11,4), %edi
addq %rbp, %rdi
movq %r11, %r14
movl 0x460(%rsp,%r11,4), %esi
orl $0x10, %r8d
movq 0x40(%rsp), %rdx
leaq 0x1c(%rsp), %rcx
callq 0x580e4
testq %rax, %rax
setne %cl
movl 0x1c(%rsp), %eax
testl %eax, %eax
setne %dl
andb %cl, %dl
cmpl %eax, 0x18(%rsp)
seta %cl
testb %cl, %dl
je 0x58819
leal 0x1(%r15), %ecx
movl %ecx, 0x2c(%rsp)
movl %eax, 0x18(%rsp)
movq 0x10(%rsp), %r10
movl 0xc(%rsp), %ecx
movq %r14, %r11
incq %r15
cmpq %r15, %rbx
jne 0x587aa
cmpl $0x7fffffff, 0x18(%rsp) # imm = 0x7FFFFFFF
movq 0x38(%rsp), %r14
movq 0x40(%rsp), %r12
je 0x58a3b
movl 0x2c(%rsp), %ecx
cmpl %ecx, %r15d
je 0x588ae
movl %r14d, %eax
subl %r12d, %eax
addl (%r10), %eax
movl %eax, 0x1c(%rsp)
movl 0x60(%rsp,%r11,4), %edi
addq %rbp, %rdi
movl 0x460(%rsp,%r11,4), %esi
movslq %ecx, %rax
movq 0x50(%rsp), %rdx
shlq $0x4, %rdx
leaq 0x431ce(%rip), %rcx     # 0x9ba50
addq %rcx, %rdx
movl (%rdx,%rax,4), %r8d
orl $0x10, %r8d
movq %r12, %rdx
leaq 0x1c(%rsp), %rcx
movq %r11, %rbx
callq 0x580e4
movq %rbx, %r11
movq 0x10(%rsp), %r10
testq %rax, %rax
je 0x58a3b
movl 0x1c(%rsp), %eax
movq 0x58(%rsp), %r15
movl %r15d, %ecx
leaq (%r14,%rcx), %rdx
movq 0x20(%rsp), %rdi
subq %rcx, %rdi
cmpq $0x4, %rdi
jg 0x5895b
movq %r11, %r13
xorl %r10d, %r10d
xorl %r8d, %r8d
movl %eax, %r11d
movl %eax, %r9d
movq 0x30(%rsp), %rbx
movq %r8, %rcx
movq %r10, %rsi
shrl $0x7, %r9d
addq $0x7, %r8
incq %r10
cmpl $0x7f, %r11d
movl %r9d, %r11d
ja 0x588e4
leaq (,%rdi,8), %r9
subq %rdi, %r9
xorl %edi, %edi
cmpq %r8, %r9
movq 0x10(%rsp), %r10
movq %r13, %r11
jl 0x58a27
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 0x5892e
jmp 0x58a27
cmpl $0x7f, %eax
movq 0x30(%rsp), %rbx
ja 0x58971
movb %al, (%rdx)
movl $0x1, %edi
jmp 0x58a27
movl %eax, %ecx
cmpl $0x3fff, %eax           # imm = 0x3FFF
ja 0x58994
shrl $0x7, %ecx
orb $-0x80, %cl
movb %cl, (%rdx)
movl %eax, %ecx
andb $0x7f, %cl
movb %cl, 0x1(%rdx)
movl $0x2, %edi
jmp 0x58a27
cmpl $0x1fffff, %eax         # imm = 0x1FFFFF
ja 0x589bd
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 0x58a27
cmpl $0xfffffff, %eax        # imm = 0xFFFFFFF
ja 0x589f1
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 0x58a27
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, %r12
addl %edi, %r15d
incq %r11
cmpq %rbx, %r11
jne 0x5873d
jmp 0x58a4e
movq %rbp, %rdi
callq 0x45c0
xorl %r12d, %r12d
xorl %r14d, %r14d
jmp 0x58a75
movq %rax, %r12
movl %r15d, %edi
addq %r14, %rdi
movq %r12, %rdx
movq 0x48(%rsp), %rbx
subq %rbx, %rdx
movq %rbx, %rsi
callq 0x4830
movq %rbp, %rdi
callq 0x45c0
addl %r15d, %r12d
subl %ebx, %r12d
movq 0x10(%rsp), %rax
movl %r12d, (%rax)
jmp 0x58ae4
shrl $0x1c, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r12d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r12d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x4(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x5(%r14)
movl $0x6, %r15d
movl 0xc(%rsp), %edx
testb %dl, %dl
setns %al
testl %r12d, %r12d
sete %cl
orb %al, %cl
jne 0x58af9
leal 0x100(%r15), %eax
cmpl (%r9), %eax
jbe 0x58b27
movl $0x0, (%r9)
xorl %r14d, %r14d
movq %r14, %rax
addq $0x868, %rsp            # imm = 0x868
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb %dl, %dl
jns 0x58b01
andb $0x7f, (%r14)
xorl %eax, %eax
testb $0x40, %dl
sete %sil
testl %r12d, %r12d
setne %cl
orb %sil, %cl
jne 0x58c0e
andb $-0x41, (%r14)
xorl %esi, %esi
xorl %r12d, %r12d
jmp 0x58c0e
movl %r12d, %esi
movl %r15d, %edx
addq %r14, %rdx
leaq 0x60(%rsp), %rcx
leaq 0x460(%rsp), %r8
movq %r13, %rdi
callq 0x61528
testq %rax, %rax
je 0x58bf8
movq 0x460(%rsp), %r12
addl 0x60(%rsp), %r15d
leaq (%r14,%r15), %r10
movq 0x20(%rsp), %rdx
subq %r15, %rdx
cmpq $0x4, %rdx
jg 0x58c9f
movq $-0x1, %rdi
xorl %ecx, %ecx
movl %r12d, %r8d
movl %r12d, %esi
movq 0x10(%rsp), %r9
shrl $0x7, %esi
incq %rdi
addq $0x7, %rcx
cmpl $0x7f, %r8d
movl %esi, %r8d
ja 0x58b85
leaq (,%rdx,8), %rsi
subq %rdx, %rsi
xorl %edx, %edx
cmpq %rcx, %rsi
jl 0x58be6
addq $-0x7, %rcx
cmpq $0x4, %rdi
movl $0x4, %esi
cmovbq %rdi, %rsi
incq %rsi
xorl %edx, %edx
movl %r12d, %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 0x58bc0
addl %edx, %r15d
subl %edx, (%r9)
movq %rax, %r13
movl 0xc(%rsp), %edx
jmp 0x58b03
andb $0x7f, (%r14)
movl 0xc(%rsp), %edx
testb $0x40, %dl
sete %sil
xorl %eax, %eax
movq 0x10(%rsp), %r9
movl %edx, %ecx
andl $0x3, %ecx
subl %r15d, (%r9)
testl %ecx, %ecx
movl %ebx, 0x18(%rsp)
movq %rax, %rbx
je 0x58c2d
cmpl $0x7, %r12d
ja 0x58c2d
andb $-0x4, (%r14)
xorl %ecx, %ecx
movl %r15d, %ebp
leaq (%r14,%rbp), %rdx
testb $0x4, 0xc(%rsp)
jne 0x58c55
movq %r13, %rdi
testb %sil, %sil
je 0x58c84
movl %r12d, %esi
cmpl $0x1, %ecx
jne 0x58c95
movq %r9, %rcx
callq 0x5a028
jmp 0x58cc7
movl $0x1e, (%rsp)
movq %rdx, %rdi
movq %r9, %rsi
movq %r13, %rdx
movl %r12d, %ecx
movl $0x9, %r8d
xorl %r9d, %r9d
callq 0x4280
movq 0x10(%rsp), %rcx
testl %eax, %eax
je 0x58cd1
movl %r12d, (%rcx)
jmp 0x58cd1
movl %r12d, %esi
testl %ecx, %ecx
je 0x58cbf
movq %r9, %rcx
callq 0x596e6
jmp 0x58cc7
movq %r9, %rcx
callq 0x5a46b
jmp 0x58cc7
cmpl $0x7f, %r12d
movq 0x10(%rsp), %r9
ja 0x58d52
movb %r12b, (%r10)
movl $0x1, %ecx
movl 0xc(%rsp), %edx
jmp 0x58e2b
movq %r9, %rcx
callq 0x58e39
testq %rax, %rax
movq 0x10(%rsp), %rcx
je 0x58d3c
cmpl %r12d, (%rcx)
jb 0x58d29
movq 0x20(%rsp), %rcx
addq %r14, %rcx
movb (%r14), %al
andb $-0x28, %al
movl 0x18(%rsp), %edx
orb %al, %dl
orb $0x20, %dl
movb %dl, (%r14)
addq %r14, %rbp
movl %r12d, %edx
leaq (%rdx,%rbp), %rax
cmpq %rcx, %rax
jbe 0x58d16
movq %rbx, %rdi
callq 0x45c0
movq 0x10(%rsp), %rax
movl $0x0, (%rax)
jmp 0x58ae1
movq %rbp, %rdi
movq %r13, %rsi
callq 0x43c0
movq 0x10(%rsp), %rcx
movl %r12d, (%rcx)
movq %rbx, %rdi
movq %rcx, %rbx
callq 0x45c0
addl %r15d, (%rbx)
jmp 0x58ae4
movq %rbx, %rdi
movq %rcx, %rbx
callq 0x45c0
movl $0x0, (%rbx)
jmp 0x58ae1
cmpl $0x3fff, %r12d          # imm = 0x3FFF
movl 0xc(%rsp), %edx
movl %r12d, %ecx
ja 0x58d7f
shrl $0x7, %ecx
orb $-0x80, %cl
movb %cl, (%r10)
movl %r12d, %ecx
andb $0x7f, %cl
movb %cl, 0x1(%r10)
movl $0x2, %ecx
jmp 0x58e2b
cmpl $0x1fffff, %r12d        # imm = 0x1FFFFF
ja 0x58daf
shrl $0xe, %ecx
orb $-0x80, %cl
movb %cl, (%r10)
movl %r12d, %ecx
shrl $0x7, %ecx
orb $-0x80, %cl
movb %cl, 0x1(%r10)
movl %r12d, %ecx
andb $0x7f, %cl
movb %cl, 0x2(%r10)
movl $0x3, %ecx
jmp 0x58e2b
cmpl $0xfffffff, %r12d       # imm = 0xFFFFFFF
ja 0x58dec
shrl $0x15, %ecx
orb $-0x80, %cl
movb %cl, (%r10)
movl %r12d, %ecx
shrl $0xe, %ecx
orb $-0x80, %cl
movb %cl, 0x1(%r10)
movl %r12d, %ecx
shrl $0x7, %ecx
orb $-0x80, %cl
movb %cl, 0x2(%r10)
movl %r12d, %ecx
andb $0x7f, %cl
movb %cl, 0x3(%r10)
movl $0x4, %ecx
jmp 0x58e2b
shrl $0x1c, %ecx
orb $-0x80, %cl
movb %cl, (%r10)
movl %r12d, %ecx
shrl $0x15, %ecx
orb $-0x80, %cl
movb %cl, 0x1(%r10)
movl %r12d, %ecx
shrl $0xe, %ecx
orb $-0x80, %cl
movb %cl, 0x2(%r10)
movl %r12d, %ecx
shrl $0x7, %ecx
orb $-0x80, %cl
movb %cl, 0x3(%r10)
movl %r12d, %ecx
andb $0x7f, %cl
movb %cl, 0x4(%r10)
movl $0x5, %ecx
addl %ecx, %r15d
subl %ecx, (%r9)
movq %rax, %r13
jmp 0x58b03