// File: /workspace/github_c_makefile_star2_O3/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 0xd9a5
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 0x36d54
movq 0x48(%rbx), %rsi
leaq 0xa8(%rsi), %rdi
subq $-0x80, %rsi
callq 0x47c0
movq 0x48(%rbx), %rsi
movl 0xd8(%rsi), %eax
cmpl $0x1, %eax
jne 0xd9c8
addq $0xa8, %rsi
movq %rsi, %rdi
callq 0x4040
movq 0x48(%rbx), %rsi
cmpl $0x2, 0xd8(%rsi)
jne 0xd968
jmp 0xd9cd
movq 0x40(%rbx), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0xf3b3
testq %rax, %rax
js 0xda15
movl $0x0, 0x8(%rbx)
movq %r14, 0x18(%rbx)
movl %ebp, 0x10(%rbx)
jmp 0xda11
cmpl $0x2, %eax
jne 0xda2a
movl $0x0, 0xd8(%rsi)
leaq 0x80(%rsi), %r15
cmpl $0x0, 0x6c(%rsi)
je 0xd9fb
orb $0x4, (%rbx)
movl 0x6c(%rsi), %ebx
callq 0x4050
movl %ebx, (%rax)
movq %r15, %rdi
callq 0x4340
jmp 0xda18
movl $0x0, 0x8(%rbx)
movq %r14, 0x18(%rbx)
movl %ebp, 0x10(%rbx)
movq %r15, %rdi
callq 0x4340
xorl %eax, %eax
jmp 0xda1f
orb $0x4, (%rbx)
movq $-0x1, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
callq 0x4270