// File: /workspace/github_c_makefile_star2_O3/wahern[P]cqueues/src/socket.c
// Function: lso_send5
static lso_nargs_t lso_send5(lua_State *L) {
	struct luasocket *S = lso_checkself(L, 1);
	const unsigned char *src, *lf;
	size_t tp, p, pe, end, n;
	int mode, byline, error;

	if ((error = lso_prepsnd(L, S))) {
		lua_pushinteger(L, 0);
		lua_pushinteger(L, error);

		return 2;
	}

	lua_settop(L, 5);

	src = (const void *)luaL_checklstring(L, 2, &end);
	tp = lso_checksize(L, 3) - 1;
	pe = lso_checksize(L, 4);
	mode = lso_imode(luaL_optstring(L, 5, ""), S->obuf.mode);
	byline = (mode & (LSO_TEXT|LSO_LINEBUF)) || (S->obuf.mode & LSO_LINEBUF);

	luaL_argcheck(L, tp <= end, 3, "start index beyond object boundary");
	luaL_argcheck(L, pe <= end, 4, "end index beyond object boundary");

	p = tp;

	so_clear(S->socket);

	while (p < pe) {
		if (byline) {
			n = MIN(pe - p, S->obuf.maxline);

			if ((lf = memchr(&src[p], '\n', n))) {
				n = lf - &src[p];

				if ((error = fifo_write(&S->obuf.fifo, &src[p], n)))
					goto error;

				if ((mode & LSO_TEXT) && (error = fifo_putc(&S->obuf.fifo, '\r')))
					goto error;

				if ((error = fifo_putc(&S->obuf.fifo, '\n')))
					goto error;

				p += n + 1;

				S->obuf.eol = fifo_rlen(&S->obuf.fifo);
			} else {
				if ((error = fifo_write(&S->obuf.fifo, &src[p], n)))
					goto error;

				p += n;
			}
		} else {
			n = MIN(pe - p, LSO_BUFSIZ);

			if ((error = fifo_write(&S->obuf.fifo, &src[p], n)))
				goto error;

			p += n;
		}

		if (fifo_rlen(&S->obuf.fifo) > S->obuf.bufsiz) {
			if ((error = lso_doflush(S, mode)))
				goto error;
		}
	}

	if ((error = lso_doflush(S, mode)))
		goto error;

	lua_pushinteger(L, p - tp);

	return 1;
error:
	lua_pushinteger(L, p - tp);
	lua_pushinteger(L, error);

	return 2;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %r13
callq 0x184cf
movq %rax, %r14
movq %r13, %rdi
movq %rax, %rsi
callq 0x19a37
testl %eax, %eax
je 0x17208
movl %eax, %ebx
movq %r13, %rdi
xorl %esi, %esi
callq 0xf910
movslq %ebx, %rsi
movq %r13, %rdi
jmp 0x17530
movq %r13, %rdi
movl $0x5, %esi
callq 0x10640
leaq 0x40(%rsp), %rdx
movq %r13, %rdi
movl $0x2, %esi
callq 0xf620
movq %rax, 0x38(%rsp)
movq %r13, %rdi
movl $0x3, %esi
callq 0x10920
movdqa %xmm0, 0x10(%rsp)
movq %r13, %rdi
movl $0x4, %esi
callq 0x10920
movq %xmm0, %r8
movq %r8, %rax
btrq $0x3f, %rax
movabsq $-0x10000000000000, %rdx # imm = 0xFFF0000000000000
leaq (%rax,%rdx), %rdi
shrq $0x35, %rdi
cvttsd2si %xmm0, %rcx
movq %rcx, %rsi
movsd 0x1ddb5(%rip), %xmm1    # 0x35030
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %r9
sarq $0x3f, %rsi
andq %rsi, %r9
orq %rcx, %r9
testq %r8, %r8
movq $-0x1, %r15
movq %r9, %rcx
cmovsq %r15, %rcx
movl $0x3ff, %esi            # imm = 0x3FF
cmpl %esi, %edi
cmovaeq %r9, %rcx
movabsq $0x7ff0000000000000, %rdi # imm = 0x7FF0000000000000
cmpq %rdi, %rax
cmoveq %r15, %rcx
testq %r8, %r8
cmovnsq %rcx, %r15
movdqa 0x10(%rsp), %xmm0
movq %xmm0, %r9
movq %r9, %r8
btrq $0x3f, %r8
addq %r8, %rdx
shrq $0x35, %rdx
cvttsd2si %xmm0, %r10
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %r11
movq %r10, %r12
sarq $0x3f, %r12
andq %r11, %r12
orq %r10, %r12
decq %r12
testq %r9, %r9
movq $-0x2, %rbp
movq %r12, %r10
cmovsq %rbp, %r10
cmpl %esi, %edx
cmovaeq %r12, %r10
cmpq %rdi, %r8
cmoveq %rbp, %r10
testq %r9, %r9
cmovnsq %r10, %rbp
decq %r8
movabsq $0xfffffffffffff, %rdx  # imm = 0xFFFFFFFFFFFFF
cmpq %rdx, %r8
cmovaeq %r10, %rbp
decq %rax
cmpq %rdx, %rax
cmovaeq %rcx, %r15
leaq 0x21cc7(%rip), %rdx     # 0x3900b
movq %r13, %rdi
movl $0x5, %esi
xorl %ecx, %ecx
callq 0xf8b0
movl 0xa8(%r14), %esi
movq %rax, %rdi
movl %esi, %ebx
callq 0x18b70
movl %eax, 0x4(%rsp)
leaq 0x40(%rsp), %rax
movq (%rax), %rax
movq %rbp, 0x8(%rsp)
cmpq %rax, %rbp
jbe 0x17393
leaq 0x1e3df(%rip), %rdx     # 0x35760
movq %r13, %rdi
movl $0x3, %esi
callq 0xf3f0
movq 0x40(%rsp), %rax
cmpq %rax, %r15
jbe 0x173ac
leaq 0x1e3e4(%rip), %rdx     # 0x35783
movq %r13, %rdi
movl $0x4, %esi
callq 0xf3f0
movq %r13, 0x30(%rsp)
movq 0x128(%r14), %rdi
callq 0xf840
movq 0x8(%rsp), %rax
movq %rax, %r12
cmpq %r15, %rax
jae 0x17502
movl 0x4(%rsp), %eax
andl $0x9, %eax
andl $0x1, %ebx
orl %eax, %ebx
movl %ebx, 0x2c(%rsp)
movq %r14, %rax
addq $0xc0, %rax
movq %rax, 0x10(%rsp)
movq 0x8(%rsp), %r12
movq %r15, %rbx
subq %r12, %rbx
cmpl $0x0, 0x2c(%rsp)
je 0x1749b
movq 0xb0(%r14), %rbp
cmpq %rbp, %rbx
cmovbq %rbx, %rbp
movq 0x38(%rsp), %rax
leaq (%rax,%r12), %r13
movq %r13, %rdi
movl $0xa, %esi
movq %rbp, %rdx
callq 0xfe90
testq %rax, %rax
je 0x174c2
movq %rax, %rbx
subq %r13, %rbx
movq 0x10(%rsp), %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq 0x19acd
testl %eax, %eax
jne 0x17512
testb $0x8, 0x4(%rsp)
je 0x1746e
movq 0x10(%rsp), %rdi
movl $0xd, %esi
callq 0x19b96
testl %eax, %eax
jne 0x17512
movq 0x10(%rsp), %rdi
movl $0xa, %esi
callq 0x19b96
testl %eax, %eax
jne 0x17512
incq %rbx
movq 0xe8(%r14), %rax
movq %rax, 0x100(%r14)
movq %rbx, %rbp
jmp 0x174d6
movl $0x1000, %eax           # imm = 0x1000
cmpq %rax, %rbx
cmovaeq %rax, %rbx
movq 0x38(%rsp), %rax
leaq (%rax,%r12), %rsi
movq 0x10(%rsp), %rdi
movq %rbx, %rdx
callq 0x19acd
movq %rbx, %rbp
jmp 0x174d2
movq 0x10(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x19acd
testl %eax, %eax
jne 0x17512
addq %rbp, %r12
movq 0xe8(%r14), %rax
cmpq 0xb8(%r14), %rax
jbe 0x174f9
movq %r14, %rdi
movl 0x4(%rsp), %esi
callq 0x1866f
testl %eax, %eax
jne 0x17512
cmpq %r15, %r12
jb 0x173f1
movq %r14, %rdi
movl 0x4(%rsp), %esi
callq 0x1866f
testl %eax, %eax
je 0x17549
movl %eax, %r13d
subq 0x8(%rsp), %r12
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf910
movslq %r13d, %rsi
movq %rbx, %rdi
callq 0xf910
movl $0x2, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subq 0x8(%rsp), %r12
movq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0xf910
movl $0x1, %eax
jmp 0x1753a