// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/cram/cram_codecs.c
// Function: cram_xrle_encode_store
int cram_xrle_encode_store(cram_codec *c, cram_block *b,
                            char *prefix, int version) {
    int len = 0, r = 0, n;
    cram_codec *tc;
    cram_block *b_rle, *b_len, *b_lit;

    if (prefix) {
        size_t l = strlen(prefix);
        BLOCK_APPEND(b, prefix, l);
        len += l;
    }

    // List of symbols to RLE
    b_rle = cram_new_block(0, 0);
    if (!b_rle)
        return -1;
    int i, nrle = 0, len1 = 0;
    for (i = 0; i < 256; i++) {
        if (c->u.e_xrle.rep_score[i] > 0) {
            nrle++;
            len1 += (n = c->vv->varint_put32_blk(b_rle,i)); r |= n;
        }
    }

    // Store length and literal sub-codecs to get encoded length
    tc = c->u.e_xrle.len_codec;
    b_len = cram_new_block(0, 0);
    if (!b_len)
        return -1;
    int len2 = tc->store(tc, b_len, NULL, version);

    tc = c->u.e_xrle.lit_codec;
    b_lit = cram_new_block(0, 0);
    if (!b_lit)
        return -1;
    int len3 = tc->store(tc, b_lit, NULL, version);

    len += (n = c->vv->varint_put32_blk(b, c->codec)); r |= n;
    len += (n = c->vv->varint_put32_blk(b, len1 + len2 + len3
                                        + c->vv->varint_size(nrle))); r |= n;
    len += (n = c->vv->varint_put32_blk(b, nrle)); r |= n;
    BLOCK_APPEND(b, BLOCK_DATA(b_rle), BLOCK_SIZE(b_rle));
    BLOCK_APPEND(b, BLOCK_DATA(b_len), BLOCK_SIZE(b_len));
    BLOCK_APPEND(b, BLOCK_DATA(b_lit), BLOCK_SIZE(b_lit));

    cram_free_block(b_rle);
    cram_free_block(b_len);
    cram_free_block(b_lit);

    if (r > 0)
        return len + len1 + len2 + len3;

 block_err:
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %ecx, %r13d
movq %rsi, %rbp
movq %rdi, %r12
testq %rdx, %rdx
je 0x8f810
movq %rdx, %rbx
movq %rdx, %rdi
callq 0x41d0
movq %rax, %r14
movq 0x30(%rbp), %r15
addq %rax, %r15
movq 0x28(%rbp), %rax
cmpq %r15, %rax
ja 0x8f7ed
leaq 0x320(%rax), %rcx
shrq $0x2, %rcx
addq %rcx, %rax
addq $0x320, %rax            # imm = 0x320
cmpq %r15, %rax
cmovaq %rax, %r15
movq 0x20(%rbp), %rdi
movq %r15, %rsi
callq 0x4840
testq %rax, %rax
je 0x8fb3a
movq %r15, 0x28(%rbp)
movq %rax, 0x20(%rbp)
testq %r14, %r14
je 0x8f809
movq 0x20(%rbp), %rdi
addq 0x30(%rbp), %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x43c0
addq %r14, 0x30(%rbp)
movl %r13d, 0x10(%rsp)
jmp 0x8f818
movl %r13d, 0x10(%rsp)
xorl %r14d, %r14d
xorl %r13d, %r13d
xorl %edi, %edi
xorl %esi, %esi
callq 0x4c675
movq %rax, %r15
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r15, %r15
je 0x8fb3f
movq %rbp, 0x8(%rsp)
movq %r14, 0x50(%rsp)
xorl %ebx, %ebx
xorl %ebp, %ebp
xorl %r14d, %r14d
cmpl $0x0, 0x90(%r12,%rbx,4)
jle 0x8f866
incl %ebp
movq 0x10(%r12), %rax
movq %r15, %rdi
movl %ebx, %esi
callq *0x58(%rax)
addl %eax, %r13d
orl %eax, %r14d
incq %rbx
cmpq $0x100, %rbx            # imm = 0x100
jne 0x8f846
movq 0x78(%r12), %rbx
xorl %edi, %edi
xorl %esi, %esi
callq 0x4c675
testq %rax, %rax
je 0x8fb3a
movq %rbx, %rdi
movq %rax, 0x40(%rsp)
movq %rax, %rsi
xorl %edx, %edx
movl 0x10(%rsp), %ecx
callq *0x38(%rbx)
movq %rax, 0x48(%rsp)
movq 0x80(%r12), %rbx
xorl %edi, %edi
xorl %esi, %esi
callq 0x4c675
testq %rax, %rax
je 0x8fb3a
movq %rbx, %rdi
movq %rax, 0x38(%rsp)
movq %rax, %rsi
xorl %edx, %edx
movl 0x10(%rsp), %ecx
callq *0x38(%rbx)
movq %rax, 0x10(%rsp)
movq 0x10(%r12), %rax
movl (%r12), %esi
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq *0x58(%rax)
movl %eax, 0x34(%rsp)
movq 0x10(%r12), %rax
movq 0x58(%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x48(%rsp), %rcx
addl %r13d, %ecx
movl %ecx, 0x4(%rsp)
movslq %ebp, %rbp
movq %rbp, %rdi
callq *0x78(%rax)
movq 0x10(%rsp), %rcx
leal (%rax,%rcx), %esi
addl 0x4(%rsp), %esi
movq %rbx, %rdi
callq *0x20(%rsp)
movl %eax, 0x20(%rsp)
movq 0x10(%r12), %rax
movq %rbx, %rdi
movl %ebp, %esi
callq *0x58(%rax)
movl %eax, 0x4(%rsp)
movq 0x20(%r15), %rsi
movq 0x30(%r15), %rcx
movq 0x28(%rbx), %rax
movq 0x30(%rbx), %r12
leaq (%r12,%rcx), %rbp
cmpq %rbp, %rax
jbe 0x8f956
movq %rax, %rbp
jmp 0x8f9a6
movq %rsi, 0x28(%rsp)
movq %rcx, 0x18(%rsp)
leaq 0x320(%rax), %rcx
shrq $0x2, %rcx
addq %rcx, %rax
addq $0x320, %rax            # imm = 0x320
cmpq %rbp, %rax
cmovaq %rax, %rbp
movq 0x20(%rbx), %rdi
movq %rbp, %rsi
callq 0x4840
testq %rax, %rax
je 0x8fb3a
movq %rbp, 0x28(%rbx)
movq %rax, 0x20(%rbx)
movq 0x30(%rbx), %r12
movq 0x18(%rsp), %rcx
movq 0x28(%rsp), %rsi
testq %rcx, %rcx
je 0x8f9ce
movq 0x8(%rsp), %rbx
addq 0x20(%rbx), %r12
movq %r12, %rdi
movq %rcx, %r12
movq %rcx, %rdx
callq 0x43c0
addq 0x30(%rbx), %r12
movq %r12, 0x30(%rbx)
movq 0x28(%rbx), %rbp
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rsi
movq 0x30(%rax), %rax
leaq (%r12,%rax), %rbx
cmpq %rbx, %rbp
jbe 0x8f9ee
movq %rbp, %rbx
movq 0x8(%rsp), %rbp
jmp 0x8fa43
movq %rsi, 0x28(%rsp)
movq %rax, 0x18(%rsp)
leaq 0x320(%rbp), %rax
shrq $0x2, %rax
addq %rbp, %rax
addq $0x320, %rax            # imm = 0x320
cmpq %rbx, %rax
cmovaq %rax, %rbx
movq 0x8(%rsp), %rbp
movq 0x20(%rbp), %rdi
movq %rbx, %rsi
callq 0x4840
testq %rax, %rax
je 0x8fb3a
movq %rbx, 0x28(%rbp)
movq %rax, 0x20(%rbp)
movq 0x30(%rbp), %r12
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rsi
testq %rax, %rax
je 0x8fa66
addq 0x20(%rbp), %r12
movq %r12, %rdi
movq %rax, %r12
movq %rax, %rdx
callq 0x43c0
addq 0x30(%rbp), %r12
movq %r12, 0x30(%rbp)
movq 0x28(%rbp), %rbx
movq 0x38(%rsp), %rax
movq 0x20(%rax), %rsi
movq 0x30(%rax), %rbp
addq %rbp, %r12
cmpq %r12, %rbx
ja 0x8fac2
movq %rsi, 0x18(%rsp)
leaq 0x320(%rbx), %rax
shrq $0x2, %rax
addq %rbx, %rax
addq $0x320, %rax            # imm = 0x320
cmpq %r12, %rax
cmovaq %rax, %r12
movq 0x8(%rsp), %rbx
movq 0x20(%rbx), %rdi
movq %r12, %rsi
callq 0x4840
testq %rax, %rax
je 0x8fb3a
movq %r12, 0x28(%rbx)
movq %rax, 0x20(%rbx)
movq 0x18(%rsp), %rsi
movl 0x34(%rsp), %r12d
orl %r12d, %r14d
orl 0x4(%rsp), %r14d
orl 0x20(%rsp), %r14d
testq %rbp, %rbp
je 0x8faf2
movq 0x8(%rsp), %rbx
movq 0x20(%rbx), %rdi
addq 0x30(%rbx), %rdi
movq %rbp, %rdx
callq 0x43c0
addq %rbp, 0x30(%rbx)
movq %r15, %rdi
callq 0x4ceb6
movq 0x40(%rsp), %rdi
callq 0x4ceb6
movq 0x38(%rsp), %rdi
callq 0x4ceb6
testl %r14d, %r14d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq 0x48(%rsp), %rcx
jle 0x8fb3f
addl 0x50(%rsp), %r13d
addl %ecx, %r13d
movq 0x10(%rsp), %rax
addl %r12d, %eax
addl %r13d, %eax
addl 0x4(%rsp), %eax
addl 0x20(%rsp), %eax
jmp 0x8fb3f
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq