// File: /workspace/github_c_makefile_star2_O1/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
movq $0x0, 0x44(%r14)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r14)
movq 0x18(%r14), %r15
movups %xmm0, 0x18(%r14)
addq $0x38, %rdi
callq 0x4340
testq %r12, %r12
je 0x3774c
movq 0x10(%r12), %rax
movq 0x20(%r12), %r13
testq %rax, %rax
je 0x3773c
movq 0x8(%r12), %rdi
callq *%rax
movq %r12, %rdi
callq 0x45c0
movq %r13, %r12
testq %r13, %r13
jne 0x37726
leaq 0x30(%r14), %r12
leaq 0x18(%r14), %r13
testq %r15, %r15
je 0x37785
movq (%r15), %rbp
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x37773
movq 0x18(%r15), %rdi
callq *%rax
movq $0x0, 0x18(%r15)
movq %r15, %rdi
movl %ebx, %esi
callq 0x37551
movq %rbp, %r15
testq %rbp, %rbp
jne 0x37759
movq %r14, %rdi
callq 0x381ae
movq (%r14), %rdi
addq $0x38, %rdi
callq 0x4750
movq 0x18(%r14), %r15
movl $0x0, 0x48(%r14)
leaq 0x90(%r14), %rdi
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
movups %xmm0, (%r12)
callq 0x4040
movq (%r14), %rdi
addq $0x38, %rdi
callq 0x4340
testq %r15, %r15
je 0x377fb
movq (%r15), %r14
movq 0x8(%r15), %rax
testq %rax, %rax
je 0x377e9
movq 0x18(%r15), %rdi
callq *%rax
movq $0x0, 0x18(%r15)
movq %r15, %rdi
movl %ebx, %esi
callq 0x37551
movq %r14, %r15
testq %r14, %r14
jne 0x377cf
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq