// File: /workspace/github_c_makefile_star2_O2/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, %r14
xorl %r15d, %r15d
pushq $0x1
popq %rbp
movq 0x88c0(%r14), %rdi
callq 0x2bbc1
testq %rax, %rax
je 0x4354f
movq %rax, %r12
movq %rax, %rdi
callq 0x2bfc2
testq %rax, %rax
je 0x43576
movq (%rax), %r14
movq 0x8(%rax), %r13
cmpl $0x77, 0x8(%r14)
jne 0x4349e
movq %r14, %rdi
movq %r13, %rsi
callq 0x430ac
testl %eax, %eax
jne 0x43580
cmpq $0x0, 0x88(%r13)
je 0x434f2
xorl %ebx, %ebx
movslq 0x58(%r13), %rax
cmpq %rax, %rbx
jge 0x434f2
movq 0x88(%r13), %rax
movq (%rax,%rbx,8), %rdi
testq %rdi, %rdi
je 0x434d5
callq 0x42611
movq 0x88(%r13), %rax
movq (%rax,%rbx,8), %rcx
jmp 0x434d7
xorl %ecx, %ecx
cmpq 0x90(%r13), %rcx
jne 0x434e8
andq $0x0, 0x90(%r13)
andq $0x0, (%rax,%rbx,8)
incq %rbx
jmp 0x434aa
movq 0x90(%r13), %rdi
testq %rdi, %rdi
je 0x4350b
callq 0x42611
andq $0x0, 0x90(%r13)
andl $0x0, 0x5c(%r13)
cmpq %r15, %r13
je 0x4353a
testq %r15, %r15
je 0x4353d
cmpq %r15, 0x38(%r14)
jne 0x43525
andq $0x0, 0x38(%r14)
cmpq %r15, 0x40(%r14)
jne 0x43530
andq $0x0, 0x40(%r14)
movq %r15, %rdi
callq 0x4237d
jmp 0x4353d
movq %r15, %r13
movq %r12, %rdi
movl %ebp, %esi
callq 0x2bfa2
movq %r13, %r15
jmp 0x43454
xorl %ebx, %ebx
testq %r15, %r15
je 0x43583
cmpq %r15, 0x38(%r14)
jne 0x43561
andq $0x0, 0x38(%r14)
cmpq %r15, 0x40(%r14)
jne 0x4356c
andq $0x0, 0x40(%r14)
movq %r15, %rdi
callq 0x4237d
jmp 0x43583
movq %r12, %rdi
xorl %esi, %esi
callq 0x2bfa2
pushq $-0x1
popq %rbx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq