// File: /workspace/github_cpp_makefile_star2_O2/zeeev[P]DASVC/bamtools/src/api/internal/io/BamFtp_p.cpp
// Function: BamTools::Internal::BamFtp::ConnectDataSocket()
bool BamFtp::ConnectDataSocket(void) {

    // failure if can't connect to command socket first
    if ( !m_commandSocket->IsConnected() ) {
        if ( !ConnectCommandSocket() )
            return false;
    }

    // make sure we're starting with a fresh data channel
    if ( m_dataSocket->IsConnected() )
        m_dataSocket->DisconnectFromHost();

    // send passive connection command
    const string passiveCommand = PASV_CMD + FTP_NEWLINE;
    if ( !SendCommand(passiveCommand, true) ) {
        // TODO: set error string
        return false;
    }

    // retrieve passive connection port
    if ( !ParsePassiveResponse() ) {
        // TODO: set error string
        return false;
    }

    // set up restart command (tell server where to start fetching bytes from)
    if ( m_filePosition >= 0 ) {

        stringstream fpStream("");
        fpStream << m_filePosition;
        string restartCommand = REST_CMD + CMD_SEPARATOR + fpStream.str() + FTP_NEWLINE;
        if ( !SendCommand(restartCommand, true) ) {
            // TODO: set error string
            return false;
        }
    }

    // main file retrieval request
    string retrieveCommand = RETR_CMD + CMD_SEPARATOR + m_filename + FTP_NEWLINE;
    if ( !SendCommand(retrieveCommand, false) ) {
        // TODO: set error string
        return false;
    }

    // make data channel connection
    if ( !m_dataSocket->ConnectToHost(m_dataHostname, m_dataPort) ) {
        // TODO: set error string
        return false;
    }

    // fetch intial reply from server
    if ( !ReceiveReply() ) {
        // TODO: set error string
        m_dataSocket->DisconnectFromHost();
        return false;
    }

    // make sure we have reply code 150 (all good)
    if ( !startsWith(m_response, "150") ) {
        // TODO: set error string
        m_dataSocket->DisconnectFromHost();
        return false;
    }

    // return success
    return true;
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x230, %rsp            # imm = 0x230
movq %rdi, %rbx
movq 0x30(%rdi), %rdi
callq 0x32cf0
testb %al, %al
jne 0x4e04f
movq %rbx, %rdi
callq 0x31520
testb %al, %al
je 0x4e29a
movq 0x38(%rbx), %rdi
callq 0x32cf0
testb %al, %al
je 0x4e065
movq 0x38(%rbx), %rdi
callq 0x34f10
leaq 0x2a18c(%rip), %rsi     # 0x781f8
leaq 0x2a0c5(%rip), %rdx     # 0x78138
leaq 0x88(%rsp), %r14
movq %r14, %rdi
callq 0x355e0
pushq $0x1
popq %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x34370
testb %al, %al
je 0x4e289
movq %rbx, %rdi
callq 0x33210
testb %al, %al
je 0x4e289
cmpq $0x0, 0x118(%rbx)
js 0x4e1a0
leaq 0xdda6(%rip), %rsi      # 0x5be64
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x31b30
leaq 0xa8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
pushq $0x18
popq %rdx
callq 0x34880
leaq 0x8(%rsp), %rdi
callq 0x33a00
leaq 0xb8(%rsp), %rdi
movq 0x118(%rbx), %rsi
callq 0x32fb0
leaq 0x2a131(%rip), %rsi     # 0x78238
leaq 0x68(%rsp), %rdi
pushq $0x20
popq %rdx
callq 0x32560
leaq 0xc0(%rsp), %rsi
leaq 0x48(%rsp), %rdi
callq 0x34870
leaq 0x28(%rsp), %rdi
leaq 0x68(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x355e0
leaq 0x29ff7(%rip), %rdx     # 0x78138
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x355e0
leaq 0x28(%rsp), %rdi
callq 0x33a00
leaq 0x48(%rsp), %rdi
callq 0x33a00
leaq 0x68(%rsp), %rdi
callq 0x33a00
leaq 0x8(%rsp), %rsi
pushq $0x1
popq %rdx
movq %rbx, %rdi
callq 0x34370
movl %eax, %ebp
leaq 0x8(%rsp), %rdi
callq 0x33a00
leaq 0xa8(%rsp), %rdi
callq 0x32870
testb %bpl, %bpl
je 0x4e289
leaq 0x2a0b1(%rip), %rsi     # 0x78258
leaq 0x28(%rsp), %rdi
pushq $0x20
popq %rdx
callq 0x32560
leaq 0x90(%rbx), %rdx
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x355e0
leaq 0x29f67(%rip), %rdx     # 0x78138
leaq 0xa8(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x355e0
leaq 0x8(%rsp), %rdi
callq 0x33a00
leaq 0x28(%rsp), %rdi
callq 0x33a00
leaq 0xa8(%rsp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x34370
testb %al, %al
je 0x4e278
movq 0x38(%rbx), %rdi
leaq 0x68(%rbx), %rsi
movzwl 0x88(%rbx), %edx
pushq $0x1
popq %rcx
callq 0x33cf0
testb %al, %al
je 0x4e278
movq %rbx, %rdi
callq 0x33760
testb %al, %al
je 0x4e26f
leaq 0xe7bf(%rip), %rsi      # 0x5c9fa
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x31b30
leaq 0xf0(%rbx), %rdi
leaq 0x8(%rsp), %rsi
xorl %edx, %edx
callq 0x35770
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x33a00
testq %r14, %r14
je 0x4e2aa
movq 0x38(%rbx), %rdi
callq 0x34f10
xorl %ebx, %ebx
leaq 0xa8(%rsp), %rdi
callq 0x33a00
jmp 0x4e28b
xorl %ebx, %ebx
leaq 0x88(%rsp), %rdi
callq 0x33a00
jmp 0x4e29c
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x230, %rsp            # imm = 0x230
popq %rbx
popq %r14
popq %rbp
retq
movb $0x1, %bl
jmp 0x4e27a
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x4e33b
jmp 0x4e338
jmp 0x4e35b
jmp 0x4e306
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x4e327
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x33a00
jmp 0x4e313
jmp 0x4e306
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x4e35e
jmp 0x4e35b
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x33a00
jmp 0x4e34f
movq %rax, %rbx
jmp 0x4e327
movq %rax, %rbx
jmp 0x4e31d
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x33a00
leaq 0x68(%rsp), %rdi
callq 0x33a00
leaq 0xa8(%rsp), %rdi
callq 0x32870
jmp 0x4e35e
jmp 0x4e35b
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x33a00
jmp 0x4e35e
jmp 0x4e35b
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x33a00
jmp 0x4e35e
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x33a00
movq %rbx, %rdi
callq 0x34ed0
movq %rax, %rdi
callq 0x39b2f
nop