// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdi, %rbx
movl $0x0, 0xc(%rsp)
xorl %eax, %eax
xorl %ecx, %ecx
cmpl $0x0, 0x90(%rbx,%rax,4)
jle 0x91d7e
movslq %ecx, %rdx
incl %ecx
movb %al, 0x20(%rsp,%rdx)
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x91d6b
movl %ecx, 0xc(%rsp)
cmpq $0x0, 0x490(%rbx)
jne 0x91db1
movq 0x8(%rbx), %rax
movq 0x20(%rax), %rcx
movq %rcx, 0x490(%rbx)
movq 0x30(%rax), %rax
movq %rax, 0x498(%rbx)
movq 0x498(%rbx), %r15
leaq 0x8(%r15), %rdi
callq 0x4680
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x92115
movq %rax, %r14
cmpq $0x7f, %r15
ja 0x91de6
movb %r15b, (%r14)
movl $0x1, %r12d
jmp 0x9209b
cmpq $0x3fff, %r15           # imm = 0x3FFF
ja 0x91e0e
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, (%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x1(%r14)
movl $0x2, %r12d
jmp 0x9209b
cmpq $0x1fffff, %r15         # imm = 0x1FFFFF
ja 0x91e42
movl %r15d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, (%r14)
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x2(%r14)
movl $0x3, %r12d
jmp 0x9209b
cmpq $0xfffffff, %r15        # imm = 0xFFFFFFF
ja 0x91e82
movl %r15d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, (%r14)
movl %r15d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x3(%r14)
movl $0x4, %r12d
jmp 0x9209b
movq %r15, %rax
shrq $0x23, %rax
jne 0x91ecf
movq %r15, %rax
shrq $0x1c, %rax
orb $-0x80, %al
movb %al, (%r14)
movl %r15d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r15d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x4(%r14)
movl $0x5, %r12d
jmp 0x9209b
movq %r15, %rcx
shrq $0x2a, %rcx
jne 0x91f22
orb $-0x80, %al
movb %al, (%r14)
movq %r15, %rax
shrq $0x1c, %rax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r15d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r15d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x4(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x5(%r14)
movl $0x6, %r12d
jmp 0x9209b
movq %r15, %rdx
shrq $0x31, %rdx
jne 0x91f7c
orb $-0x80, %cl
movb %cl, (%r14)
orb $-0x80, %al
movb %al, 0x1(%r14)
movq %r15, %rax
shrq $0x1c, %rax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r15d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r15d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x4(%r14)
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x5(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x6(%r14)
movl $0x7, %r12d
jmp 0x9209b
movq %r15, %rsi
shrq $0x38, %rsi
jne 0x91fdd
orb $-0x80, %dl
movb %dl, (%r14)
orb $-0x80, %cl
movb %cl, 0x1(%r14)
orb $-0x80, %al
movb %al, 0x2(%r14)
movq %r15, %rax
shrq $0x1c, %rax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r15d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x4(%r14)
movl %r15d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x5(%r14)
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x6(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x7(%r14)
movl $0x8, %r12d
jmp 0x9209b
testq %r15, %r15
js 0x9203f
orb $-0x80, %sil
movb %sil, (%r14)
orb $-0x80, %dl
movb %dl, 0x1(%r14)
orb $-0x80, %cl
movb %cl, 0x2(%r14)
orb $-0x80, %al
movb %al, 0x3(%r14)
movq %r15, %rax
shrq $0x1c, %rax
orb $-0x80, %al
movb %al, 0x4(%r14)
movl %r15d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x5(%r14)
movl %r15d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x6(%r14)
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x7(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x8(%r14)
movl $0x9, %r12d
jmp 0x9209b
movb $-0x7f, (%r14)
movb %sil, 0x1(%r14)
orb $-0x80, %dl
movb %dl, 0x2(%r14)
orb $-0x80, %cl
movb %cl, 0x3(%r14)
orb $-0x80, %al
movb %al, 0x4(%r14)
movq %r15, %rax
shrq $0x1c, %rax
orb $-0x80, %al
movb %al, 0x5(%r14)
movl %r15d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x6(%r14)
movl %r15d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x7(%r14)
movl %r15d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x8(%r14)
movl %r15d, %eax
andb $0x7f, %al
movb %al, 0x9(%r14)
movl $0xa, %r12d
movq 0x490(%rbx), %rdi
movq %r14, %rdx
addq %r12, %rdx
leaq 0x10(%rsp), %rax
leaq 0x18(%rsp), %r13
leaq 0x20(%rsp), %r8
leaq 0xc(%rsp), %r9
movq %r15, %rsi
movq %r13, %rcx
pushq %rax
pushq $0x0
callq 0x7cac8
addq $0x10, %rsp
movq %rax, %r15
addq (%r13), %r12
movq %r12, (%r13)
movq 0x78(%rbx), %rsi
xorl %edi, %edi
movq %r14, %rdx
movl %r12d, %ecx
callq *0x30(%rsi)
testl %eax, %eax
jne 0x92115
movq 0x80(%rbx), %rsi
movl 0x10(%rsp), %ecx
xorl %edi, %edi
movq %r15, %rdx
callq *0x30(%rsi)
testl %eax, %eax
jne 0x92115
movq %r14, %rdi
callq 0x45c0
movq %r15, %rdi
callq 0x45c0
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq