LLM4Binary/decompile-bench-makefile huggingface dataset:
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/RollingBuffer_p.cpp
// Function: BamTools::Internal::RollingBuffer::Read(char*, unsigned long)
size_t RollingBuffer::Read(char* dest, size_t max) {

    size_t bytesToRead    = std::min(Size(), max);
    size_t bytesReadSoFar = 0;

    while ( bytesReadSoFar < bytesToRead ) {
        const char* readPtr = ReadPointer();
        size_t blockBytes = std::min( (bytesToRead - bytesReadSoFar), BlockSize() );
        if ( dest )
            memcpy(dest+bytesReadSoFar, readPtr, blockBytes);
        bytesReadSoFar += blockBytes;
        Free(blockBytes);
    }

    return bytesReadSoFar;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movq %rdx, 0x40(%rsp)
movq 0x50(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x72090
movq %rax, 0x30(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x74f40
movq (%rax), %rax
movq %rax, 0x38(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x28(%rsp), %rax
cmpq 0x38(%rsp), %rax
jae 0xdc2fb
movq (%rsp), %rdi
callq 0x7c330
movq (%rsp), %rdi
movq %rax, 0x20(%rsp)
movq 0x38(%rsp), %rax
subq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
callq 0x73cd0
movq %rax, 0x8(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x74f40
movq (%rax), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x48(%rsp)
je 0xdc2d9
movq 0x48(%rsp), %rdi
addq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x757c0
movq (%rsp), %rdi
movq 0x18(%rsp), %rax
addq 0x28(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x18(%rsp), %rsi
callq 0x77250
jmp 0xdc266
movq 0x28(%rsp), %rax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/RollingBuffer_p.cpp
// Function: BamTools::Internal::RollingBuffer::ReadPointer() const
const char* RollingBuffer::ReadPointer(void) const {

    // return null if empty buffer
    if ( m_data.empty() )
        return 0;

    // otherwise return pointer to current position
    const ByteArray& first = m_data.front();
    return first.ConstData() + m_head;
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x18(%rsp)
movq 0x18(%rsp), %rdi
movq %rdi, 0x8(%rsp)
addq $0x28, %rdi
callq 0x77f30
testb $0x1, %al
jne 0xdc342
jmp 0xdc34d
movq $0x0, 0x20(%rsp)
jmp 0xdc377
movq 0x8(%rsp), %rdi
addq $0x28, %rdi
callq 0x7a240
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rdi
callq 0x71e90
movq 0x8(%rsp), %rcx
addq (%rcx), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/RollingBuffer_p.cpp
// Function: BamTools::Internal::RollingBuffer::ReadLine(char*, unsigned long)
size_t RollingBuffer::ReadLine(char* dest, size_t max) {

    // if we can't read line or if max is 0
    if ( !CanReadLine() || max == 0 )
        return 0;

    // otherwise, read until we hit newline
    size_t bytesReadSoFar = 0;
    bool finished = false;
    while ( !finished ) {

        const size_t index = IndexOf('\n');
        const char* readPtr = ReadPointer();
        size_t bytesToRead = std::min( (index+1)-bytesReadSoFar, BlockSize() );
        bytesToRead = std::min( bytesToRead, (max-1)-bytesReadSoFar );
        memcpy(dest+bytesReadSoFar, readPtr, bytesToRead);
        bytesReadSoFar += bytesToRead;
        Free(bytesToRead);

        if ( !((bytesReadSoFar < index+1) && (bytesReadSoFar < max-1)) )
            finished = true;
    }

    // null terminate 'dest' & return numBytesRead
    dest[bytesReadSoFar] = '\0';
    return bytesReadSoFar;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq 0x58(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x7b020
testb $0x1, %al
jne 0xdc3b7
jmp 0xdc3bf
cmpq $0x0, 0x48(%rsp)
jne 0xdc3cd
movq $0x0, 0x60(%rsp)
jmp 0xdc4eb
movq $0x0, 0x40(%rsp)
movb $0x0, 0x3f(%rsp)
movb 0x3f(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xdc3ea
jmp 0xdc4d3
movq (%rsp), %rdi
movl $0xa, %esi
callq 0x7a390
movq (%rsp), %rdi
movq %rax, 0x30(%rsp)
callq 0x7c330
movq (%rsp), %rdi
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rax
addq $0x1, %rax
subq 0x40(%rsp), %rax
movq %rax, 0x18(%rsp)
callq 0x73cd0
movq %rax, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x74f40
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x48(%rsp), %rax
subq $0x1, %rax
subq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x74f40
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x50(%rsp), %rdi
addq 0x40(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x20(%rsp), %rdx
callq 0x757c0
movq (%rsp), %rdi
movq 0x20(%rsp), %rax
addq 0x40(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x20(%rsp), %rsi
callq 0x77250
movq 0x40(%rsp), %rax
movq 0x30(%rsp), %rcx
addq $0x1, %rcx
cmpq %rcx, %rax
jae 0xdc4c9
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rcx
subq $0x1, %rcx
cmpq %rcx, %rax
jb 0xdc4ce
movb $0x1, 0x3f(%rsp)
jmp 0xdc3db
movq 0x50(%rsp), %rax
movq 0x40(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x40(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
addq $0x68, %rsp
retq
nopw %cs:(%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocket_p.cpp
// Function: BamTools::Internal::TcpSocket::DisconnectFromHost()
void TcpSocket::DisconnectFromHost(void) {

    // close socket engine & delete
    if ( m_state == TcpSocket::ConnectedState )
        ResetSocketEngine();

    // reset connection state
//    m_localPort = 0;
    m_remotePort = 0;
//    m_localAddress.Clear();
    m_remoteAddress.Clear();
    m_hostName.clear();
    m_cachedSocketDescriptor = -1;

    // for future, make sure there's outgoing data that needs to be flushed
    m_readBuffer.Clear();
}

// Assembly:
subq $0x18, %rsp
movq %rdi, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpl $0x1, 0xfc(%rax)
jne 0xdfb06
movq 0x8(%rsp), %rdi
callq 0x787e0
movq 0x8(%rsp), %rdi
movw $0x0, 0x28(%rdi)
addq $0x30, %rdi
callq 0x7c220
movq 0x8(%rsp), %rdi
addq $0x8, %rdi
callq 0x78800
movq 0x8(%rsp), %rdi
movl $0xffffffff, 0x78(%rdi) # imm = 0xFFFFFFFF
addq $0x80, %rdi
callq 0x77c40
addq $0x18, %rsp
retq
nopw %cs:(%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocket_p.cpp
// Function: BamTools::Internal::TcpSocket::ResetSocketEngine()
void TcpSocket::ResetSocketEngine(void) {

    // shut down socket engine
    if ( m_engine ) {
        m_engine->Close();
        delete m_engine;
        m_engine = 0;
    }

    // reset our state & cached socket handle
    m_state = TcpSocket::UnconnectedState;
    m_cachedSocketDescriptor = -1;
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x70(%rax)
je 0xe0557
movq 0x8(%rsp), %rax
movq 0x70(%rax), %rdi
callq 0x76c70
movq 0x8(%rsp), %rax
movq 0x70(%rax), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0xe052f
movq (%rsp), %rdi
callq 0x7c9f0
jmp 0xe0526
movq (%rsp), %rdi
callq 0x764d0
movq 0x8(%rsp), %rax
movq $0x0, 0x70(%rax)
jmp 0xe0557
movq (%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x18(%rsp)
movl %eax, 0x14(%rsp)
callq 0x764d0
jmp 0xe0572
movq 0x8(%rsp), %rax
movl $0x0, 0xfc(%rax)
movl $0xffffffff, 0x78(%rax) # imm = 0xFFFFFFFF
addq $0x28, %rsp
retq
movq 0x18(%rsp), %rdi
callq 0x7b550
nopl (%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocket_p.cpp
// Function: BamTools::Internal::TcpSocket::Read(char*, unsigned int)
int64_t TcpSocket::Read(char* data, const unsigned int numBytes) {

    // if we have data in buffer, just return it
    if ( !m_readBuffer.IsEmpty() ) {
        const size_t bytesRead = m_readBuffer.Read(data, numBytes);
        return static_cast<int64_t>(bytesRead);
    }

    // otherwise, we'll need to fetch data from socket
    // first make sure we have a valid socket engine
    if ( m_engine == 0 ) {
        // TODO: set error string/state?
        return -1;
    }

    // fetch data from socket, return 0 for success, -1 for failure
    // since this should be called in a loop,
    // we'll pull the actual bytes from the buffer on next iteration
    const int64_t socketBytesRead = ReadFromSocket();
    if ( socketBytesRead < 0 ) {
        // TODO: set error string/state ?
        return -1;
    }

    // we should have data now in buffer, try to fetch requested amount
    // if nothing in buffer, we will return 0 bytes read (signals EOF reached)
    const size_t numBytesRead = m_readBuffer.Read(data, numBytes);
    return static_cast<int64_t>(numBytesRead);
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
movl %edx, 0x2c(%rsp)
movq 0x38(%rsp), %rdi
movq %rdi, 0x8(%rsp)
addq $0x80, %rdi
callq 0x74cf0
testb $0x1, %al
jne 0xe0729
movq 0x8(%rsp), %rdi
addq $0x80, %rdi
movq 0x30(%rsp), %rsi
movl 0x2c(%rsp), %eax
movl %eax, %edx
callq 0x72d80
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0xe078d
movq 0x8(%rsp), %rax
cmpq $0x0, 0x70(%rax)
jne 0xe0740
movq $-0x1, 0x40(%rsp)
jmp 0xe078d
movq 0x8(%rsp), %rdi
callq 0x78f30
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x18(%rsp)
jge 0xe0762
movq $-0x1, 0x40(%rsp)
jmp 0xe078d
movq 0x8(%rsp), %rdi
addq $0x80, %rdi
movq 0x30(%rsp), %rsi
movl 0x2c(%rsp), %eax
movl %eax, %edx
callq 0x72d80
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
addq $0x48, %rsp
retq
nopw (%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocket_p.cpp
// Function: BamTools::Internal::TcpSocket::ReadLine(char*, unsigned long)
int64_t TcpSocket::ReadLine(char* dest, size_t max) {

    // wait for buffer to contain line contents
    if ( !WaitForReadLine() ) {
        m_errorString = "TcpSocket::ReadLine - error waiting for read line";
        return -1;
    }

    // leave room for null term
    if ( max < 2 )
        return -1;
    --max;

    // read from buffer, handle newlines
    int64_t readSoFar = m_readBuffer.ReadLine(dest, max);
    if ( readSoFar && dest[readSoFar-1] == '\n' ) {

        // adjust for windows-style '\r\n'
        if ( readSoFar > 1 && dest[readSoFar-2] == '\r') {
            --readSoFar;
            dest[readSoFar-1] = '\n';
        }
    }

    // null terminate & return number of bytes read
    dest[readSoFar] = '\0';
    return readSoFar;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq 0x28(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x72410
testb $0x1, %al
jne 0xe0d0c
movq 0x8(%rsp), %rdi
addq $0x100, %rdi            # imm = 0x100
leaq 0xb7b9(%rip), %rsi      # 0xec4b2
callq 0x78d10
movq $-0x1, 0x30(%rsp)
jmp 0xe0dc8
cmpq $0x2, 0x18(%rsp)
jae 0xe0d22
movq $-0x1, 0x30(%rsp)
jmp 0xe0dc8
movq 0x8(%rsp), %rdi
movq 0x18(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x18(%rsp)
addq $0x80, %rdi
movq 0x20(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x7a250
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
je 0xe0db0
movq 0x20(%rsp), %rax
movq 0x10(%rsp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
jne 0xe0db0
cmpq $0x1, 0x10(%rsp)
jle 0xe0dae
movq 0x20(%rsp), %rax
movq 0x10(%rsp), %rcx
subq $0x2, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xd, %eax
jne 0xe0dae
movq 0x10(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rax
movq 0x10(%rsp), %rcx
subq $0x1, %rcx
movb $0xa, (%rax,%rcx)
jmp 0xe0db0
movq 0x20(%rsp), %rax
movq 0x10(%rsp), %rcx
movb $0x0, (%rax,%rcx)
movq 0x10(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocket_p.cpp
// Function: BamTools::Internal::TcpSocket::WaitForReadLine()
bool TcpSocket::WaitForReadLine(void) {

    // wait until we can read a line (will return immediately if already capable)
    while ( !CanReadLine() ) {
        if ( !ReadFromSocket() )
            return false;
    }

    // if we get here, success
    return true;
}

// Assembly:
subq $0x18, %rsp
movq %rdi, 0x8(%rsp)
movq 0x8(%rsp), %rax
movq %rax, (%rsp)
movq (%rsp), %rdi
callq 0x7b9e0
xorb $-0x1, %al
testb $0x1, %al
jne 0xe0e03
jmp 0xe0e1b
movq (%rsp), %rdi
callq 0x78f30
cmpq $0x0, %rax
jne 0xe0e19
movb $0x0, 0x17(%rsp)
jmp 0xe0e20
jmp 0xe0df2
movb $0x1, 0x17(%rsp)
movb 0x17(%rsp), %al
andb $0x1, %al
addq $0x18, %rsp
retq
nopl (%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocket_p.cpp
// Function: BamTools::Internal::TcpSocket::Write(char const*, unsigned int)
int64_t TcpSocket::Write(const char* data, const unsigned int numBytes) {

    // single-shot attempt at write (not buffered, just try to shove the data through socket)
    // this method purely exists to send 'small' HTTP requests/FTP commands from client to server

    // wait for our socket to be write-able
    bool timedOut;
    const bool isReadyWrite = m_engine->WaitForWrite(3000, &timedOut);

    // if ready, return number of bytes written
    if ( isReadyWrite )
        return m_engine->Write(data, numBytes);

    // otherwise, socket not ready for writing
    // set error string depending on reason & return failure
    if ( !timedOut ) {
        // TODO: get add'l error info from engine ??
        m_errorString = "TcpSocket::Write - timed out waiting for ready-write";
    }
    else {
        // TODO: get add'l error info from engine ??
        m_errorString = "TcpSocket::Write - error encountered while waiting for ready-write";
    }
    return -1;
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movl %edx, 0xc(%rsp)
movq 0x18(%rsp), %rax
movq %rax, (%rsp)
movq 0x70(%rax), %rdi
movl $0xbb8, %esi            # imm = 0xBB8
leaq 0xb(%rsp), %rdx
callq 0x73890
andb $0x1, %al
movb %al, 0xa(%rsp)
testb $0x1, 0xa(%rsp)
je 0xe0e8a
movq (%rsp), %rax
movq 0x70(%rax), %rdi
movq 0x10(%rsp), %rsi
movl 0xc(%rsp), %eax
movl %eax, %edx
callq 0x7abf0
movq %rax, 0x20(%rsp)
jmp 0xe0eca
testb $0x1, 0xb(%rsp)
jne 0xe0eaa
movq (%rsp), %rdi
addq $0x100, %rdi            # imm = 0x100
leaq 0xb641(%rip), %rsi      # 0xec4e4
callq 0x78d10
jmp 0xe0ec1
movq (%rsp), %rdi
addq $0x100, %rdi            # imm = 0x100
leaq 0xb65d(%rip), %rsi      # 0xec519
callq 0x78d10
movq $-0x1, 0x20(%rsp)
movq 0x20(%rsp), %rax
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)
nop
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocketEngine_p.cpp
// Function: BamTools::Internal::TcpSocketEngine::Close()
void TcpSocketEngine::Close(void) {

    // close socket if we have valid FD
    if ( m_socketDescriptor != -1 ) {
        nativeClose();
        m_socketDescriptor = -1;
    }

    // reset state
    m_socketState = TcpSocket::UnconnectedState;
//    m_localAddress.Clear();
    m_remoteAddress.Clear();
//    m_localPort = 0;
    m_remotePort = 0;
}

// Assembly:
subq $0x18, %rsp
movq %rdi, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpl $-0x1, (%rax)
je 0xe145d
movq 0x8(%rsp), %rdi
callq 0x7a380
movq 0x8(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rdi
movl $0x0, 0x50(%rdi)
addq $0x8, %rdi
callq 0x7c220
movq 0x8(%rsp), %rax
movw $0x0, 0x48(%rax)
addq $0x18, %rsp
retq
nopw %cs:(%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocketEngine_p.cpp
// Function: BamTools::Internal::TcpSocketEngine::Connect(BamTools::Internal::HostAddress const&, unsigned short)
bool TcpSocketEngine::Connect(const HostAddress& address, const uint16_t port) {

    // return failure if invalid FD or already connected
    if ( !IsValid() || (m_socketState == TcpSocket::ConnectedState) ) {
        // TODO: set error string
        return false;
    }

    // attempt to connect to host address on requested port
    if ( !nativeConnect(address, port) ) {
        // TODO: set error string
        return false;
    }

    // if successful, store remote host address port & return success
    // TODO: (later) fetch proxied remote & local host/port  here
    m_remoteAddress = address;
    m_remotePort    = port;
    return true;
}

// Assembly:
subq $0x28, %rsp
movw %dx, %ax
movq %rdi, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movw %ax, 0xe(%rsp)
movq 0x18(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x72350
testb $0x1, %al
jne 0xe14ba
jmp 0xe14c4
movq (%rsp), %rax
cmpl $0x1, 0x50(%rax)
jne 0xe14cb
movb $0x0, 0x27(%rsp)
jmp 0xe150d
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movzwl 0xe(%rsp), %edx
callq 0x7c400
testb $0x1, %al
jne 0xe14e9
movb $0x0, 0x27(%rsp)
jmp 0xe150d
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
addq $0x8, %rdi
callq 0x7a2b0
movq (%rsp), %rax
movw 0xe(%rsp), %cx
movw %cx, 0x48(%rax)
movb $0x1, 0x27(%rsp)
movb 0x27(%rsp), %al
andb $0x1, %al
addq $0x28, %rsp
retq
nopl (%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocketEngine_p.cpp
// Function: BamTools::Internal::TcpSocketEngine::Initialize(BamTools::Internal::HostAddress::NetworkProtocol)
bool TcpSocketEngine::Initialize(HostAddress::NetworkProtocol protocol) {

    // close current socket if we have one open
    if ( IsValid() )
        Close();

    // attempt to create new socket
    return nativeCreateSocket(protocol);
}

// Assembly:
subq $0x18, %rsp
movq %rdi, 0x10(%rsp)
movl %esi, 0xc(%rsp)
movq 0x10(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x72350
testb $0x1, %al
jne 0xe1601
jmp 0xe160a
movq (%rsp), %rdi
callq 0x76c70
movq (%rsp), %rdi
movl 0xc(%rsp), %esi
callq 0x791a0
andb $0x1, %al
addq $0x18, %rsp
retq
nop
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocketEngine_p.cpp
// Function: BamTools::Internal::TcpSocketEngine::NumBytesAvailable() const
int64_t TcpSocketEngine::NumBytesAvailable(void) const {

    // return 0 if socket FD is invalid
    if ( !IsValid() ) {
        // TODO: set error string
        return -1;
    }

    // otherwise check socket to see how much is ready
    return nativeNumBytesAvailable();
}

// Assembly:
subq $0x18, %rsp
movq %rdi, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x72350
testb $0x1, %al
jne 0xe1646
movq $-0x1, 0x10(%rsp)
jmp 0xe1654
movq (%rsp), %rdi
callq 0x72a10
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
addq $0x18, %rsp
retq
nop
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocketEngine_p.cpp
// Function: BamTools::Internal::TcpSocketEngine::Read(char*, unsigned long)
int64_t TcpSocketEngine::Read(char* dest, size_t max) {

    // return failure if can't read
    if ( !IsValid() || (m_socketState != TcpSocket::ConnectedState) )
        return -1;

    // otherwise return number of bytes read
    return nativeRead(dest, max);
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq 0x18(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x72350
testb $0x1, %al
jne 0xe1687
jmp 0xe1691
movq (%rsp), %rax
cmpl $0x1, 0x50(%rax)
je 0xe169c
movq $-0x1, 0x20(%rsp)
jmp 0xe16b4
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x7aaa0
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
addq $0x28, %rsp
retq
nop
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocketEngine_p.cpp
// Function: BamTools::Internal::TcpSocketEngine::WaitForRead(int, bool*)
bool TcpSocketEngine::WaitForRead(int msec, bool* timedOut) {

    // reset timedOut flag
    *timedOut = false;

    // need to wait for our socket to be ready to read
    const int ret = nativeSelect(msec, true);

    // if timed out
    if ( ret == 0 ) {
        *timedOut = true;
        m_socketError = TcpSocket::SocketTimeoutError;
        m_errorString = "socket timed out";
    }

    // return if any sockets available for reading
    return ( ret > 0 );
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movl %esi, 0x1c(%rsp)
movq %rdx, 0x10(%rsp)
movq 0x20(%rsp), %rdi
movq %rdi, (%rsp)
movq 0x10(%rsp), %rax
movb $0x0, (%rax)
movl 0x1c(%rsp), %esi
movl $0x1, %edx
callq 0x7ae90
movl %eax, 0xc(%rsp)
cmpl $0x0, 0xc(%rsp)
jne 0xe171f
movq (%rsp), %rdi
movq 0x10(%rsp), %rax
movb $0x1, (%rax)
movl $0x5, 0x4c(%rdi)
addq $0x58, %rdi
leaq 0xae42(%rip), %rsi      # 0xec55c
callq 0x78d10
cmpl $0x0, 0xc(%rsp)
setg %al
andb $0x1, %al
addq $0x28, %rsp
retq
nop
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocketEngine_p.cpp
// Function: BamTools::Internal::TcpSocketEngine::WaitForWrite(int, bool*)
bool TcpSocketEngine::WaitForWrite(int msec, bool* timedOut) {

    // reset timedOut flag
    *timedOut = false;

    // need to wait for our socket to be ready to write
    const int ret = nativeSelect(msec, false);

    // if timed out
    if ( ret == 0 ) {
        *timedOut = true;
        m_socketError = TcpSocket::SocketTimeoutError;
        m_errorString = "socket timed out";
    }

    // return if any sockets available for reading
    return ( ret > 0 );
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movl %esi, 0x1c(%rsp)
movq %rdx, 0x10(%rsp)
movq 0x20(%rsp), %rdi
movq %rdi, (%rsp)
movq 0x10(%rsp), %rax
movb $0x0, (%rax)
movl 0x1c(%rsp), %esi
xorl %edx, %edx
callq 0x7ae90
movl %eax, 0xc(%rsp)
cmpl $0x0, 0xc(%rsp)
jne 0xe178c
movq (%rsp), %rdi
movq 0x10(%rsp), %rax
movb $0x1, (%rax)
movl $0x5, 0x4c(%rdi)
addq $0x58, %rdi
leaq 0xadd5(%rip), %rsi      # 0xec55c
callq 0x78d10
cmpl $0x0, 0xc(%rsp)
setg %al
andb $0x1, %al
addq $0x28, %rsp
retq
nopl (%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocketEngine_p.cpp
// Function: BamTools::Internal::TcpSocketEngine::Write(char const*, unsigned long)
int64_t TcpSocketEngine::Write(const char* data, size_t length) {

    // return failure if can't write
    if ( !IsValid() || (m_socketState != TcpSocket::ConnectedState) ) {
        // TODO: set error string
        return -1;
    }

    // otherwise return number of bytes written
    return nativeWrite(data, length);
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x18(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdx, 0x8(%rsp)
movq 0x18(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x72350
testb $0x1, %al
jne 0xe17c7
jmp 0xe17d1
movq (%rsp), %rax
cmpl $0x1, 0x50(%rax)
je 0xe17dc
movq $-0x1, 0x20(%rsp)
jmp 0xe17f4
movq (%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %rdx
callq 0x78c50
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
addq $0x28, %rsp
retq
nop
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocketEngine_unix_p.cpp
// Function: BamTools::Internal::TcpSocketEngine::nativeCreateSocket(BamTools::Internal::HostAddress::NetworkProtocol)
bool TcpSocketEngine::nativeCreateSocket(HostAddress::NetworkProtocol protocol) {

    // get protocol value for requested protocol type
    const int protocolNum = ( (protocol == HostAddress::IPv6Protocol) ? AF_INET6
                                                                      : AF_INET );

    // attempt to create socket
    int socketFd = socket(protocolNum, SOCK_STREAM, IPPROTO_TCP);

    // if we fetched an invalid socket descriptor
    if ( socketFd <= 0 ) {

        // see what error we got
        switch ( errno ) {
            case EPROTONOSUPPORT:
            case EAFNOSUPPORT:
            case EINVAL:
                m_socketError = TcpSocket::UnsupportedSocketOperationError;
                m_errorString = "protocol not supported";
                break;
            case ENFILE:
            case EMFILE:
            case ENOBUFS:
            case ENOMEM:
                m_socketError = TcpSocket::SocketResourceError;
                m_errorString = "out of resources";
                break;
            case EACCES:
                m_socketError = TcpSocket::SocketAccessError;
                m_errorString = "permission denied";
                break;
            default:
                break;
        }

        // return failure
        return false;
    }

    // otherwise, store our socket FD & return success
    m_socketDescriptor = socketFd;
    return true;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movl %esi, 0x24(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x10(%rsp)
movl 0x24(%rsp), %edx
movl $0x2, %eax
movl $0xa, %ecx
cmpl $0x1, %edx
cmovel %ecx, %eax
movl %eax, 0x20(%rsp)
movl 0x20(%rsp), %edi
movl $0x1, %esi
movl $0x6, %edx
callq 0x721b0
movl %eax, 0x1c(%rsp)
cmpl $0x0, 0x1c(%rsp)
jg 0xe1bdb
callq 0x712b0
movl (%rax), %eax
movl %eax, 0xc(%rsp)
subl $0xc, %eax
je 0xe1b96
jmp 0xe1b33
movl 0xc(%rsp), %eax
subl $0xd, %eax
je 0xe1bb4
jmp 0xe1b3e
movl 0xc(%rsp), %eax
subl $0x16, %eax
je 0xe1b78
jmp 0xe1b49
movl 0xc(%rsp), %eax
addl $-0x17, %eax
subl $0x2, %eax
jb 0xe1b96
jmp 0xe1b57
movl 0xc(%rsp), %eax
subl $0x5d, %eax
je 0xe1b78
jmp 0xe1b62
movl 0xc(%rsp), %eax
subl $0x61, %eax
je 0xe1b78
jmp 0xe1b6d
movl 0xc(%rsp), %eax
subl $0x69, %eax
je 0xe1b96
jmp 0xe1bd2
movq 0x10(%rsp), %rdi
movl $0x7, 0x4c(%rdi)
addq $0x58, %rdi
leaq 0xaa54(%rip), %rsi      # 0xec5e3
callq 0x78d10
jmp 0xe1bd4
movq 0x10(%rsp), %rdi
movl $0x4, 0x4c(%rdi)
addq $0x58, %rdi
leaq 0xaa4d(%rip), %rsi      # 0xec5fa
callq 0x78d10
jmp 0xe1bd4
movq 0x10(%rsp), %rdi
movl $0x3, 0x4c(%rdi)
addq $0x58, %rdi
leaq 0xaa06(%rip), %rsi      # 0xec5d1
callq 0x78d10
jmp 0xe1bd4
jmp 0xe1bd4
movb $0x0, 0x37(%rsp)
jmp 0xe1beb
movq 0x10(%rsp), %rax
movl 0x1c(%rsp), %ecx
movl %ecx, (%rax)
movb $0x1, 0x37(%rsp)
movb 0x37(%rsp), %al
andb $0x1, %al
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocketEngine_unix_p.cpp
// Function: BamTools::Internal::TcpSocketEngine::nativeNumBytesAvailable() const
int64_t TcpSocketEngine::nativeNumBytesAvailable(void) const {

    // fetch number of bytes, return 0 on error
    int numBytes(0);
    if ( ioctl(m_socketDescriptor, FIONREAD, (char*)&numBytes) < 0 )
        return -1;
    return static_cast<int64_t>(numBytes);
}

// Assembly:
subq $0x18, %rsp
movq %rdi, 0x8(%rsp)
movq 0x8(%rsp), %rax
movl $0x0, 0x4(%rsp)
movl (%rax), %edi
movl $0x541b, %esi           # imm = 0x541B
leaq 0x4(%rsp), %rdx
movb $0x0, %al
callq 0x793c0
cmpl $0x0, %eax
jge 0xe1c39
movq $-0x1, 0x10(%rsp)
jmp 0xe1c43
movslq 0x4(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
addq $0x18, %rsp
retq
nopl (%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/io/TcpSocketEngine_unix_p.cpp
// Function: BamTools::Internal::TcpSocketEngine::nativeSelect(int, bool) const
int TcpSocketEngine::nativeSelect(int msecs, bool isRead) const {

    // set up FD set
    fd_set fds;
    FD_ZERO(&fds);
    FD_SET(m_socketDescriptor, &fds);

    // setup our timeout
    timeval tv;
    tv.tv_sec  = msecs / 1000;
    tv.tv_usec = (msecs % 1000) * 1000;

    // do 'select'
    if ( isRead )
        return select(m_socketDescriptor + 1, &fds, 0, 0, (msecs < 0 ? 0 : &tv));
    else
        return select(m_socketDescriptor + 1, 0, &fds, 0, (msecs < 0 ? 0 : &tv));
}

// Assembly:
subq $0xe8, %rsp
movb %dl, %al
movq %rdi, 0xd8(%rsp)
movl %esi, 0xd4(%rsp)
andb $0x1, %al
movb %al, 0xd3(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpq $0x10, %rax
jae 0xe1cf8
movq 0x40(%rsp), %rax
movl 0x4c(%rsp), %ecx
movq $0x0, (%rax,%rcx,8)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0xe1cd0
jmp 0xe1cfa
movq 0x28(%rsp), %rax
movl (%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq 0x28(%rsp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
movl (%rax), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
orq 0x50(%rsp,%rax,8), %rcx
movq %rcx, 0x50(%rsp,%rax,8)
movl 0xd4(%rsp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
cltd
idivl %ecx
cltq
movq %rax, 0x30(%rsp)
movl 0xd4(%rsp), %eax
movl $0x3e8, %ecx            # imm = 0x3E8
cltd
idivl %ecx
imull $0x3e8, %edx, %eax      # imm = 0x3E8
cltq
movq %rax, 0x38(%rsp)
testb $0x1, 0xd3(%rsp)
je 0xe1dbd
movq 0x28(%rsp), %rax
movl (%rax), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
cmpl $0x0, 0xd4(%rsp)
jge 0xe1d8e
xorl %eax, %eax
movq %rax, 0x18(%rsp)
jmp 0xe1d9a
leaq 0x30(%rsp), %rax
movq %rax, 0x18(%rsp)
jmp 0xe1d9a
movl 0x24(%rsp), %edi
movq 0x18(%rsp), %r8
leaq 0x50(%rsp), %rsi
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, %rdx
callq 0x76510
movl %eax, 0xe4(%rsp)
jmp 0xe1e0b
movq 0x28(%rsp), %rax
movl (%rax), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
cmpl $0x0, 0xd4(%rsp)
jge 0xe1dde
xorl %eax, %eax
movq %rax, 0x8(%rsp)
jmp 0xe1dea
leaq 0x30(%rsp), %rax
movq %rax, 0x8(%rsp)
jmp 0xe1dea
movl 0x14(%rsp), %edi
movq 0x8(%rsp), %r8
xorl %eax, %eax
movl %eax, %ecx
leaq 0x50(%rsp), %rdx
movq %rcx, %rsi
callq 0x76510
movl %eax, 0xe4(%rsp)
movl 0xe4(%rsp), %eax
addq $0xe8, %rsp
retq
nopw (%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/sam/SamFormatParser_p.cpp
// Function: BamTools::Internal::SamFormatParser::Parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void SamFormatParser::Parse(const string& headerText) {

    // clear header's prior contents
    m_header.Clear();

    // empty header is OK, but skip processing
    if ( headerText.empty() )
        return;

    // other wise parse SAM lines
    istringstream headerStream(headerText);
    string headerLine("");
    while ( getline(headerStream, headerLine) )
         ParseSamLine(headerLine);
}

// Assembly:
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rdi, 0x1e0(%rsp)
movq %rsi, 0x1d8(%rsp)
movq 0x1e0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq (%rax), %rdi
callq 0x7c7f0
movq 0x1d8(%rsp), %rdi
callq 0x7aba0
testb $0x1, %al
jne 0xe1ecf
jmp 0xe1ed4
jmp 0xe1fb3
movq 0x1d8(%rsp), %rsi
leaq 0x58(%rsp), %rdi
movl $0x8, %edx
callq 0x7ad80
leaq 0x37(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x7b5f0
movq 0x10(%rsp), %rdx
leaq 0x91d6(%rip), %rsi      # 0xeb0dc
leaq 0x38(%rsp), %rdi
callq 0x78e70
jmp 0xe1f12
leaq 0x37(%rsp), %rdi
callq 0x76f80
leaq 0x58(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x71a40
movq %rax, 0x8(%rsp)
jmp 0xe1f32
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x7a210
movq %rax, (%rsp)
jmp 0xe1f4c
movq (%rsp), %rax
cmpq $0x0, %rax
je 0xe1f9d
movq 0x18(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x77850
jmp 0xe1f67
jmp 0xe1f1c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x28(%rsp)
movl %eax, 0x24(%rsp)
leaq 0x37(%rsp), %rdi
callq 0x76f80
jmp 0xe1fcd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x28(%rsp)
movl %eax, 0x24(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x7cce8
jmp 0xe1fcb
leaq 0x38(%rsp), %rdi
callq 0x7cce8
jmp 0xe1fa9
leaq 0x58(%rsp), %rdi
callq 0x734f0
addq $0x1e8, %rsp            # imm = 0x1E8
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x28(%rsp)
movl %eax, 0x24(%rsp)
jmp 0xe1fcd
jmp 0xe1fcd
leaq 0x58(%rsp), %rdi
callq 0x734f0
jmp 0xe1fd9
jmp 0xe1fdb
movq 0x28(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopl (%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/sam/SamFormatParser_p.cpp
// Function: BamTools::Internal::SamFormatParser::ParseSamLine(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void SamFormatParser::ParseSamLine(const string& line) {

    // skip if line is not long enough to contain true values
    if ( line.length() < 5 ) return;

    // determine token at beginning of line
    const string firstToken = line.substr(0,3);
    const string restOfLine = line.substr(4);
    if      ( firstToken == Constants::SAM_HD_BEGIN_TOKEN) ParseHDLine(restOfLine);
    else if ( firstToken == Constants::SAM_SQ_BEGIN_TOKEN) ParseSQLine(restOfLine);
    else if ( firstToken == Constants::SAM_RG_BEGIN_TOKEN) ParseRGLine(restOfLine);
    else if ( firstToken == Constants::SAM_PG_BEGIN_TOKEN) ParsePGLine(restOfLine);
    else if ( firstToken == Constants::SAM_CO_BEGIN_TOKEN) ParseCOLine(restOfLine);
}

// Assembly:
subq $0x78, %rsp
movq %rdi, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x68(%rsp), %rdi
callq 0x79c80
cmpq $0x5, %rax
jae 0xe201d
jmp 0xe21aa
movq 0x68(%rsp), %rsi
xorl %eax, %eax
movl %eax, %edx
leaq 0x48(%rsp), %rdi
movl $0x3, %ecx
callq 0x76c50
movq 0x68(%rsp), %rsi
leaq 0x28(%rsp), %rdi
movl $0x4, %edx
movq $-0x1, %rcx
callq 0x76c50
jmp 0xe2052
leaq 0x36eaf(%rip), %rsi     # 0x118f08
leaq 0x48(%rsp), %rdi
callq 0x74120
movb %al, 0xf(%rsp)
jmp 0xe2069
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0xe2073
jmp 0xe20b9
movq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x74260
jmp 0xe2084
jmp 0xe2194
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x20(%rsp)
movl %eax, 0x1c(%rsp)
jmp 0xe21b1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x20(%rsp)
movl %eax, 0x1c(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x7cce8
jmp 0xe21af
leaq 0x36ec8(%rip), %rsi     # 0x118f88
leaq 0x48(%rsp), %rdi
callq 0x74120
movb %al, 0xe(%rsp)
jmp 0xe20d0
movb 0xe(%rsp), %al
testb $0x1, %al
jne 0xe20da
jmp 0xe20f0
movq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x7bae0
jmp 0xe20eb
jmp 0xe2192
leaq 0x36f71(%rip), %rsi     # 0x119068
leaq 0x48(%rsp), %rdi
callq 0x74120
movb %al, 0xd(%rsp)
jmp 0xe2107
movb 0xd(%rsp), %al
testb $0x1, %al
jne 0xe2111
jmp 0xe2124
movq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x723a0
jmp 0xe2122
jmp 0xe2190
leaq 0x370dd(%rip), %rsi     # 0x119208
leaq 0x48(%rsp), %rdi
callq 0x74120
movb %al, 0xc(%rsp)
jmp 0xe213b
movb 0xc(%rsp), %al
testb $0x1, %al
jne 0xe2145
jmp 0xe2158
movq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x74290
jmp 0xe2156
jmp 0xe218e
leaq 0x37169(%rip), %rsi     # 0x1192c8
leaq 0x48(%rsp), %rdi
callq 0x74120
movb %al, 0xb(%rsp)
jmp 0xe216f
movb 0xb(%rsp), %al
testb $0x1, %al
jne 0xe2179
jmp 0xe218c
movq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x71610
jmp 0xe218a
jmp 0xe218c
jmp 0xe218e
jmp 0xe2190
jmp 0xe2192
jmp 0xe2194
leaq 0x28(%rsp), %rdi
callq 0x7cce8
jmp 0xe21a0
leaq 0x48(%rsp), %rdi
callq 0x7cce8
addq $0x78, %rsp
retq
jmp 0xe21b1
leaq 0x48(%rsp), %rdi
callq 0x7cce8
jmp 0xe21bd
jmp 0xe21bf
movq 0x20(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopw %cs:(%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/sam/SamFormatParser_p.cpp
// Function: BamTools::Internal::SamFormatParser::Split(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, char)
const vector<string> SamFormatParser::Split(const string& line, const char delim) {
    vector<string> tokens;
    stringstream lineStream(line);
    string token;
    while ( getline(lineStream, token, delim) )
        tokens.push_back(token);
    return tokens;
}

// Assembly:
subq $0x208, %rsp            # imm = 0x208
movq %rdi, 0x10(%rsp)
movb %cl, %al
movq %rdi, %rcx
movq %rcx, 0x18(%rsp)
movq %rdi, 0x200(%rsp)
movq %rsi, 0x1f8(%rsp)
movq %rdx, 0x1f0(%rsp)
movb %al, 0x1ef(%rsp)
movb $0x0, 0x1ee(%rsp)
callq 0x7b6e0
movq 0x1f0(%rsp), %rax
movq %rax, 0x20(%rsp)
movl $0x10, %edi
movl $0x8, %esi
callq 0x7b8d0
movl %eax, 0x2c(%rsp)
jmp 0xe3bd4
movl 0x2c(%rsp), %edx
movq 0x20(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0x7a4b0
jmp 0xe3be9
leaq 0x30(%rsp), %rdi
callq 0x79100
jmp 0xe3bf5
jmp 0xe3bf7
movsbl 0x1ef(%rsp), %edx
leaq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x7be00
movq %rax, 0x8(%rsp)
jmp 0xe3c15
movq 0x8(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x7a210
movq %rax, (%rsp)
jmp 0xe3c2f
movq (%rsp), %rax
cmpq $0x0, %rax
je 0xe3c86
movq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0x73a70
jmp 0xe3c4a
jmp 0xe3bf7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0xe3cd9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
jmp 0xe3cb4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x58(%rsp)
movl %eax, 0x54(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x7cce8
jmp 0xe3ca6
movb $0x1, 0x1ee(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x7cce8
jmp 0xe3c9a
leaq 0x60(%rsp), %rdi
callq 0x74f60
jmp 0xe3ca8
jmp 0xe3cb4
testb $0x1, 0x1ee(%rsp)
jne 0xe3ccc
jmp 0xe3cc2
leaq 0x60(%rsp), %rdi
callq 0x74f60
jmp 0xe3cc0
jmp 0xe3cd9
movq 0x10(%rsp), %rdi
callq 0x74e60
movq 0x18(%rsp), %rax
addq $0x208, %rsp            # imm = 0x208
retq
movq 0x10(%rsp), %rdi
callq 0x74e60
jmp 0xe3ce5
jmp 0xe3ce7
movq 0x58(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopl (%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/sam/SamFormatPrinter_p.cpp
// Function: BamTools::Internal::SamFormatPrinter::ToString[abi:cxx11]() const
const string SamFormatPrinter::ToString(void) const {

    // clear out stream
    stringstream out("");

    // generate formatted header text
    PrintHD(out);
    PrintSQ(out);
    PrintRG(out);
    PrintPG(out);
    PrintCO(out);

    // return result
    return out.str();
}

// Assembly:
subq $0x1f8, %rsp            # imm = 0x1F8
movq %rdi, 0x8(%rsp)
movq %rdi, %rax
movq %rax, 0x10(%rsp)
movq %rdi, 0x1f0(%rsp)
movq %rsi, 0x1e8(%rsp)
movq 0x1e8(%rsp), %rax
movq %rax, 0x18(%rsp)
leaq 0x3f(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x7b5f0
movq 0x20(%rsp), %rdx
leaq 0x6c40(%rip), %rsi      # 0xeb0dc
leaq 0x40(%rsp), %rdi
callq 0x78e70
jmp 0xe44a8
movl $0x10, %edi
movl $0x8, %esi
callq 0x7b8d0
movl %eax, 0x4(%rsp)
jmp 0xe44bd
movl 0x4(%rsp), %edx
leaq 0x60(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0x7a4b0
jmp 0xe44d2
leaq 0x40(%rsp), %rdi
callq 0x7cce8
jmp 0xe44de
leaq 0x3f(%rsp), %rdi
callq 0x76f80
movq 0x18(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x7b930
jmp 0xe44f9
movq 0x18(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x7c970
jmp 0xe450a
movq 0x18(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x7b6b0
jmp 0xe451b
movq 0x18(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x7c730
jmp 0xe452c
movq 0x18(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x73c50
jmp 0xe453d
movq 0x8(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x76880
jmp 0xe454e
leaq 0x60(%rsp), %rdi
callq 0x74f60
movq 0x10(%rsp), %rax
addq $0x1f8, %rsp            # imm = 0x1F8
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
jmp 0xe4591
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x7cce8
jmp 0xe458f
jmp 0xe4591
leaq 0x3f(%rsp), %rdi
callq 0x76f80
jmp 0xe45b9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x30(%rsp)
movl %eax, 0x2c(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x74f60
jmp 0xe45b7
jmp 0xe45b9
movq 0x30(%rsp), %rdi
callq 0x7b550
movq %rax, %rdi
callq 0x88ef0
nopl (%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/sam/SamFormatPrinter_p.cpp
// Function: BamTools::Internal::SamFormatPrinter::PrintCO(std::__cxx11::basic_stringstream<char, std::char_traits<char>, std::allocator<char>>&) const
void SamFormatPrinter::PrintCO(std::stringstream& out) const {

    // iterate over comments
    vector<string>::const_iterator commentIter = m_header.Comments.begin();
    vector<string>::const_iterator commentEnd  = m_header.Comments.end();
    for ( ; commentIter != commentEnd; ++commentIter ) {

        // @CO <Comment>
        out << Constants::SAM_CO_BEGIN_TOKEN
            << Constants::SAM_TAB
            << (*commentIter)
            << endl;
    }
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x10(%rsp)
movq (%rax), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x71c40
movq %rax, %rcx
movq 0x10(%rsp), %rax
movq %rcx, 0x20(%rsp)
movq (%rax), %rdi
addq $0x120, %rdi            # imm = 0x120
callq 0x74ae0
movq %rax, 0x18(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x750f0
testb $0x1, %al
jne 0xe5c2d
jmp 0xe5c86
movq 0x28(%rsp), %rdi
addq $0x10, %rdi
leaq 0x33c73(%rip), %rsi     # 0x1198b0
callq 0x75e40
movq %rax, %rdi
movl $0x9, %esi
callq 0x779c0
movq %rax, 0x8(%rsp)
leaq 0x20(%rsp), %rdi
callq 0x71410
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x75e40
movq %rax, %rdi
movq 0x2c2a3(%rip), %rsi     # 0x111f18
callq 0x76cc0
leaq 0x20(%rsp), %rdi
callq 0x75880
jmp 0xe5c18
addq $0x38, %rsp
retq
nopl (%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/sam/SamHeaderValidator_p.cpp
// Function: BamTools::Internal::SamHeaderValidator::PrintErrorMessages(std::ostream&)
void SamHeaderValidator::PrintErrorMessages(ostream& stream) {

    // skip if no error messages
    if ( m_errorMessages.empty() )
        return;

    // print error header line
    stream << "* SAM header has " << m_errorMessages.size() << " errors:" << endl;

    // print each error message
    vector<string>::const_iterator errorIter = m_errorMessages.begin();
    vector<string>::const_iterator errorEnd  = m_errorMessages.end();
    for ( ; errorIter != errorEnd; ++errorIter )
        stream << (*errorIter);
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq 0x40(%rsp), %rdi
movq %rdi, 0x10(%rsp)
addq $0x8, %rdi
callq 0x7b320
testb $0x1, %al
jne 0xe6207
jmp 0xe620c
jmp 0xe62df
movq 0x38(%rsp), %rdi
leaq 0x6500(%rip), %rsi      # 0xec718
callq 0x768e0
movq 0x10(%rsp), %rdi
movq %rax, 0x8(%rsp)
addq $0x8, %rdi
callq 0x7bb00
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x720a0
movq %rax, %rdi
leaq 0x64e3(%rip), %rsi      # 0xec72a
callq 0x768e0
movq %rax, %rdi
movq 0x2bcc2(%rip), %rsi     # 0x111f18
callq 0x76cc0
movq 0x10(%rsp), %rdi
addq $0x8, %rdi
callq 0x7aa40
movq %rax, 0x28(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x76ee0
movq 0x10(%rsp), %rdi
addq $0x8, %rdi
callq 0x7ad60
movq %rax, 0x18(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x76ee0
leaq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x750f0
testb $0x1, %al
jne 0xe62b4
jmp 0xe62df
movq 0x38(%rsp), %rax
movq %rax, (%rsp)
leaq 0x30(%rsp), %rdi
callq 0x71410
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x75e40
leaq 0x30(%rsp), %rdi
callq 0x75880
jmp 0xe629f
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/sam/SamHeaderValidator_p.cpp
// Function: BamTools::Internal::SamHeaderValidator::PrintWarningMessages(std::ostream&)
void SamHeaderValidator::PrintWarningMessages(ostream& stream) {

    // skip if no warning messages
    if ( m_warningMessages.empty() )
        return;

    // print warning header line
    stream << "* SAM header has " << m_warningMessages.size() << " warnings:" << endl;

    // print each warning message
    vector<string>::const_iterator warnIter = m_warningMessages.begin();
    vector<string>::const_iterator warnEnd  = m_warningMessages.end();
    for ( ; warnIter != warnEnd; ++warnIter )
        stream << (*warnIter);
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movq 0x40(%rsp), %rdi
movq %rdi, 0x10(%rsp)
addq $0x20, %rdi
callq 0x7b320
testb $0x1, %al
jne 0xe6357
jmp 0xe635c
jmp 0xe642f
movq 0x38(%rsp), %rdi
leaq 0x63b0(%rip), %rsi      # 0xec718
callq 0x768e0
movq 0x10(%rsp), %rdi
movq %rax, 0x8(%rsp)
addq $0x20, %rdi
callq 0x7bb00
movq 0x8(%rsp), %rdi
movq %rax, %rsi
callq 0x720a0
movq %rax, %rdi
leaq 0x639c(%rip), %rsi      # 0xec733
callq 0x768e0
movq %rax, %rdi
movq 0x2bb72(%rip), %rsi     # 0x111f18
callq 0x76cc0
movq 0x10(%rsp), %rdi
addq $0x20, %rdi
callq 0x7aa40
movq %rax, 0x28(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x76ee0
movq 0x10(%rsp), %rdi
addq $0x20, %rdi
callq 0x7ad60
movq %rax, 0x18(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x76ee0
leaq 0x30(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x750f0
testb $0x1, %al
jne 0xe6404
jmp 0xe642f
movq 0x38(%rsp), %rax
movq %rax, (%rsp)
leaq 0x30(%rsp), %rdi
callq 0x71410
movq (%rsp), %rdi
movq %rax, %rsi
callq 0x75e40
leaq 0x30(%rsp), %rdi
callq 0x75880
jmp 0xe63ef
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/sam/SamHeaderValidator_p.cpp
// Function: BamTools::Internal::SamHeaderValidator::Validate()
bool SamHeaderValidator::Validate(void) {
    bool isValid = true;
    isValid &= ValidateMetadata();
    isValid &= ValidateSequenceDictionary();
    isValid &= ValidateReadGroupDictionary();
    isValid &= ValidateProgramChain();
    return isValid;
}

// Assembly:
subq $0x18, %rsp
movq %rdi, 0x10(%rsp)
movq 0x10(%rsp), %rdi
movq %rdi, (%rsp)
movb $0x1, 0xf(%rsp)
callq 0x77d10
movq (%rsp), %rdi
andb $0x1, %al
movzbl %al, %ecx
movb 0xf(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0xf(%rsp)
callq 0x746c0
movq (%rsp), %rdi
andb $0x1, %al
movzbl %al, %ecx
movb 0xf(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0xf(%rsp)
callq 0x71170
movq (%rsp), %rdi
andb $0x1, %al
movzbl %al, %ecx
movb 0xf(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0xf(%rsp)
callq 0x74560
andb $0x1, %al
movzbl %al, %ecx
movb 0xf(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
andb $0x1, %al
addq $0x18, %rsp
retq
nopw %cs:(%rax,%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/sam/SamHeaderValidator_p.cpp
// Function: BamTools::Internal::SamHeaderValidator::ValidateMetadata()
bool SamHeaderValidator::ValidateMetadata(void) {
    bool isValid = true;
    isValid &= ValidateVersion();
    isValid &= ValidateSortOrder();
    isValid &= ValidateGroupOrder();
    return isValid;
}

// Assembly:
subq $0x18, %rsp
movq %rdi, 0x10(%rsp)
movq 0x10(%rsp), %rdi
movq %rdi, (%rsp)
movb $0x1, 0xf(%rsp)
callq 0x7af70
movq (%rsp), %rdi
andb $0x1, %al
movzbl %al, %ecx
movb 0xf(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0xf(%rsp)
callq 0x7bd40
movq (%rsp), %rdi
andb $0x1, %al
movzbl %al, %ecx
movb 0xf(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0xf(%rsp)
callq 0x78070
andb $0x1, %al
movzbl %al, %ecx
movb 0xf(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
andb $0x1, %al
addq $0x18, %rsp
retq
nopl (%rax)
// File: zeeev[P]DASVC/bamtools/src/api/internal/sam/SamHeaderValidator_p.cpp
// Function: BamTools::Internal::SamHeaderValidator::ValidateSequenceDictionary()
bool SamHeaderValidator::ValidateSequenceDictionary(void) {

    bool isValid = true;

    // check for unique sequence names
    isValid &= ContainsUniqueSequenceNames();

    // iterate over sequences
    const SamSequenceDictionary& sequences = m_header.Sequences;
    SamSequenceConstIterator seqIter = sequences.ConstBegin();
    SamSequenceConstIterator seqEnd  = sequences.ConstEnd();
    for ( ; seqIter != seqEnd; ++seqIter ) {
        const SamSequence& seq = (*seqIter);
        isValid &= ValidateSequence(seq);
    }

    // return validation state
    return isValid;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq 0x30(%rsp), %rdi
movq %rdi, (%rsp)
movb $0x1, 0x2f(%rsp)
callq 0x75a60
movb %al, %cl
movq (%rsp), %rax
andb $0x1, %cl
movzbl %cl, %edx
movb 0x2f(%rsp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %edx, %ecx
cmpl $0x0, %ecx
setne %cl
andb $0x1, %cl
movb %cl, 0x2f(%rsp)
movq (%rax), %rax
addq $0x78, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
callq 0x79d20
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rdi
callq 0x7bfb0
movq %rax, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x75e90
testb $0x1, %al
jne 0xe6610
jmp 0xe6655
leaq 0x18(%rsp), %rdi
callq 0x767c0
movq (%rsp), %rdi
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rsi
callq 0x76160
andb $0x1, %al
movzbl %al, %ecx
movb 0x2f(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0x2f(%rsp)
leaq 0x18(%rsp), %rdi
callq 0x76200
jmp 0xe65fb
movb 0x2f(%rsp), %al
andb $0x1, %al
addq $0x38, %rsp
retq
// File: zeeev[P]DASVC/bamtools/src/api/internal/sam/SamHeaderValidator_p.cpp
// Function: BamTools::Internal::SamHeaderValidator::ValidateReadGroupDictionary()
bool SamHeaderValidator::ValidateReadGroupDictionary(void) {

    bool isValid = true;

    // check for unique read group IDs & platform units
    isValid &= ContainsUniqueIDsAndPlatformUnits();

    // iterate over read groups
    const SamReadGroupDictionary& readGroups = m_header.ReadGroups;
    SamReadGroupConstIterator rgIter = readGroups.ConstBegin();
    SamReadGroupConstIterator rgEnd  = readGroups.ConstEnd();
    for ( ; rgIter != rgEnd; ++rgIter ) {
        const SamReadGroup& rg = (*rgIter);
        isValid &= ValidateReadGroup(rg);
    }

    // return validation state
    return isValid;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq 0x30(%rsp), %rdi
movq %rdi, (%rsp)
movb $0x1, 0x2f(%rsp)
callq 0x728e0
movb %al, %cl
movq (%rsp), %rax
andb $0x1, %cl
movzbl %cl, %edx
movb 0x2f(%rsp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
andl %edx, %ecx
cmpl $0x0, %ecx
setne %cl
andb $0x1, %cl
movb %cl, 0x2f(%rsp)
movq (%rax), %rax
addq $0xc0, %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
callq 0x7ab20
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rdi
callq 0x7b990
movq %rax, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x736e0
testb $0x1, %al
jne 0xe66e2
jmp 0xe6727
leaq 0x18(%rsp), %rdi
callq 0x737d0
movq (%rsp), %rdi
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rsi
callq 0x78ec0
andb $0x1, %al
movzbl %al, %ecx
movb 0x2f(%rsp), %al
andb $0x1, %al
movzbl %al, %eax
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, 0x2f(%rsp)
leaq 0x18(%rsp), %rdi
callq 0x7aa70
jmp 0xe66cd
movb 0x2f(%rsp), %al
andb $0x1, %al
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)