// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/bgzf.c
// Function: bgzf_useek
int bgzf_useek(BGZF *fp, off_t uoffset, int where)
{
    if (fp->is_write || where != SEEK_SET || fp->is_gzip) {
        fp->errcode |= BGZF_ERR_MISUSE;
        return -1;
    }
    if (uoffset >= fp->uncompressed_address - fp->block_offset &&
        uoffset < fp->uncompressed_address + fp->block_length - fp->block_offset) {
        // Can seek into existing data
        fp->block_offset += uoffset - fp->uncompressed_address;
        fp->uncompressed_address = uoffset;
        return 0;
    }
    if ( !fp->is_compressed )
    {
        if (hseek(fp->fp, uoffset, SEEK_SET) < 0)
        {
            fp->errcode |= BGZF_ERR_IO;
            return -1;
        }
        fp->block_length = 0;  // indicates current block has not been loaded
        fp->block_address = uoffset;
        fp->block_offset = 0;
        if (bgzf_read_block(fp) < 0) {
            fp->errcode |= BGZF_ERR_IO;
            return -1;
        }
        fp->uncompressed_address = uoffset;
        return 0;
    }

    if ( !fp->idx )
    {
        fp->errcode |= BGZF_ERR_IO;
        return -1;
    }

    // binary search
    int ilo = 0, ihi = fp->idx->noffs - 1;
    while ( ilo<=ihi )
    {
        int i = (ilo+ihi)*0.5;
        if ( uoffset < fp->idx->offs[i].uaddr ) ihi = i - 1;
        else if ( uoffset >= fp->idx->offs[i].uaddr ) ilo = i + 1;
        else break;
    }
    int i = ilo-1;
    off_t offset = 0;
    if (bgzf_seek_common(fp, fp->idx->offs[i].caddr, 0) < 0)
        return -1;

    if ( bgzf_read_block(fp) < 0 ) {
        fp->errcode |= BGZF_ERR_IO;
        return -1;
    }
    offset = uoffset - fp->idx->offs[i].uaddr;
    if ( offset > 0 )
    {
        if (offset > fp->block_length) {
            fp->errcode |= BGZF_ERR_IO;
            return -1;                                      //offset outside the available data
        }
        fp->block_offset = offset;
        assert( fp->block_offset <= fp->block_length );     // todo: skipped, unindexed, blocks
    }
    fp->uncompressed_address = uoffset;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl (%rdi), %ecx
testl %ecx, %ecx
js 0xc9a9
movl %ecx, %eax
andl $0x20000, %eax          # imm = 0x20000
orl %edx, %eax
jne 0xc9a9
movq %rsi, %r14
movq 0x20(%rbx), %rdx
movslq 0x10(%rbx), %rax
movq %rdx, %rsi
subq %rax, %rsi
cmpq %r14, %rsi
jg 0xc9b3
movslq 0x8(%rbx), %rdi
addq %rdi, %rsi
cmpq %r14, %rsi
jle 0xc9b3
movl %r14d, %ecx
subl %edx, %ecx
addl %eax, %ecx
movl %ecx, 0x10(%rbx)
jmp 0xc9ee
orl $0x8, %ecx
movl %ecx, (%rbx)
pushq $-0x1
popq %rbp
jmp 0xc9f4
cmpl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
ja 0xca01
movq 0x40(%rbx), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0xd7cb
testq %rax, %rax
js 0xcab3
andl $0x0, 0x8(%rbx)
movq %r14, 0x18(%rbx)
andl $0x0, 0x10(%rbx)
movq %rbx, %rdi
callq 0x9d84
testl %eax, %eax
js 0xcab3
movq %r14, 0x20(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x50(%rbx), %rax
testq %rax, %rax
je 0xcabb
movl (%rax), %ecx
decl %ecx
xorl %edx, %edx
movsd 0x68604(%rip), %xmm0    # 0x75020
cmpl %ecx, %edx
jg 0xca55
leal (%rdx,%rcx), %esi
cvtsi2sd %esi, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %esi
movq 0x8(%rax), %rdi
movslq %esi, %rsi
movq %rsi, %r8
shlq $0x4, %r8
leal -0x1(%rsi), %r9d
incl %esi
cmpq %r14, (%rdi,%r8)
cmovbel %ecx, %r9d
cmoval %edx, %esi
movl %r9d, %ecx
movl %esi, %edx
jmp 0xca1c
movslq %edx, %r15
decq %r15
movq 0x8(%rax), %rax
shlq $0x4, %r15
movq 0x8(%rax,%r15), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0xc0a9
pushq $-0x1
popq %rbp
testq %rax, %rax
js 0xc9f4
movq %rbx, %rdi
callq 0x9d84
testl %eax, %eax
js 0xcaab
movq 0x50(%rbx), %rax
movq 0x8(%rax), %rcx
movq %r14, %rax
subq (%rcx,%r15), %rax
testq %rax, %rax
jle 0xc9ee
movslq 0x8(%rbx), %rcx
cmpq %rcx, %rax
jle 0xcac3
orb $0x4, (%rbx)
jmp 0xc9f4
orb $0x4, (%rbx)
jmp 0xc9ae
orl $0x4, %ecx
jmp 0xc9ac
movl %eax, 0x10(%rbx)
cmpl %eax, %ecx
jge 0xc9ee
leaq 0x6a3bf(%rip), %rdi     # 0x76e94
leaq 0x6a0f4(%rip), %rsi     # 0x76bd0
leaq 0x6a3d6(%rip), %rcx     # 0x76eb9
movl $0xa26, %edx            # imm = 0xA26
callq 0x42f0