// File: lianxings[P]ftp_benchmark/ftplib.cc
// Function: ftplib::FtpSendCmd(char const*, char, ftphandle*)
int ftplib::FtpSendCmd(const char *cmd, char expresp, ftphandle *nControl)
{
	char buf[4096];
	int x;

	if (!nControl->handle)  {
        assert(0);
        return 0;
    }

	if (nControl->dir != FTPLIB_CONTROL) {
        assert(0);
        return 0;
    }

    if(gFtpDebug)
        printf("Thread:%-8ld  sock:%-4d  %s\n", syscall(SYS_gettid), nControl->handle, cmd);

    sprintf(buf,"%s\r\n",cmd);

#ifndef NOSSL
	if (nControl->tlsctrl) 
        x = SSL_write(nControl->ssl,buf,strlen(buf));
	else 
        x = net_write(nControl->handle,buf,strlen(buf));
#else
	x = net_write(nControl->handle,buf,strlen(buf));
#endif
	if (x <= 0) {
		perror("write");
		return 0;
	}

	if (mp_ftphandle->logcb != NULL) 
        mp_ftphandle->logcb(buf, mp_ftphandle->cbarg, false);
	
	int ret = readresp(expresp, nControl);

    if(gFtpDebug)
        printf("Thread:%-8ld  sock:%-4d  %s\n", syscall(SYS_gettid), nControl->handle, nControl->response);
    
    return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1050, %rsp           # imm = 0x1050
movb %dl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movb %al, -0x19(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1040(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x17210
leaq 0x64f4(%rip), %rdi      # 0x1d6ec
leaq 0x6607(%rip), %rsi      # 0x1d806
movl $0x209, %edx            # imm = 0x209
leaq 0x6605(%rip), %rcx      # 0x1d810
callq 0x42a0
movq -0x28(%rbp), %rax
cmpl $0x0, 0x28(%rax)
je 0x17239
leaq 0x64cb(%rip), %rdi      # 0x1d6ec
leaq 0x65de(%rip), %rsi      # 0x1d806
movl $0x20e, %edx            # imm = 0x20E
leaq 0x65dc(%rip), %rcx      # 0x1d810
callq 0x42a0
leaq 0xf390(%rip), %rax      # 0x265d0
testb $0x1, (%rax)
je 0x1726d
movl $0xba, %edi
movb $0x0, %al
callq 0x4090
movq %rax, %rsi
movq -0x28(%rbp), %rax
movl 0x10(%rax), %edx
movq -0x18(%rbp), %rcx
leaq 0x65e2(%rip), %rdi      # 0x1d848
movb $0x0, %al
callq 0x4070
leaq -0x1030(%rbp), %rdi
movq -0x18(%rbp), %rdx
leaq 0x65e6(%rip), %rsi      # 0x1d865
movb $0x0, %al
callq 0x40d0
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x104c(%rbp)
leaq -0x1030(%rbp), %rax
movq %rax, -0x1048(%rbp)
leaq -0x1030(%rbp), %rdi
callq 0x41d0
movl -0x104c(%rbp), %edi
movq -0x1048(%rbp), %rsi
movq %rax, %rdx
callq 0x4160
movl %eax, -0x1034(%rbp)
cmpl $0x0, -0x1034(%rbp)
jg 0x172e9
leaq 0x675b(%rip), %rdi      # 0x1da33
callq 0x43a0
movl $0x0, -0x4(%rbp)
jmp 0x1737a
movq -0x1040(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, 0x60(%rax)
je 0x1731a
movq -0x1040(%rbp), %rcx
movq (%rcx), %rax
movq 0x60(%rax), %rax
leaq -0x1030(%rbp), %rdi
movq (%rcx), %rcx
movq 0x68(%rcx), %rsi
xorl %edx, %edx
callq *%rax
movq -0x1040(%rbp), %rdi
movb -0x19(%rbp), %al
movq -0x28(%rbp), %rdx
movsbl %al, %esi
callq 0x16cc0
movl %eax, -0x1038(%rbp)
leaq 0xf293(%rip), %rax      # 0x265d0
testb $0x1, (%rax)
je 0x17371
movl $0xba, %edi
movb $0x0, %al
callq 0x4090
movq %rax, %rsi
movq -0x28(%rbp), %rax
movl 0x10(%rax), %edx
movq -0x28(%rbp), %rcx
addq $0x88, %rcx
leaq 0x64de(%rip), %rdi      # 0x1d848
movb $0x0, %al
callq 0x4070
movl -0x1038(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1050, %rsp           # imm = 0x1050
popq %rbp
retq
nopw %cs:(%rax,%rax)