// File: /workspace/github_cpp_makefile_star2_O3/lianxings[P]ftp_benchmark/ftplib.cc
// Function: ftplib::FtpAccess(char const*, ftplib::accesstype, ftplib::transfermode, ftphandle*, ftphandle**)
int ftplib::FtpAccess(const char *path, accesstype type, transfermode mode, ftphandle *nControl, ftphandle **nData)
{
	char buf[256];
	int dir;

	if ((path == NULL) && ((type == ftplib::filewrite)
		|| (type == ftplib::fileread)
		|| (type == ftplib::filereadappend)
		|| (type == ftplib::filewriteappend)))
	{
		sprintf(nControl->response,"Missing path argument for file transfer\n");
		return 0;
	}
	sprintf(buf, "TYPE %c", mode);
	if (!FtpSendCmd(buf, '2', nControl)) 
        return 0;

	switch (type)
	{
	case ftplib::dir:
		strcpy(buf,"NLST");
		dir = FTPLIB_READ;
		break;
	case ftplib::dirverbose:
		strcpy(buf,"LIST -aL");
		dir = FTPLIB_READ;
		break;
	case ftplib::filereadappend:
	case ftplib::fileread:
		strcpy(buf,"RETR");
		dir = FTPLIB_READ;
		break;
	case ftplib::filewriteappend:
	case ftplib::filewrite:
		strcpy(buf,"STOR");
		dir = FTPLIB_WRITE;
		break;
	default:
		sprintf(nControl->response, "Invalid open type %d\n", type);
		return 0;
	}
	if (path != NULL)
	{
		int i = strlen(buf);
		buf[i++] = ' ';
		if ((strlen(path) + i) >= sizeof(buf)) return 0;
		strcpy(&buf[i],path);
	}

	if (nControl->cmode == ftplib::pasv)
	{
		if (FtpOpenPasv(nControl, nData, mode, dir, buf) == -1) 
            return 0;
	}

	if (nControl->cmode == ftplib::port)
	{
		if (FtpOpenPort(nControl, nData, mode, dir, buf) == -1) 
            return 0;
		if (!FtpAcceptConnection(*nData,nControl))
		{
			FtpClose(*nData);
			*nData = NULL;
			return 0;
		}
	}

#ifndef NOSSL
	if (nControl->tlsdata)
	{
		(*nData)->ssl = SSL_new(nControl->ctx);
		(*nData)->sbio = BIO_new_socket((*nData)->handle, BIO_NOCLOSE);
		SSL_set_bio((*nData)->ssl,(*nData)->sbio,(*nData)->sbio);
		int ret = SSL_connect((*nData)->ssl);
		if (ret != 1) return 0;
		(*nData)->tlsdata = 1;
	}
#endif
	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %r8, %r14
movl %ecx, %ebp
movl %edx, %r13d
testq %rsi, %rsi
setne %al
leal -0x3(%r13), %ecx
cmpl $0x4, %ecx
setae %cl
orb %al, %cl
jne 0xf021
movups 0x482c(%rip), %xmm0     # 0x13822
movups %xmm0, 0xa1(%r14)
movups 0x4814(%rip), %xmm0     # 0x13819
movups %xmm0, 0x98(%r14)
movups 0x47f5(%rip), %xmm0     # 0x13809
movups %xmm0, 0x88(%r14)
jmp 0xf1a8
movq %rsi, %r12
movq %rdi, %r15
movq %r9, 0x8(%rsp)
leaq 0x47ff(%rip), %rsi      # 0x13832
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x40a0
movq %r15, %rdi
movq %rbx, %rsi
movl $0x32, %edx
movq %r14, %rcx
callq 0xeb90
testl %eax, %eax
je 0xf1a8
leal -0x1(%r13), %eax
cmpl $0x5, %eax
ja 0xf09c
leaq 0x45ed(%rip), %rcx      # 0x1365c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x0, 0x14(%rsp)
movl $0x52544552, 0x10(%rsp) # imm = 0x52544552
jmp 0xf0e2
movb $0x0, 0x14(%rsp)
movl $0x524f5453, 0x10(%rsp) # imm = 0x524F5453
movl $0x2, %r13d
jmp 0xf0e8
addq $0x88, %r14
leaq 0x47a8(%rip), %rsi      # 0x13852
xorl %r12d, %r12d
movq %r14, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0x40a0
jmp 0xf1ab
movb $0x0, 0x14(%rsp)
movl $0x54534c4e, 0x10(%rsp) # imm = 0x54534C4E
jmp 0xf0e2
movabsq $0x4c612d205453494c, %rax # imm = 0x4C612D205453494C
movq %rax, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
movl $0x1, %r13d
testq %r12, %r12
je 0xf12b
leaq 0x10(%rsp), %rdi
callq 0x4180
movslq %eax, %rbx
movb $0x20, 0x10(%rsp,%rbx)
movq %r12, %rdi
callq 0x4180
incl %ebx
movslq %ebx, %rcx
addq %rcx, %rax
cmpq $0xff, %rax
ja 0xf1a8
leaq (%rsp,%rcx), %rdi
addq $0x10, %rdi
movq %r12, %rsi
callq 0x4380
movl 0x38(%r14), %eax
cmpl $0x1, %eax
jne 0xf157
leaq 0x10(%rsp), %r9
movq %r15, %rdi
movq %r14, %rsi
movq 0x8(%rsp), %rdx
movl %ebp, %ecx
movl %r13d, %r8d
callq 0xf1c0
cmpl $-0x1, %eax
je 0xf1a8
movl 0x38(%r14), %eax
movl $0x1, %r12d
cmpl $0x2, %eax
jne 0xf1ab
leaq 0x10(%rsp), %r9
movq %r15, %rdi
movq %r14, %rsi
movq 0x8(%rsp), %rbx
movq %rbx, %rdx
movl %ebp, %ecx
movl %r13d, %r8d
callq 0xf644
cmpl $-0x1, %eax
je 0xf1a8
movq (%rbx), %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0xedae
testl %eax, %eax
jne 0xf1ab
movq (%rbx), %rsi
movq %r15, %rdi
callq 0xf9cc
movq $0x0, (%rbx)
xorl %r12d, %r12d
movl %r12d, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq