// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/bgzf.c
// Function: bgzf_mt_reader
static void *bgzf_mt_reader(void *vp) {
    BGZF *fp = (BGZF *)vp;
    mtaux_t *mt = fp->mt;

restart:
    pthread_mutex_lock(&mt->job_pool_m);
    bgzf_job *j = pool_alloc(mt->job_pool);
    pthread_mutex_unlock(&mt->job_pool_m);
    if (!j) goto err;
    j->errcode = 0;
    j->comp_len = 0;
    j->uncomp_len = 0;
    j->hit_eof = 0;
    j->fp = fp;

    while (bgzf_mt_read_block(fp, j) == 0) {
        // Dispatch
        if (hts_tpool_dispatch3(mt->pool, mt->out_queue, bgzf_decode_func, j,
                                job_cleanup, job_cleanup, 0) < 0) {
            job_cleanup(j);
            goto err;
        }

        // Check for command
        pthread_mutex_lock(&mt->command_m);
        switch (mt->command) {
        case SEEK:
            bgzf_mt_seek(fp);  // Sets mt->command to SEEK_DONE
            pthread_mutex_unlock(&mt->command_m);
            goto restart;

        case HAS_EOF:
            bgzf_mt_eof(fp);   // Sets mt->command to HAS_EOF_DONE
            break;

        case SEEK_DONE:
        case HAS_EOF_DONE:
            pthread_cond_signal(&mt->command_c);
            break;

        case CLOSE:
            pthread_cond_signal(&mt->command_c);
            pthread_mutex_unlock(&mt->command_m);
            hts_tpool_process_destroy(mt->out_queue);
            return NULL;

        default:
            break;
        }
        pthread_mutex_unlock(&mt->command_m);

        // Allocate buffer for next block
        pthread_mutex_lock(&mt->job_pool_m);
        j = pool_alloc(mt->job_pool);
        pthread_mutex_unlock(&mt->job_pool_m);
        if (!j) {
            hts_tpool_process_destroy(mt->out_queue);
            return NULL;
        }
        j->errcode = 0;
        j->comp_len = 0;
        j->uncomp_len = 0;
        j->hit_eof = 0;
        j->fp = fp;
    }

    if (j->errcode == BGZF_ERR_MT) {
        // Attempt to multi-thread decode a raw gzip stream cannot be done.
        // We tear down the multi-threaded decoder and revert to the old code.
        if (hts_tpool_dispatch3(mt->pool, mt->out_queue, bgzf_nul_func, j,
                                job_cleanup, job_cleanup, 0) < 0) {
            job_cleanup(j);
            hts_tpool_process_destroy(mt->out_queue);
            return NULL;
        }
        hts_tpool_process_ref_decr(mt->out_queue);
        return &j->errcode;
    }

    // Dispatch an empty block so EOF is spotted.
    // We also use this mechanism for returning errors, in which case
    // j->errcode is set already.

    j->hit_eof = 1;
    if (hts_tpool_dispatch3(mt->pool, mt->out_queue, bgzf_nul_func, j,
                            job_cleanup, job_cleanup, 0) < 0) {
        job_cleanup(j);
        hts_tpool_process_destroy(mt->out_queue);
        return NULL;
    }
    if (j->errcode != 0) {
        hts_tpool_process_destroy(mt->out_queue);
        return &j->errcode;
    }

    // We hit EOF so can stop reading, but we may get a subsequent
    // seek request.  In this case we need to restart the reader.
    //
    // To handle this we wait on a condition variable and then
    // monitor the command. (This could be either seek or close.)
    for (;;) {
        pthread_mutex_lock(&mt->command_m);
        if (mt->command == NONE)
            pthread_cond_wait(&mt->command_c, &mt->command_m);
        switch(mt->command) {
        default:
            pthread_mutex_unlock(&mt->command_m);
            break;

        case SEEK:
            bgzf_mt_seek(fp);
            pthread_mutex_unlock(&mt->command_m);
            goto restart;

        case HAS_EOF:
            bgzf_mt_eof(fp);   // Sets mt->command to HAS_EOF_DONE
            pthread_mutex_unlock(&mt->command_m);
            break;

        case SEEK_DONE:
        case HAS_EOF_DONE:
            pthread_cond_signal(&mt->command_c);
            pthread_mutex_unlock(&mt->command_m);
            break;

        case CLOSE:
            pthread_cond_signal(&mt->command_c);
            pthread_mutex_unlock(&mt->command_m);
            hts_tpool_process_destroy(mt->out_queue);
            return NULL;
        }
    }

 err:
    pthread_mutex_lock(&mt->command_m);
    mt->command = CLOSE;
    pthread_cond_signal(&mt->command_c);
    pthread_mutex_unlock(&mt->command_m);
    hts_tpool_process_destroy(mt->out_queue);
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
addq $0x30, %rdi
callq 0x4730
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x82110
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
addq $0x30, %rdi
callq 0x4330
cmpq $0x0, -0x28(%rbp)
jne 0xf2e6
jmp 0xf70e
movq -0x28(%rbp), %rax
movl $0x0, 0x20018(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x10008(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x20010(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x20028(%rax)
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xe9e0
cmpl $0x0, %eax
jne 0xf4df
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x28(%rbp), %rcx
leaq 0x3df4(%rip), %rdx      # 0x13150
leaq 0x3e9d(%rip), %r9       # 0x13200
xorl %eax, %eax
movq %r9, %r8
movl $0x0, (%rsp)
callq 0x4e2e0
cmpl $0x0, %eax
jge 0xf387
movq -0x28(%rbp), %rdi
callq 0x13200
jmp 0xf70e
movq -0x20(%rbp), %rdi
subq $-0x80, %rdi
callq 0x4730
movq -0x20(%rbp), %rax
movl 0xd8(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x30(%rbp)
subl $0x4, %eax
ja 0xf438
movq -0x30(%rbp), %rax
leaq 0xdf77e(%rip), %rcx     # 0xeeb38
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rdi
callq 0x13260
movq -0x20(%rbp), %rdi
addq $0x80, %rdi
callq 0x4330
jmp 0xf2b0
movq -0x18(%rbp), %rdi
callq 0x13300
jmp 0xf43a
movq -0x20(%rbp), %rdi
addq $0xa8, %rdi
callq 0x4040
jmp 0xf43a
movq -0x20(%rbp), %rdi
addq $0xa8, %rdi
callq 0x4040
movq -0x20(%rbp), %rdi
addq $0x80, %rdi
callq 0x4330
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x4d090
movq $0x0, -0x8(%rbp)
jmp 0xf761
jmp 0xf43a
movq -0x20(%rbp), %rdi
addq $0x80, %rdi
callq 0x4330
movq -0x20(%rbp), %rdi
addq $0x30, %rdi
callq 0x4730
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x82110
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
addq $0x30, %rdi
callq 0x4330
cmpq $0x0, -0x28(%rbp)
jne 0xf495
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x4d090
movq $0x0, -0x8(%rbp)
jmp 0xf761
movq -0x28(%rbp), %rax
movl $0x0, 0x20018(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x10008(%rax)
movq -0x28(%rbp), %rax
movq $0x0, 0x20010(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x20028(%rax)
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
jmp 0xf32b
movq -0x28(%rbp), %rax
cmpl $0x10, 0x20018(%rax)
jne 0xf567
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x28(%rbp), %rcx
leaq 0x3e69(%rip), %rdx      # 0x13370
leaq 0x3cf2(%rip), %r9       # 0x13200
xorl %eax, %eax
movq %r9, %r8
movl $0x0, (%rsp)
callq 0x4e2e0
cmpl $0x0, %eax
jge 0xf547
movq -0x28(%rbp), %rdi
callq 0x13200
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x4d090
movq $0x0, -0x8(%rbp)
jmp 0xf761
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x4d240
movq -0x28(%rbp), %rax
addq $0x20018, %rax          # imm = 0x20018
movq %rax, -0x8(%rbp)
jmp 0xf761
movq -0x28(%rbp), %rax
movl $0x1, 0x20028(%rax)
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x28(%rbp), %rcx
leaq 0x3de0(%rip), %rdx      # 0x13370
leaq 0x3c69(%rip), %r9       # 0x13200
xorl %eax, %eax
movq %r9, %r8
movl $0x0, (%rsp)
callq 0x4e2e0
cmpl $0x0, %eax
jge 0xf5d0
movq -0x28(%rbp), %rdi
callq 0x13200
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x4d090
movq $0x0, -0x8(%rbp)
jmp 0xf761
movq -0x28(%rbp), %rax
cmpl $0x0, 0x20018(%rax)
je 0xf5fd
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x4d090
movq -0x28(%rbp), %rax
addq $0x20018, %rax          # imm = 0x20018
movq %rax, -0x8(%rbp)
jmp 0xf761
jmp 0xf5ff
movq -0x20(%rbp), %rdi
addq $0x80, %rdi
callq 0x4730
movq -0x20(%rbp), %rax
cmpl $0x0, 0xd8(%rax)
jne 0xf637
movq -0x20(%rbp), %rdi
addq $0xa8, %rdi
movq -0x20(%rbp), %rsi
addq $0x80, %rsi
callq 0x47a0
movq -0x20(%rbp), %rax
movl 0xd8(%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0x4, %eax
ja 0xf662
movq -0x38(%rbp), %rax
leaq 0xdf4cb(%rip), %rcx     # 0xeeb24
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x20(%rbp), %rdi
addq $0x80, %rdi
callq 0x4330
jmp 0xf709
movq -0x18(%rbp), %rdi
callq 0x13260
movq -0x20(%rbp), %rdi
addq $0x80, %rdi
callq 0x4330
jmp 0xf2b0
movq -0x18(%rbp), %rdi
callq 0x13300
movq -0x20(%rbp), %rdi
addq $0x80, %rdi
callq 0x4330
jmp 0xf709
movq -0x20(%rbp), %rdi
addq $0xa8, %rdi
callq 0x4040
movq -0x20(%rbp), %rdi
addq $0x80, %rdi
callq 0x4330
jmp 0xf709
movq -0x20(%rbp), %rdi
addq $0xa8, %rdi
callq 0x4040
movq -0x20(%rbp), %rdi
addq $0x80, %rdi
callq 0x4330
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x4d090
movq $0x0, -0x8(%rbp)
jmp 0xf761
jmp 0xf5ff
movq -0x20(%rbp), %rdi
addq $0x80, %rdi
callq 0x4730
movq -0x20(%rbp), %rax
movl $0x5, 0xd8(%rax)
movq -0x20(%rbp), %rdi
addq $0xa8, %rdi
callq 0x4040
movq -0x20(%rbp), %rdi
addq $0x80, %rdi
callq 0x4330
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x4d090
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)