// File: zeeev[P]DASVC/bamtools/src/api/internal/io/BgzfStream_p.cpp
// Function: BamTools::Internal::BgzfStream::Seek(long const&)
void BgzfStream::Seek(const int64_t& position) {

    BT_ASSERT_X( m_device, "BgzfStream::Seek() - trying to seek on null IO device");

    // skip if device is not open
    if ( !IsOpen() ) return;

    // determine adjusted offset & address
    int     blockOffset  = (position & 0xFFFF);
    int64_t blockAddress = (position >> 16) & 0xFFFFFFFFFFFFLL;

    // attempt seek in file
    if ( m_device->IsRandomAccess() && m_device->Seek(blockAddress) ) {

        // update block data & return success
        m_blockLength  = 0;
        m_blockAddress = blockAddress;
        m_blockOffset  = blockOffset;
    }
    else {
        stringstream s("");
        s << "unable to seek to position: " << position;
        throw BamException("BgzfStream::Seek", s.str());
    }
}

// Assembly:
subq $0x268, %rsp            # imm = 0x268
movq %rdi, 0x260(%rsp)
movq %rsi, 0x258(%rsp)
movq 0x260(%rsp), %rax
movq %rax, 0x30(%rsp)
callq 0x761a0
movq 0x30(%rsp), %rdi
callq 0x7a940
testb $0x1, %al
jne 0xcf5bc
jmp 0xcf874
movq 0x30(%rsp), %rax
movq 0x258(%rsp), %rcx
movq (%rcx), %rcx
andq $0xffff, %rcx           # imm = 0xFFFF
movl %ecx, 0x254(%rsp)
movq 0x258(%rsp), %rcx
movq (%rcx), %rcx
sarq $0x10, %rcx
movabsq $0xffffffffffff, %rdx   # imm = 0xFFFFFFFFFFFF
andq %rdx, %rcx
movq %rcx, 0x248(%rsp)
movq 0x18(%rax), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
testb $0x1, %al
jne 0xcf60e
jmp 0xcf653
movq 0x30(%rsp), %rax
movq 0x18(%rax), %rdi
movq (%rdi), %rax
leaq 0x248(%rsp), %rsi
xorl %edx, %edx
callq *0x30(%rax)
testb $0x1, %al
jne 0xcf62d
jmp 0xcf653
movq 0x30(%rsp), %rax
movl $0x0, (%rax)
movq 0x248(%rsp), %rcx
movq %rcx, 0x8(%rax)
movl 0x254(%rsp), %ecx
movl %ecx, 0x4(%rax)
jmp 0xcf874
leaq 0x9f(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x7b5f0
movq 0x28(%rsp), %rdx
leaq 0x1ba6b(%rip), %rsi     # 0xeb0dc
leaq 0xa0(%rsp), %rdi
callq 0x78e70
jmp 0xcf680
movl $0x10, %edi
movl $0x8, %esi
callq 0x7b8d0
movl %eax, 0x24(%rsp)
jmp 0xcf695
movl 0x24(%rsp), %edx
leaq 0xc0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x7a4b0
jmp 0xcf6b0
leaq 0xa0(%rsp), %rdi
callq 0x7cce8
jmp 0xcf6bf
leaq 0x9f(%rsp), %rdi
callq 0x76f80
leaq 0xd0(%rsp), %rdi
leaq 0x1cab2(%rip), %rsi     # 0xec18d
callq 0x768e0
movq %rax, 0x18(%rsp)
jmp 0xcf6e7
movq 0x18(%rsp), %rdi
movq 0x258(%rsp), %rax
movq (%rax), %rsi
callq 0x7ba30
jmp 0xcf6fe
movb $0x1, 0x3f(%rsp)
movl $0x28, %edi
callq 0x737c0
movq %rax, 0x8(%rsp)
leaq 0x67(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x7b5f0
movq 0x10(%rsp), %rdx
leaq 0x1ca7d(%rip), %rsi     # 0xec1aa
leaq 0x68(%rsp), %rdi
callq 0x78e70
jmp 0xcf739
leaq 0x40(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x76880
jmp 0xcf74d
movq 0x8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
leaq 0x40(%rsp), %rdx
callq 0x79cd0
jmp 0xcf763
movq 0x8(%rsp), %rdi
movb $0x0, 0x3f(%rsp)
movq 0x4279c(%rip), %rsi     # 0x111f10
movq 0x427e5(%rip), %rdx     # 0x111f60
callq 0x7b010
jmp 0xcf891
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0xcf7c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x7cce8
jmp 0xcf7be
jmp 0xcf7c0
leaq 0x9f(%rsp), %rdi
callq 0x76f80
jmp 0xcf87c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0xcf863
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0xcf844
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
jmp 0xcf836
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x90(%rsp)
movl %eax, 0x8c(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x7cce8
jmp 0xcf834
jmp 0xcf836
leaq 0x68(%rsp), %rdi
callq 0x7cce8
jmp 0xcf842
jmp 0xcf844
leaq 0x67(%rsp), %rdi
callq 0x76f80
testb $0x1, 0x3f(%rsp)
jne 0xcf857
jmp 0xcf861
movq 0x8(%rsp), %rdi
callq 0x74e00
jmp 0xcf863
leaq 0xc0(%rsp), %rdi
callq 0x74f60
jmp 0xcf872
jmp 0xcf87c
addq $0x268, %rsp            # imm = 0x268
retq
movq 0x90(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopw %cs:(%rax,%rax)