// File: /workspace/github_c_makefile_star2_O3/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 0x90f9
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 0x90ec
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 0x9115
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x9115
movl 0x8(%rax), %edx
cmpl $0x1, %edx
jne 0x912f
movl 0xc(%rax), %edx
cmpl $0x1, %edx
jne 0x9142
movq (%rax), %rdx
cmpq $0x14, %rdx
jne 0x915c
movl 0x10(%rax), %edx
testl %edx, %edx
jns 0x9197
movq 0xbf1a(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
leaq 0x4764(%rip), %rsi      # 0xd844
leaq 0x4852(%rip), %rdx      # 0xd939
jmp 0x916d
callq 0x45b0
movq %rax, %r14
jmp 0x9182
movq 0xbef0(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
leaq 0x473a(%rip), %rsi      # 0xd844
leaq 0x473f(%rip), %rdx      # 0xd850
xorl %ebx, %ebx
jmp 0x916d
movq 0xbed4(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
leaq 0x471e(%rip), %rsi      # 0xd844
leaq 0x474e(%rip), %rdx      # 0xd87b
jmp 0x916d
movq 0xbeba(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
leaq 0x475f(%rip), %rsi      # 0xd89f
jmp 0x9153
movq 0xbea7(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
leaq 0x477d(%rip), %rsi      # 0xd8d0
xorl %eax, %eax
callq 0x4820
jmp 0x9174
movq 0xbe8d(%rip), %rax      # 0x14ff0
movq (%rax), %rdi
leaq 0x4794(%rip), %rsi      # 0xd901
xorl %eax, %eax
callq 0x4820
callq 0x45b0
movq %rax, %r14
movl $0x46, (%rax)
movl (%r14), %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