// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/cram/cram_codecs.c
// Function: cram_xrle_encode_flush
int cram_xrle_encode_flush(cram_codec *c) {
    uint8_t *out_lit, *out_len;
    uint64_t out_lit_size, out_len_size;
    uint8_t rle_syms[256];
    int rle_nsyms = 0, i;

    for (i = 0; i < 256; i++)
        if (c->u.e_xrle.rep_score[i] > 0)
            rle_syms[rle_nsyms++] = i;

    if (!c->u.e_xrle.to_flush) {
        c->u.e_xrle.to_flush = (char *)BLOCK_DATA(c->out);
        c->u.e_xrle.to_flush_size = BLOCK_SIZE(c->out);
    }

    out_len = malloc(c->u.e_xrle.to_flush_size+8);
    if (!out_len)
        return -1;

    int nb = var_put_u64(out_len, NULL, c->u.e_xrle.to_flush_size);

    out_lit = hts_rle_encode((uint8_t *)c->u.e_xrle.to_flush, c->u.e_xrle.to_flush_size,
                             out_len+nb, &out_len_size,
                             rle_syms, &rle_nsyms,
                             NULL, &out_lit_size);
    out_len_size += nb;


    // TODO: can maybe "gift" the sub codec the data block, to remove
    // one level of memcpy.
    if (c->u.e_xrle.len_codec->encode(NULL,
                                      c->u.e_xrle.len_codec,
                                      (char *)out_len, out_len_size))
        return -1;

    if (c->u.e_xrle.lit_codec->encode(NULL,
                                      c->u.e_xrle.lit_codec,
                                      (char *)out_lit, out_lit_size))
        return -1;

    free(out_len);
    free(out_lit);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0x10(%rbp)
movl $0x0, -0x134(%rbp)
movl $0x0, -0x138(%rbp)
cmpl $0x100, -0x138(%rbp)    # imm = 0x100
jge 0xe7329
movq -0x10(%rbp), %rax
movslq -0x138(%rbp), %rcx
cmpl $0x0, 0x90(%rax,%rcx,4)
jle 0xe7316
movl -0x138(%rbp), %eax
movb %al, %cl
movl -0x134(%rbp), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, -0x134(%rbp)
cltq
movb %cl, -0x130(%rbp,%rax)
jmp 0xe7318
movl -0x138(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x138(%rbp)
jmp 0xe72d3
movq -0x10(%rbp), %rax
cmpq $0x0, 0x490(%rax)
jne 0xe7365
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x490(%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x30(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x498(%rax)
movq -0x10(%rbp), %rax
movq 0x498(%rax), %rdi
addq $0x8, %rdi
callq 0x4650
movq %rax, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0xe7390
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe748a
movq -0x20(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x498(%rax), %rdx
xorl %eax, %eax
movl %eax, %esi
callq 0xe74a0
movl %eax, -0x13c(%rbp)
movq -0x10(%rbp), %rax
movq 0x490(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x498(%rax), %rsi
movq -0x20(%rbp), %rdx
movslq -0x13c(%rbp), %rax
addq %rax, %rdx
leaq -0x130(%rbp), %r8
leaq -0x30(%rbp), %rcx
leaq -0x134(%rbp), %r9
xorl %eax, %eax
leaq -0x28(%rbp), %rax
movq $0x0, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xc7a20
movq %rax, -0x18(%rbp)
movslq -0x13c(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x78(%rax), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x78(%rcx), %rsi
movq -0x20(%rbp), %rdx
movq -0x30(%rbp), %rcx
xorl %edi, %edi
callq *%rax
cmpl $0x0, %eax
je 0xe743d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe748a
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movq 0x30(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x80(%rcx), %rsi
movq -0x18(%rbp), %rdx
movq -0x28(%rbp), %rcx
xorl %edi, %edi
callq *%rax
cmpl $0x0, %eax
je 0xe7471
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xe748a
movq -0x20(%rbp), %rdi
callq 0x45a0
movq -0x18(%rbp), %rdi
callq 0x45a0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopw %cs:(%rax,%rax)