// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/cram/cram_io.c
// Function: cram_flush_result
static int cram_flush_result(cram_fd *fd) {
    int i, ret = 0;
    hts_tpool_result *r;
    cram_container *lc = NULL;

    // NB: we can have one result per slice, not per container,
    // so we need to free the container only after all slices
    // within it have been freed.  (Automatic via reference counting.)
    while ((r = hts_tpool_next_result(fd->rqueue))) {
        cram_job *j = (cram_job *)hts_tpool_result_data(r);
        cram_container *c;

        if (!j) {
            hts_tpool_delete_result(r, 0);
            return -1;
        }

        fd = j->fd;
        c = j->c;

        if (fd->mode == 'w')
            if (0 != cram_flush_container2(fd, c))
                return -1;

        // Free the slices; filled out by encoder only
        if (c->slices) {
            for (i = 0; i < c->max_slice; i++) {
                if (c->slices[i])
                    cram_free_slice(c->slices[i]);
                if (c->slices[i] == c->slice)
                    c->slice = NULL;
                c->slices[i] = NULL;
            }
        }

        // Free the current slice; set by both encoder & decoder
        if (c->slice) {
            cram_free_slice(c->slice);
            c->slice = NULL;
        }
        c->curr_slice = 0;

        // Our jobs will be in order, so we free the last
        // container when our job has switched to a new one.
        if (c != lc) {
            if (lc) {
                if (fd->ctr == lc)
                    fd->ctr = NULL;
                if (fd->ctr_mt == lc)
                    fd->ctr_mt = NULL;
                cram_free_container(lc);
            }
            lc = c;
        }

        hts_tpool_delete_result(r, 1);
    }
    if (lc) {
        if (fd->ctr == lc)
            fd->ctr = NULL;
        if (fd->ctr_mt == lc)
            fd->ctr_mt = NULL;
        cram_free_container(lc);
    }

    return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
xorl %r14d, %r14d
movq 0x88c0(%rbx), %rdi
callq 0x37162
testq %rax, %rax
je 0x53e0f
movq %rax, %r15
movq %rax, %rdi
callq 0x37576
testq %rax, %rax
setne %r13b
je 0x53ded
movq (%rax), %rbx
movq 0x8(%rax), %r12
cmpl $0x77, 0x8(%rbx)
jne 0x53d2f
movq %rbx, %rdi
movq %r12, %rsi
callq 0x53906
testl %eax, %eax
je 0x53d2f
xorl %r13d, %r13d
jmp 0x53dff
cmpq $0x0, 0x88(%r12)
je 0x53d91
cmpl $0x0, 0x58(%r12)
jle 0x53d91
xorl %ebp, %ebp
movq 0x88(%r12), %rax
movq (%rax,%rbp,8), %rdi
testq %rdi, %rdi
je 0x53d5a
callq 0x52c5d
movq 0x88(%r12), %rax
movq (%rax,%rbp,8), %rcx
cmpq 0x90(%r12), %rcx
jne 0x53d7c
movq $0x0, 0x90(%r12)
movq $0x0, (%rax,%rbp,8)
incq %rbp
movslq 0x58(%r12), %rax
cmpq %rax, %rbp
jl 0x53d44
movq 0x90(%r12), %rdi
testq %rdi, %rdi
je 0x53daf
callq 0x52c5d
movq $0x0, 0x90(%r12)
movl $0x0, 0x5c(%r12)
movl $0x1, %ebp
cmpq %r14, %r12
je 0x53def
testq %r14, %r14
je 0x53df2
cmpq %r14, 0x38(%rbx)
jne 0x53dd5
movq $0x0, 0x38(%rbx)
cmpq %r14, 0x40(%rbx)
jne 0x53de3
movq $0x0, 0x40(%rbx)
movq %r14, %rdi
callq 0x5295e
jmp 0x53df2
xorl %ebp, %ebp
movq %r14, %r12
movq %r15, %rdi
movl %ebp, %esi
callq 0x37551
movq %r12, %r14
testb %r13b, %r13b
jne 0x53cde
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x53e3a
xorl %ebp, %ebp
testq %r14, %r14
je 0x53e3a
cmpq %r14, 0x38(%rbx)
jne 0x53e24
movq $0x0, 0x38(%rbx)
cmpq %r14, 0x40(%rbx)
jne 0x53e32
movq $0x0, 0x40(%rbx)
movq %r14, %rdi
callq 0x5295e
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq