// File: /workspace/github_cpp_makefile_star2_O1/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 0xf031
movups 0x480c(%rip), %xmm0     # 0x13812
movups %xmm0, 0xa1(%r14)
movups 0x47f4(%rip), %xmm0     # 0x13809
movups %xmm0, 0x98(%r14)
movups 0x47d5(%rip), %xmm0     # 0x137f9
movups %xmm0, 0x88(%r14)
jmp 0xf1b4
movq %rsi, %r12
movq %rdi, %r15
movq %r9, 0x8(%rsp)
leaq 0x47df(%rip), %rsi      # 0x13822
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 0xeba0
testl %eax, %eax
je 0xf1b4
leal -0x1(%r13), %eax
cmpl $0x5, %eax
ja 0xf0ac
leaq 0x45dd(%rip), %rcx      # 0x1365c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movb $0x0, 0x14(%rsp)
movl $0x52544552, 0x10(%rsp) # imm = 0x52544552
jmp 0xf0f2
movb $0x0, 0x14(%rsp)
movl $0x524f5453, 0x10(%rsp) # imm = 0x524F5453
movl $0x2, %r13d
jmp 0xf0f8
addq $0x88, %r14
leaq 0x4788(%rip), %rsi      # 0x13842
xorl %r12d, %r12d
movq %r14, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0x40a0
jmp 0xf1b7
movb $0x0, 0x14(%rsp)
movl $0x54534c4e, 0x10(%rsp) # imm = 0x54534C4E
jmp 0xf0f2
movabsq $0x4c612d205453494c, %rax # imm = 0x4C612D205453494C
movq %rax, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
movl $0x1, %r13d
testq %r12, %r12
je 0xf13b
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 0xf1b4
leaq (%rsp,%rcx), %rdi
addq $0x10, %rdi
movq %r12, %rsi
callq 0x4380
cmpl $0x1, 0x38(%r14)
jne 0xf161
leaq 0x10(%rsp), %r9
movq %r15, %rdi
movq %r14, %rsi
movq 0x8(%rsp), %rdx
movl %ebp, %ecx
movl %r13d, %r8d
callq 0xf1cc
cmpl $-0x1, %eax
je 0xf1b4
movl $0x1, %r12d
cmpl $0x2, 0x38(%r14)
jne 0xf1b7
leaq 0x10(%rsp), %r9
movq %r15, %rdi
movq %r14, %rsi
movq 0x8(%rsp), %rbx
movq %rbx, %rdx
movl %ebp, %ecx
movl %r13d, %r8d
callq 0xf660
cmpl $-0x1, %eax
je 0xf1b4
movq (%rbx), %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0xedbe
testl %eax, %eax
jne 0xf1b7
movq (%rbx), %rsi
movq %r15, %rdi
callq 0xfa02
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