// File: /workspace/github_c_makefile_star2_O2/containers[P]conmon/src/cmsg.c
// Function: recvfd
struct file_t recvfd(int sockfd)
{
	struct msghdr msg = {0};
	struct iovec iov[1] = {{0}};
	struct cmsghdr *cmsg;
	struct file_t file = {0};
	void *new_name;
	int *fdptr;
	int olderrno;

	union {
		char buf[CMSG_SPACE(sizeof(file.fd))];
		struct cmsghdr align;
	} u;

	/* Allocate a buffer. */
	file.name = malloc(TAG_BUFFER);
	if (!file.name)
		error("recvfd: failed to allocate file.tag buffer");

	/*
	 * We need to "receive" the non-ancillary data even though we don't
	 * plan to use it at all. Otherwise, things won't work as expected.
	 * See unix(7) and other well-hidden documentation.
	 */
	iov[0].iov_base = file.name;
	iov[0].iov_len = TAG_BUFFER - 1;

	msg.msg_name = NULL;
	msg.msg_namelen = 0;
	msg.msg_iov = iov;
	msg.msg_iovlen = 1;
	msg.msg_control = u.buf;
	msg.msg_controllen = sizeof(u.buf);

	ssize_t ret = recvmsg(sockfd, &msg, 0);
	if (ret < 0)
		goto err;
	file.name[ret] = '\0';

	/* Shrink the buffer to what is effectively used.  */
	new_name = realloc(file.name, ret + 1);
	if (new_name)
		file.name = new_name;

	cmsg = CMSG_FIRSTHDR(&msg);
	if (!cmsg)
		error("recvfd: got NULL from CMSG_FIRSTHDR");
	if (cmsg->cmsg_level != SOL_SOCKET)
		errorf("recvfd: expected SOL_SOCKET in cmsg: %d", cmsg->cmsg_level);
	if (cmsg->cmsg_type != SCM_RIGHTS)
		errorf("recvfd: expected SCM_RIGHTS in cmsg: %d", cmsg->cmsg_type);
	if (cmsg->cmsg_len != CMSG_LEN(sizeof(int)))
		errorf("recvfd: expected correct CMSG_LEN in cmsg: %lu", (unsigned long)cmsg->cmsg_len);

	fdptr = (int *)CMSG_DATA(cmsg);
	if (!fdptr || *fdptr < 0)
		error("recvfd: received invalid pointer");

	file.fd = *fdptr;
	return file;

err:
	olderrno = errno;
	free(file.name);
	errno = olderrno;
	return (struct file_t){.name = NULL, .fd = -1};
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
subq $0x60, %rsp
movl %edi, %ebp
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x40(%rsp)
movaps %xmm0, (%rsp)
movl $0x1000, %edi           # imm = 0x1000
callq 0x4250
testq %rax, %rax
je 0x661e
movq %rax, %rbx
movq %rsp, %rax
movq %rbx, (%rax)
movq $0xfff, 0x8(%rax)       # imm = 0xFFF
leaq 0x10(%rsp), %rsi
andq $0x0, (%rsi)
andl $0x0, 0x8(%rsi)
movq %rax, 0x10(%rsi)
movq $0x1, 0x18(%rsi)
leaq 0x48(%rsp), %rax
movq %rax, 0x20(%rsi)
movq $0x18, 0x28(%rsi)
movl %ebp, %edi
xorl %edx, %edx
callq 0x41c0
testq %rax, %rax
js 0x6611
movb $0x0, (%rbx,%rax)
incq %rax
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4810
testq %rax, %rax
cmovneq %rax, %rbx
cmpq $0x10, 0x38(%rsp)
jb 0x663a
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x663a
movl 0x8(%rax), %edx
cmpl $0x1, %edx
jne 0x6654
movl 0xc(%rax), %edx
cmpl $0x1, %edx
jne 0x6667
movq (%rax), %rdx
cmpq $0x14, %rdx
jne 0x6681
movl 0x10(%rax), %edx
testl %edx, %edx
jns 0x66ba
movq 0xd9f5(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x723f(%rip), %rsi      # 0xd844
leaq 0x732d(%rip), %rdx      # 0xd939
jmp 0x6692
callq 0x45c0
movq %rax, %r14
jmp 0x66a7
movq 0xd9cb(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x7215(%rip), %rsi      # 0xd844
leaq 0x721a(%rip), %rdx      # 0xd850
xorl %ebx, %ebx
jmp 0x6692
movq 0xd9af(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x71f9(%rip), %rsi      # 0xd844
leaq 0x7229(%rip), %rdx      # 0xd87b
jmp 0x6692
movq 0xd995(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x723a(%rip), %rsi      # 0xd89f
jmp 0x6678
movq 0xd982(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x7258(%rip), %rsi      # 0xd8d0
xorl %eax, %eax
callq 0x4830
jmp 0x6699
movq 0xd968(%rip), %rax      # 0x13ff0
movq (%rax), %rdi
leaq 0x726f(%rip), %rsi      # 0xd901
xorl %eax, %eax
callq 0x4830
callq 0x45c0
movq %rax, %r14
movl $0x46, (%rax)
movl (%r14), %ebp
movq %rbx, %rdi
callq 0x48f8
movl %ebp, (%r14)
pushq $-0x1
popq %rdx
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x60, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nop