// File: /workspace/github_c_makefile_star2_O2/wahern[P]cqueues/src/socket.c
// Function: lso_recv3
static lso_nargs_t lso_recv3(lua_State *L) {
	struct luasocket *S = lso_checkself(L, 1);
	struct lso_rcvop op;
	struct iovec iov;
	size_t count;
	int error;

	if ((error = lso_preprcv(L, S)))
		goto error;

	lua_settop(L, 3);

	op = lso_checkrcvop(L, 2, lso_imode(luaL_optstring(L, 3, ""), S->ibuf.mode));

	switch (op.type) {
	case LSO_NUMBER:
		return luaL_argerror(L, op.index, "*n not implemented yet");
	case LSO_SLURP:
		error = lso_fill(S, (size_t)-1);

		if (!(S->ibuf.eom || S->ibuf.eof))
			goto error;

		fifo_rvec(&S->ibuf.fifo, &iov, 1);

		if ((count = iov.iov_len)) {
			if (op.mode & LSO_TEXT)
				iov_trimcr(&iov, 0);

			lua_pushlstring(L, iov.iov_base, iov.iov_len);
			fifo_discard(&S->ibuf.fifo, count);
		} else {
			lua_pushnil(L);
		}

		break;
	case LSO_CHOMP:
		if ((error = lso_getline(S, &iov)))
			goto error;

		count = iov.iov_len;

		if (op.mode & LSO_TEXT)
			iov_trimcr(&iov, 1);

		if (iov_lc(&iov) == '\n')
			--iov.iov_len;

		lua_pushlstring(L, iov.iov_base, iov.iov_len);
		fifo_discard(&S->ibuf.fifo, count);

		break;
	case LSO_LINE:
		if ((error = lso_getline(S, &iov)))
			goto error;

		count = iov.iov_len;

		if (op.mode & LSO_TEXT)
			iov_trimcr(&iov, 1);

		lua_pushlstring(L, iov.iov_base, iov.iov_len);
		fifo_discard(&S->ibuf.fifo, count);

		break;
	case LSO_FIELD:
		if ((error = lso_getheader(S, &iov)))
			goto error;

		if ((count = iov.iov_len)) {
			iov_trimcrlf(&iov, 0);

			lua_pushlstring(L, iov.iov_base, iov.iov_len);
			fifo_discard(&S->ibuf.fifo, count);
		} else {
			lua_pushnil(L);
		}

		break;
	case LSO_HEADER:
		if ((error = lso_getheader(S, &iov)))
			goto error;

		if ((count = iov.iov_len)) {
			if (op.mode & LSO_TEXT)
				iov_trimcr(&iov, 0);

			lua_pushlstring(L, iov.iov_base, iov.iov_len);
			fifo_discard(&S->ibuf.fifo, count);
		} else {
			lua_pushnil(L);
		}

		break;
	case LSO_BODY: {
		int eom = 0; /* it would be confusing to overload ibuf.eom */

		if ((error = lso_getbody(S, &iov, &eom, op.body.eob, op.body.eoblen, op.mode)))
			goto error;

		if ((count = iov.iov_len)) {
			if (eom) {
				/* trim any \r\n preceding the boundary */
				iov_trimcrlf(&iov, 1);

				if (op.mode & LSO_TEXT)
					iov_trimcr(&iov, 0);

				if (iov.iov_len)
					lua_pushlstring(L, iov.iov_base, iov.iov_len);
				else
					lua_pushnil(L);
			} else {
				if (op.mode & LSO_TEXT)
					iov_trimcr(&iov, 0);

				lua_pushlstring(L, iov.iov_base, iov.iov_len);
			}

			fifo_discard(&S->ibuf.fifo, count);
		} else {
			lua_pushnil(L);
		}

		break;
	}
	case LSO_BLOCK:
		if (op.size == 0) {
			lua_pushlstring(L, "", 0);

			break;
		}

		if ((error = lso_getblock(S, &iov, op.size, op.size, op.mode)))
			goto error;

		if ((count = iov.iov_len)) {
			if (op.mode & LSO_TEXT)
				iov_trimcr(&iov, 0);

			lua_pushlstring(L, iov.iov_base, iov.iov_len);
			fifo_discard(&S->ibuf.fifo, count);
		} else {
			lua_pushnil(L);
		}

		break;
	case LSO_LIMIT:
		if (op.size == 0) {
			lua_pushlstring(L, "", 0);

			break;
		}

		if ((error = lso_getblock(S, &iov, 1, op.size, op.mode)))
			goto error;

		if ((count = iov.iov_len)) {
			if (op.mode & LSO_TEXT)
				iov_trimcr(&iov, 0);

			lua_pushlstring(L, iov.iov_base, iov.iov_len);
			fifo_discard(&S->ibuf.fifo, count);
		} else {
			lua_pushnil(L);
		}

		break;
	default:
		error = EFAULT;

		goto error;
	} /* switch(op) */

	if (!fifo_rlen(&S->ibuf.fifo))
		S->ibuf.eom = 0;

	return 1;
error:
	lua_pushnil(L);
	lua_pushinteger(L, lso_asserterror(error));

	return 2;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %r14
callq 0x16f98
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
callq 0x17a46
pushq $0xe
popq %rbx
testl %eax, %eax
je 0x158a5
movl %eax, %r12d
movq %r14, %rdi
callq 0xf9d0
testl %r12d, %r12d
cmovnel %r12d, %ebx
movslq %ebx, %rsi
movq %r14, %rdi
callq 0xf960
pushq $0x2
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %r13
pushq $0x3
popq %rbp
movq %r14, %rdi
movl %ebp, %esi
callq 0x106f0
leaq 0x1e73f(%rip), %rdx     # 0x33ffb
movq %r14, %rdi
movl %ebp, %esi
xorl %ecx, %ecx
callq 0xf900
movl 0x40(%r15), %esi
movq %rax, %rdi
callq 0x17631
movl %eax, %ebp
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0xfc00
testl %eax, %eax
je 0x1593d
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0x10a00
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x159d1
movapd 0x1ac2a(%rip), %xmm1    # 0x30530
xorpd %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subsd 0x1a712(%rip), %xmm1    # 0x30030
cvttsd2si %xmm1, %rcx
andq %rdx, %rcx
orq %rax, %rcx
je 0x15a59
movq %rsp, %rsi
pushq $0x1
popq %rdx
movq %r13, %rdi
jmp 0x159fb
movq %r13, 0x10(%rsp)
leaq 0x1ae02(%rip), %rdx     # 0x3074b
pushq $0x2
popq %rsi
movq %rsp, %r12
movq %r14, %rdi
movq %r12, %rcx
callq 0xf900
movq %rax, %r13
movb (%rax), %al
cmpb $0x2a, %al
sete %cl
movq (%r12), %r12
cmpq $0x2, %r12
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x15a6f
movzbl 0x1(%r13), %eax
cmpl $0x48, %eax
je 0x15c38
cmpl $0x4c, %eax
movq 0x10(%rsp), %r13
je 0x15c08
cmpl $0x61, %eax
je 0x15afb
cmpl $0x68, %eax
je 0x15bc8
cmpl $0x6c, %eax
je 0x15b71
cmpl $0x6e, %eax
jne 0x15ac3
leaq 0x1ad4f(%rip), %rdx     # 0x30710
pushq $0x2
popq %rsi
movq %r14, %rdi
callq 0xf410
jmp 0x15896
cvttsd2si %xmm0, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subsd 0x1a64b(%rip), %xmm0    # 0x30030
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rax, %rcx
je 0x15a59
movq %rsp, %rsi
movq %r13, %rdi
movq %rcx, %rdx
movl %ebp, %r8d
callq 0x17f10
testl %eax, %eax
jne 0x15876
movq 0x8(%rsp), %r12
testq %r12, %r12
je 0x15c82
movq %r12, %rdx
testb $0x8, %bpl
je 0x15a39
movq %r13, %rbx
movq %rsp, %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0x17c2b
movq 0x8(%r13), %rdx
movq %rbx, %r13
movq (%rsp), %rsi
movq %r14, %rdi
callq 0xf4e0
addq $0x58, %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x17320
jmp 0x15df5
leaq 0x1e59b(%rip), %rsi     # 0x33ffb
movq %r14, %rdi
xorl %edx, %edx
callq 0xf4e0
jmp 0x15df5
cmpb $0x2d, %al
jne 0x15ac3
cmpb $0x2d, 0x1(%r13)
jne 0x15ac3
movq 0x10(%rsp), %rcx
movq 0x50(%rcx), %rax
testb $0x8, %bpl
je 0x15a94
movq 0x48(%rcx), %rcx
cmpq %rcx, %rax
cmovbeq %rcx, %rax
cmpq $0x3, %rax
pushq $0x2
popq %rdx
cmovaeq %rax, %rdx
cmpq $-0x2, %rax
setae %al
pushq $-0x3
popq %rcx
subq %rdx, %rcx
cmpq %r12, %rcx
setb %cl
orb %al, %cl
je 0x15c8f
pushq $0x4b
popq %r12
jmp 0x15879
pushq $0x2
popq %rbp
movq %r14, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0xf660
leaq 0x1ac75(%rip), %rsi     # 0x3074e
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x10080
movq %r14, %rdi
movl %ebp, %esi
movq %rax, %rdx
callq 0xf410
movl %ebx, %r12d
jmp 0x15879
pushq $-0x1
popq %rsi
movq %r13, %rdi
callq 0x17b10
cmpb $0x0, 0x91(%r13)
jne 0x15b1e
cmpb $0x1, 0x90(%r13)
jne 0x15876
addq $0x58, %r15
movq %rsp, %r12
pushq $0x1
popq %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x17262
movq 0x8(%r12), %r12
testq %r12, %r12
je 0x15c82
movq %r12, %rdx
testb $0x8, %bpl
je 0x15b60
movq %rsp, %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0x17c2b
movq 0x8(%r13), %rdx
movq 0x10(%rsp), %r13
movq (%rsp), %rsi
movq %r14, %rdi
callq 0xf4e0
jmp 0x15a49
movq %rsp, %rsi
movq %r13, %rdi
callq 0x17cb4
testl %eax, %eax
jne 0x15876
movq 0x8(%rsp), %r12
movq %r12, %rdx
testb $0x8, %bpl
je 0x15ba9
movq %rsp, %r13
pushq $0x1
popq %rsi
movq %r13, %rdi
callq 0x17c2b
movq 0x8(%r13), %rdx
movq 0x10(%rsp), %r13
movq (%rsp), %rsi
testq %rdx, %rdx
je 0x15d7d
xorl %eax, %eax
cmpb $0xa, -0x1(%rsi,%rdx)
sete %al
subq %rax, %rdx
jmp 0x15a3d
movq %rsp, %rsi
movq %r13, %rdi
callq 0x17d50
testl %eax, %eax
jne 0x15876
movq 0x8(%rsp), %r12
testq %r12, %r12
je 0x15c82
movq %rsp, %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0x17e3d
movq (%r13), %rsi
movq 0x8(%r13), %rdx
movq 0x10(%rsp), %r13
jmp 0x15a3d
movq %rsp, %rsi
movq %r13, %rdi
callq 0x17cb4
testl %eax, %eax
jne 0x15876
movq 0x8(%rsp), %r12
movq %r12, %rdx
testb $0x8, %bpl
je 0x15a39
movq %rsp, %r13
pushq $0x1
popq %rsi
movq %r13, %rdi
jmp 0x15c6f
movq %rsp, %rsi
movq 0x10(%rsp), %r13
movq %r13, %rdi
callq 0x17d50
testl %eax, %eax
jne 0x15876
movq 0x8(%rsp), %r12
testq %r12, %r12
je 0x15c82
movq %r12, %rdx
testb $0x8, %bpl
je 0x15a39
movq %rsp, %r13
movq %r13, %rdi
xorl %esi, %esi
callq 0x17c2b
movq 0x8(%r13), %rdx
movq 0x10(%rsp), %r13
jmp 0x15a39
movq %r14, %rdi
callq 0xf9d0
jmp 0x15df5
leaq (%r12,%rdx), %rbx
addq $0x2, %rbx
movq 0x10(%rsp), %rdi
movq %rbx, %rsi
movq %rdx, 0x18(%rsp)
callq 0x17b10
addq $0x58, %r15
movq %rsp, %rsi
movq %r15, %rdi
movq %rbx, 0x20(%rsp)
movq %rbx, %rdx
callq 0x172bc
movq %rsp, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x1822d
testq %rax, %rax
movq 0x18(%rsp), %rbx
je 0x15d1b
movq %rax, %r13
subq %r12, %r13
movq %r13, 0x8(%rsp)
je 0x15d33
movq %rsp, %rdi
pushq $0x1
popq %rsi
callq 0x17e3d
testb $0x8, %bpl
je 0x15d00
movq %rsp, %rdi
xorl %esi, %esi
callq 0x17c2b
movq 0x8(%rsp), %rdx
testq %rdx, %rdx
je 0x15d84
movq (%rsp), %rsi
movq %r14, %rdi
callq 0xf4e0
jmp 0x15de5
movq 0x8(%rsp), %rax
cmpq 0x20(%rsp), %rax
jae 0x15d40
movq %rax, %rbx
testq %rax, %rax
jne 0x15db9
movq %r14, %rdi
callq 0xf9d0
jmp 0x15df0
testb $0x8, %bpl
je 0x15dbf
movq %rbx, %rax
movq (%rsp), %rbx
leaq (%rbx,%rax), %r13
xorl %r12d, %r12d
movq %rbx, %rax
cmpq %r13, %rax
jae 0x15d8e
movq %r13, %rdx
subq %rax, %rdx
movq %rax, %rdi
pushq $0xa
popq %rsi
callq 0xff20
testq %rax, %rax
je 0x15d8e
incq %rax
movq %rax, %r12
subq %rbx, %r12
jmp 0x15d57
xorl %edx, %edx
jmp 0x15a3d
movq %r14, %rdi
callq 0xf9d0
jmp 0x15de5
testq %r12, %r12
movq 0x18(%rsp), %rax
cmovneq %r12, %rax
movq %rax, 0x8(%rsp)
cmpb $0xd, -0x1(%rbx,%rax)
movq %rax, %rbx
jne 0x15db9
decq %rbx
movq %rbx, 0x8(%rsp)
movq %rbx, %rax
jmp 0x15d27
testb $0x8, %bpl
jne 0x15dc4
movq %rbx, %rdx
jmp 0x15dd6
movq %rsp, %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x17c2b
movq 0x8(%r12), %rdx
movq (%rsp), %rsi
movq %r14, %rdi
callq 0xf4e0
movq %rbx, %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x17320
movq 0x10(%rsp), %r13
pushq $0x1
popq %rax
cmpq $0x0, 0x80(%r13)
jne 0x15896
movb $0x0, 0x91(%r13)
jmp 0x15896