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

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

    // open stdin/stdout depending on requested openmode
#if defined( SYSTEM_NODEJS ) && SYSTEM_NODEJS == 1
    if ( mode == IBamIODevice::ReadOnly )
        m_stream = stdin;
    else if ( mode == IBamIODevice::WriteOnly )
        m_stream = stdout;
#else
    if ( mode == IBamIODevice::ReadOnly )
        m_stream = freopen(0, "rb", stdin);
    else if ( mode == IBamIODevice::WriteOnly )
        m_stream = freopen(0, "wb", stdout);
#endif // SYSTEM_NODEJS

    else {
        const string errorType = string( (mode == IBamIODevice::ReadWrite) ? "unsupported"
                                                                           : "unknown" );
        const string message = errorType + " open mode requested";
        SetErrorString("BamPipe::Open", message);
        return false;
    }

// Assembly:
subq $0x138, %rsp            # imm = 0x138
movq %rdi, 0x128(%rsp)
movl %esi, 0x124(%rsp)
movq 0x128(%rsp), %rdi
movq %rdi, 0x28(%rsp)
movq (%rdi), %rax
callq *0x10(%rax)
cmpl $0x1, 0x124(%rsp)
jne 0xcca5e
movq 0x45516(%rip), %rax     # 0x111f50
movq (%rax), %rdx
xorl %eax, %eax
movl %eax, %edi
leaq 0x1f106(%rip), %rsi     # 0xebb4e
callq 0x764b0
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x30(%rax)
jmp 0xccc46
cmpl $0x2, 0x124(%rsp)
jne 0xcca93
movq 0x45459(%rip), %rax     # 0x111ec8
movq (%rax), %rdx
xorl %eax, %eax
movl %eax, %edi
leaq 0x1f0d4(%rip), %rsi     # 0xebb51
callq 0x764b0
movq %rax, %rcx
movq 0x28(%rsp), %rax
movq %rcx, 0x30(%rax)
jmp 0xccc44
movl 0x124(%rsp), %eax
subl $0x3, %eax
leaq 0x1f45f(%rip), %rcx     # 0xebf03
leaq 0x1d947(%rip), %rax     # 0xea3f2
cmoveq %rcx, %rax
movq %rax, 0x18(%rsp)
leaq 0xff(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x7b5f0
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
leaq 0x100(%rsp), %rdi
callq 0x78e70
jmp 0xccadf
leaq 0xff(%rsp), %rdi
callq 0x76f80
leaq 0x1f07a(%rip), %rdx     # 0xebb6d
leaq 0xc8(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x785a0
jmp 0xccb0a
leaq 0xa7(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x7b5f0
movq 0x10(%rsp), %rdx
leaq 0x1f3e7(%rip), %rsi     # 0xebf0f
leaq 0xa8(%rsp), %rdi
callq 0x78e70
jmp 0xccb37
movq 0x28(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
callq 0x7ab60
jmp 0xccb53
leaq 0xa8(%rsp), %rdi
callq 0x7cce8
jmp 0xccb62
leaq 0xa7(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x137(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x7cce8
jmp 0xccc1c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
leaq 0xff(%rsp), %rdi
callq 0x76f80
jmp 0xccdf3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
jmp 0xccc30
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
jmp 0xccc00
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x7cce8
jmp 0xccbfe
jmp 0xccc00
leaq 0xa7(%rsp), %rdi
callq 0x76f80
leaq 0xc8(%rsp), %rdi
callq 0x7cce8
jmp 0xccc2e
leaq 0x100(%rsp), %rdi
callq 0x7cce8
jmp 0xccde2
jmp 0xccc30
leaq 0x100(%rsp), %rdi
callq 0x7cce8
jmp 0xccc3f
jmp 0xccdf3
jmp 0xccc46
movq 0x28(%rsp), %rax
cmpq $0x0, 0x30(%rax)
jne 0xccdcb
leaq 0x7f(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x7b5f0
movq 0x8(%rsp), %rdx
leaq 0x1f2ac(%rip), %rsi     # 0xebf1d
leaq 0x80(%rsp), %rdi
callq 0x78e70
jmp 0xccc80
leaq 0x7f(%rsp), %rdi
callq 0x76f80
movl 0x124(%rsp), %eax
subl $0x1, %eax
leaq 0x1ee97(%rip), %rax     # 0xebb32
leaq 0x1ee96(%rip), %rdx     # 0xebb38
cmoveq %rax, %rdx
leaq 0x58(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x785a0
jmp 0xcccba
leaq 0x37(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x7b5f0
movq (%rsp), %rdx
leaq 0x1f23c(%rip), %rsi     # 0xebf0f
leaq 0x38(%rsp), %rdi
callq 0x78e70
jmp 0xcccdf
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rsi
leaq 0x58(%rsp), %rdx
callq 0x7ab60
jmp 0xcccf5
leaq 0x38(%rsp), %rdi
callq 0x7cce8
jmp 0xccd01
leaq 0x37(%rsp), %rdi
callq 0x76f80
movb $0x0, 0x137(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x7cce8
jmp 0xccda9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
leaq 0x7f(%rsp), %rdi
callq 0x76f80
jmp 0xccdf3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
jmp 0xccdba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
jmp 0xccd93
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xf0(%rsp)
movl %eax, 0xec(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x7cce8
jmp 0xccd91
jmp 0xccd93
leaq 0x37(%rsp), %rdi
callq 0x76f80
leaq 0x58(%rsp), %rdi
callq 0x7cce8
jmp 0xccdb8
leaq 0x80(%rsp), %rdi
callq 0x7cce8
jmp 0xccde2
jmp 0xccdba
leaq 0x80(%rsp), %rdi
callq 0x7cce8
jmp 0xccdc9
jmp 0xccdf3
movq 0x28(%rsp), %rax
movl 0x124(%rsp), %ecx
movl %ecx, 0x8(%rax)
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)