// File: /workspace/github_c_makefile_star2_O1/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
cmpl $0x0, 0x18(%r15)
jle 0x38205
movl $0x18, %r12d
xorl %r13d, %r13d
movq 0x28(%r15), %rax
cmpl $0x0, (%rax,%r13,4)
je 0x381f5
movq 0x20(%r15), %rdi
addq %r12, %rdi
callq 0x4040
incq %r13
movslq 0x18(%r15), %rax
addq $0x48, %r12
cmpq %rax, %r13
jl 0x381de
movl 0x44(%r14), %eax
addl 0x48(%r14), %eax
addl 0x4c(%r14), %eax
cmpl %eax, 0x28(%r14)
jge 0x3821b
movl %eax, 0x28(%r14)
cmpl $0x0, 0x50(%r14)
je 0x38242
cmpl $0x0, 0x4c(%r14)
je 0x38242
leaq 0xf0(%r14), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x47c0
cmpl $0x0, 0x4c(%r14)
jne 0x38230
leaq 0xc0(%r14), %r15
leaq 0xf0(%r14), %r12
leaq 0x18(%rsp), %r13
leaq 0x8(%rsp), %rbp
cmpl $0x0, 0x50(%r14)
jne 0x382ff
cmpl $0x0, 0x44(%r14)
jne 0x38277
cmpl $0x0, 0x4c(%r14)
je 0x382ff
cmpl $0x0, 0x44(%r14)
je 0x382ed
cmpl $0x0, 0x50(%r14)
jne 0x382ed
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
jmp 0x38277
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 0x382ba
cmpl $0x0, 0x50(%r14)
je 0x3825a
movq %rbx, %rdi
callq 0x4340
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq