// File: /workspace/github_cpp_makefile_star2_O3/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 0x46523
movq %rbx, %rdi
callq 0x26380
testb %al, %al
je 0x46811
movq 0x38(%rbx), %rdi
callq 0x27370
testb %al, %al
je 0x46539
movq 0x38(%rbx), %rdi
callq 0x28c40
leaq 0x27210(%rip), %rsi     # 0x6d750
leaq 0x27149(%rip), %rdx     # 0x6d690
leaq 0x80(%rsp), %r14
movq %r14, %rdi
callq 0x29120
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x28360
testb %al, %al
je 0x467f7
movq %rbx, %rdi
callq 0x27780
testb %al, %al
je 0x467f7
cmpq $0x0, 0x118(%rbx)
js 0x466c3
leaq 0x10(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xf8f2(%rip), %rdx      # 0x55e8f
movq %rsp, %rdi
movq %rdx, %rsi
callq 0x26750
leaq 0xa0(%rsp), %rdi
movq %rsp, %rsi
movl $0x18, %edx
callq 0x28740
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x465cb
callq 0x27560
leaq 0xb0(%rsp), %rdi
movq 0x118(%rbx), %rsi
callq 0x27570
leaq 0x50(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x271a1(%rip), %rsi     # 0x6d790
movq 0x271a2(%rip), %rdx     # 0x6d798
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 0x28f20
leaq 0xb8(%rsp), %rsi
leaq 0x60(%rsp), %rdi
callq 0x28730
leaq 0x20(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x60(%rsp), %rdx
callq 0x29120
leaq 0x27045(%rip), %rdx     # 0x6d690
movq %rsp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x29120
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4666b
callq 0x27560
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4667e
callq 0x27560
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x4668d
callq 0x27560
movq %rsp, %rsi
movq %rbx, %rdi
movl $0x1, %edx
callq 0x28360
movl %eax, %ebp
movq (%rsp), %rdi
cmpq %r14, %rdi
je 0x466ad
callq 0x27560
leaq 0xa0(%rsp), %rdi
callq 0x270d0
testb %bpl, %bpl
je 0x467f7
leaq 0x30(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x270dd(%rip), %rsi     # 0x6d7b0
movq 0x270de(%rip), %rdx     # 0x6d7b8
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 0x28f20
leaq 0x90(%rbx), %rdx
movq %rsp, %rdi
leaq 0x20(%rsp), %rsi
callq 0x29120
leaq 0x26f73(%rip), %rdx     # 0x6d690
leaq 0xa0(%rsp), %rdi
movq %rsp, %rsi
callq 0x29120
leaq 0x10(%rsp), %r15
movq -0x10(%r15), %rdi
cmpq %r15, %rdi
je 0x46740
callq 0x27560
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x4674f
callq 0x27560
leaq 0xa0(%rsp), %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x28360
testb %al, %al
je 0x467dd
movq 0x38(%rbx), %rdi
leaq 0x68(%rbx), %rsi
movzwl 0x88(%rbx), %edx
movl $0x1, %ecx
callq 0x27ec0
testb %al, %al
je 0x467dd
movq %rbx, %rdi
callq 0x27af0
testb %al, %al
je 0x467d4
movq %rsp, %rdi
movq %r15, (%rdi)
leaq 0x10240(%rip), %rsi     # 0x569db
leaq 0x1023c(%rip), %rdx     # 0x569de
callq 0x26750
leaq 0xf0(%rbx), %rdi
movq (%rsp), %rsi
movq 0x8(%rsp), %rcx
xorl %edx, %edx
callq 0x28af0
movq %rax, %r14
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x467cf
callq 0x27560
testq %r14, %r14
je 0x46823
movq 0x38(%rbx), %rdi
callq 0x28c40
xorl %ebx, %ebx
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x467f9
callq 0x27560
jmp 0x467f9
xorl %ebx, %ebx
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x46813
callq 0x27560
jmp 0x46813
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %bl
jmp 0x467df
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x468ec
callq 0x27560
jmp 0x468ec
jmp 0x468e9
jmp 0x4690c
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r14, %rdi
jne 0x46898
jmp 0x468a4
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x46874
callq 0x27560
jmp 0x46874
movq %rax, %rbx
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4688e
callq 0x27560
jmp 0x4688e
jmp 0x4688b
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r15, %rdi
je 0x468a4
callq 0x27560
jmp 0x468a4
jmp 0x468a1
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x270d0
jmp 0x4690f
movq %rax, %rbx
movq (%rsp), %rdi
jmp 0x468e0
jmp 0x4690c
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x468db
callq 0x27560
jmp 0x468db
jmp 0x468d8
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
jne 0x468fd
jmp 0x4690f
jmp 0x4690c
movq %rax, %rbx
leaq 0xb0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4690f
callq 0x27560
jmp 0x4690f
movq %rax, %rdi
callq 0x2f047
movq %rax, %rbx
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x46925
callq 0x27560
movq %rbx, %rdi
callq 0x28c10
nop