// File: lianxings[P]ftp_benchmark/ftplib.cc
// Function: ftplib::FtpAcceptConnection(ftphandle*, ftphandle*)
int ftplib::FtpAcceptConnection(ftphandle *nData, ftphandle *nControl)
{
	int sData;
	struct sockaddr addr;
	socklen_t l;
	int i;
	struct timeval tv;
	fd_set mask;
	int rv = 0;

	FD_ZERO(&mask);
	FD_SET(nControl->handle, &mask);
	FD_SET(nData->handle, &mask);
	tv.tv_usec = 0;
	tv.tv_sec = ACCEPT_TIMEOUT;
	i = nControl->handle;
	if (i < nData->handle) 
        i = nData->handle;
	i = select(i+1, &mask, NULL, NULL, &tv);

	if (i == -1) 	{
		strncpy(nControl->response, strerror(errno), sizeof(nControl->response));
		net_close(nData->handle);
		nData->handle = 0;
		rv = 0;
	} else if (i == 0) 	{
		strcpy(nControl->response, "timed out waiting for connection");
		net_close(nData->handle);
		nData->handle = 0;
		rv = 0;
	} else 	{
		if (FD_ISSET(nData->handle, &mask)) 	{
			l = sizeof(addr);
			sData = accept(nData->handle, &addr, &l);
			i = errno;
			net_close(nData->handle);
 			if (sData > 0) 	{
				rv = 1;
				nData->handle = sData;
				nData->ctrl = nControl;
			} else	{
				strncpy(nControl->response, strerror(i), sizeof(nControl->response));
				nData->handle = 0;
				rv = 0;
			}
		}
		else if (FD_ISSET(nControl->handle, &mask)) {
			net_close(nData->handle);
			nData->handle = 0;
			readresp('2', nControl);
			rv = 0;
		}
	}
    
	return rv;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xe0(%rbp)
movl $0x0, -0xcc(%rbp)
leaq -0xc8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movl $0x0, -0xd0(%rbp)
movl -0xd0(%rbp), %eax
cmpq $0x10, %rax
jae 0x174f6
movq -0xd8(%rbp), %rax
movl -0xd0(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
movl -0xd0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xd0(%rbp)
jmp 0x174c4
jmp 0x174f8
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0xc8(%rbp,%rax,8), %rcx
movq %rcx, -0xc8(%rbp,%rax,8)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movl %edx, %eax
movl %eax, %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rax, %rcx
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl $0x40, %esi
cltd
idivl %esi
cltq
orq -0xc8(%rbp,%rax,8), %rcx
movq %rcx, -0xc8(%rbp,%rax,8)
movq $0x0, -0x40(%rbp)
movq $0x1e, -0x48(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x175a6
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %edi
addl $0x1, %edi
leaq -0xc8(%rbp), %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x48(%rbp), %r8
movq %rcx, %rdx
callq 0x4450
movl %eax, -0x34(%rbp)
cmpl $-0x1, -0x34(%rbp)
jne 0x17623
movq -0x18(%rbp), %rax
addq $0x88, %rax
movq %rax, -0xe8(%rbp)
callq 0x4060
movl (%rax), %edi
callq 0x4150
movq -0xe8(%rbp), %rdi
movq %rax, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x4230
movq -0x10(%rbp), %rax
movl 0x10(%rax), %edi
callq 0x48b0
movq -0x10(%rbp), %rax
movl $0x0, 0x10(%rax)
movl $0x0, -0xcc(%rbp)
jmp 0x177e1
cmpl $0x0, -0x34(%rbp)
jne 0x17666
movq -0x18(%rbp), %rdi
addq $0x88, %rdi
leaq 0x623f(%rip), %rsi      # 0x1d87a
callq 0x4430
movq -0x10(%rbp), %rax
movl 0x10(%rax), %edi
callq 0x48b0
movq -0x10(%rbp), %rax
movl $0x0, 0x10(%rax)
movl $0x0, -0xcc(%rbp)
jmp 0x177df
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0xc8(%rbp,%rax,8), %rax
movq %rax, -0xf0(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0xf0(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x17759
movl $0x10, -0x30(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %edi
leaq -0x2c(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x4140
movl %eax, -0x1c(%rbp)
callq 0x4060
movl (%rax), %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rax
movl 0x10(%rax), %edi
callq 0x48b0
cmpl $0x0, -0x1c(%rbp)
jle 0x17712
movl $0x1, -0xcc(%rbp)
movl -0x1c(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x30(%rax)
jmp 0x17754
movq -0x18(%rbp), %rax
addq $0x88, %rax
movq %rax, -0xf8(%rbp)
movl -0x34(%rbp), %edi
callq 0x4150
movq -0xf8(%rbp), %rdi
movq %rax, %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x4230
movq -0x10(%rbp), %rax
movl $0x0, 0x10(%rax)
movl $0x0, -0xcc(%rbp)
jmp 0x177dd
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
cltq
movq -0xc8(%rbp,%rax,8), %rax
movq %rax, -0x100(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl $0x40, %ecx
cltd
idivl %ecx
movq -0x100(%rbp), %rax
movl %edx, %ecx
movl $0x1, %edx
shlq %cl, %rdx
movq %rdx, %rcx
andq %rcx, %rax
cmpq $0x0, %rax
je 0x177db
movq -0x10(%rbp), %rax
movl 0x10(%rax), %edi
callq 0x48b0
movq -0xe0(%rbp), %rdi
movq -0x10(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x18(%rbp), %rdx
movl $0x32, %esi
callq 0x16cc0
movl $0x0, -0xcc(%rbp)
jmp 0x177dd
jmp 0x177df
jmp 0x177e1
movl -0xcc(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq