// File: zeeev[P]DASVC/bamtools/src/api/internal/io/BamHttp_p.cpp
// Function: BamTools::Internal::BamHttp::Seek(long const&, int)
bool BamHttp::Seek(const int64_t& position, const int origin) {

    // if HTTP device not in a valid state
    if ( !IsOpen() ) {
        SetErrorString("BamHttp::Seek", "cannot seek on unopen connection");
        return false;
    }

    // reset the connection
    DisconnectSocket();
    if ( !ConnectSocket() ) {
        SetErrorString("BamHttp::Seek", m_socket->GetErrorString());
        return false;
    }

    // udpate file position
    switch ( origin ) {
        case SEEK_CUR : m_filePosition += position; break;
        case SEEK_SET : m_filePosition  = position; break;
        default :
            SetErrorString("BamHttp::Seek", "unsupported seek origin");
            return false;
    }

    // return success
    return true;
}

// Assembly:
subq $0x158, %rsp            # imm = 0x158
movq %rdi, 0x148(%rsp)
movq %rsi, 0x140(%rsp)
movl %edx, 0x13c(%rsp)
movq 0x148(%rsp), %rdi
movq %rdi, 0x38(%rsp)
movq (%rdi), %rax
callq *0x50(%rax)
testb $0x1, %al
jne 0xcc495
leaq 0x117(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x7b5f0
movq 0x30(%rsp), %rdx
leaq 0x1fae8(%rip), %rsi     # 0xebe5f
leaq 0x118(%rsp), %rdi
callq 0x78e70
jmp 0xcc386
leaq 0xdf(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x7b5f0
movq 0x28(%rsp), %rdx
leaq 0x1fac9(%rip), %rsi     # 0xebe6d
leaq 0xe0(%rsp), %rdi
callq 0x78e70
jmp 0xcc3b3
movq 0x38(%rsp), %rdi
leaq 0x118(%rsp), %rsi
leaq 0xe0(%rsp), %rdx
callq 0x7ab60
jmp 0xcc3cf
leaq 0xe0(%rsp), %rdi
callq 0x7cce8
jmp 0xcc3de
leaq 0xdf(%rsp), %rdi
callq 0x76f80
leaq 0x118(%rsp), %rdi
callq 0x7cce8
jmp 0xcc3fa
leaq 0x117(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x157(%rsp)
jmp 0xcc72d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0xcc483
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0xcc465
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0xe0(%rsp), %rdi
callq 0x7cce8
jmp 0xcc463
jmp 0xcc465
leaq 0xdf(%rsp), %rdi
callq 0x76f80
leaq 0x118(%rsp), %rdi
callq 0x7cce8
jmp 0xcc481
jmp 0xcc483
leaq 0x117(%rsp), %rdi
callq 0x76f80
jmp 0xcc73e
movq 0x38(%rsp), %rdi
callq 0x73bd0
movq 0x38(%rsp), %rdi
callq 0x7a9f0
testb $0x1, %al
jne 0xcc5be
leaq 0xb7(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x7b5f0
movq 0x20(%rsp), %rdx
leaq 0x1f990(%rip), %rsi     # 0xebe5f
leaq 0xb8(%rsp), %rdi
callq 0x78e70
jmp 0xcc4de
movq 0x38(%rsp), %rax
movq 0x30(%rax), %rsi
leaq 0x90(%rsp), %rdi
callq 0x77a20
jmp 0xcc4f6
movq 0x38(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
leaq 0x90(%rsp), %rdx
callq 0x7ab60
jmp 0xcc512
leaq 0x90(%rsp), %rdi
callq 0x7cce8
jmp 0xcc521
leaq 0xb8(%rsp), %rdi
callq 0x7cce8
jmp 0xcc530
leaq 0xb7(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x157(%rsp)
jmp 0xcc72d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0xcc5ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0xcc59b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x7cce8
jmp 0xcc599
jmp 0xcc59b
leaq 0xb8(%rsp), %rdi
callq 0x7cce8
jmp 0xcc5aa
jmp 0xcc5ac
leaq 0xb7(%rsp), %rdi
callq 0x76f80
jmp 0xcc73e
movl 0x13c(%rsp), %eax
movl %eax, 0x1c(%rsp)
testl %eax, %eax
je 0xcc5fd
jmp 0xcc5cf
movl 0x1c(%rsp), %eax
subl $0x1, %eax
jne 0xcc619
jmp 0xcc5da
movq 0x38(%rsp), %rax
movq 0x140(%rsp), %rcx
movq (%rcx), %rcx
addq 0xb0(%rax), %rcx
movq %rcx, 0xb0(%rax)
jmp 0xcc725
movq 0x38(%rsp), %rax
movq 0x140(%rsp), %rcx
movq (%rcx), %rcx
movq %rcx, 0xb0(%rax)
jmp 0xcc725
leaq 0x6f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x7b5f0
movq 0x10(%rsp), %rdx
leaq 0x1f82b(%rip), %rsi     # 0xebe5f
leaq 0x70(%rsp), %rdi
callq 0x78e70
jmp 0xcc640
leaq 0x47(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x7b5f0
movq 0x8(%rsp), %rdx
leaq 0x1f833(%rip), %rsi     # 0xebe8e
leaq 0x48(%rsp), %rdi
callq 0x78e70
jmp 0xcc667
movq 0x38(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x7ab60
jmp 0xcc67d
leaq 0x48(%rsp), %rdi
callq 0x7cce8
jmp 0xcc689
leaq 0x47(%rsp), %rdi
callq 0x76f80
leaq 0x70(%rsp), %rdi
callq 0x7cce8
jmp 0xcc69f
leaq 0x6f(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x157(%rsp)
jmp 0xcc72d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0xcc719
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
jmp 0xcc701
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x108(%rsp)
movl %eax, 0x104(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x7cce8
jmp 0xcc6ff
jmp 0xcc701
leaq 0x47(%rsp), %rdi
callq 0x76f80
leaq 0x70(%rsp), %rdi
callq 0x7cce8
jmp 0xcc717
jmp 0xcc719
leaq 0x6f(%rsp), %rdi
callq 0x76f80
jmp 0xcc73e
movb $0x1, 0x157(%rsp)
movb 0x157(%rsp), %al
andb $0x1, %al
addq $0x158, %rsp            # imm = 0x158
retq
movq 0x108(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopw %cs:(%rax,%rax)