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

    // make sure we're starting with a fresh file stream
    Close();

    // attempt to open FILE* depending on requested openmode
    if ( mode == IBamIODevice::ReadOnly )
        m_stream = fopen(m_filename.c_str(), "rb");
    else if ( mode == IBamIODevice::WriteOnly )
        m_stream = fopen(m_filename.c_str(), "wb");
    else if ( mode == IBamIODevice::ReadWrite )
        m_stream = fopen(m_filename.c_str(), "w+b");
    else {
        SetErrorString("BamFile::Open", "unknown open mode requested");
        return false;
    }

    // check that we obtained a valid FILE*
    if ( m_stream == 0 ) {
        const string message_base = string("could not open file handle for ");
        const string message = message_base + ( (m_filename.empty()) ? "empty filename" : m_filename );
        SetErrorString("BamFile::Open", message);
        return false;
    }

    // store current IO mode & return success
    m_mode = mode;
    return true;
}

// Assembly:
subq $0x148, %rsp            # imm = 0x148
movq %rdi, 0x138(%rsp)
movl %esi, 0x134(%rsp)
movq 0x138(%rsp), %rdi
movq %rdi, 0x30(%rsp)
movq (%rdi), %rax
callq *0x10(%rax)
cmpl $0x1, 0x134(%rsp)
jne 0xc62c1
movq 0x30(%rsp), %rdi
addq $0x38, %rdi
callq 0x73020
movq %rax, %rdi
leaq 0x258a3(%rip), %rsi     # 0xebb4e
callq 0x77500
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x30(%rax)
jmp 0xc6471
cmpl $0x2, 0x134(%rsp)
jne 0xc62f9
movq 0x30(%rsp), %rdi
addq $0x38, %rdi
callq 0x73020
movq %rax, %rdi
leaq 0x2586e(%rip), %rsi     # 0xebb51
callq 0x77500
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x30(%rax)
jmp 0xc646f
cmpl $0x3, 0x134(%rsp)
jne 0xc6331
movq 0x30(%rsp), %rdi
addq $0x38, %rdi
callq 0x73020
movq %rax, %rdi
leaq 0x25839(%rip), %rsi     # 0xebb54
callq 0x77500
movq %rax, %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x30(%rax)
jmp 0xc646d
leaq 0x10f(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x7b5f0
movq 0x28(%rsp), %rdx
leaq 0x25809(%rip), %rsi     # 0xebb58
leaq 0x110(%rsp), %rdi
callq 0x78e70
jmp 0xc635e
leaq 0xd7(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x7b5f0
movq 0x20(%rsp), %rdx
leaq 0x257ea(%rip), %rsi     # 0xebb66
leaq 0xd8(%rsp), %rdi
callq 0x78e70
jmp 0xc638b
movq 0x30(%rsp), %rdi
leaq 0x110(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
callq 0x7ab60
jmp 0xc63a7
leaq 0xd8(%rsp), %rdi
callq 0x7cce8
jmp 0xc63b6
leaq 0xd7(%rsp), %rdi
callq 0x76f80
leaq 0x110(%rsp), %rdi
callq 0x7cce8
jmp 0xc63d2
leaq 0x10f(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x147(%rsp)
jmp 0xc66e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0xc645b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0xc643d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x7cce8
jmp 0xc643b
jmp 0xc643d
leaq 0xd7(%rsp), %rdi
callq 0x76f80
leaq 0x110(%rsp), %rdi
callq 0x7cce8
jmp 0xc6459
jmp 0xc645b
leaq 0x10f(%rsp), %rdi
callq 0x76f80
jmp 0xc66f3
jmp 0xc646f
jmp 0xc6471
movq 0x30(%rsp), %rax
cmpq $0x0, 0x30(%rax)
jne 0xc66cb
leaq 0xaf(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x7b5f0
movq 0x18(%rsp), %rdx
leaq 0x256e3(%rip), %rsi     # 0xebb82
leaq 0xb0(%rsp), %rdi
callq 0x78e70
jmp 0xc64ae
leaq 0xaf(%rsp), %rdi
callq 0x76f80
movq 0x30(%rsp), %rdi
addq $0x38, %rdi
movb $0x0, 0x66(%rsp)
callq 0x7aba0
movb %al, 0x17(%rsp)
jmp 0xc64d4
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0xc64de
jmp 0xc650c
leaq 0x67(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x7b5f0
movq 0x8(%rsp), %rdx
movb $0x1, 0x66(%rsp)
leaq 0x256a4(%rip), %rsi     # 0xebba2
leaq 0x68(%rsp), %rdi
callq 0x78e70
jmp 0xc650a
jmp 0xc6523
movq 0x30(%rsp), %rsi
addq $0x38, %rsi
leaq 0x68(%rsp), %rdi
callq 0x73370
jmp 0xc6521
jmp 0xc6523
leaq 0x88(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
leaq 0x68(%rsp), %rdx
callq 0x7c720
jmp 0xc653f
leaq 0x68(%rsp), %rdi
callq 0x7cce8
jmp 0xc654b
testb $0x1, 0x66(%rsp)
jne 0xc6554
jmp 0xc655e
leaq 0x67(%rsp), %rdi
callq 0x76f80
leaq 0x3f(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x7b5f0
movq (%rsp), %rdx
leaq 0x255e1(%rip), %rsi     # 0xebb58
leaq 0x40(%rsp), %rdi
callq 0x78e70
jmp 0xc6583
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x88(%rsp), %rdx
callq 0x7ab60
jmp 0xc659c
leaq 0x40(%rsp), %rdi
callq 0x7cce8
jmp 0xc65a8
leaq 0x3f(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x147(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x7cce8
jmp 0xc66a9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0xaf(%rsp), %rdi
callq 0x76f80
jmp 0xc66f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0xc66ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0xc6643
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x7cce8
jmp 0xc6641
jmp 0xc6643
testb $0x1, 0x66(%rsp)
jne 0xc664c
jmp 0xc6656
leaq 0x67(%rsp), %rdi
callq 0x76f80
jmp 0xc66ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
jmp 0xc6690
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x100(%rsp)
movl %eax, 0xfc(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x7cce8
jmp 0xc668e
jmp 0xc6690
leaq 0x3f(%rsp), %rdi
callq 0x76f80
leaq 0x88(%rsp), %rdi
callq 0x7cce8
jmp 0xc66b8
leaq 0xb0(%rsp), %rdi
callq 0x7cce8
jmp 0xc66e2
jmp 0xc66ba
leaq 0xb0(%rsp), %rdi
callq 0x7cce8
jmp 0xc66c9
jmp 0xc66f3
movq 0x30(%rsp), %rax
movl 0x134(%rsp), %ecx
movl %ecx, 0x8(%rax)
movb $0x1, 0x147(%rsp)
movb 0x147(%rsp), %al
andb $0x1, %al
addq $0x148, %rsp            # imm = 0x148
retq
movq 0x100(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopl (%rax,%rax)