// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/bgzf.c
// Function: bgzf_seek_common
static inline int64_t bgzf_seek_common(BGZF* fp,
                                       int64_t block_address, int block_offset)
{
    if (fp->mt) {
        // The reader runs asynchronous and does loops of:
        //    Read block
        //    Check & process command
        //    Dispatch decode job
        //
        // Once at EOF it then switches to loops of
        //    Wait for command
        //    Process command (possibly switching back to above loop).
        //
        // To seek we therefore send the reader thread a SEEK command,
        // waking it up if blocked in dispatch and signalling if
        // waiting for a command.  We then wait for the response so we
        // know the seek succeeded.
        pthread_mutex_lock(&fp->mt->command_m);
        fp->mt->hit_eof = 0;
        // fp->mt->command state transitions should be:
        // NONE -> SEEK -> SEEK_DONE -> NONE
        // (SEEK -> SEEK_DONE happens in bgzf_mt_reader thread)
        fp->mt->command = SEEK;
        fp->mt->block_address = block_address;
        pthread_cond_signal(&fp->mt->command_c);
        hts_tpool_wake_dispatch(fp->mt->out_queue);
        do {
            pthread_cond_wait(&fp->mt->command_c, &fp->mt->command_m);
            switch (fp->mt->command) {
            case SEEK_DONE: break;
            case SEEK:
                // Resend signal intended for bgzf_mt_reader()
                pthread_cond_signal(&fp->mt->command_c);
                break;
            default:
                abort();  // Should not get to any other state
            }
        } while (fp->mt->command != SEEK_DONE);

        fp->mt->command = NONE;

        if (fp->mt->errcode) {
            fp->errcode |= BGZF_ERR_IO;
            errno = fp->mt->errcode;
            pthread_mutex_unlock(&fp->mt->command_m);
            return -1;
        }

        fp->block_length = 0;  // indicates current block has not been loaded
        fp->block_address = block_address;
        fp->block_offset = block_offset;

        pthread_mutex_unlock(&fp->mt->command_m);
    } else {
        if (hseek(fp->fp, block_address, SEEK_SET) < 0) {
            fp->errcode |= BGZF_ERR_IO;
            return -1;
        }
        fp->block_length = 0;  // indicates current block has not been loaded
        fp->block_address = block_address;
        fp->block_offset = block_offset;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movq 0x48(%rdi), %rdi
testq %rdi, %rdi
je 0xdaa5
subq $-0x80, %rdi
callq 0x4750
movq 0x48(%rbx), %rdi
movl $0x0, 0x68(%rdi)
movl $0x1, 0xd8(%rdi)
movq %r14, 0x70(%rdi)
addq $0xa8, %rdi
callq 0x4040
movq 0x48(%rbx), %rax
movq 0x20(%rax), %rdi
callq 0x3817e
movq 0x48(%rbx), %rsi
leaq 0xa8(%rsi), %rdi
subq $-0x80, %rsi
callq 0x47c0
movq 0x48(%rbx), %rdi
movl 0xd8(%rdi), %eax
cmpl $0x2, %eax
je 0xda6a
cmpl $0x1, %eax
jne 0xdaf7
addq $0xa8, %rdi
callq 0x4040
movq 0x48(%rbx), %rax
cmpl $0x2, 0xd8(%rax)
jne 0xda32
movl $0x0, 0xd8(%rax)
leaq 0x80(%rax), %r15
cmpl $0x0, 0x6c(%rax)
je 0xdac8
orb $0x4, (%rbx)
movl 0x6c(%rax), %ebx
callq 0x4050
movl %ebx, (%rax)
movq %r15, %rdi
callq 0x4340
jmp 0xdae5
movq 0x40(%rbx), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0xf583
testq %rax, %rax
js 0xdae2
movl $0x0, 0x8(%rbx)
movq %r14, 0x18(%rbx)
movl %ebp, 0x10(%rbx)
jmp 0xdade
movl $0x0, 0x8(%rbx)
movq %r14, 0x18(%rbx)
movl %ebp, 0x10(%rbx)
movq %r15, %rdi
callq 0x4340
xorl %eax, %eax
jmp 0xdaec
orb $0x4, (%rbx)
movq $-0x1, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x4270