// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/cram/cram_decode.c
// Function: cram_drain_rqueue
void cram_drain_rqueue(cram_fd *fd) {
    cram_container *lc = NULL;

    if (!fd->pool || !fd->rqueue)
        return;

    // drain queue of any in-flight decode jobs
    while (!hts_tpool_process_empty(fd->rqueue)) {
        hts_tpool_result *r = hts_tpool_next_result_wait(fd->rqueue);
        if (!r)
            break;
        cram_decode_job *j = (cram_decode_job *)hts_tpool_result_data(r);
        if (j->c->slice == j->s)
            j->c->slice = NULL;
        if (j->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 = j->c;
        }
        cram_free_slice(j->s);
        hts_tpool_delete_result(r, 1);
    }

    // Also tidy up any pending decode job that we didn't submit to the workers
    // due to the input queue being full.
    if (fd->job_pending) {
        cram_decode_job *j = (cram_decode_job *)fd->job_pending;
        if (j->c->slice == j->s)
            j->c->slice = NULL;
        if (j->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 = j->c;
        }
        cram_free_slice(j->s);
        free(j);
        fd->job_pending = NULL;
    }

    if (lc) {
        if (fd->ctr == lc)
            fd->ctr = NULL;
        if (fd->ctr_mt == lc)
            fd->ctr_mt = NULL;
        cram_free_container(lc);
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
cmpq $0x0, 0x88b8(%rdi)
je 0x4040a
movq %rdi, %rbx
cmpq $0x0, 0x88c0(%rdi)
je 0x4040a
xorl %r14d, %r14d
movq 0x88c0(%rbx), %rdi
callq 0x373c6
testl %eax, %eax
jne 0x40360
movq 0x88c0(%rbx), %rdi
callq 0x37249
movq %rax, %r15
testq %rax, %rax
je 0x40357
movq %r15, %rdi
callq 0x37576
movq %rax, %r12
movq 0x8(%rax), %rax
movq 0x90(%rax), %rcx
cmpq 0x10(%r12), %rcx
jne 0x4030d
movq $0x0, 0x90(%rax)
cmpq %r14, %rax
je 0x40340
testq %r14, %r14
je 0x4033b
cmpq %r14, 0x38(%rbx)
jne 0x40325
movq $0x0, 0x38(%rbx)
cmpq %r14, 0x40(%rbx)
jne 0x40333
movq $0x0, 0x40(%rbx)
movq %r14, %rdi
callq 0x5295e
movq 0x8(%r12), %r14
movq 0x10(%r12), %rdi
callq 0x52c5d
movq %r15, %rdi
movl $0x1, %esi
callq 0x37551
testq %r15, %r15
jne 0x402bd
movq 0x8970(%rbx), %r15
testq %r15, %r15
je 0x403d6
movq 0x8(%r15), %rax
movq 0x90(%rax), %rcx
cmpq 0x10(%r15), %rcx
jne 0x40388
movq $0x0, 0x90(%rax)
cmpq %r14, %rax
je 0x403ba
testq %r14, %r14
je 0x403b6
cmpq %r14, 0x38(%rbx)
jne 0x403a0
movq $0x0, 0x38(%rbx)
cmpq %r14, 0x40(%rbx)
jne 0x403ae
movq $0x0, 0x40(%rbx)
movq %r14, %rdi
callq 0x5295e
movq 0x8(%r15), %r14
movq 0x10(%r15), %rdi
callq 0x52c5d
movq %r15, %rdi
callq 0x45c0
movq $0x0, 0x8970(%rbx)
testq %r14, %r14
je 0x4040a
cmpq %r14, 0x38(%rbx)
jne 0x403e9
movq $0x0, 0x38(%rbx)
cmpq %r14, 0x40(%rbx)
jne 0x403f7
movq $0x0, 0x40(%rbx)
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x5295e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq