// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/bgzf.c
// Function: mt_destroy
static int mt_destroy(mtaux_t *mt)
{
    int ret = 0;

    // Tell the reader to shut down
    pthread_mutex_lock(&mt->command_m);
    mt->command = CLOSE;
    pthread_cond_signal(&mt->command_c);
    hts_tpool_wake_dispatch(mt->out_queue); // unstick the reader
    pthread_mutex_unlock(&mt->command_m);

    // Check for thread worker failure, indicated by is_shutdown returning 2
    // It's possible really late errors might be missed, but we can live with
    // that.
    ret = -(hts_tpool_process_is_shutdown(mt->out_queue) > 1);
    // Destroying the queue first forces the writer to exit.
    // mt->out_queue is reference counted, so destroy gets called in both
    // this and the IO threads.  The last to do it will clean up.
    hts_tpool_process_destroy(mt->out_queue);

    // IO thread will now exit.  Wait for it and perform final clean-up.
    // If it returned non-NULL, it was not happy.
    void *retval = NULL;
    pthread_join(mt->io_task, &retval);
    ret = retval != NULL ? -1 : ret;

    pthread_mutex_destroy(&mt->job_pool_m);
    pthread_mutex_destroy(&mt->command_m);
    pthread_mutex_destroy(&mt->idx_m);
    pthread_cond_destroy(&mt->command_c);
    if (mt->curr_job)
        pool_free(mt->job_pool, mt->curr_job);

    if (mt->own_pool)
        hts_tpool_destroy(mt->pool);

    pool_destroy(mt->job_pool);

    if (mt->idx_cache.e)
        free(mt->idx_cache.e);

    free(mt);
    fflush(stderr);

    return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movq -0x8(%rbp), %rdi
addq $0x80, %rdi
callq 0x4730
movq -0x8(%rbp), %rax
movl $0x5, 0xd8(%rax)
movq -0x8(%rbp), %rdi
addq $0xa8, %rdi
callq 0x4040
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x4e6f0
movq -0x8(%rbp), %rdi
addq $0x80, %rdi
callq 0x4330
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x4d3d0
cmpl $0x1, %eax
setg %al
andb $0x1, %al
movzbl %al, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x4d090
movq $0x0, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rdi
leaq -0x18(%rbp), %rsi
callq 0x4400
cmpq $0x0, -0x18(%rbp)
je 0xda74
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, -0x1c(%rbp)
jmp 0xda7a
movl -0xc(%rbp), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rdi
addq $0x30, %rdi
callq 0x4570
movq -0x8(%rbp), %rdi
addq $0x80, %rdi
callq 0x4570
movq -0x8(%rbp), %rdi
addq $0xe0, %rdi
callq 0x4570
movq -0x8(%rbp), %rdi
addq $0xa8, %rdi
callq 0x49a0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0xdadc
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x822f0
movq -0x8(%rbp), %rax
cmpl $0x0, 0x14(%rax)
je 0xdaf3
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x4e970
movq -0x8(%rbp), %rax
movq (%rax), %rdi
callq 0x820a0
movq -0x8(%rbp), %rax
cmpq $0x0, 0x128(%rax)
je 0xdb1d
movq -0x8(%rbp), %rax
movq 0x128(%rax), %rdi
callq 0x45a0
movq -0x8(%rbp), %rdi
callq 0x45a0
movq 0xff4b3(%rip), %rax     # 0x10cfe0
movq (%rax), %rdi
callq 0x4580
movl -0xc(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nop