// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdi, %rbx
movq 0x30(%rdi), %rdi
callq 0x27370
testb %al, %al
jne 0x46575
movq %rbx, %rdi
callq 0x26380
testb %al, %al
je 0x46863
movq 0x38(%rbx), %rdi
callq 0x27370
testb %al, %al
je 0x4658b
movq 0x38(%rbx), %rdi
callq 0x28c50
leaq 0x271c6(%rip), %rsi     # 0x6d758
leaq 0x270ff(%rip), %rdx     # 0x6d698
leaq 0x80(%rsp), %r14
movq %r14, %rdi
callq 0x29130
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x28370
testb %al, %al
je 0x46849
movq %rbx, %rdi
callq 0x27780
testb %al, %al
je 0x46849
cmpq $0x0, 0x118(%rbx)
js 0x46715
leaq 0x10(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xf8a0(%rip), %rdx      # 0x55e8f
movq %rsp, %rdi
movq %rdx, %rsi
callq 0x26750
leaq 0xa0(%rsp), %rdi
movq %rsp, %rsi
movl $0x18, %edx
callq 0x28750
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x4661d
callq 0x27560
leaq 0xb0(%rsp), %rdi
movq 0x118(%rbx), %rsi
callq 0x27570
leaq 0x50(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x27157(%rip), %rsi     # 0x6d798
movq 0x27158(%rip), %rdx     # 0x6d7a0
addq %rsi, %rdx
leaq 0x40(%rsp), %rdi
callq 0x267c0
leaq 0x40(%rsp), %rdi
movq 0x8(%rdi), %rsi
movl $0x1, %ecx
xorl %edx, %edx
movl $0x20, %r8d
callq 0x28f30
leaq 0xb8(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0x28740
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0x29130
leaq 0x26ffb(%rip), %rdx     # 0x6d698
movq %rsp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x29130
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x466bd
callq 0x27560
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x466d0
callq 0x27560
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x466df
callq 0x27560
movq %rsp, %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x28370
movl %eax, %ebp
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x466ff
callq 0x27560
leaq 0xa0(%rsp), %rdi
callq 0x270d0
testb %bpl, %bpl
je 0x46849
leaq 0x30(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x27093(%rip), %rsi     # 0x6d7b8
movq 0x27094(%rip), %rdx     # 0x6d7c0
addq %rsi, %rdx
leaq 0x20(%rsp), %rdi
callq 0x267c0
leaq 0x20(%rsp), %rdi
movq 0x8(%rdi), %rsi
movl $0x1, %ecx
xorl %edx, %edx
movl $0x20, %r8d
callq 0x28f30
leaq 0x90(%rbx), %rdx
movq %rsp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x29130
leaq 0x26f29(%rip), %rdx     # 0x6d698
leaq 0xa0(%rsp), %rdi
movq %rsp, %rsi
callq 0x29130
leaq 0x10(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %r15, %rdi
je 0x46792
callq 0x27560
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x467a1
callq 0x27560
leaq 0xa0(%rsp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x28370
testb %al, %al
je 0x4682f
movq 0x38(%rbx), %rdi
leaq 0x68(%rbx), %rsi
movzwl 0x88(%rbx), %edx
movl $0x1, %ecx
callq 0x27ed0
testb %al, %al
je 0x4682f
movq %rbx, %rdi
callq 0x27af0
testb %al, %al
je 0x46826
movq %rsp, %rdi
movq %r15, (%rdi)
leaq 0x101ee(%rip), %rsi     # 0x569db
leaq 0x101ea(%rip), %rdx     # 0x569de
callq 0x26750
leaq 0xf0(%rbx), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rcx
xorl %edx, %edx
callq 0x28b00
movq %rax, %r14
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x46821
callq 0x27560
testq %r14, %r14
je 0x46875
movq 0x38(%rbx), %rdi
callq 0x28c50
xorl %ebx, %ebx
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4684b
callq 0x27560
jmp 0x4684b
xorl %ebx, %ebx
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x46865
callq 0x27560
jmp 0x46865
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %bl
jmp 0x46831
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x4693e
callq 0x27560
jmp 0x4693e
jmp 0x4693b
jmp 0x4695e
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
jne 0x468ea
jmp 0x468f6
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x468c6
callq 0x27560
jmp 0x468c6
movq %rax, %rbx
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x468e0
callq 0x27560
jmp 0x468e0
jmp 0x468dd
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x468f6
callq 0x27560
jmp 0x468f6
jmp 0x468f3
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x270d0
jmp 0x46961
movq %rax, %rbx
movq (%rsp), %rdi
jmp 0x46932
jmp 0x4695e
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4692d
callq 0x27560
jmp 0x4692d
jmp 0x4692a
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
jne 0x4694f
jmp 0x46961
jmp 0x4695e
movq %rax, %rbx
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x46961
callq 0x27560
jmp 0x46961
movq %rax, %rdi
callq 0x2f0bd
movq %rax, %rbx
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x46977
callq 0x27560
movq %rbx, %rdi
callq 0x28c20
nop