// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x10cca
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
addq $0x80, %rdi
callq 0x4730
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl $0x0, 0x68(%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl $0x1, 0xd8(%rax)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq %rcx, 0x70(%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
addq $0xa8, %rdi
callq 0x4040
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movq 0x20(%rax), %rdi
callq 0x4e6f0
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rsi
movq %rsi, %rdi
addq $0xa8, %rdi
subq $-0x80, %rsi
callq 0x47a0
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl 0xd8(%rax), %eax
movl %eax, -0x20(%rbp)
subl $0x1, %eax
je 0x10beb
jmp 0x10bdf
movl -0x20(%rbp), %eax
subl $0x2, %eax
jne 0x10c01
jmp 0x10be9
jmp 0x10c06
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
addq $0xa8, %rdi
callq 0x4040
jmp 0x10c06
callq 0x4260
jmp 0x10c08
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
cmpl $0x2, 0xd8(%rax)
jne 0x10bac
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl $0x0, 0xd8(%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
cmpl $0x0, 0x6c(%rax)
je 0x10c93
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
orl $0x4, %edx
movl (%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movl 0x6c(%rax), %eax
movl %eax, -0x24(%rbp)
callq 0x4050
movl -0x24(%rbp), %ecx
movl %ecx, (%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
addq $0x80, %rdi
callq 0x4330
movq $-0x1, -0x8(%rbp)
jmp 0x10d37
movq -0x10(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
addq $0x80, %rdi
callq 0x4330
jmp 0x10d2f
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
movq -0x18(%rbp), %rsi
xorl %edx, %edx
callq 0x146a0
cmpq $0x0, %rax
jge 0x10d0e
movq -0x10(%rbp), %rax
movl (%rax), %edx
andl $0xffff, %edx           # imm = 0xFFFF
orl $0x4, %edx
movl (%rax), %ecx
andl $0xffff, %edx           # imm = 0xFFFF
andl $0xffff0000, %ecx       # imm = 0xFFFF0000
orl %edx, %ecx
movl %ecx, (%rax)
movq $-0x1, -0x8(%rbp)
jmp 0x10d37
movq -0x10(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)