// File: /workspace/github_c_makefile_star2_O0/wahern[P]cqueues/src/socket.c
// Function: lso_recvfd2
static lso_nargs_t lso_recvfd2(lua_State *L) {
	struct luasocket *S = lso_checkself(L, 1);
	size_t bufsiz = luaL_optunsigned(L, 2, S->ibuf.maxline);
	struct msghdr *msg;
	struct cmsghdr *cmsg;
	struct iovec iov;
	int fd = -1, error;

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

	if ((error = fifo_grow(&S->ibuf.fifo, bufsiz)))
		goto error;

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

	msg = so_fdmsg(iov.iov_base, iov.iov_len, -1);

#if defined MSG_CMSG_CLOEXEC
	if ((error = so_recvmsg(S->socket, msg, MSG_CMSG_CLOEXEC)))
		goto error;
#else
	if ((error = so_recvmsg(S->socket, msg, 0)))
		goto error;
#endif

	for (cmsg = CMSG_FIRSTHDR(msg); cmsg; cmsg = CMSG_NXTHDR(msg, cmsg)) {
		if (cmsg->cmsg_level != SOL_SOCKET || cmsg->cmsg_type != SCM_RIGHTS)
			continue;

		cqs_closefd(&fd);
		memcpy(&fd, CMSG_DATA(cmsg), sizeof fd);
	}

	if (msg->msg_flags & (MSG_TRUNC|MSG_CTRUNC))
		goto trunc;

	if (msg->msg_iovlen > 0 && msg->msg_iov[0].iov_len > 0)
		lua_pushlstring(L, msg->msg_iov[0].iov_base, msg->msg_iov[0].iov_len);
	else
		lua_pushliteral(L, "");

	if (fd == -1)
		lua_pushnil(L);
	else if ((error = cqs_socket_fdopen(L, fd, so_opts())))
		goto error;

	return 2;
trunc:
	error = ENOBUFS;
error:
	cqs_closefd(&fd);

	lua_pushnil(L);
	lua_pushnil(L);
	lua_pushinteger(L, error);

	return 3;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movl $0x1, %esi
callq 0x1bba0
movq %rax, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x48(%rax), %rdx
movl $0x2, %esi
callq 0xf450
movq %rax, -0x20(%rbp)
movl $0xffffffff, -0x44(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x1cf90
movl %eax, -0x48(%rbp)
cmpl $0x0, %eax
je 0x1abfc
jmp 0x1ae5b
movq -0x18(%rbp), %rdi
addq $0x40, %rdi
addq $0x18, %rdi
movq -0x20(%rbp), %rsi
callq 0x1deb0
movl %eax, -0x48(%rbp)
cmpl $0x0, %eax
je 0x1ac1e
jmp 0x1ae5b
movq -0x18(%rbp), %rdi
addq $0x40, %rdi
addq $0x18, %rdi
leaq -0x40(%rbp), %rsi
movl $0x1, %edx
callq 0x1df20
movq $0x0, -0x80(%rbp)
movl $0x0, -0x78(%rbp)
movq $0x0, -0x90(%rbp)
movq $0x0, -0x88(%rbp)
leaq -0x90(%rbp), %rax
movq %rax, -0x70(%rbp)
movq $0x1, -0x68(%rbp)
leaq -0xd0(%rbp), %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0xf7d0
leaq -0xd0(%rbp), %rax
movq %rax, -0x60(%rbp)
movq $0x40, -0x58(%rbp)
movl $0x0, -0x50(%rbp)
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
leaq -0x80(%rbp), %rdi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x1ed30
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x128(%rax), %rdi
movq -0x28(%rbp), %rsi
movl $0x40000000, %edx       # imm = 0x40000000
callq 0x10570
movl %eax, -0x48(%rbp)
cmpl $0x0, %eax
je 0x1acdd
jmp 0x1ae5b
movq -0x28(%rbp), %rax
cmpq $0x10, 0x28(%rax)
jb 0x1acf9
movq -0x28(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x128(%rbp)
jmp 0x1ad04
xorl %eax, %eax
movq %rax, -0x128(%rbp)
jmp 0x1ad04
movq -0x128(%rbp), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x1ad52
movq -0x30(%rbp), %rax
cmpl $0x1, 0x8(%rax)
jne 0x1ad2a
movq -0x30(%rbp), %rax
cmpl $0x1, 0xc(%rax)
je 0x1ad2c
jmp 0x1ad3f
leaq -0x44(%rbp), %rdi
callq 0x194f0
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x44(%rbp)
movq -0x28(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xf2c0
movq %rax, -0x30(%rbp)
jmp 0x1ad0f
movq -0x28(%rbp), %rax
movl 0x30(%rax), %eax
andl $0x28, %eax
cmpl $0x0, %eax
je 0x1ad66
jmp 0x1ae54
movq -0x28(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jbe 0x1ada2
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
cmpq $0x0, 0x8(%rax)
jbe 0x1ada2
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rsi
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rdx
callq 0xf510
jmp 0x1adb2
movq -0x10(%rbp), %rdi
leaq 0x327be(%rip), %rsi     # 0x4d56b
callq 0xfcc0
cmpl $-0x1, -0x44(%rbp)
jne 0x1adc6
movq -0x10(%rbp), %rdi
callq 0xfa10
jmp 0x1ae4b
movq -0x10(%rbp), %rax
movq %rax, -0x138(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x12c(%rbp)
leaq -0x120(%rbp), %rdi
xorl %esi, %esi
movl $0x50, %edx
callq 0xf7d0
movq -0x138(%rbp), %rdi
movl -0x12c(%rbp), %esi
movb $0x1, -0x10f(%rbp)
movl $0x0, -0x108(%rbp)
movb $0x1, -0x104(%rbp)
movb $0x1, -0x103(%rbp)
movb $0x1, -0x102(%rbp)
movl $0x1, %eax
movq %rax, -0xe0(%rbp)
movb $0x1, -0xd8(%rbp)
leaq -0x120(%rbp), %rdx
callq 0x102c0
movl %eax, -0x48(%rbp)
cmpl $0x0, %eax
je 0x1ae49
jmp 0x1ae5b
jmp 0x1ae4b
movl $0x2, -0x4(%rbp)
jmp 0x1ae8a
movl $0x69, -0x48(%rbp)
leaq -0x44(%rbp), %rdi
callq 0x194f0
movq -0x10(%rbp), %rdi
callq 0xfa10
movq -0x10(%rbp), %rdi
callq 0xfa10
movq -0x10(%rbp), %rdi
movslq -0x48(%rbp), %rsi
callq 0xf9a0
movl $0x3, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopw %cs:(%rax,%rax)