// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/cram/thread_pool.c
// Function: t_pool_dispatch
int t_pool_dispatch(t_pool *p, t_results_queue *q,
		    void *(*func)(void *arg), void *arg) {
    t_pool_job *j = malloc(sizeof(*j));

    if (!j)
	return -1;
    j->func = func;
    j->arg = arg;
    j->next = NULL;
    j->p = p;
    j->q = q;
    if (q) {
	pthread_mutex_lock(&q->result_m);
	j->serial = q->curr_serial++;
	q->pending++;
	pthread_mutex_unlock(&q->result_m);
    } else {
	j->serial = 0;
    }

#ifdef DEBUG
    fprintf(stderr, "Dispatching job %p for queue %p, serial %d\n", j, q, j->serial);
#endif

    pthread_mutex_lock(&p->pool_m);

    // Check if queue is full
    while (p->njobs >= p->qsize)
	pthread_cond_wait(&p->full_c, &p->pool_m);

    p->njobs++;

    if (p->tail) {
	p->tail->next = j;
	p->tail = j;
    } else {
	p->head = p->tail = j;
    }

    // Let a worker know we have data.
#ifdef IN_ORDER
    if (p->t_stack_top >= 0 && p->njobs > p->tsize - p->nwaiting)
	pthread_cond_signal(&p->t[p->t_stack_top].pending_c);
#else
    pthread_cond_signal(&p->pending_c);
#endif
    pthread_mutex_unlock(&p->pool_m);

#ifdef DEBUG
    fprintf(stderr, "Dispatched (serial %d)\n", j->serial);
#endif

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x30, %edi
callq 0x69c0
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
jne 0x98a79
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x98be2
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq $0x0, 0x10(%rax)
movq -0x10(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x20(%rax)
cmpq $0x0, -0x18(%rbp)
je 0x98afa
movq -0x18(%rbp), %rdi
addq $0x20, %rdi
callq 0x6ae0
movq -0x18(%rbp), %rax
movl 0x14(%rax), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x14(%rax)
movq -0x30(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1c(%rax)
movq -0x18(%rbp), %rdi
addq $0x20, %rdi
callq 0x64e0
jmp 0x98b05
movq -0x30(%rbp), %rax
movl $0x0, 0x28(%rax)
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
callq 0x6ae0
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
cmpl (%rcx), %eax
jl 0x98b3b
movq -0x10(%rbp), %rdi
addq $0xb8, %rdi
movq -0x10(%rbp), %rsi
addq $0x30, %rsi
callq 0x6b90
jmp 0x98b12
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x4(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0x98b71
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rcx, 0x10(%rax)
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0x98b85
movq -0x30(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0xf0(%rax)
jl 0x98bce
movq -0x10(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x10(%rbp), %rcx
movl 0x20(%rcx), %ecx
movq -0x10(%rbp), %rdx
subl 0x8(%rdx), %ecx
cmpl %ecx, %eax
jle 0x98bce
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0xf0(%rax), %rax
imulq $0x50, %rax, %rax
addq %rax, %rdi
addq $0x18, %rdi
callq 0x6040
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
callq 0x64e0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax,%rax)