// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x88c0(%rax), %rdi
callq 0x4cde0
movq %rax, -0x20(%rbp)
cmpq $0x0, %rax
je 0x76d96
movq -0x20(%rbp), %rdi
callq 0x4d460
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x76c04
movq -0x20(%rbp), %rdi
xorl %esi, %esi
callq 0x4d410
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x76de0
movq -0x30(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x77, 0x8(%rax)
jne 0x76c48
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x76690
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x76c46
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x76de0
jmp 0x76c48
movq -0x38(%rbp), %rax
cmpq $0x0, 0x88(%rax)
je 0x76cf5
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl 0x58(%rcx), %eax
jge 0x76cf3
movq -0x38(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x14(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x76c9f
movq -0x38(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x74f20
movq -0x38(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq -0x38(%rbp), %rcx
cmpq 0x90(%rcx), %rax
jne 0x76cce
movq -0x38(%rbp), %rax
movq $0x0, 0x90(%rax)
movq -0x38(%rbp), %rax
movq 0x88(%rax), %rax
movslq -0x14(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x76c61
jmp 0x76cf5
movq -0x38(%rbp), %rax
cmpq $0x0, 0x90(%rax)
je 0x76d22
movq -0x38(%rbp), %rax
movq 0x90(%rax), %rdi
callq 0x74f20
movq -0x38(%rbp), %rax
movq $0x0, 0x90(%rax)
movq -0x38(%rbp), %rax
movl $0x0, 0x5c(%rax)
movq -0x38(%rbp), %rax
cmpq -0x28(%rbp), %rax
je 0x76d83
cmpq $0x0, -0x28(%rbp)
je 0x76d7b
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
cmpq -0x28(%rbp), %rax
jne 0x76d58
movq -0x10(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
cmpq -0x28(%rbp), %rax
jne 0x76d72
movq -0x10(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x28(%rbp), %rdi
callq 0x74a70
movq -0x38(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
movl $0x1, %esi
callq 0x4d410
jmp 0x76bbb
cmpq $0x0, -0x28(%rbp)
je 0x76dda
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
cmpq -0x28(%rbp), %rax
jne 0x76db7
movq -0x10(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rax
cmpq -0x28(%rbp), %rax
jne 0x76dd1
movq -0x10(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x28(%rbp), %rdi
callq 0x74a70
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)