// File: /workspace/github_cpp_makefile_star2_O2/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
pushq $-0x1
popq %rax
cmpl $0x2, 0x28(%rcx)
jne 0xc621
movq %rcx, %r15
movq %rsi, %r13
movq 0x20(%rcx), %r12
xorl %r14d, %r14d
testl %edx, %edx
movl $0x0, %esi
movl %edx, 0xc(%rsp)
cmovgl %edx, %esi
xorl %ebx, %ebx
xorl %eax, %eax
movq %rsi, 0x10(%rsp)
cmpl %r14d, %esi
je 0xc5ac
cmpb $0xa, (%r13,%r14)
sete %cl
cmpb $0xd, %al
setne %al
andb %cl, %al
cmpb $0x1, %al
jne 0xc557
cmpl $0x400, %ebx            # imm = 0x400
jne 0xc54d
movq %r15, %rsi
callq 0xc1f0
testl %eax, %eax
je 0xc5ff
movl 0x10(%r15), %edi
movl $0x400, %edx            # imm = 0x400
movq %r12, %rsi
callq 0x4120
movq %rax, %rbp
xorl %ebx, %ebx
cmpl $0x400, %ebp            # imm = 0x400
movq 0x10(%rsp), %rsi
jne 0xc607
movslq %ebx, %rax
incl %ebx
movb $0xd, (%r12,%rax)
cmpl $0x400, %ebx            # imm = 0x400
jne 0xc596
movq %r15, %rsi
callq 0xc1f0
testl %eax, %eax
je 0xc5ff
movl 0x10(%r15), %edi
movl $0x400, %edx            # imm = 0x400
movq %r12, %rsi
callq 0x4120
movq %rax, %rbp
xorl %ebx, %ebx
cmpl $0x400, %ebp            # imm = 0x400
movq 0x10(%rsp), %rsi
jne 0xc636
movb (%r13,%r14), %al
movslq %ebx, %rcx
incl %ebx
movb %al, (%r12,%rcx)
incq %r14
jmp 0xc4f1
testl %ebx, %ebx
je 0xc601
movq %r15, %rsi
callq 0xc1f0
movq 0x10(%rsp), %r14
testl %eax, %eax
je 0xc624
movl 0x10(%r15), %edi
movslq %ebx, %rdx
movq %r12, %rsi
callq 0x4120
movq %rax, %r15
movl 0xc(%rsp), %eax
movl %eax, %r14d
cmpl %r15d, %ebx
je 0xc624
movq 0xa9e2(%rip), %rax      # 0x16fc8
movq (%rax), %rbx
callq 0x4040
movl (%rax), %ecx
leaq 0x50ab(%rip), %rsi      # 0x116a2
movq %rbx, %rdi
movl %r15d, %edx
jmp 0xc653
jmp 0xc624
movl 0xc(%rsp), %eax
jmp 0xc621
callq 0x4040
movl (%rax), %edx
leaq 0x5049(%rip), %rdi      # 0x1165e
movl %ebp, %esi
xorl %eax, %eax
callq 0x4050
pushq $-0x1
popq %rax
movl %eax, %r14d
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xa98b(%rip), %rax      # 0x16fc8
movq (%rax), %rbx
callq 0x4040
movl (%rax), %ecx
leaq 0x5032(%rip), %rsi      # 0x11680
movq %rbx, %rdi
movl %ebp, %edx
xorl %eax, %eax
callq 0x4530
jmp 0xc61e