// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
jmp 0x4e759
movq -0x18(%rbp), %rdi
addq $0x38, %rdi
callq 0x4730
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x4e7b4
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0xc(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x4e7a7
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
movslq -0xc(%rbp), %rax
imulq $0x48, %rax, %rax
addq %rax, %rdi
addq $0x18, %rdi
callq 0x4040
jmp 0x4e7a9
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x4e76d
movq -0x8(%rbp), %rax
movl 0x28(%rax), %eax
movq -0x8(%rbp), %rcx
movl 0x48(%rcx), %ecx
movq -0x8(%rbp), %rdx
addl 0x44(%rdx), %ecx
movq -0x8(%rbp), %rdx
addl 0x4c(%rdx), %ecx
cmpl %ecx, %eax
jge 0x4e7f0
movq -0x8(%rbp), %rax
movl 0x48(%rax), %ecx
movq -0x8(%rbp), %rax
addl 0x44(%rax), %ecx
movq -0x8(%rbp), %rax
addl 0x4c(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x4e822
jmp 0x4e7fc
movq -0x8(%rbp), %rax
cmpl $0x0, 0x4c(%rax)
je 0x4e820
movq -0x8(%rbp), %rdi
addq $0xf0, %rdi
movq -0x18(%rbp), %rsi
addq $0x38, %rsi
callq 0x47a0
jmp 0x4e7fc
jmp 0x4e822
jmp 0x4e824
movq -0x8(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, 0x50(%rcx)
movb %al, -0x39(%rbp)
jne 0x4e856
movq -0x8(%rbp), %rcx
movb $0x1, %al
cmpl $0x0, 0x44(%rcx)
movb %al, -0x3a(%rbp)
jne 0x4e850
movq -0x8(%rbp), %rax
cmpl $0x0, 0x4c(%rax)
setne %al
movb %al, -0x3a(%rbp)
movb -0x3a(%rbp), %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0x4e862
jmp 0x4e92f
jmp 0x4e864
movq -0x8(%rbp), %rcx
xorl %eax, %eax
cmpl $0x0, 0x44(%rcx)
movb %al, -0x3b(%rbp)
je 0x4e883
movq -0x8(%rbp), %rax
cmpl $0x0, 0x50(%rax)
setne %al
xorb $-0x1, %al
movb %al, -0x3b(%rbp)
movb -0x3b(%rbp), %al
testb $0x1, %al
jne 0x4e88c
jmp 0x4e8cf
leaq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x47f0
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
imulq $0x3e8, -0x20(%rbp), %rax # imm = 0x3E8
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
addq $0xc0, %rdi
movq -0x18(%rbp), %rsi
addq $0x38, %rsi
leaq -0x38(%rbp), %rdx
callq 0x4780
jmp 0x4e864
jmp 0x4e8d1
movq -0x8(%rbp), %rax
cmpl $0x0, 0x4c(%rax)
je 0x4e91e
leaq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x47f0
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
imulq $0x3e8, -0x20(%rbp), %rax # imm = 0x3E8
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
addq $0xf0, %rdi
movq -0x18(%rbp), %rsi
addq $0x38, %rsi
leaq -0x38(%rbp), %rdx
callq 0x4780
jmp 0x4e8d1
movq -0x8(%rbp), %rax
cmpl $0x0, 0x50(%rax)
je 0x4e92a
jmp 0x4e92f
jmp 0x4e824
movq -0x18(%rbp), %rdi
addq $0x38, %rdi
callq 0x4330
jmp 0x4e93e
xorl %eax, %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)