// File: /workspace/github_c_makefile_star2_O1/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 0x18609
movq %rax, %rbx
movq %r14, %rdi
movq %rax, %rsi
callq 0x190fa
testl %eax, %eax
je 0x16aa4
movl %eax, %r15d
movq %r14, %rdi
callq 0xf980
testl %r15d, %r15d
movl $0xe, %eax
cmovnel %r15d, %eax
movslq %eax, %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 0x22593(%rip), %rdx     # 0x3904b
movq %r14, %rdi
movl $0x3, %esi
xorl %ecx, %ecx
callq 0xf8b0
movl 0x40(%rbx), %esi
movq %rax, %rdi
callq 0x18ca2
movl %eax, %ebp
movq %r14, %rdi
movl $0x2, %esi
callq 0xfb80
testl %eax, %eax
je 0x16b45
movq %r14, %rdi
movl $0x2, %esi
callq 0x10920
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x16bd4
movapd 0x1ea28(%rip), %xmm1    # 0x35530
xorpd %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x1e510(%rip), %xmm1    # 0x35030
cvttsd2si %xmm1, %r12
andq %rcx, %r12
orq %rax, %r12
movl $0x9, %eax
xorl %r13d, %r13d
movl %eax, %eax
leaq 0x1ea04(%rip), %rcx     # 0x35540
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x1ec27(%rip), %rdx     # 0x35773
movq %rsp, %r15
movq %r14, %rdi
movl $0x2, %esi
movq %r15, %rcx
callq 0xf8b0
movb (%rax), %sil
cmpb $0x2a, %sil
sete %dl
movq (%r15), %rcx
cmpq $0x2, %rcx
sete %dil
andb %dl, %dil
cmpb $0x1, %dil
jne 0x16c0d
movzbl 0x1(%rax), %eax
xorl %r13d, %r13d
cmpl $0x67, %eax
jg 0x16c3d
cmpl $0x48, %eax
je 0x16ccc
cmpl $0x4c, %eax
je 0x16d06
movl $0x0, %edx
movl $0x0, %r12d
cmpl $0x61, %eax
jne 0x16c7c
movl $0x2, %eax
xorl %r12d, %r12d
movl %eax, %eax
leaq 0x1e978(%rip), %rcx     # 0x35540
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
xorl %r13d, %r13d
jmpq *%rax
cvttsd2si %xmm0, %rax
movq %rax, %rcx
sarq $0x3f, %rcx
subsd 0x1e448(%rip), %xmm0    # 0x35030
cvttsd2si %xmm0, %r12
andq %rcx, %r12
orq %rax, %r12
movl $0x8, %eax
xorl %r13d, %r13d
movl %eax, %eax
leaq 0x1e93c(%rip), %rcx     # 0x35540
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %r13d, %r13d
movl $0x0, %edx
movl $0x0, %r12d
cmpb $0x2d, %sil
jne 0x16c7c
xorl %r13d, %r13d
cmpb $0x2d, 0x1(%rax)
movl $0x0, %r12d
jne 0x16c7c
movl $0x7, %edx
movq %rcx, %r13
movq %rax, %r12
jmp 0x16c7c
cmpl $0x68, %eax
je 0x16ce9
cmpl $0x6c, %eax
je 0x16d23
movl $0x0, %edx
movl $0x0, %r12d
cmpl $0x6e, %eax
jne 0x16c7c
movl $0x1, %eax
xorl %r12d, %r12d
movl %eax, %eax
leaq 0x1e8d0(%rip), %rcx     # 0x35540
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
xorl %r13d, %r13d
jmpq *%rax
movl %edx, %eax
leaq 0x1e8bb(%rip), %rcx     # 0x35540
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, %rdi
movl $0x2, %esi
xorl %edx, %edx
callq 0xf620
leaq 0x1ead2(%rip), %rsi     # 0x35776
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0xfff0
movq %r14, %rdi
movl $0x2, %esi
movq %rax, %rdx
callq 0xf3f0
movl $0xe, %r15d
jmp 0x16a71
movl $0x6, %eax
xorl %r12d, %r12d
movl %eax, %eax
leaq 0x1e863(%rip), %rcx     # 0x35540
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
xorl %r13d, %r13d
jmpq *%rax
movl $0x5, %eax
xorl %r12d, %r12d
movl %eax, %eax
leaq 0x1e846(%rip), %rcx     # 0x35540
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
xorl %r13d, %r13d
jmpq *%rax
movl $0x4, %eax
xorl %r12d, %r12d
movl %eax, %eax
leaq 0x1e829(%rip), %rcx     # 0x35540
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
xorl %r13d, %r13d
jmpq *%rax
movl $0x3, %eax
xorl %r12d, %r12d
movl %eax, %eax
leaq 0x1e80c(%rip), %rcx     # 0x35540
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
xorl %r13d, %r13d
jmpq *%rax
leaq 0x1e9f1(%rip), %rdx     # 0x35738
movq %r14, %rdi
movl $0x2, %esi
callq 0xf3f0
jmp 0x16a95
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x193b0
testl %eax, %eax
jne 0x16a6e
movq 0x8(%rsp), %r15
testb $0x8, %bpl
je 0x16fa9
movq (%rsp), %rax
leaq (%rax,%r15), %rcx
cmpq $0x2, %r15
jl 0x16d9c
cmpb $0xa, -0x1(%rcx)
jne 0x16d9c
cmpb $0xd, -0x2(%rcx)
jne 0x16d9c
movb $0xa, -0x2(%rcx)
decq %rcx
subq %rax, %rcx
movq %rcx, 0x8(%rsp)
jmp 0x16fa9
testq %r12, %r12
je 0x16ff8
movq %rsp, %rsi
movl $0x1, %edx
movq %rbx, %rdi
jmp 0x16f7c
movq %rbx, %rdi
movq $-0x1, %rsi
callq 0x191c4
cmpb $0x0, 0x91(%rbx)
jne 0x16de7
cmpb $0x1, 0x90(%rbx)
jne 0x16a6e
movq %rbx, %rdi
addq $0x58, %rdi
movq %rsp, %r15
movq %r15, %rsi
movl $0x1, %edx
callq 0x18901
movq 0x8(%r15), %r15
jmp 0x16f94
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x193b0
testl %eax, %eax
jne 0x16a6e
movq 0x8(%rsp), %r15
testb $0x8, %bpl
je 0x16e4e
movq (%rsp), %rax
leaq (%rax,%r15), %rcx
cmpq $0x2, %r15
jl 0x16e46
cmpb $0xa, -0x1(%rcx)
jne 0x16e46
cmpb $0xd, -0x2(%rcx)
jne 0x16e46
movb $0xa, -0x2(%rcx)
decq %rcx
subq %rax, %rcx
movq %rcx, 0x8(%rsp)
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x16fa9
movq (%rsp), %rcx
cmpb $0xa, -0x1(%rcx,%rax)
jne 0x16fa9
decq %rax
movq %rax, 0x8(%rsp)
jmp 0x16fa9
movq 0x50(%rbx), %rax
testb $0x8, %bpl
movl %ebp, 0x14(%rsp)
je 0x16e91
movq 0x48(%rbx), %rcx
cmpq %rcx, %rax
cmovbeq %rcx, %rax
cmpq $0x3, %rax
movl $0x2, %ebp
cmovaeq %rax, %rbp
xorl %edx, %edx
movl $0x4b, %ecx
movl $0x4b, %r15d
movb $0x1, %dil
cmpq $-0x2, %rax
cmovbl %edx, %r15d
jae 0x170f7
movq $-0x3, %rsi
subq %rbp, %rsi
movl $0x0, %eax
cmpq %r13, %rsi
cmovaeq %r13, %rax
cmovael %edx, %ecx
jae 0x17032
movl %ecx, %r15d
jmp 0x170f7
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x195bf
testl %eax, %eax
jne 0x16a6e
movq 0x8(%rsp), %r12
testq %r12, %r12
je 0x1700b
movq %rsp, %r15
movq %r15, %rdi
xorl %esi, %esi
callq 0x196b1
movq (%r15), %rsi
movq 0x8(%r15), %rdx
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 0x16fee
jmp 0x17013
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x195bf
jmp 0x16f87
testq %r12, %r12
je 0x16ff8
movq %rsp, %rsi
movq %rbx, %rdi
movq %r12, %rdx
movq %r12, %rcx
movl %ebp, %r8d
callq 0x1977e
testl %eax, %eax
jne 0x16a6e
movq 0x8(%rsp), %r15
testq %r15, %r15
je 0x1700b
testb $0x8, %bpl
je 0x16fa9
movq %rsp, %rdi
xorl %esi, %esi
callq 0x19329
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
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 0x17013
movq $0x0, 0x78(%rbx)
jmp 0x17013
leaq 0x2204c(%rip), %rsi     # 0x3904b
movq %r14, %rdi
xorl %edx, %edx
callq 0xf4c0
jmp 0x17013
movq %r14, %rdi
callq 0xf980
movl $0x1, %eax
cmpq $0x0, 0x80(%rbx)
jne 0x16a95
movb $0x0, 0x91(%rbx)
jmp 0x16a95
leaq (%rax,%rbp), %r15
addq $0x2, %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x191c4
movq %rbx, %rdi
addq $0x58, %rdi
movq %rsp, %rsi
movq %r15, 0x20(%rsp)
movq %r15, %rdx
callq 0x18955
movq %rsp, %rax
movq 0x8(%rax), %rsi
cmpq %r13, %rsi
jae 0x1706f
xorl %eax, %eax
movb $0x1, %dil
jmp 0x1709d
movq (%rsp), %r15
movq %r15, %rdi
movq %rsi, 0x18(%rsp)
movq %r12, %rdx
movq %r13, %rcx
callq 0x10680
testq %rax, %rax
je 0x17093
addq %r13, %rax
subq %r15, %rax
jmp 0x17095
xorl %eax, %eax
movb $0x1, %dil
movq 0x18(%rsp), %rsi
testq %rax, %rax
sete %r12b
je 0x170b6
subq %r13, %rax
movq %rax, 0x8(%rsp)
xorl %r15d, %r15d
movl %r12d, %edi
jmp 0x170f7
xorl %r15d, %r15d
cmpq 0x20(%rsp), %rsi
jb 0x170f7
movq %rbp, 0x8(%rsp)
movl 0x14(%rsp), %eax
testb $0x8, %al
je 0x170f7
movq %rsp, %r13
movq %r13, %rdi
callq 0x199f2
movq %rax, 0x8(%r13)
testq %rax, %rax
je 0x170f4
movq (%rsp), %rcx
cmpb $0xd, -0x1(%rcx,%rax)
movb $0x1, %dil
jne 0x170f7
decq %rax
jmp 0x170a9
movb $0x1, %dil
testl %r15d, %r15d
jne 0x16a71
movq 0x8(%rsp), %r12
testq %r12, %r12
movl 0x14(%rsp), %esi
je 0x1712e
testb %dil, %dil
je 0x1713b
testb $0x8, %sil
je 0x17123
movq %rsp, %rdi
xorl %esi, %esi
callq 0x19329
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
jmp 0x1718c
movq %r14, %rdi
callq 0xf980
jmp 0x171d0
movq (%rsp), %rax
leaq (%rax,%r12), %rcx
testq %r12, %r12
jle 0x17166
cmpb $0xa, -0x1(%rcx)
jne 0x17166
leaq -0x1(%rcx), %rdx
cmpq %rdx, %rax
jae 0x17163
cmpb $0xd, -0x2(%rcx)
leaq -0x2(%rcx), %rcx
cmoveq %rcx, %rdx
movq %rdx, %rcx
subq %rax, %rcx
movq %rcx, 0x8(%rsp)
testb $0x8, %sil
je 0x1717e
movq %rsp, %rdi
xorl %esi, %esi
callq 0x19329
movq 0x8(%rsp), %rdx
testq %rdx, %rdx
je 0x171de
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
ja 0x171d0
movq $0x0, 0x78(%rbx)
testl %r15d, %r15d
jne 0x16a71
jmp 0x17013
movq %r14, %rdi
callq 0xf980
jmp 0x17194