// File: /workspace/github_cpp_makefile_star2_O2/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 0xcde1
movups 0x4a0c(%rip), %xmm0     # 0x117c2
movups %xmm0, 0xa1(%r14)
movups 0x49f4(%rip), %xmm0     # 0x117b9
movups %xmm0, 0x98(%r14)
movups 0x49d5(%rip), %xmm0     # 0x117a9
movups %xmm0, 0x88(%r14)
jmp 0xcf5d
movq %rsi, %r12
movq %rdi, %r15
movq %r9, 0x8(%rsp)
leaq 0x49df(%rip), %rsi      # 0x117d2
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x4090
pushq $0x32
popq %rdx
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rcx
callq 0xc9ae
testl %eax, %eax
je 0xcf5d
leal -0x1(%r13), %eax
cmpl $0x5, %eax
ja 0xce5c
leaq 0x47cf(%rip), %rcx      # 0x115fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
pushq $0x1
popq %r13
jmpq *%rax
movb $0x0, 0x14(%rsp)
movl $0x52544552, 0x10(%rsp) # imm = 0x52544552
jmp 0xcea2
movb $0x0, 0x14(%rsp)
movl $0x524f5453, 0x10(%rsp) # imm = 0x524F5453
pushq $0x2
popq %r13
jmp 0xcea2
addq $0x88, %r14
leaq 0x4988(%rip), %rsi      # 0x117f2
xorl %r12d, %r12d
movq %r14, %rdi
movl %r13d, %edx
xorl %eax, %eax
callq 0x4090
jmp 0xcf60
movb $0x0, 0x14(%rsp)
movl $0x54534c4e, 0x10(%rsp) # imm = 0x54534C4E
jmp 0xcea2
movabsq $0x4c612d205453494c, %rax # imm = 0x4C612D205453494C
movq %rax, 0x10(%rsp)
movb $0x0, 0x18(%rsp)
testq %r12, %r12
je 0xcee5
leaq 0x10(%rsp), %rdi
callq 0x4160
movslq %eax, %rbx
movb $0x20, 0x10(%rsp,%rbx)
movq %r12, %rdi
callq 0x4160
incl %ebx
movslq %ebx, %rcx
addq %rcx, %rax
cmpq $0xff, %rax
ja 0xcf5d
leaq (%rsp,%rcx), %rdi
addq $0x10, %rdi
movq %r12, %rsi
callq 0x4370
movl 0x38(%r14), %eax
cmpl $0x1, %eax
jne 0xcf11
leaq 0x10(%rsp), %r9
movq %r15, %rdi
movq %r14, %rsi
movq 0x8(%rsp), %rdx
movl %ebp, %ecx
movl %r13d, %r8d
callq 0xcf76
cmpl $-0x1, %eax
je 0xcf5d
movl 0x38(%r14), %eax
pushq $0x1
popq %r12
cmpl $0x2, %eax
jne 0xcf60
leaq 0x10(%rsp), %r9
movq %r15, %rdi
movq %r14, %rsi
movq 0x8(%rsp), %rbx
movq %rbx, %rdx
movl %ebp, %ecx
movl %r13d, %r8d
callq 0xd3d6
cmpl $-0x1, %eax
je 0xcf5d
movq (%rbx), %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0xcbc8
testl %eax, %eax
jne 0xcf60
movq (%rbx), %rsi
movq %r15, %rdi
callq 0xd740
andq $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
nop