// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpq $0x0, 0x88b8(%rdi)
je 0x335ca
movq %rdi, %rbx
movq 0x88c0(%rdi), %rdi
testq %rdi, %rdi
je 0x335ca
xorl %r14d, %r14d
pushq $0x1
popq %rbp
callq 0x2be17
testl %eax, %eax
jne 0x33525
movq 0x88c0(%rbx), %rdi
callq 0x2bca5
testq %rax, %rax
je 0x33525
movq %rax, %r15
movq %rax, %rdi
callq 0x2bfc2
movq %rax, %r12
movq 0x8(%rax), %r13
movq 0x10(%rax), %rdi
cmpq %rdi, 0x90(%r13)
jne 0x334d0
andq $0x0, 0x90(%r13)
cmpq %r14, %r13
je 0x33504
testq %r14, %r14
je 0x33507
cmpq %r14, 0x38(%rbx)
jne 0x334e5
andq $0x0, 0x38(%rbx)
cmpq %r14, 0x40(%rbx)
jne 0x334f0
andq $0x0, 0x40(%rbx)
movq %r14, %rdi
callq 0x4237d
movq 0x8(%r12), %r13
movq 0x10(%r12), %rdi
jmp 0x33507
movq %r14, %r13
callq 0x42611
movq %r15, %rdi
movl %ebp, %esi
callq 0x2bfa2
movq 0x88c0(%rbx), %rdi
movq %r13, %r14
jmp 0x3348b
movq 0x8970(%rbx), %r15
testq %r15, %r15
je 0x33599
movq 0x8(%r15), %r12
movq 0x10(%r15), %rdi
cmpq %rdi, 0x90(%r12)
jne 0x3354c
andq $0x0, 0x90(%r12)
cmpq %r14, %r12
je 0x3357e
testq %r14, %r14
je 0x33581
cmpq %r14, 0x38(%rbx)
jne 0x33561
andq $0x0, 0x38(%rbx)
cmpq %r14, 0x40(%rbx)
jne 0x3356c
andq $0x0, 0x40(%rbx)
movq %r14, %rdi
callq 0x4237d
movq 0x8(%r15), %r12
movq 0x10(%r15), %rdi
jmp 0x33581
movq %r14, %r12
callq 0x42611
movq %r15, %rdi
callq 0x45c0
andq $0x0, 0x8970(%rbx)
movq %r12, %r14
testq %r14, %r14
je 0x335ca
cmpq %r14, 0x38(%rbx)
jne 0x335a9
andq $0x0, 0x38(%rbx)
cmpq %r14, 0x40(%rbx)
jne 0x335b4
andq $0x0, 0x40(%rbx)
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4237d
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq