// File: /workspace/github_c_makefile_star2_O3/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), %eax
testl %eax, %eax
js 0xe507
movl %eax, %ecx
andl $0x20000, %ecx          # imm = 0x20000
orl %edx, %ecx
jne 0xe507
movq %rsi, %r14
movq 0x20(%rbx), %rdx
movslq 0x10(%rbx), %rcx
movq %rdx, %rsi
subq %rcx, %rsi
cmpq %r14, %rsi
jg 0xe513
movslq 0x8(%rbx), %rdi
addq %rdi, %rsi
cmpq %r14, %rsi
jle 0xe513
movl %r14d, %eax
subl %edx, %eax
addl %ecx, %eax
movl %eax, 0x10(%rbx)
jmp 0xe549
orl $0x8, %eax
movl %eax, (%rbx)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0xe54f
cmpl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
ja 0xe55c
movq 0x40(%rbx), %rdi
xorl %ebp, %ebp
movq %r14, %rsi
xorl %edx, %edx
callq 0xf3b3
testq %rax, %rax
js 0xe5b9
movl %ebp, 0x8(%rbx)
movq %r14, 0x18(%rbx)
movl %ebp, 0x10(%rbx)
movq %rbx, %rdi
callq 0xae59
testl %eax, %eax
js 0xe5b9
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), %rdx
testq %rdx, %rdx
je 0xe5c1
movl (%rdx), %ecx
testl %ecx, %ecx
jle 0xe5c9
decl %ecx
movq 0x8(%rdx), %rax
xorl %edx, %edx
movsd 0x84aa5(%rip), %xmm0    # 0x93020
movl %edx, %esi
leal (%rsi,%rcx), %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
mulsd %xmm0, %xmm1
cvttsd2si %xmm1, %edx
movslq %edx, %rdx
movq %rdx, %rdi
shlq $0x4, %rdi
leal -0x1(%rdx), %r8d
incl %edx
cmpq %r14, (%rax,%rdi)
cmovbel %ecx, %r8d
cmoval %esi, %edx
movl %r8d, %ecx
cmpl %r8d, %edx
jle 0xe57b
decl %edx
movslq %edx, %r15
jmp 0xe5d4
orb $0x4, (%rbx)
jmp 0xe50c
orl $0x4, %eax
jmp 0xe50a
movq 0x8(%rdx), %rax
movq $-0x1, %r15
shlq $0x4, %r15
movq 0x8(%rax,%r15), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0xd911
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
js 0xe54f
movq %rbx, %rdi
callq 0xae59
testl %eax, %eax
js 0xe622
movq 0x50(%rbx), %rax
movq 0x8(%rax), %rcx
movq %r14, %rax
subq (%rcx,%r15), %rax
testq %rax, %rax
jle 0xe549
movslq 0x8(%rbx), %rcx
cmpq %rcx, %rax
jle 0xe62a
orb $0x4, (%rbx)
jmp 0xe54f
movl %eax, 0x10(%rbx)
cmpl %eax, %ecx
jge 0xe549
leaq 0x868a8(%rip), %rdi     # 0x94ee4
leaq 0x865dd(%rip), %rsi     # 0x94c20
leaq 0x868bf(%rip), %rcx     # 0x94f09
movl $0xa26, %edx            # imm = 0xA26
callq 0x42f0