// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/thread_pool.c
// Function: hts_tpool_process_reset
int hts_tpool_process_reset(hts_tpool_process *q, int free_results) {
    hts_tpool_job *j, *jn, *j_head;
    hts_tpool_result *r, *rn, *r_head;

    pthread_mutex_lock(&q->p->pool_m);
    // prevent next_result from returning data during our flush
    q->next_serial = INT_MAX;

    // Remove any queued input not yet being acted upon
    j_head = q->input_head;
    q->input_head = q->input_tail = NULL;
    q->n_input = 0;

    // Remove any queued output, thus ensuring we have room to flush.
    r_head = q->output_head;
    q->output_head = q->output_tail = NULL;
    q->n_output = 0;
    pthread_mutex_unlock(&q->p->pool_m);

    // Release memory.  This can be done unlocked now the lists have been
    // removed from the queue
    for (j = j_head; j; j = jn) {
        jn = j->next;
        if (j->job_cleanup) j->job_cleanup(j->arg);
        free(j);
    }

    for (r = r_head; r; r = rn) {
        rn = r->next;
        if (r->result_cleanup) {
            r->result_cleanup(r->data);
            r->data = NULL;
        }
        hts_tpool_delete_result(r, free_results);
    }

    // Wait for any jobs being processed to complete.
    // (TODO: consider how to cancel any currently processing jobs.
    // Probably this is too hard.)
    if (hts_tpool_process_flush(q) != 0)
        return -1;

    // Remove any new output.
    pthread_mutex_lock(&q->p->pool_m);
    r_head = q->output_head;
    q->output_head = q->output_tail = NULL;
    q->n_output = 0;

    // Finally reset the serial back to the starting point.
    q->next_serial = q->curr_serial = 0;
    pthread_cond_signal(&q->input_not_full_c);
    pthread_mutex_unlock(&q->p->pool_m);

    // Discard unwanted output
    for (r = r_head; r; r = rn) {
        //fprintf(stderr, "Discard output %d\n", r->serial);
        rn = r->next;
        if (r->result_cleanup) {
            r->result_cleanup(r->data);
            r->data = NULL;
        }
        hts_tpool_delete_result(r, free_results);
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movq (%rdi), %rdi
addq $0x38, %rdi
callq 0x4750
movq $0x7fffffff, 0x30(%r14) # imm = 0x7FFFFFFF
movq (%r14), %rdi
movq 0x8(%r14), %r12
andq $0x0, 0x44(%r14)
leaq 0x30(%r14), %rax
movq %rax, (%rsp)
leaq 0x18(%r14), %rbp
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r14)
movq 0x18(%r14), %r15
movups %xmm0, 0x18(%r14)
addq $0x38, %rdi
callq 0x4340
testq %r12, %r12
je 0x2c1ac
movq 0x10(%r12), %rax
movq 0x20(%r12), %r13
testq %rax, %rax
je 0x2c17b
movq 0x8(%r12), %rdi
callq *%rax
movq %r12, %rdi
callq 0x45c0
movq %r13, %r12
jmp 0x2c160
movq (%r15), %r12
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x2c19f
movq 0x18(%r15), %rdi
callq *%rax
andq $0x0, 0x18(%r15)
movq %r15, %rdi
movl %ebx, %esi
callq 0x2bfa2
movq %r12, %r15
testq %r15, %r15
jne 0x2c188
movq %r14, %rdi
callq 0x2cb1f
movq (%r14), %rdi
addq $0x38, %rdi
callq 0x4750
movq 0x18(%r14), %r15
andl $0x0, 0x48(%r14)
leaq 0x90(%r14), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%rbp)
movq (%rsp), %rax
movups %xmm0, (%rax)
callq 0x4040
movq (%r14), %rdi
addq $0x38, %rdi
callq 0x4340
testq %r15, %r15
je 0x2c21f
movq (%r15), %r14
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x2c210
movq 0x18(%r15), %rdi
callq *%rax
andq $0x0, 0x18(%r15)
movq %r15, %rdi
movl %ebx, %esi
callq 0x2bfa2
movq %r14, %r15
jmp 0x2c1f4
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq