// File: /workspace/github_c_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
cmpq $0x0, 0x88b8(%rdi)
je 0x3e385
movq %rdi, %rbx
movq 0x88c0(%rdi), %rdi
testq %rdi, %rdi
je 0x3e385
callq 0x35ff4
testl %eax, %eax
je 0x3e228
xorl %r14d, %r14d
jmp 0x3e2d3
xorl %r15d, %r15d
movq 0x88c0(%rbx), %rdi
callq 0x35e75
testq %rax, %rax
je 0x3e2d0
movq %rax, %r12
movq %rax, %rdi
callq 0x361a4
movq %rax, %r13
movq 0x8(%rax), %r14
movq 0x10(%rax), %rdi
cmpq %rdi, 0x90(%r14)
jne 0x3e26a
movq $0x0, 0x90(%r14)
cmpq %r15, %r14
je 0x3e2a2
testq %r15, %r15
je 0x3e2a5
cmpq %r15, 0x38(%rbx)
jne 0x3e282
movq $0x0, 0x38(%rbx)
cmpq %r15, 0x40(%rbx)
jne 0x3e290
movq $0x0, 0x40(%rbx)
movq %r15, %rdi
callq 0x4fe2e
movq 0x8(%r13), %r14
movq 0x10(%r13), %rdi
jmp 0x3e2a5
movq %r15, %r14
callq 0x50127
movq %r12, %rdi
movl $0x1, %esi
callq 0x3617f
movq 0x88c0(%rbx), %rdi
callq 0x35ff4
movq %r14, %r15
testl %eax, %eax
je 0x3e22b
jmp 0x3e2d3
movq %r15, %r14
movq 0x8970(%rbx), %r15
testq %r15, %r15
je 0x3e353
movq 0x8(%r15), %r12
movq 0x10(%r15), %rdi
cmpq %rdi, 0x90(%r12)
jne 0x3e2fd
movq $0x0, 0x90(%r12)
cmpq %r14, %r12
je 0x3e335
testq %r14, %r14
je 0x3e338
cmpq %r14, 0x38(%rbx)
jne 0x3e315
movq $0x0, 0x38(%rbx)
cmpq %r14, 0x40(%rbx)
jne 0x3e323
movq $0x0, 0x40(%rbx)
movq %r14, %rdi
callq 0x4fe2e
movq 0x8(%r15), %r12
movq 0x10(%r15), %rdi
jmp 0x3e338
movq %r14, %r12
callq 0x50127
movq %r15, %rdi
callq 0x45c0
movq $0x0, 0x8970(%rbx)
movq %r12, %r14
testq %r14, %r14
je 0x3e385
cmpq %r14, 0x38(%rbx)
jne 0x3e366
movq $0x0, 0x38(%rbx)
cmpq %r14, 0x40(%rbx)
jne 0x3e374
movq $0x0, 0x40(%rbx)
movq %r14, %rdi
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
jmp 0x4fe2e
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq