// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x970, %rsp            # imm = 0x970
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
cmpl $0x7fffffff, -0x14(%rbp) # imm = 0x7FFFFFFF
ja 0x82837
cmpq $0x0, -0x20(%rbp)
je 0x8284e
movq -0x28(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x8284e
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x833bf
cmpq $0x0, -0x20(%rbp)
jne 0x82898
movl -0x14(%rbp), %edi
movl -0x2c(%rbp), %esi
callq 0x826c0
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, %edi
callq 0x4650
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
jne 0x82896
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x833bf
jmp 0x82898
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
movl (%rcx), %ecx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
cmpl $0x14, -0x14(%rbp)
ja 0x828b8
movl -0x2c(%rbp), %eax
andl $-0x9, %eax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x8292d
movq -0x20(%rbp), %rax
movb $0x20, (%rax)
movq -0x20(%rbp), %rdi
addq $0x1, %rdi
movq -0x48(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x833d0
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
addl -0x14(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jbe 0x82909
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x833bf
movq -0x20(%rbp), %rdi
movl -0x30(%rbp), %eax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %eax
movl %eax, %edx
callq 0x43b0
movl -0x14(%rbp), %ecx
addl -0x30(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movl -0x2c(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x8302d
movl -0x2c(%rbp), %eax
sarl $0x8, %eax
andl $0xff, %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jne 0x82957
movl $0x4, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jbe 0x82965
movl -0x14(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %edi
callq 0x4650
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x82991
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x833bf
movl $0x0, -0x864(%rbp)
movl -0x864(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x82a42
movl -0x14(%rbp), %eax
xorl %edx, %edx
divl -0x4c(%rbp)
movl %eax, %ecx
movl -0x14(%rbp), %eax
xorl %edx, %edx
divl -0x4c(%rbp)
cmpl -0x864(%rbp), %edx
seta %al
andb $0x1, %al
movzbl %al, %eax
addl %eax, %ecx
movslq -0x864(%rbp), %rax
movl %ecx, -0x460(%rbp,%rax,4)
cmpl $0x0, -0x864(%rbp)
je 0x82a10
movl -0x864(%rbp), %eax
subl $0x1, %eax
cltq
movl -0x860(%rbp,%rax,4), %eax
movl -0x864(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
addl -0x460(%rbp,%rcx,4), %eax
movl %eax, -0x914(%rbp)
jmp 0x82a1a
xorl %eax, %eax
movl %eax, -0x914(%rbp)
jmp 0x82a1a
movl -0x914(%rbp), %ecx
movslq -0x864(%rbp), %rax
movl %ecx, -0x860(%rbp,%rax,4)
movl -0x864(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x864(%rbp)
jmp 0x8299b
movl $0x0, -0x86c(%rbp)
movl $0x0, -0x864(%rbp)
movl -0x864(%rbp), %eax
movl -0x14(%rbp), %ecx
subl -0x4c(%rbp), %ecx
cmpl %ecx, %eax
jae 0x82ae4
movl $0x0, -0x868(%rbp)
movl -0x868(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x82abf
movq -0x10(%rbp), %rax
movl -0x864(%rbp), %ecx
addl -0x868(%rbp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x58(%rbp), %rax
movslq -0x868(%rbp), %rcx
movl -0x860(%rbp,%rcx,4), %ecx
addl -0x86c(%rbp), %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x868(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x868(%rbp)
jmp 0x82a70
jmp 0x82ac1
movl -0x4c(%rbp), %eax
addl -0x864(%rbp), %eax
movl %eax, -0x864(%rbp)
movl -0x86c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x86c(%rbp)
jmp 0x82a56
jmp 0x82ae6
movl -0x864(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x82b79
movl $0x0, -0x868(%rbp)
movl -0x864(%rbp), %eax
addl -0x868(%rbp), %eax
cmpl -0x14(%rbp), %eax
jae 0x82b54
movq -0x10(%rbp), %rax
movl -0x864(%rbp), %ecx
addl -0x868(%rbp), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x58(%rbp), %rax
movslq -0x868(%rbp), %rcx
movl -0x860(%rbp,%rcx,4), %ecx
addl -0x86c(%rbp), %ecx
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movl -0x868(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x868(%rbp)
jmp 0x82aff
jmp 0x82b56
movl -0x4c(%rbp), %eax
addl -0x864(%rbp), %eax
movl %eax, -0x864(%rbp)
movl -0x86c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x86c(%rbp)
jmp 0x82ae6
movl $0x1, -0x30(%rbp)
movl -0x2c(%rbp), %eax
andl $-0x11, %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movq -0x20(%rbp), %rdi
movl -0x30(%rbp), %eax
addq %rax, %rdi
movq -0x48(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x833d0
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jb 0x82bd5
movq -0x58(%rbp), %rdi
callq 0x45a0
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x833bf
movl -0x4c(%rbp), %eax
movb %al, %dl
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x30(%rbp)
movl %ecx, %ecx
movb %dl, (%rax,%rcx)
movq -0x20(%rbp), %rax
addq $0x7, %rax
imull $0x5, -0x4c(%rbp), %ecx
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x878(%rbp)
movq %rax, -0x880(%rbp)
movl $0x0, -0x864(%rbp)
movl -0x864(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x82fcf
movl $0x0, -0x888(%rbp)
movl $0x7fffffff, -0x88c(%rbp) # imm = 0x7FFFFFFF
leaq -0x8e0(%rbp), %rdi
leaq 0x735b7(%rip), %rsi     # 0xf6200
movl $0x40, %edx
callq 0x43b0
movl $0x1, -0x884(%rbp)
movl -0x884(%rbp), %eax
movl %eax, -0x918(%rbp)
cmpl $0x3, -0x864(%rbp)
jge 0x82c80
movl -0x864(%rbp), %eax
movl %eax, -0x91c(%rbp)
jmp 0x82c8d
movl $0x3, %eax
movl %eax, -0x91c(%rbp)
jmp 0x82c8d
movl -0x918(%rbp), %eax
movl -0x91c(%rbp), %ecx
movslq %ecx, %rdx
leaq -0x8e0(%rbp), %rcx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jg 0x82e48
movq -0x878(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
movq -0x28(%rbp), %rcx
movl (%rcx), %ecx
cmpq %rcx, %rax
jle 0x82cd0
jmp 0x82e34
movq -0x28(%rbp), %rax
movl (%rax), %eax
movq -0x878(%rbp), %rcx
movq -0x20(%rbp), %rdx
subq %rdx, %rcx
subq %rcx, %rax
movl %eax, -0x870(%rbp)
movl -0x2c(%rbp), %eax
andl $0x3, %eax
cmpl $0x0, %eax
jne 0x82d4a
cmpl $0x3, -0x864(%rbp)
jge 0x82d0f
movl -0x864(%rbp), %eax
movl %eax, -0x920(%rbp)
jmp 0x82d1c
movl $0x3, %eax
movl %eax, -0x920(%rbp)
jmp 0x82d1c
movl -0x920(%rbp), %eax
movslq %eax, %rcx
leaq -0x8e0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x884(%rbp), %rcx
movl (%rax,%rcx,4), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x82d4a
jmp 0x82e34
movq -0x58(%rbp), %rax
movslq -0x864(%rbp), %rcx
movl -0x860(%rbp,%rcx,4), %ecx
addq %rcx, %rax
movq %rax, -0x938(%rbp)
movslq -0x864(%rbp), %rax
movl -0x460(%rbp,%rax,4), %eax
movl %eax, -0x92c(%rbp)
movq -0x878(%rbp), %rax
movq %rax, -0x928(%rbp)
cmpl $0x3, -0x864(%rbp)
jge 0x82d9f
movl -0x864(%rbp), %eax
movl %eax, -0x93c(%rbp)
jmp 0x82dac
movl $0x3, %eax
movl %eax, -0x93c(%rbp)
jmp 0x82dac
movq -0x928(%rbp), %rdx
movl -0x92c(%rbp), %esi
movq -0x938(%rbp), %rdi
movl -0x93c(%rbp), %eax
movslq %eax, %rcx
leaq -0x8e0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x884(%rbp), %rcx
movl (%rax,%rcx,4), %r8d
orl $0x10, %r8d
leaq -0x870(%rbp), %rcx
callq 0x827f0
movq %rax, -0x898(%rbp)
cmpq $0x0, -0x898(%rbp)
je 0x82e32
cmpl $0x0, -0x870(%rbp)
je 0x82e32
movl -0x88c(%rbp), %eax
cmpl -0x870(%rbp), %eax
jbe 0x82e32
movl -0x870(%rbp), %eax
movl %eax, -0x88c(%rbp)
movl -0x884(%rbp), %eax
movl %eax, -0x888(%rbp)
jmp 0x82e34
movl -0x884(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x884(%rbp)
jmp 0x82c5d
cmpl $0x7fffffff, -0x88c(%rbp) # imm = 0x7FFFFFFF
jne 0x82e74
movq -0x58(%rbp), %rdi
callq 0x45a0
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x833bf
movl -0x888(%rbp), %eax
movl -0x884(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x82f83
movq -0x28(%rbp), %rax
movl (%rax), %eax
movq -0x878(%rbp), %rcx
movq -0x20(%rbp), %rdx
subq %rdx, %rcx
subq %rcx, %rax
movl %eax, -0x870(%rbp)
movq -0x58(%rbp), %rax
movslq -0x864(%rbp), %rcx
movl -0x860(%rbp,%rcx,4), %ecx
addq %rcx, %rax
movq %rax, -0x958(%rbp)
movslq -0x864(%rbp), %rax
movl -0x460(%rbp,%rax,4), %eax
movl %eax, -0x94c(%rbp)
movq -0x878(%rbp), %rax
movq %rax, -0x948(%rbp)
cmpl $0x3, -0x864(%rbp)
jge 0x82efd
movl -0x864(%rbp), %eax
movl %eax, -0x95c(%rbp)
jmp 0x82f0a
movl $0x3, %eax
movl %eax, -0x95c(%rbp)
jmp 0x82f0a
movq -0x948(%rbp), %rdx
movl -0x94c(%rbp), %esi
movq -0x958(%rbp), %rdi
movl -0x95c(%rbp), %eax
movslq %eax, %rcx
leaq -0x8e0(%rbp), %rax
shlq $0x4, %rcx
addq %rcx, %rax
movslq -0x888(%rbp), %rcx
movl (%rax,%rcx,4), %r8d
orl $0x10, %r8d
leaq -0x870(%rbp), %rcx
callq 0x827f0
movq %rax, -0x898(%rbp)
cmpq $0x0, -0x898(%rbp)
jne 0x82f81
movq -0x58(%rbp), %rdi
callq 0x45a0
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x833bf
jmp 0x82f83
movl -0x870(%rbp), %ecx
movq -0x878(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x878(%rbp)
movq -0x20(%rbp), %rdi
movl -0x30(%rbp), %eax
addq %rax, %rdi
movq -0x48(%rbp), %rsi
movl -0x870(%rbp), %edx
callq 0x833d0
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x864(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x864(%rbp)
jmp 0x82c18
movq -0x20(%rbp), %rdi
movl -0x30(%rbp), %eax
addq %rax, %rdi
movq -0x880(%rbp), %rsi
movq -0x878(%rbp), %rdx
movq -0x880(%rbp), %rax
subq %rax, %rdx
callq 0x4810
movq -0x58(%rbp), %rdi
callq 0x45a0
movl -0x30(%rbp), %ecx
movq -0x878(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq -0x880(%rbp), %rcx
subq %rcx, %rax
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x833bf
movl -0x2c(%rbp), %eax
andl $0x80, %eax
movl %eax, -0x8e4(%rbp)
movl -0x2c(%rbp), %eax
andl $0x40, %eax
movl %eax, -0x8e8(%rbp)
movl -0x2c(%rbp), %eax
andl $0x10, %eax
movl %eax, -0x8ec(%rbp)
movl -0x2c(%rbp), %eax
andl $0x4, %eax
movl %eax, -0x8f0(%rbp)
movl -0x2c(%rbp), %eax
movb %al, %cl
movq -0x20(%rbp), %rax
movb %cl, (%rax)
movl $0x1, -0x30(%rbp)
cmpl $0x0, -0x8ec(%rbp)
jne 0x83094
movq -0x20(%rbp), %rdi
addq $0x1, %rdi
movq -0x48(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x833d0
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x2c(%rbp), %eax
andl $0x3, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x8e4(%rbp)
je 0x83190
cmpl $0x0, -0x14(%rbp)
je 0x83190
movl -0x30(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jbe 0x830db
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x833bf
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, %esi
movq -0x20(%rbp), %rdx
movl -0x30(%rbp), %eax
addq %rax, %rdx
leaq -0x8f4(%rbp), %rcx
leaq -0x900(%rbp), %r8
callq 0x8ce30
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x83138
movq -0x20(%rbp), %rax
movzbl (%rax), %ecx
andl $0xffffff7f, %ecx       # imm = 0xFFFFFF7F
movb %cl, (%rax)
movl $0x0, -0x8e4(%rbp)
movq -0x40(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x40(%rbp)
jmp 0x8318e
movq -0x40(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x900(%rbp), %rax
movl %eax, -0x14(%rbp)
movl -0x8f4(%rbp), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
movl -0x30(%rbp), %eax
addq %rax, %rdi
movq -0x48(%rbp), %rsi
movl -0x14(%rbp), %edx
callq 0x833d0
movl %eax, -0x904(%rbp)
movl -0x904(%rbp), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x904(%rbp), %edx
movq -0x28(%rbp), %rax
movl (%rax), %ecx
subl %edx, %ecx
movl %ecx, (%rax)
jmp 0x831aa
cmpl $0x0, -0x8e4(%rbp)
je 0x831a8
movq -0x20(%rbp), %rax
movzbl (%rax), %ecx
andl $0xffffff7f, %ecx       # imm = 0xFFFFFF7F
movb %cl, (%rax)
jmp 0x831aa
cmpl $0x0, -0x8e8(%rbp)
je 0x831c5
cmpl $0x0, -0x14(%rbp)
jne 0x831c5
movq -0x20(%rbp), %rax
movzbl (%rax), %ecx
andl $-0x41, %ecx
movb %cl, (%rax)
movl -0x30(%rbp), %edx
movq -0x28(%rbp), %rax
movl (%rax), %ecx
subl %edx, %ecx
movl %ecx, (%rax)
cmpl $0x0, -0x2c(%rbp)
je 0x831f3
cmpl $0x8, -0x14(%rbp)
jae 0x831f3
movq -0x20(%rbp), %rax
movzbl (%rax), %ecx
andl $-0x4, %ecx
movb %cl, (%rax)
movl -0x2c(%rbp), %eax
andl $-0x4, %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x8f0(%rbp)
je 0x8323c
movq -0x20(%rbp), %rdi
movl -0x30(%rbp), %eax
addq %rax, %rdi
movq -0x28(%rbp), %rsi
movq -0x10(%rbp), %rdx
movl -0x14(%rbp), %ecx
movl $0x9, %r8d
xorl %r9d, %r9d
movl $0x1e, (%rsp)
callq 0x4270
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x83237
movl -0x14(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
jmp 0x83312
cmpl $0x0, -0x8e8(%rbp)
je 0x83291
cmpl $0x0, -0x2c(%rbp)
jne 0x8326e
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x20(%rbp), %rdx
movl -0x30(%rbp), %eax
addq %rax, %rdx
movq -0x28(%rbp), %rcx
callq 0x83640
movq %rax, -0x910(%rbp)
jmp 0x8328f
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x20(%rbp), %rdx
movl -0x30(%rbp), %eax
addq %rax, %rdx
movq -0x28(%rbp), %rcx
callq 0x839f0
movq %rax, -0x910(%rbp)
jmp 0x832dd
cmpl $0x1, -0x2c(%rbp)
jne 0x832ba
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x20(%rbp), %rdx
movl -0x30(%rbp), %eax
addq %rax, %rdx
movq -0x28(%rbp), %rcx
callq 0x83e00
movq %rax, -0x910(%rbp)
jmp 0x832db
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
movq -0x20(%rbp), %rdx
movl -0x30(%rbp), %eax
addq %rax, %rdx
movq -0x28(%rbp), %rcx
callq 0x84030
movq %rax, -0x910(%rbp)
jmp 0x832dd
cmpq $0x0, -0x910(%rbp)
jne 0x83310
movq -0x38(%rbp), %rdi
callq 0x45a0
movq -0x40(%rbp), %rdi
callq 0x45a0
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x833bf
jmp 0x83312
movq -0x28(%rbp), %rax
movl (%rax), %eax
cmpl -0x14(%rbp), %eax
jb 0x8339a
movq -0x20(%rbp), %rax
movzbl (%rax), %ecx
andl $-0x8, %ecx
movb %cl, (%rax)
movl -0x8ec(%rbp), %edx
orl $0x20, %edx
movq -0x20(%rbp), %rax
movzbl (%rax), %ecx
orl %edx, %ecx
movb %cl, (%rax)
movq -0x20(%rbp), %rax
movl -0x30(%rbp), %ecx
addq %rcx, %rax
movl -0x14(%rbp), %ecx
addq %rcx, %rax
cmpq -0x48(%rbp), %rax
jbe 0x83379
movq -0x38(%rbp), %rdi
callq 0x45a0
movq -0x40(%rbp), %rdi
callq 0x45a0
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq $0x0, -0x8(%rbp)
jmp 0x833bf
movq -0x20(%rbp), %rdi
movl -0x30(%rbp), %eax
addq %rax, %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %eax
movl %eax, %edx
callq 0x43b0
movl -0x14(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x38(%rbp), %rdi
callq 0x45a0
movq -0x40(%rbp), %rdi
callq 0x45a0
movl -0x30(%rbp), %ecx
movq -0x28(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x970, %rsp            # imm = 0x970
popq %rbp
retq
nopl (%rax)