// File: /workspace/github_c_makefile_star2_O3/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 0x184cf
movq %rax, %rbx
movq %r14, %rdi
movq %rax, %rsi
callq 0x18fc8
testl %eax, %eax
je 0x16b0d
movl %eax, %r12d
movq %r14, %rdi
callq 0xf980
movslq %r12d, %rsi
movq %r14, %rdi
callq 0xf910
movl $0x2, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movl $0x3, %esi
callq 0x10640
leaq 0x224ea(%rip), %rdx     # 0x3900b
movq %r14, %rdi
movl $0x3, %esi
xorl %ecx, %ecx
callq 0xf8b0
movl 0x40(%rbx), %esi
movq %rax, %rdi
callq 0x18b70
movl %eax, %ebp
movq %r14, %rdi
movl $0x2, %esi
callq 0xfb80
testl %eax, %eax
je 0x16baa
movq %r14, %rdi
movl $0x2, %esi
callq 0x10920
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x16c4f
movapd 0x1e9bf(%rip), %xmm1    # 0x35530
xorpd %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subsd 0x1e4a7(%rip), %xmm1    # 0x35030
cvttsd2si %xmm1, %rcx
andq %rdx, %rcx
orq %rax, %rcx
je 0x16cfe
movq %rsp, %rsi
movl $0x1, %edx
movq %rbx, %rdi
jmp 0x16c7d
leaq 0x1eb9a(%rip), %rdx     # 0x3574b
movq %rsp, %r12
movq %r14, %rdi
movl $0x2, %esi
movq %r12, %rcx
callq 0xf8b0
movq %rax, %r15
movb (%rax), %al
cmpb $0x2a, %al
sete %cl
movq (%r12), %r13
cmpq $0x2, %r13
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x16d14
movzbl 0x1(%r15), %eax
cmpl $0x67, %eax
jg 0x16e4b
cmpl $0x48, %eax
je 0x16eb5
cmpl $0x4c, %eax
je 0x16eff
cmpl $0x61, %eax
jne 0x16e77
movq %rbx, %rdi
movq $-0x1, %rsi
callq 0x19094
cmpb $0x0, 0x91(%rbx)
jne 0x16c32
cmpb $0x1, 0x90(%rbx)
jne 0x16fd6
movq %rbx, %rdi
addq $0x58, %rdi
movq %rsp, %r15
movq %r15, %rsi
movl $0x1, %edx
callq 0x187c1
movq 0x8(%r15), %r12
jmp 0x16c92
cvttsd2si %xmm0, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
subsd 0x1e3cd(%rip), %xmm0    # 0x35030
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rax, %rcx
je 0x16cfe
movq %rsp, %rsi
movq %rbx, %rdi
movq %rcx, %rdx
movl %ebp, %r8d
callq 0x19691
testl %eax, %eax
jne 0x16ae3
movq 0x8(%rsp), %r12
testq %r12, %r12
je 0x17048
movq %r12, %rdx
testb $0x8, %bpl
je 0x16cb5
movq %rsp, %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x19214
movq 0x8(%r15), %rdx
movq (%rsp), %rsi
movq %r14, %rdi
callq 0xf4c0
movq 0x80(%rbx), %rcx
cmpq %r12, %rcx
movq %r12, %rsi
cmovbq %rcx, %rsi
movq 0x78(%rbx), %rax
addq %rsi, %rax
xorl %edx, %edx
divq 0x70(%rbx)
movq %rcx, %rax
subq %rsi, %rax
movq %rdx, 0x78(%rbx)
movq %rax, 0x80(%rbx)
cmpq %r12, %rcx
jbe 0x17090
jmp 0x17098
leaq 0x22306(%rip), %rsi     # 0x3900b
movq %r14, %rdi
xorl %edx, %edx
callq 0xf4c0
jmp 0x17098
cmpb $0x2d, %al
jne 0x16e77
cmpb $0x2d, 0x1(%r15)
jne 0x16e77
movq 0x50(%rbx), %rax
testb $0x8, %bpl
je 0x16d3c
movq 0x48(%rbx), %rcx
cmpq %rcx, %rax
cmovbeq %rcx, %rax
cmpq $0x3, %rax
movl $0x2, %edx
cmovaeq %rax, %rdx
cmpq $-0x2, %rax
setae %al
movq $-0x3, %rcx
subq %rdx, %rcx
cmpq %r13, %rcx
setb %cl
orb %al, %cl
movl $0x4b, %r12d
jne 0x16ae6
movq %rdx, 0x10(%rsp)
leaq (%rdx,%r13), %r12
addq $0x2, %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x19094
movq %rbx, %rdi
addq $0x58, %rdi
movq %rsp, %rsi
movq %r12, %rdx
callq 0x1881b
movq %rsp, %rax
movq 0x8(%rax), %rdx
cmpq %r13, %rdx
jb 0x16fad
movq (%rsp), %rdi
movq %rdi, 0x18(%rsp)
movq %rdx, %rsi
movq %rdx, 0x20(%rsp)
movq %r15, %rdx
movq %r13, %rcx
callq 0x10680
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
testq %rax, %rax
je 0x16fad
movq %rax, %r15
addq %r13, %r15
cmpq %rsi, %r15
je 0x16fad
addq %rsi, %r13
subq %r13, %r15
je 0x17048
leaq (%rsi,%r15), %rdx
testq %r15, %r15
jle 0x16e19
cmpb $0xa, -0x1(%rdx)
jne 0x16e19
leaq -0x1(%rdx), %rax
cmpq %rax, %rsi
jae 0x16e16
cmpb $0xd, -0x2(%rdx)
leaq -0x2(%rdx), %rcx
cmoveq %rcx, %rax
movq %rax, %rdx
subq %rsi, %rdx
movq %rdx, 0x8(%rsp)
testb $0x8, %bpl
je 0x16e39
movq %rsp, %r12
movq %r12, %rdi
xorl %esi, %esi
callq 0x19214
movq 0x8(%r12), %rdx
testq %rdx, %rdx
je 0x170b7
movq (%rsp), %rsi
jmp 0x17054
cmpl $0x68, %eax
je 0x16ec5
cmpl $0x6c, %eax
je 0x16f4d
cmpl $0x6e, %eax
jne 0x16e77
leaq 0x1e8ab(%rip), %rdx     # 0x35710
movq %r14, %rdi
movl $0x2, %esi
callq 0xf3f0
jmp 0x16afe
movq %r14, %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0xf620
leaq 0x1e8c1(%rip), %rsi     # 0x3574e
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xfff0
movq %r14, %rdi
movl $0x2, %esi
movq %rax, %rdx
callq 0xf3f0
movl $0xe, %r12d
jmp 0x16ae6
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x194bb
jmp 0x16c85
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x194bb
testl %eax, %eax
jne 0x16ae3
movq 0x8(%rsp), %r12
testq %r12, %r12
je 0x17048
movq %rsp, %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x195bd
movq (%r15), %rsi
movq 0x8(%r15), %rdx
jmp 0x16cb9
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x1929b
testl %eax, %eax
jne 0x16ae3
movq (%rsp), %rsi
movq 0x8(%rsp), %r15
movq %r15, %rdx
testb $0x8, %bpl
je 0x17054
leaq (%rsi,%r15), %rdx
cmpq $0x2, %r15
jl 0x16f45
cmpb $0xa, -0x1(%rdx)
jne 0x16f45
cmpb $0xd, -0x2(%rdx)
jne 0x16f45
movb $0xa, -0x2(%rdx)
decq %rdx
subq %rsi, %rdx
jmp 0x17054
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x1929b
testl %eax, %eax
jne 0x16ae3
movq (%rsp), %rsi
movq 0x8(%rsp), %r15
movq %r15, %rdx
testb $0x8, %bpl
je 0x16f92
leaq (%rsi,%r15), %rdx
cmpq $0x2, %r15
jl 0x16f8f
cmpb $0xa, -0x1(%rdx)
jne 0x16f8f
cmpb $0xd, -0x2(%rdx)
jne 0x16f8f
movb $0xa, -0x2(%rdx)
decq %rdx
subq %rsi, %rdx
testq %rdx, %rdx
je 0x17052
xorl %eax, %eax
cmpb $0xa, -0x1(%rsi,%rdx)
sete %al
subq %rax, %rdx
jmp 0x17054
cmpq %r12, %rdx
jae 0x16fc6
testq %rdx, %rdx
je 0x17048
movq %rdx, %r12
testb $0x8, %bpl
jne 0x17023
jmp 0x17037
testb $0x8, %bpl
jne 0x16ff3
movq 0x10(%rsp), %r12
movq %r12, %rdx
jmp 0x17037
movl %eax, %r15d
movq %r14, %rdi
callq 0xf980
testl %r15d, %r15d
movl $0xe, %r12d
cmovnel %r15d, %r12d
jmp 0x16aee
movq (%rsp), %r15
movq %r15, %rdi
movq 0x10(%rsp), %rsi
callq 0x198f0
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x17048
movq %rax, %rdx
cmpb $0xd, -0x1(%r15,%rax)
jne 0x17023
decq %rdx
movq %rdx, 0x8(%rsp)
je 0x17048
movq %rdx, %r12
movq %rsp, %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x19214
movq 0x8(%r15), %rdx
movq (%rsp), %rsi
movq %r14, %rdi
callq 0xf4c0
movq %r12, %r15
jmp 0x1705c
movq %r14, %rdi
callq 0xf980
jmp 0x17098
xorl %edx, %edx
movq %r14, %rdi
callq 0xf4c0
movq 0x80(%rbx), %rcx
cmpq %r15, %rcx
movq %r15, %rsi
cmovbq %rcx, %rsi
movq 0x78(%rbx), %rax
addq %rsi, %rax
xorl %edx, %edx
divq 0x70(%rbx)
movq %rcx, %rax
subq %rsi, %rax
movq %rdx, 0x78(%rbx)
movq %rax, 0x80(%rbx)
cmpq %r15, %rcx
ja 0x17098
movq $0x0, 0x78(%rbx)
movl $0x1, %eax
cmpq $0x0, 0x80(%rbx)
jne 0x16afe
movb $0x0, 0x91(%rbx)
jmp 0x16afe
movq %r14, %rdi
callq 0xf980
jmp 0x1705c