// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/bgzf.c
// Function: bgzf_thread_pool
int bgzf_thread_pool(BGZF *fp, hts_tpool *pool, int qsize) {
    // No gain from multi-threading when not compressed
    if (!fp->is_compressed)
        return 0;

    mtaux_t *mt;
    mt = (mtaux_t*)calloc(1, sizeof(mtaux_t));
    if (!mt) return -1;
    fp->mt = mt;

    mt->pool = pool;
    mt->n_threads = hts_tpool_size(pool);
    if (!qsize)
        qsize = mt->n_threads*2;
    if (!(mt->out_queue = hts_tpool_process_init(mt->pool, qsize, 0)))
        goto err;
    hts_tpool_process_ref_incr(mt->out_queue);

    mt->job_pool = pool_create(sizeof(bgzf_job));
    if (!mt->job_pool)
        goto err;

    pthread_mutex_init(&mt->job_pool_m, NULL);
    pthread_mutex_init(&mt->command_m, NULL);
    pthread_mutex_init(&mt->idx_m, NULL);
    pthread_cond_init(&mt->command_c, NULL);
    mt->flush_pending = 0;
    mt->jobs_pending = 0;
    mt->free_block = fp->uncompressed_block; // currently in-use block
    mt->block_address = fp->block_address;
    pthread_create(&mt->io_task, NULL,
                   fp->is_write ? bgzf_mt_writer : bgzf_mt_reader, fp);

    return 0;

 err:
    free(mt);
    fp->mt = NULL;
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x1e, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xec50
movl $0x0, -0x4(%rbp)
jmp 0xede5
movl $0x1, %edi
movl $0x130, %esi            # imm = 0x130
callq 0x42f0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xec76
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xede5
movq -0x28(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x18(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rdi
callq 0x4e270
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
cmpl $0x0, -0x1c(%rbp)
jne 0xecb2
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
shll %eax
movl %eax, -0x1c(%rbp)
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x1c(%rbp), %esi
xorl %edx, %edx
callq 0x4d480
movq -0x28(%rbp), %rcx
movq %rax, 0x20(%rcx)
cmpq $0x0, %rax
jne 0xecd7
jmp 0xedc9
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x4d200
movl $0x20030, %edi          # imm = 0x20030
callq 0x81f60
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
jne 0xed07
jmp 0xedc9
movq -0x28(%rbp), %rdi
addq $0x30, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4760
movq -0x28(%rbp), %rdi
addq $0x80, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4760
movq -0x28(%rbp), %rdi
addq $0xe0, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4760
movq -0x28(%rbp), %rdi
addq $0xa8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x45b0
movq -0x28(%rbp), %rax
movl $0x0, 0x5c(%rax)
movq -0x28(%rbp), %rax
movl $0x0, 0x58(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
movq -0x10(%rbp), %rax
movl (%rax), %ecx
shrl $0x11, %ecx
andl $0x1, %ecx
leaq 0x4eb(%rip), %rdx       # 0xf290
leaq 0x44(%rip), %rax        # 0xedf0
cmpl $0x0, %ecx
cmovneq %rax, %rdx
movq -0x10(%rbp), %rcx
xorl %eax, %eax
movl %eax, %esi
callq 0x4910
movl $0x0, -0x4(%rbp)
jmp 0xede5
movq -0x28(%rbp), %rdi
callq 0x45a0
movq -0x10(%rbp), %rax
movq $0x0, 0x48(%rax)
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nop