// File: /workspace/github_c_makefile_star2_O3/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 0x88c0(%rdi), %rdi
callq 0x35d8e
testq %rax, %rax
je 0x51313
movq %rax, %r14
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x361a4
testq %rax, %rax
je 0x51317
movq (%rax), %r15
movq 0x8(%rax), %r12
cmpl $0x77, 0x8(%r15)
jne 0x51202
movq %r15, %rdi
movq %r12, %rsi
callq 0x50dcf
testl %eax, %eax
jne 0x51321
cmpq $0x0, 0x88(%r12)
je 0x51269
cmpl $0x0, 0x58(%r12)
jle 0x51269
xorl %r13d, %r13d
movq 0x88(%r12), %rax
movq (%rax,%r13,8), %rdi
testq %rdi, %rdi
je 0x5123c
callq 0x50127
movq 0x88(%r12), %rax
movq (%rax,%r13,8), %rcx
jmp 0x5123e
xorl %ecx, %ecx
cmpq 0x90(%r12), %rcx
jne 0x51254
movq $0x0, 0x90(%r12)
movq $0x0, (%rax,%r13,8)
incq %r13
movslq 0x58(%r12), %rax
cmpq %rax, %r13
jl 0x51218
movq 0x90(%r12), %rdi
testq %rdi, %rdi
je 0x51287
callq 0x50127
movq $0x0, 0x90(%r12)
movl $0x0, 0x5c(%r12)
cmpq %rbx, %r12
je 0x512c1
testq %rbx, %rbx
je 0x512be
cmpq %rbx, 0x38(%r15)
jne 0x512a8
movq $0x0, 0x38(%r15)
cmpq %rbx, 0x40(%r15)
jne 0x512b6
movq $0x0, 0x40(%r15)
movq %rbx, %rdi
callq 0x4fe2e
movq %r12, %rbx
movq %r14, %rdi
movl $0x1, %esi
callq 0x3617f
movq 0x88c0(%r15), %rdi
callq 0x35d8e
movq %rax, %r14
testq %rax, %rax
jne 0x511d0
xorl %ebp, %ebp
testq %rbx, %rbx
je 0x51326
cmpq %rbx, 0x38(%r15)
jne 0x512fb
movq $0x0, 0x38(%r15)
cmpq %rbx, 0x40(%r15)
jne 0x51309
movq $0x0, 0x40(%r15)
movq %rbx, %rdi
callq 0x4fe2e
jmp 0x51326
xorl %ebp, %ebp
jmp 0x51326
movq %r14, %rdi
xorl %esi, %esi
callq 0x3617f
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq