// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movq %rdi, %r12
callq 0x16f98
movq %rax, %r15
movq %r12, %rdi
movq %rax, %rsi
callq 0x1834f
testl %eax, %eax
je 0x15f31
movl %eax, %ebx
movq %r12, %rdi
xorl %esi, %esi
callq 0xf960
movslq %ebx, %rsi
movq %r12, %rdi
jmp 0x16151
pushq $0x5
popq %rbx
movq %r12, %rdi
movl %ebx, %esi
callq 0x106f0
pushq $0x2
popq %rsi
leaq 0x30(%rsp), %r14
movq %r12, %rdi
movq %r14, %rdx
callq 0xf660
movq %rax, 0x20(%rsp)
pushq $0x3
popq %rsi
movq %r12, %rdi
callq 0x183e5
movq %rax, %r13
decq %r13
pushq $0x4
popq %rsi
movq %r12, %rdi
callq 0x183e5
movq %rax, 0x28(%rsp)
leaq 0x1e07d(%rip), %rdx     # 0x33ffb
movq %r12, %rdi
movl %ebx, %esi
xorl %ecx, %ecx
callq 0xf900
movl 0xa8(%r15), %ebx
movq %rax, %rdi
movl %ebx, %esi
callq 0x17631
movl %eax, 0x4(%rsp)
movq (%r14), %rax
cmpq %rax, %r13
jbe 0x15fbe
leaq 0x1a7b2(%rip), %rdx     # 0x30760
pushq $0x3
popq %rsi
movq %r12, %rdi
callq 0xf410
movq 0x30(%rsp), %rax
movl 0x4(%rsp), %ecx
andl $0x9, %ecx
movl %ecx, 0x1c(%rsp)
andl $0x1, %ebx
cmpq %rax, 0x28(%rsp)
jbe 0x15fe5
leaq 0x1a7a9(%rip), %rdx     # 0x30783
pushq $0x4
popq %rsi
movq %r12, %rdi
callq 0xf410
movq %r12, 0x10(%rsp)
orl %ebx, 0x1c(%rsp)
movq 0x128(%r15), %rdi
callq 0xf890
movq %r15, %r12
addq $0xc0, %r12
movq %r13, 0x8(%rsp)
movq %r13, %rbx
movq 0x28(%rsp), %r13
subq %rbx, %r13
jbe 0x16121
cmpl $0x0, 0x1c(%rsp)
je 0x160b2
movq 0xb0(%r15), %r14
cmpq %r14, %r13
cmovbq %r13, %r14
movq 0x20(%rsp), %rax
leaq (%rax,%rbx), %rbp
movq %rbp, %rdi
pushq $0xa
popq %rsi
movq %r14, %rdx
callq 0xff20
testq %rax, %rax
je 0x160d7
movq %rax, %r13
subq %rbp, %r13
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x1846d
testl %eax, %eax
jne 0x16131
testb $0x8, 0x4(%rsp)
je 0x16089
movq %r12, %rdi
pushq $0xd
popq %rsi
callq 0x18505
testl %eax, %eax
jne 0x16131
movq %r12, %rdi
pushq $0xa
popq %rsi
callq 0x18505
testl %eax, %eax
jne 0x16131
incq %r13
movq 0xe8(%r15), %rax
movq %rax, 0x100(%r15)
movq %r13, %r14
jmp 0x160e9
movl $0x1000, %eax           # imm = 0x1000
cmpq %rax, %r13
cmovaeq %rax, %r13
movq 0x20(%rsp), %rax
leaq (%rax,%rbx), %rsi
movq %r12, %rdi
movq %r13, %rdx
callq 0x1846d
movq %r13, %r14
jmp 0x160e5
movq %r12, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq 0x1846d
testl %eax, %eax
jne 0x16131
addq %rbx, %r14
movq 0xe8(%r15), %rax
movq %r14, %rbx
cmpq 0xb8(%r15), %rax
jbe 0x1600c
movq %r15, %rdi
movl 0x4(%rsp), %esi
callq 0x17161
movq %r14, %rbx
testl %eax, %eax
je 0x1600c
movl %eax, %ebp
movq %r14, %rbx
jmp 0x16133
movq %r15, %rdi
movl 0x4(%rsp), %esi
callq 0x17161
testl %eax, %eax
je 0x16168
movl %eax, %ebp
movq 0x10(%rsp), %r14
movq 0x8(%rsp), %rax
subq %rax, %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0xf960
movslq %ebp, %rsi
movq %r14, %rdi
callq 0xf960
pushq $0x2
popq %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
subq 0x8(%rsp), %rbx
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
callq 0xf960
pushq $0x1
jmp 0x16158