// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/htslib/bgzf.c
// Function: bgzf_useek
int bgzf_useek(BGZF *fp, long uoffset, int where)
{
    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;
    if (hseek(fp->fp, fp->idx->offs[i].caddr, SEEK_SET) < 0)
    {
        fp->errcode |= BGZF_ERR_IO;
        return -1;
    }
    fp->block_length = 0;  // indicates current block has not been loaded
    fp->block_address = fp->idx->offs[i].caddr;
    fp->block_offset = 0;
    if ( bgzf_read_block(fp) < 0 ) {
        fp->errcode |= BGZF_ERR_IO;
        return -1;
    }
    if ( uoffset - fp->idx->offs[i].uaddr > 0 )
    {
        fp->block_offset = uoffset - fp->idx->offs[i].uaddr;
        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 %rsi, %r14
movq %rdi, %rbx
movl (%rdi), %ecx
testl $0x60000000, %ecx       # imm = 0x60000000
je 0x44ee3
movq 0x48(%rbx), %rax
testq %rax, %rax
je 0x44f14
movl (%rax), %ecx
testl %ecx, %ecx
jle 0x44f1b
decl %ecx
movq 0x8(%rax), %rax
xorl %edx, %edx
movsd 0xba53(%rip), %xmm0     # 0x508f8
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 0x44ea5
decl %edx
movslq %edx, %r15
jmp 0x44f26
movq 0x38(%rbx), %rdi
movq %r14, %rsi
xorl %edx, %edx
callq 0x473bc
testq %rax, %rax
js 0x44f8a
movq $0x0, 0x8(%rbx)
movq %r14, 0x10(%rbx)
movq %rbx, %rdi
callq 0x42e17
testl %eax, %eax
jns 0x44f82
jmp 0x44f8a
orl $0x4, %ecx
movl %ecx, (%rbx)
jmp 0x44f8d
movq 0x8(%rax), %rax
movq $-0x1, %r15
movq 0x38(%rbx), %rdi
shlq $0x4, %r15
movq 0x8(%rax,%r15), %rsi
xorl %ebp, %ebp
xorl %edx, %edx
callq 0x473bc
testq %rax, %rax
js 0x44f8a
movl %ebp, 0x8(%rbx)
movq 0x48(%rbx), %rax
movq 0x8(%rax), %rax
movq 0x8(%rax,%r15), %rax
movq %rax, 0x10(%rbx)
movl %ebp, 0xc(%rbx)
movq %rbx, %rdi
callq 0x42e17
testl %eax, %eax
js 0x44f8a
movq 0x48(%rbx), %rax
movq 0x8(%rax), %rax
movq (%rax,%r15), %rax
cmpq %rax, %r14
je 0x44f82
movl %r14d, %ecx
subl %eax, %ecx
movl %ecx, 0xc(%rbx)
cmpl %ecx, 0x8(%rbx)
jl 0x44f9d
movq %r14, 0x18(%rbx)
xorl %eax, %eax
jmp 0x44f92
orb $0x4, (%rbx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0xefe1(%rip), %rdi      # 0x53f85
leaq 0xec5a(%rip), %rsi      # 0x53c05
leaq 0xeff8(%rip), %rcx      # 0x53faa
movl $0x529, %edx            # imm = 0x529
callq 0x4350