// File: zeeev[P]DASVC/bamtools/src/api/internal/io/BamHttp_p.cpp
// Function: BamTools::Internal::BamHttp::Open(BamTools::IBamIODevice::OpenMode)
bool BamHttp::Open(const IBamIODevice::OpenMode mode) {

    // BamHttp only supports read-only access
    if ( mode != IBamIODevice::ReadOnly ) {
        SetErrorString("BamHttp::Open", "writing on this device is not supported");
        return false;
    }
    m_mode = mode;

    // attempt connection to socket
    if ( !ConnectSocket() ) {
        SetErrorString("BamHttp::Open", m_socket->GetErrorString());
        return false;
    }

    // initialize our file positions
    m_filePosition     = 0;
    m_fileEndPosition  = 0;
    m_rangeEndPosition = 0;

    // attempt to send initial request (just 'HEAD' to check connection)
    if ( !SendHeadRequest() ) {
        SetErrorString("BamHttp::Open", m_socket->GetErrorString());
        return false;
    }

    // clear response from HEAD request, not needed
    ClearResponse();

    // return success
    return true;
}

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rdi, 0x128(%rsp)
movl %esi, 0x124(%rsp)
movq 0x128(%rsp), %rax
movq %rax, 0x28(%rsp)
cmpl $0x1, 0x124(%rsp)
je 0xca2cd
leaq 0xff(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x7b5f0
movq 0x20(%rsp), %rdx
leaq 0x21c25(%rip), %rsi     # 0xebdd4
leaq 0x100(%rsp), %rdi
callq 0x78e70
jmp 0xca1be
leaq 0xc7(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x7b5f0
movq 0x18(%rsp), %rdx
leaq 0x21a7d(%rip), %rsi     # 0xebc59
leaq 0xc8(%rsp), %rdi
callq 0x78e70
jmp 0xca1eb
movq 0x28(%rsp), %rdi
leaq 0x100(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
callq 0x7ab60
jmp 0xca207
leaq 0xc8(%rsp), %rdi
callq 0x7cce8
jmp 0xca216
leaq 0xc7(%rsp), %rdi
callq 0x76f80
leaq 0x100(%rsp), %rdi
callq 0x7cce8
jmp 0xca232
leaq 0xff(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x137(%rsp)
jmp 0xca515
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
jmp 0xca2bb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
jmp 0xca29d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x7cce8
jmp 0xca29b
jmp 0xca29d
leaq 0xc7(%rsp), %rdi
callq 0x76f80
leaq 0x100(%rsp), %rdi
callq 0x7cce8
jmp 0xca2b9
jmp 0xca2bb
leaq 0xff(%rsp), %rdi
callq 0x76f80
jmp 0xca526
movq 0x28(%rsp), %rdi
movl 0x124(%rsp), %eax
movl %eax, 0x8(%rdi)
callq 0x7a9f0
testb $0x1, %al
jne 0xca3ea
leaq 0x9f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x7b5f0
movq 0x10(%rsp), %rdx
leaq 0x21acd(%rip), %rsi     # 0xebdd4
leaq 0xa0(%rsp), %rdi
callq 0x78e70
jmp 0xca316
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rsi
leaq 0x78(%rsp), %rdi
callq 0x77a20
jmp 0xca32b
movq 0x28(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
leaq 0x78(%rsp), %rdx
callq 0x7ab60
jmp 0xca344
leaq 0x78(%rsp), %rdi
callq 0x7cce8
jmp 0xca350
leaq 0xa0(%rsp), %rdi
callq 0x7cce8
jmp 0xca35f
leaq 0x9f(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x137(%rsp)
jmp 0xca515
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
jmp 0xca3d8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
jmp 0xca3c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x7cce8
jmp 0xca3c5
jmp 0xca3c7
leaq 0xa0(%rsp), %rdi
callq 0x7cce8
jmp 0xca3d6
jmp 0xca3d8
leaq 0x9f(%rsp), %rdi
callq 0x76f80
jmp 0xca526
movq 0x28(%rsp), %rdi
movq $0x0, 0xb0(%rdi)
movq $0x0, 0xb8(%rdi)
movq $0x0, 0xc0(%rdi)
callq 0x75ff0
testb $0x1, %al
jne 0xca503
leaq 0x57(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x7b5f0
movq 0x8(%rsp), %rdx
leaq 0x2199c(%rip), %rsi     # 0xebdd4
leaq 0x58(%rsp), %rdi
callq 0x78e70
jmp 0xca444
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rsi
leaq 0x30(%rsp), %rdi
callq 0x77a20
jmp 0xca459
movq 0x28(%rsp), %rdi
leaq 0x58(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x7ab60
jmp 0xca46f
leaq 0x30(%rsp), %rdi
callq 0x7cce8
jmp 0xca47b
leaq 0x58(%rsp), %rdi
callq 0x7cce8
jmp 0xca487
leaq 0x57(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x137(%rsp)
jmp 0xca515
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
jmp 0xca4f7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
jmp 0xca4e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x7cce8
jmp 0xca4e7
jmp 0xca4e9
leaq 0x58(%rsp), %rdi
callq 0x7cce8
jmp 0xca4f5
jmp 0xca4f7
leaq 0x57(%rsp), %rdi
callq 0x76f80
jmp 0xca526
movq 0x28(%rsp), %rdi
callq 0x73f50
movb $0x1, 0x137(%rsp)
movb 0x137(%rsp), %al
andb $0x1, %al
addq $0x138, %rsp            # imm = 0x138
retq
movq 0xf0(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopl (%rax,%rax)