// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/thread_pool.c
// Function: hts_tpool_add_result
static int hts_tpool_add_result(hts_tpool_job *j, void *data) {
    hts_tpool_process *q = j->q;
    hts_tpool_result *r;

    pthread_mutex_lock(&q->p->pool_m);

    DBG_OUT(stderr, "%d: Adding result to queue %p, serial %"PRId64", %d of %d\n",
            hts_tpool_worker_id(j->p), q, j->serial, q->n_output+1, q->qsize);

    if (--q->n_processing == 0)
        pthread_cond_signal(&q->none_processing_c);

    /* No results queue is fine if we don't want any results back */
    if (q->in_only) {
        pthread_mutex_unlock(&q->p->pool_m);
        return 0;
    }

    if (!(r = malloc(sizeof(*r)))) {
        pthread_mutex_unlock(&q->p->pool_m);
        hts_tpool_process_shutdown(q);
        return -1;
    }

    r->next = NULL;
    r->data = data;
    r->result_cleanup = j->result_cleanup;
    r->serial = j->serial;

    q->n_output++;
    if (q->output_tail) {
        q->output_tail->next = r;
        q->output_tail = r;
    } else {
        q->output_head = q->output_tail = r;
    }

    assert(r->serial >= q->next_serial    // Or it will never be dequeued ...
           || q->next_serial == INT_MAX); // ... unless flush in progress.
    if (r->serial == q->next_serial) {
        DBG_OUT(stderr, "%d: Broadcasting result_avail (id %"PRId64")\n",
                hts_tpool_worker_id(j->p), r->serial);
        pthread_cond_broadcast(&q->output_avail_c);
        DBG_OUT(stderr, "%d: Broadcast complete\n", hts_tpool_worker_id(j->p));
    }

    pthread_mutex_unlock(&q->p->pool_m);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
addq $0x38, %rdi
callq 0x4730
jmp 0x4eb9e
movq -0x20(%rbp), %rcx
movl 0x4c(%rcx), %eax
addl $-0x1, %eax
movl %eax, 0x4c(%rcx)
cmpl $0x0, %eax
jne 0x4ebc0
movq -0x20(%rbp), %rdi
addq $0xf0, %rdi
callq 0x4040
movq -0x20(%rbp), %rax
cmpl $0x0, 0x54(%rax)
je 0x4ebe6
movq -0x20(%rbp), %rax
movq (%rax), %rdi
addq $0x38, %rdi
callq 0x4330
movl $0x0, -0x4(%rbp)
jmp 0x4ed1e
movl $0x20, %edi
callq 0x4650
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x4ec1f
movq -0x20(%rbp), %rax
movq (%rax), %rdi
addq $0x38, %rdi
callq 0x4330
movq -0x20(%rbp), %rdi
callq 0x4d330
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4ed1e
movq -0x28(%rbp), %rax
movq $0x0, (%rax)
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x20(%rbp), %rax
movl 0x48(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x48(%rax)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x4ec8b
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
jmp 0x4ec9f
movq -0x28(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x20(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jae 0x4ecbf
movq -0x20(%rbp), %rax
cmpq $0x7fffffff, 0x30(%rax) # imm = 0x7FFFFFFF
jne 0x4ecc1
jmp 0x4ece0
leaq 0xa4856(%rip), %rdi     # 0xf351e
leaq 0xa476f(%rip), %rsi     # 0xf343e
movl $0x85, %edx
leaq 0xa487c(%rip), %rcx     # 0xf3557
callq 0x42e0
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x20(%rbp), %rcx
cmpq 0x30(%rcx), %rax
jne 0x4ed07
jmp 0x4ecf4
jmp 0x4ecf6
movq -0x20(%rbp), %rdi
addq $0x60, %rdi
callq 0x4150
jmp 0x4ed05
jmp 0x4ed07
movq -0x20(%rbp), %rax
movq (%rax), %rdi
addq $0x38, %rdi
callq 0x4330
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw (%rax,%rax)