// File: /workspace/github_c_makefile_star2_O3/sabotage-linux[P]libnl-tiny/nl.c
// Function: nl_recv
int nl_recv(struct nl_sock *sk, struct sockaddr_nl *nla,
	    unsigned char **buf, struct ucred **creds)
{
	int n;
	int flags = 0;
	static int page_size = 0;
	struct iovec iov;
	struct msghdr msg = {
		.msg_name = (void *) nla,
		.msg_namelen = sizeof(struct sockaddr_nl),
		.msg_iov = &iov,
		.msg_iovlen = 1,
		.msg_control = NULL,
		.msg_controllen = 0,
		.msg_flags = 0,
	};
	struct cmsghdr *cmsg;

	if (sk->s_flags & NL_MSG_PEEK)
		flags |= MSG_PEEK;

	if (page_size == 0)
		page_size = getpagesize() * 4;

	iov.iov_len = page_size;
	iov.iov_base = *buf = calloc(1, iov.iov_len);
	if (!*buf)
		return -nl_syserr2nlerr(errno);

	if (sk->s_flags & NL_SOCK_PASSCRED) {
		msg.msg_controllen = CMSG_SPACE(sizeof(struct ucred));
		msg.msg_control = calloc(1, msg.msg_controllen);
	}
retry:

	n = recvmsg(sk->s_fd, &msg, flags);
	if (!n)
		goto abort;
	else if (n < 0) {
		if (errno == EINTR) {
			NL_DBG(3, "recvmsg() returned EINTR, retrying\n");
			goto retry;
		} else if (errno == EAGAIN) {
			NL_DBG(3, "recvmsg() returned EAGAIN, aborting\n");
			goto abort;
		} else {
			free(msg.msg_control);
			free(*buf);
			*buf = NULL;
			return -nl_syserr2nlerr(errno);
		}
	}

	if (iov.iov_len < (size_t) n ||
	    msg.msg_flags & MSG_TRUNC) {
		/* Provided buffer is not long enough, enlarge it
		 * and try again. */
		iov.iov_len *= 2;
		iov.iov_base = *buf = realloc(*buf, iov.iov_len);
		goto retry;
	} else if (msg.msg_flags & MSG_CTRUNC) {
		msg.msg_controllen *= 2;
		msg.msg_control = realloc(msg.msg_control, msg.msg_controllen);
		goto retry;
	} else if (flags != 0) {
		/* Buffer is big enough, do the actual reading */
		flags = 0;
		goto retry;
	}

	if (msg.msg_namelen != sizeof(struct sockaddr_nl)) {
		free(msg.msg_control);
		free(*buf);
		*buf = NULL;
		return -NLE_NOADDR;
	}

	for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) {
		if (cmsg->cmsg_level == SOL_SOCKET &&
		    cmsg->cmsg_type == SCM_CREDENTIALS) {
			*creds = calloc(1, sizeof(struct ucred));
			memcpy(*creds, CMSG_DATA(cmsg), sizeof(struct ucred));
			break;
		}
	}

	free(msg.msg_control);
	return n;

abort:
	free(msg.msg_control);
	free(*buf);
	*buf = NULL;
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, %rbx
movq %rdx, %r14
movq %rdi, %r15
movq %rsi, (%rsp)
movl $0xc, 0x8(%rsp)
leaq 0x38(%rsp), %rax
movq %rax, 0x10(%rsp)
movq $0x1, 0x18(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rsp)
movl $0x0, 0x30(%rsp)
movl 0x28(%rdi), %r12d
movl 0x779b(%rip), %eax      # 0xb5a4
testl %eax, %eax
jne 0x3e1b
callq 0x3510
shll $0x2, %eax
movl %eax, 0x7789(%rip)      # 0xb5a4
movslq %eax, %rsi
movq %rsi, 0x40(%rsp)
movl $0x1, %edi
callq 0x3270
movq %rax, (%r14)
movq %rax, 0x38(%rsp)
testq %rax, %rax
je 0x3f72
movl %r12d, %ebp
shrl $0x2, %ebp
testb $0x2, %r12b
je 0x3e67
movq $0x20, 0x28(%rsp)
movl $0x1, %edi
movl $0x20, %esi
callq 0x3270
movq %rax, 0x20(%rsp)
andl $0x2, %ebp
movq %rsp, %r13
movl 0x18(%r15), %edi
movq %r13, %rsi
movl %ebp, %edx
callq 0x33f0
movq %rax, %r12
testl %r12d, %r12d
je 0x3f80
movq %r12, %rax
testl %r12d, %r12d
js 0x3ee2
movq 0x40(%rsp), %rsi
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %rax, %rsi
jb 0x3ec8
movl 0x30(%rsp), %eax
testb $0x20, %al
jne 0x3ec8
testb $0x8, %al
je 0x3f11
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
addq %rsi, %rsi
movq %rsi, 0x28(%rsp)
callq 0x33c0
movq %rax, 0x20(%rsp)
jmp 0x3ef5
addq %rsi, %rsi
movq %rsi, 0x40(%rsp)
movq (%r14), %rdi
callq 0x33c0
movq %rax, (%r14)
movq %rax, 0x38(%rsp)
jmp 0x3ef5
callq 0x3090
movq %rax, %r12
movl (%rax), %eax
cmpl $0x4, %eax
jne 0x3f7b
movl 0x18(%r15), %edi
movq %r13, %rsi
movl %ebp, %edx
callq 0x33f0
movq %rax, %r12
testl %r12d, %r12d
jne 0x3e8a
jmp 0x3f80
testl %ebp, %ebp
movl $0x0, %ebp
jne 0x3e6d
cmpl $0xc, 0x8(%rsp)
jne 0x3fd8
movq 0x20(%rsp), %r14
cmpq $0x10, 0x28(%rsp)
setb %al
testq %r14, %r14
sete %cl
orb %al, %cl
jne 0x4019
movq %rsp, %r15
cmpl $0x1, 0x8(%r14)
jne 0x3f5a
cmpl $0x2, 0xc(%r14)
je 0x3ff9
movq %r15, %rdi
movq %r14, %rsi
callq 0x35c0
movq %rax, %r14
testq %rax, %rax
jne 0x3f48
jmp 0x4019
callq 0x3090
movl (%rax), %edi
jmp 0x3fbb
cmpl $0xb, %eax
jne 0x3f9e
movq 0x20(%rsp), %rdi
callq 0x3060
movq (%r14), %rdi
callq 0x3060
movq $0x0, (%r14)
xorl %r12d, %r12d
jmp 0x3fc6
movq 0x20(%rsp), %rdi
callq 0x3060
movq (%r14), %rdi
callq 0x3060
movq $0x0, (%r14)
movl (%r12), %edi
callq 0x3330
movl %eax, %r12d
negl %r12d
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsp), %rdi
callq 0x3060
movq (%r14), %rdi
callq 0x3060
movq $0x0, (%r14)
movl $0xffffffed, %r12d      # imm = 0xFFFFFFED
jmp 0x3fc6
movl $0x1, %edi
movl $0xc, %esi
callq 0x3270
movq %rax, (%rbx)
movq 0x10(%r14), %rcx
movq %rcx, (%rax)
movl 0x18(%r14), %ecx
movl %ecx, 0x8(%rax)
movq 0x20(%rsp), %rdi
callq 0x3060
jmp 0x3fc6