// File: /workspace/github_cpp_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
cmpl $0x2, 0x28(%rcx)
jne 0xe731
movq %rcx, %r15
movq 0x20(%rcx), %r12
testl %edx, %edx
jle 0xe6d9
movq %rsi, %r13
movl %edx, 0xc(%rsp)
movl %edx, %eax
movq %rax, 0x10(%rsp)
xorl %r14d, %r14d
xorl %eax, %eax
xorl %ebx, %ebx
cmpb $0xa, (%r13,%r14)
sete %cl
cmpb $0xd, %al
setne %al
andb %cl, %al
cmpb $0x1, %al
jne 0xe67e
cmpl $0x400, %ebx            # imm = 0x400
jne 0xe674
movq %r15, %rsi
callq 0xe346
testl %eax, %eax
je 0xe731
movl 0x10(%r15), %edi
movl $0x400, %edx            # imm = 0x400
movq %r12, %rsi
callq 0x4140
movq %rax, %rbp
xorl %ebx, %ebx
cmpl $0x400, %ebp            # imm = 0x400
jne 0xe714
movslq %ebx, %rax
incl %ebx
movb $0xd, (%r12,%rax)
cmpl $0x400, %ebx            # imm = 0x400
jne 0xe6b4
movq %r15, %rsi
callq 0xe346
testl %eax, %eax
je 0xe731
movl 0x10(%r15), %edi
movl $0x400, %edx            # imm = 0x400
movq %r12, %rsi
callq 0x4140
xorl %ebx, %ebx
cmpl $0x400, %eax            # imm = 0x400
jne 0xe743
movb (%r13,%r14), %al
movslq %ebx, %rcx
incl %ebx
movb %al, (%r12,%rcx)
incq %r14
cmpl %r14d, 0x10(%rsp)
jne 0xe626
movl 0xc(%rsp), %edx
movl %edx, %r14d
jmp 0xe6de
xorl %r14d, %r14d
xorl %ebx, %ebx
testl %ebx, %ebx
je 0xe70f
movl %edx, %ebp
movq %r15, %rsi
callq 0xe346
testl %eax, %eax
je 0xe731
movl 0x10(%r15), %edi
movslq %ebx, %rdx
movq %r12, %rsi
callq 0x4140
movl %ebp, %r14d
cmpl %eax, %ebx
je 0xe731
movl %eax, %edi
callq 0x4c87
jmp 0xe72b
movl %edx, %r14d
jmp 0xe731
callq 0x4050
movl (%rax), %edx
leaq 0x4f8c(%rip), %rdi      # 0x136ae
movl %ebp, %esi
xorl %eax, %eax
callq 0x4060
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %edi
callq 0x4c56
jmp 0xe72b