// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xc0, %rsp
movl %edi, -0x14(%rbp)
leaq -0x50(%rbp), %rdi
xorl %esi, %esi
movl $0x38, %edx
callq 0x40b0
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x40b0
leaq -0x78(%rbp), %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x40b0
movl $0x1000, %edi           # imm = 0x1000
callq 0x4250
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x6e14
jmp 0x6de5
movq 0xf204(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x8a4e(%rip), %rsi      # 0xf844
leaq 0x8a53(%rip), %rdx      # 0xf850
movb $0x0, %al
callq 0x4830
callq 0x45c0
movl $0x46, (%rax)
jmp 0x7031
movq -0x78(%rbp), %rax
movq %rax, -0x60(%rbp)
movq $0xfff, -0x58(%rbp)     # imm = 0xFFF
movq $0x0, -0x50(%rbp)
movl $0x0, -0x48(%rbp)
leaq -0x60(%rbp), %rax
movq %rax, -0x40(%rbp)
movq $0x1, -0x38(%rbp)
leaq -0xa8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq $0x18, -0x28(%rbp)
movl -0x14(%rbp), %edi
leaq -0x50(%rbp), %rsi
xorl %edx, %edx
callq 0x41c0
movq %rax, -0xb0(%rbp)
cmpq $0x0, -0xb0(%rbp)
jge 0x6e7a
jmp 0x7031
movq -0x78(%rbp), %rax
movq -0xb0(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x78(%rbp), %rdi
movq -0xb0(%rbp), %rsi
addq $0x1, %rsi
callq 0x4810
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
je 0x6eb0
movq -0x80(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x10, -0x28(%rbp)
jb 0x6ec4
movq -0x30(%rbp), %rax
movq %rax, -0xb8(%rbp)
jmp 0x6ecf
xorl %eax, %eax
movq %rax, -0xb8(%rbp)
jmp 0x6ecf
movq -0xb8(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
jne 0x6f12
jmp 0x6ee3
movq 0xf106(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x8950(%rip), %rsi      # 0xf844
leaq 0x8980(%rip), %rdx      # 0xf87b
movb $0x0, %al
callq 0x4830
callq 0x45c0
movl $0x46, (%rax)
jmp 0x7031
movq -0x68(%rbp), %rax
cmpl $0x1, 0x8(%rax)
je 0x6f4d
jmp 0x6f1e
movq 0xf0cb(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq -0x68(%rbp), %rax
movl 0x8(%rax), %edx
leaq 0x8969(%rip), %rsi      # 0xf89f
movb $0x0, %al
callq 0x4830
callq 0x45c0
movl $0x46, (%rax)
jmp 0x7031
movq -0x68(%rbp), %rax
cmpl $0x1, 0xc(%rax)
je 0x6f88
jmp 0x6f59
movq 0xf090(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq -0x68(%rbp), %rax
movl 0xc(%rax), %edx
leaq 0x895f(%rip), %rsi      # 0xf8d0
movb $0x0, %al
callq 0x4830
callq 0x45c0
movl $0x46, (%rax)
jmp 0x7031
movq -0x68(%rbp), %rax
cmpq $0x14, (%rax)
je 0x6fc0
jmp 0x6f94
movq 0xf055(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
movq -0x68(%rbp), %rax
movq (%rax), %rdx
leaq 0x8955(%rip), %rsi      # 0xf901
movb $0x0, %al
callq 0x4830
callq 0x45c0
movl $0x46, (%rax)
jmp 0x7031
movq -0x68(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x88(%rbp)
cmpq $0x0, -0x88(%rbp)
je 0x6fe5
movq -0x88(%rbp), %rax
cmpl $0x0, (%rax)
jge 0x7013
jmp 0x6fe7
movq 0xf002(%rip), %rax      # 0x15ff0
movq (%rax), %rdi
leaq 0x884c(%rip), %rsi      # 0xf844
leaq 0x893a(%rip), %rdx      # 0xf939
movb $0x0, %al
callq 0x4830
callq 0x45c0
movl $0x46, (%rax)
jmp 0x7031
movq -0x88(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x70(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x706f
callq 0x45c0
movl (%rax), %eax
movl %eax, -0x8c(%rbp)
movq -0x78(%rbp), %rdi
callq 0x48f8
movl -0x8c(%rbp), %eax
movl %eax, -0xbc(%rbp)
callq 0x45c0
movl -0xbc(%rbp), %ecx
movl %ecx, (%rax)
movq $0x0, -0x10(%rbp)
movl $0xffffffff, -0x8(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movl -0x8(%rbp), %edx
addq $0xc0, %rsp
popq %rbp
retq
nop