// File: /workspace/github_c_makefile_star2_O1/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)
movq $0x0, 0x40(%rsp)
movaps %xmm0, (%rsp)
movl $0x1000, %edi           # imm = 0x1000
callq 0x4250
testq %rax, %rax
je 0x9127
movq %rax, %rbx
movq %rsp, %rax
movq %rbx, (%rax)
movq $0xfff, 0x8(%rax)       # imm = 0xFFF
leaq 0x10(%rsp), %rsi
movq $0x0, (%rsi)
movl $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 0x9187
movb $0x0, (%rbx,%rax)
incq %rax
movq %rbx, %rdi
movq %rax, %rsi
callq 0x4800
testq %rax, %rax
cmovneq %rax, %rbx
cmpq $0x10, 0x38(%rsp)
jb 0x9130
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x9130
movl 0x8(%rax), %edx
cmpl $0x1, %edx
jne 0x9137
movl 0xc(%rax), %edx
cmpl $0x1, %edx
jne 0x914a
movq (%rax), %rdx
cmpq $0x14, %rdx
jne 0x9164
movl 0x10(%rax), %edx
testl %edx, %edx
jns 0x91a3
callq 0x579b
jmp 0x917c
callq 0x57e5
xorl %ebx, %ebx
jmp 0x917c
callq 0x57c0
jmp 0x917c
movq 0xbeb2(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
leaq 0x4757(%rip), %rsi      # 0xd89f
jmp 0x915b
movq 0xbe9f(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
leaq 0x4775(%rip), %rsi      # 0xd8d0
xorl %eax, %eax
callq 0x4820
jmp 0x917c
movq 0xbe85(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
leaq 0x478c(%rip), %rsi      # 0xd901
xorl %eax, %eax
callq 0x4820
callq 0x45b0
movl $0x46, (%rax)
callq 0x45b0
movq %rax, %r14
movl (%rax), %ebp
movq %rbx, %rdi
callq 0x48e8
movl %ebp, (%r14)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x60, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nop