// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq $0x0, -0x10(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x88b8(%rax)
je 0x59610
movq -0x8(%rbp), %rax
cmpq $0x0, 0x88c0(%rax)
jne 0x59615
jmp 0x59823
jmp 0x59617
movq -0x8(%rbp), %rax
movq 0x88c0(%rax), %rdi
callq 0x4d190
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x59638
jmp 0x5970f
movq -0x8(%rbp), %rax
movq 0x88c0(%rax), %rdi
callq 0x4cf90
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x59658
jmp 0x5970f
movq -0x18(%rbp), %rdi
callq 0x4d460
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x90(%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x59691
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq $0x0, 0x90(%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x10(%rbp), %rax
je 0x596ef
cmpq $0x0, -0x10(%rbp)
je 0x596e3
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
cmpq -0x10(%rbp), %rax
jne 0x596c0
movq -0x8(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
cmpq -0x10(%rbp), %rax
jne 0x596da
movq -0x8(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x10(%rbp), %rdi
callq 0x74a70
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x20(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x74f20
movq -0x18(%rbp), %rdi
movl $0x1, %esi
callq 0x4d410
jmp 0x59617
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8970(%rax)
je 0x597df
movq -0x8(%rbp), %rax
movq 0x8970(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x90(%rax), %rax
movq -0x28(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x5975c
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq $0x0, 0x90(%rax)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x10(%rbp), %rax
je 0x597ba
cmpq $0x0, -0x10(%rbp)
je 0x597ae
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
cmpq -0x10(%rbp), %rax
jne 0x5978b
movq -0x8(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
cmpq -0x10(%rbp), %rax
jne 0x597a5
movq -0x8(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x10(%rbp), %rdi
callq 0x74a70
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x74f20
movq -0x28(%rbp), %rdi
callq 0x45a0
movq -0x8(%rbp), %rax
movq $0x0, 0x8970(%rax)
cmpq $0x0, -0x10(%rbp)
je 0x59823
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rax
cmpq -0x10(%rbp), %rax
jne 0x59800
movq -0x8(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x8(%rbp), %rax
movq 0x40(%rax), %rax
cmpq -0x10(%rbp), %rax
jne 0x5981a
movq -0x8(%rbp), %rax
movq $0x0, 0x40(%rax)
movq -0x10(%rbp), %rdi
callq 0x74a70
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)