// File: /workspace/github_cpp_makefile_star2_O3/lianxings[P]ftp_benchmark/ftplib.cc
// Function: ftplib::writeline(char*, int, ftphandle*)
int ftplib::writeline(char *buf, int len, ftphandle *nData)
{
	int x, nb=0, w;
	char *ubp = buf, *nbp;
	char lc=0;

	if (nData->dir != FTPLIB_WRITE)
	return -1;
	nbp = nData->buf;
	for (x=0; x < len; x++) 
	{
		if ((*ubp == '\n') && (lc != '\r'))
		{
			if (nb == FTPLIB_BUFSIZ)
			{
				if (!socket_wait(nData)) 
                    return x;
#ifndef NOSSL
				if (nData->tlsctrl) 
                    w = SSL_write(nData->ssl, nbp, FTPLIB_BUFSIZ);
				else 
                    w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ);
#else
				w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ);
#endif
				if (w != FTPLIB_BUFSIZ) 	{
					printf("write(1) returned %d, errno = %d\n", w, errno);
					return(-1);
				}
				nb = 0;
			}
			nbp[nb++] = '\r';
		}
		if (nb == FTPLIB_BUFSIZ)
		{
			if (!socket_wait(nData))
			    return x;
#ifndef NOSSL
			if (nData->tlsctrl) 
                w = SSL_write(nData->ssl, nbp, FTPLIB_BUFSIZ);
			else 
                w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ);
#else
			w = net_write(nData->handle, nbp, FTPLIB_BUFSIZ);
#endif	
			if (w != FTPLIB_BUFSIZ) 			{
				fprintf(stderr, "write(2) returned %d, errno = %d\n", w, errno);
				return(-1);
			}
			nb = 0;
		}
		nbp[nb++] = lc = *ubp++;
	}
	if (nb)
	{
		if (!socket_wait(nData)) return x;
#ifndef NOSSL
		if (nData->tlsctrl) 
            w = SSL_write(nData->ssl, nbp, nb);
		else 
            w = net_write(nData->handle, nbp, nb);
#else
		w = net_write(nData->handle, nbp, nb);	
#endif
		if (w != nb) 		{
			fprintf(stderr, "write(3) returned %d, errno = %d\n", w, errno);
			return(-1);
		}
	}
	return len;
}

// Assembly:
cmpl $0x2, 0x28(%rcx)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jne 0xe729
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %r13d
testl %edx, %edx
jle 0xe6f5
movq %rsi, %r12
movq %rcx, (%rsp)
movq 0x20(%rcx), %r15
xorl %ebx, %ebx
xorl %eax, %eax
xorl %ebp, %ebp
cmpb $0xa, (%r12,%rbx)
sete %cl
cmpb $0xd, %al
setne %al
andb %cl, %al
cmpb $0x1, %al
jne 0xe684
movq %r13, %r14
cmpl $0x400, %ebp            # imm = 0x400
jne 0xe677
movq (%rsp), %r13
movq %r13, %rsi
callq 0xe344
testl %eax, %eax
je 0xe6fa
movl 0x10(%r13), %edi
movl $0x400, %edx            # imm = 0x400
movq %r15, %rsi
callq 0x4140
movq %rax, %r13
xorl %ebp, %ebp
cmpl $0x400, %r13d           # imm = 0x400
jne 0xe6fe
movslq %ebp, %rax
incl %ebp
movb $0xd, (%r15,%rax)
movq %r14, %r13
cmpl $0x400, %ebp            # imm = 0x400
jne 0xe6b6
movq (%rsp), %r14
movq %r14, %rsi
callq 0xe344
testl %eax, %eax
je 0xe6fa
movl 0x10(%r14), %edi
movl $0x400, %edx            # imm = 0x400
movq %r15, %rsi
callq 0x4140
xorl %ebp, %ebp
cmpl $0x400, %eax            # imm = 0x400
jne 0xe72a
movb (%r12,%rbx), %al
movslq %ebp, %rcx
incl %ebp
movb %al, (%r15,%rcx)
incq %rbx
cmpl %ebx, %r13d
jne 0xe622
testl %ebp, %ebp
je 0xe6f5
movq (%rsp), %rbx
movq %rbx, %rsi
callq 0xe344
testl %eax, %eax
je 0xe6f5
movl 0x10(%rbx), %edi
movslq %ebp, %rdx
movq %r15, %rsi
callq 0x4140
cmpl %eax, %ebp
jne 0xe733
movl %r13d, %eax
jmp 0xe71b
movl %ebx, %eax
jmp 0xe71b
callq 0x4050
movl (%rax), %edx
leaq 0x4fb2(%rip), %rdi      # 0x136be
movl %r13d, %esi
xorl %eax, %eax
callq 0x4060
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x4c2c
jmp 0xe716
movl %eax, %edi
callq 0x4c5d
jmp 0xe716