// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/cram/cram_codecs.c
// Function: cram_xrle_decode_expand_char
static int cram_xrle_decode_expand_char(cram_slice *slice, cram_codec *c) {
    cram_block *b = slice->block_by_id[512 + c->codec_id];
    if (b)
        return 0;

    b = slice->block_by_id[512 + c->codec_id] = cram_new_block(0, 0);
    if (!b)
        return -1;
    cram_block *lit_b = c->u.xrle.lit_codec->get_block(slice, c->u.xrle.lit_codec);
    if (!lit_b)
        return -1;
    unsigned char *lit_dat = lit_b->data;
    unsigned int lit_sz = lit_b->uncomp_size;
    unsigned int len_sz = c->u.xrle.len_codec->size(slice, c->u.xrle.len_codec);

    cram_block *len_b = c->u.xrle.len_codec->get_block(slice, c->u.xrle.len_codec);
    if (!len_b)
        return -1;
    unsigned char *len_dat = len_b->data;

    uint8_t rle_syms[256];
    int rle_nsyms = 0;
    int i;
    for (i = 0; i < 256; i++) {
        if (c->u.xrle.rep_score[i] > 0)
            rle_syms[rle_nsyms++] = i;
    }

    uint64_t out_sz;
    int nb = var_get_u64(len_dat, len_dat+len_sz, &out_sz);
    if (!(b->data = malloc(out_sz)))
        return -1;
    hts_rle_decode(lit_dat, lit_sz,
                   len_dat+nb, len_sz-nb,
                   rle_syms, rle_nsyms,
                   b->data, &out_sz);
    b->uncomp_size = out_sz;

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq 0x18(%rdi), %rax
movslq 0x18(%rsi), %rcx
cmpq $0x0, 0x1000(%rax,%rcx,8)
je 0x8ef64
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %r14
movq %rdi, %r13
xorl %edi, %edi
xorl %esi, %esi
callq 0x4c675
movq %rax, %rbx
movq 0x18(%r13), %rax
movslq 0x18(%r14), %rcx
movq %rbx, 0x1000(%rax,%rcx,8)
testq %rbx, %rbx
je 0x8ef52
movq 0x80(%r14), %rsi
movq %r13, %rdi
callq *0x50(%rsi)
testq %rax, %rax
je 0x8ef52
movq 0x20(%rax), %rbp
movl 0x14(%rax), %r15d
movq 0x78(%r14), %rsi
movq %r13, %rdi
callq *0x40(%rsi)
movl %eax, %r12d
movq 0x78(%r14), %rsi
movq %r13, %rdi
callq *0x50(%rsi)
testq %rax, %rax
je 0x8ef52
movq %rbp, 0x8(%rsp)
movq 0x20(%rax), %r13
xorl %eax, %eax
xorl %ebp, %ebp
cmpl $0x0, 0x90(%r14,%rax,4)
jle 0x8efe2
movslq %ebp, %rcx
incl %ebp
movb %al, 0x10(%rsp,%rcx)
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x8efce
cmpl $0xa, %r12d
ja 0x8f02d
testq %r13, %r13
je 0x8f02d
testl %r12d, %r12d
je 0x8f0ab
movl %r12d, %eax
addq %r13, %rax
xorl %edi, %edi
movq %r13, %r14
movzbl (%r14), %ecx
incq %r14
movq %rdi, %rdx
shlq $0x7, %rdx
movl %ecx, %edi
andl $0x7f, %edi
orq %rdx, %rdi
testb %cl, %cl
jns 0x8f059
cmpq %rax, %r14
jb 0x8f00c
jmp 0x8f059
xorl %eax, %eax
xorl %edi, %edi
movzbl (%r13,%rax), %ecx
movq %rdi, %rdx
shlq $0x7, %rdx
movl %ecx, %edi
andl $0x7f, %edi
orq %rdx, %rdi
leaq 0x1(%rax), %r14
testb %cl, %cl
jns 0x8f056
cmpl $0xa, %eax
movq %r14, %rax
jne 0x8f031
addq %r13, %r14
movq %rdi, (%rsp)
subl %r13d, %r14d
callq 0x4680
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x8ef52
movslq %r14d, %rcx
addq %rcx, %r13
subl %ecx, %r12d
movq %rsp, %r14
leaq 0x10(%rsp), %r8
movq 0x8(%rsp), %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r12, %rcx
movl %ebp, %r9d
pushq %r14
pushq %rax
callq 0x7adbb
addq $0x10, %rsp
movl (%r14), %eax
movl %eax, 0x14(%rbx)
jmp 0x8ef52
movq $0x0, (%rsp)
xorl %edi, %edi
xorl %r14d, %r14d
jmp 0x8f060