// File: /workspace/github_c_makefile_star2_O3/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
xorl %eax, %eax
xorl %ecx, %ecx
cmpl $0x0, 0x90(%rbx,%rax,4)
jle 0x8f3c5
movslq %ecx, %rdx
incl %ecx
movb %al, 0x20(%rsp,%rdx)
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x8f3b2
movl %ecx, 0xc(%rsp)
movq 0x490(%rbx), %r15
testq %r15, %r15
je 0x8f3e9
movq 0x498(%rbx), %r12
jmp 0x8f403
movq 0x8(%rbx), %rax
movq 0x20(%rax), %r15
movq %r15, 0x490(%rbx)
movq 0x30(%rax), %r12
movq %r12, 0x498(%rbx)
leaq 0x8(%r12), %rdi
callq 0x4680
movq %rax, %r14
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x8f769
cmpq $0x7f, %r12
ja 0x8f432
movb %r12b, (%r14)
movl $0x1, %r13d
jmp 0x8f6e7
cmpq $0x3fff, %r12           # imm = 0x3FFF
ja 0x8f45a
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, (%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x1(%r14)
movl $0x2, %r13d
jmp 0x8f6e7
cmpq $0x1fffff, %r12         # imm = 0x1FFFFF
ja 0x8f48e
movl %r12d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, (%r14)
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x2(%r14)
movl $0x3, %r13d
jmp 0x8f6e7
cmpq $0xfffffff, %r12        # imm = 0xFFFFFFF
ja 0x8f4ce
movl %r12d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, (%r14)
movl %r12d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x3(%r14)
movl $0x4, %r13d
jmp 0x8f6e7
movq %r12, %rax
shrq $0x23, %rax
jne 0x8f51b
movq %r12, %rax
shrq $0x1c, %rax
orb $-0x80, %al
movb %al, (%r14)
movl %r12d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r12d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x4(%r14)
movl $0x5, %r13d
jmp 0x8f6e7
movq %r12, %rcx
shrq $0x2a, %rcx
jne 0x8f56e
orb $-0x80, %al
movb %al, (%r14)
movq %r12, %rax
shrq $0x1c, %rax
orb $-0x80, %al
movb %al, 0x1(%r14)
movl %r12d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r12d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x4(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x5(%r14)
movl $0x6, %r13d
jmp 0x8f6e7
movq %r12, %rdx
shrq $0x31, %rdx
jne 0x8f5c8
orb $-0x80, %cl
movb %cl, (%r14)
orb $-0x80, %al
movb %al, 0x1(%r14)
movq %r12, %rax
shrq $0x1c, %rax
orb $-0x80, %al
movb %al, 0x2(%r14)
movl %r12d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r12d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x4(%r14)
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x5(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x6(%r14)
movl $0x7, %r13d
jmp 0x8f6e7
movq %r12, %rsi
shrq $0x38, %rsi
jne 0x8f629
orb $-0x80, %dl
movb %dl, (%r14)
orb $-0x80, %cl
movb %cl, 0x1(%r14)
orb $-0x80, %al
movb %al, 0x2(%r14)
movq %r12, %rax
shrq $0x1c, %rax
orb $-0x80, %al
movb %al, 0x3(%r14)
movl %r12d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x4(%r14)
movl %r12d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x5(%r14)
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x6(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x7(%r14)
movl $0x8, %r13d
jmp 0x8f6e7
testq %r12, %r12
js 0x8f68b
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 %r12, %rax
shrq $0x1c, %rax
orb $-0x80, %al
movb %al, 0x4(%r14)
movl %r12d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x5(%r14)
movl %r12d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x6(%r14)
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x7(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x8(%r14)
movl $0x9, %r13d
jmp 0x8f6e7
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 %r12, %rax
shrq $0x1c, %rax
orb $-0x80, %al
movb %al, 0x5(%r14)
movl %r12d, %eax
shrl $0x15, %eax
orb $-0x80, %al
movb %al, 0x6(%r14)
movl %r12d, %eax
shrl $0xe, %eax
orb $-0x80, %al
movb %al, 0x7(%r14)
movl %r12d, %eax
shrl $0x7, %eax
orb $-0x80, %al
movb %al, 0x8(%r14)
movl %r12d, %eax
andb $0x7f, %al
movb %al, 0x9(%r14)
movl $0xa, %r13d
movq %r14, %rdx
addq %r13, %rdx
leaq 0x10(%rsp), %rax
leaq 0x18(%rsp), %rbp
leaq 0x20(%rsp), %r8
leaq 0xc(%rsp), %r9
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rcx
pushq %rax
pushq $0x0
callq 0x7a9d0
addq $0x10, %rsp
movq %rax, %r15
addq (%rbp), %r13
movq %r13, (%rbp)
movq 0x78(%rbx), %rsi
xorl %edi, %edi
movq %r14, %rdx
movl %r13d, %ecx
callq *0x30(%rsi)
testl %eax, %eax
je 0x8f73b
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x8f769
movq 0x80(%rbx), %rsi
movl 0x10(%rsp), %ecx
xorl %edi, %edi
movq %r15, %rdx
callq *0x30(%rsi)
testl %eax, %eax
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jne 0x8f769
movq %r14, %rdi
callq 0x45c0
movq %r15, %rdi
callq 0x45c0
xorl %eax, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq