// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/thread_pool.c
// Function: hts_tpool_process_flush
int hts_tpool_process_flush(hts_tpool_process *q) {
    int i;
    hts_tpool *p = q->p;

    DBG_OUT(stderr, "Flushing pool %p\n", p);

    // Drains the queue
    pthread_mutex_lock(&p->pool_m);

    // Wake up everything for the final sprint!
    for (i = 0; i < p->tsize; i++)
        if (p->t_stack[i])
            pthread_cond_signal(&p->t[i].pending_c);

    // Ensure there is room for the final sprint.
    // Ideally we shouldn't get here, but the "q->qsize - q->n_output >
    // n_processing" check in tpool_worker means we can trigger a
    // deadlock there.  This negates that possibility.
    if (q->qsize < q->n_output + q->n_input + q->n_processing)
        q->qsize = q->n_output + q->n_input + q->n_processing;

    // When shutdown, we won't be launching more, but we can still
    // wait for any processing jobs complete.
    if (q->shutdown) {
        while (q->n_processing)
            pthread_cond_wait(&q->none_processing_c, &p->pool_m);
    }

    // Wait for n_input and n_processing to hit zero.
    while (!q->shutdown && (q->n_input || q->n_processing)) {
        struct timeval now;
        struct timespec timeout;

        while (q->n_input && !q->shutdown) {
            gettimeofday(&now, NULL);
            timeout.tv_sec = now.tv_sec + 1;
            timeout.tv_nsec = now.tv_usec * 1000;
            pthread_cond_timedwait(&q->input_empty_c, &p->pool_m, &timeout);
        }

        // Note: even if q->shutdown is set, we still have to wait until
        // q->n_processing is zero as we cannot terminate while things are
        // running otherwise we free up the data being worked on.
        while (q->n_processing) {
            gettimeofday(&now, NULL);
            timeout.tv_sec = now.tv_sec + 1;
            timeout.tv_nsec = now.tv_usec * 1000;
            pthread_cond_timedwait(&q->none_processing_c, &p->pool_m,
                                   &timeout);
        }
        if (q->shutdown) break;
    }

    pthread_mutex_unlock(&p->pool_m);

    DBG_OUT(stderr, "Flushed complete for pool %p, queue %p\n", p, q);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r14
movq (%rdi), %r15
leaq 0x38(%r15), %rbx
movq %rbx, %rdi
callq 0x4750
movl 0x18(%r15), %eax
testl %eax, %eax
jle 0x36ddf
movl $0x18, %r12d
xorl %r13d, %r13d
movq 0x28(%r15), %rcx
cmpl $0x0, (%rcx,%r13,4)
je 0x36dd0
movq 0x20(%r15), %rdi
addq %r12, %rdi
callq 0x4040
movl 0x18(%r15), %eax
incq %r13
movslq %eax, %rcx
addq $0x48, %r12
cmpq %rcx, %r13
jl 0x36db5
movl 0x44(%r14), %ecx
addl 0x48(%r14), %ecx
movl 0x4c(%r14), %eax
addl %eax, %ecx
cmpl %ecx, 0x28(%r14)
jge 0x36df7
movl %ecx, 0x28(%r14)
cmpl $0x0, 0x50(%r14)
je 0x36e2c
testl %eax, %eax
je 0x36ede
leaq 0xf0(%r14), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x47c0
cmpl $0x0, 0x4c(%r14)
jne 0x36e0d
cmpl $0x0, 0x50(%r14)
jne 0x36ede
xorl %eax, %eax
leaq 0xc0(%r14), %r15
leaq 0xf0(%r14), %r12
testl %eax, %eax
sete %al
leaq 0x18(%rsp), %r13
leaq 0x8(%rsp), %rbp
cmpl $0x0, 0x44(%r14)
je 0x36e93
cmpl $0x0, 0x50(%r14)
jne 0x36eca
movq %r13, %rdi
xorl %esi, %esi
callq 0x4810
movq 0x18(%rsp), %rax
incq %rax
movq %rax, 0x8(%rsp)
imulq $0x3e8, 0x20(%rsp), %rax # imm = 0x3E8
movq %rax, 0x10(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x47a0
cmpl $0x0, 0x44(%r14)
jne 0x36e50
jmp 0x36eca
testb $0x1, %al
jne 0x36ede
movq %r13, %rdi
xorl %esi, %esi
callq 0x4810
movq 0x18(%rsp), %rax
incq %rax
movq %rax, 0x8(%rsp)
imulq $0x3e8, 0x20(%rsp), %rax # imm = 0x3E8
movq %rax, 0x10(%rsp)
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x47a0
cmpl $0x0, 0x4c(%r14)
jne 0x36e97
cmpl $0x0, 0x50(%r14)
movb $0x1, %al
je 0x36e49
movq %rbx, %rdi
callq 0x4340
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq