// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x78(%rbp)
movl $0xc, -0x70(%rbp)
leaq -0x40(%rbp), %rax
movq %rax, -0x68(%rbp)
movq $0x1, -0x60(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movl $0x0, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl 0x28(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x3e90
movl -0x30(%rbp), %eax
orl $0x2, %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, 0xa88d(%rip)      # 0xe724
jne 0x3ea7
callq 0x35c0
shll $0x2, %eax
movl %eax, 0xa87d(%rip)      # 0xe724
movslq 0xa876(%rip), %rax      # 0xe724
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rsi
movl $0x1, %edi
callq 0x32c0
movq -0x20(%rbp), %rcx
movq %rax, (%rcx)
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x3eef
callq 0x30a0
movl (%rax), %edi
callq 0x3390
movl %eax, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x411f
movq -0x10(%rbp), %rax
movl 0x28(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x3f18
movq $0x20, -0x50(%rbp)
movq -0x50(%rbp), %rsi
movl $0x1, %edi
callq 0x32c0
movq %rax, -0x58(%rbp)
jmp 0x3f1a
movq -0x10(%rbp), %rax
movl 0x18(%rax), %edi
movl -0x30(%rbp), %edx
leaq -0x78(%rbp), %rsi
callq 0x3460
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jne 0x3f3b
jmp 0x40f8
cmpl $0x0, -0x2c(%rbp)
jge 0x3f9e
callq 0x30a0
cmpl $0x4, (%rax)
jne 0x3f51
jmp 0x3f4d
jmp 0x3f4f
jmp 0x3f1a
callq 0x30a0
cmpl $0xb, (%rax)
jne 0x3f64
jmp 0x3f5d
jmp 0x3f5f
jmp 0x40f8
movq -0x58(%rbp), %rdi
callq 0x3070
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x3070
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
callq 0x30a0
movl (%rax), %edi
callq 0x3390
movl %eax, %ecx
xorl %eax, %eax
subl %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x411f
jmp 0x3fa0
movq -0x38(%rbp), %rax
movslq -0x2c(%rbp), %rcx
cmpq %rcx, %rax
jb 0x3fb8
movl -0x48(%rbp), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x3fe3
movq -0x38(%rbp), %rax
shlq %rax
movq %rax, -0x38(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq -0x38(%rbp), %rsi
callq 0x3420
movq -0x20(%rbp), %rcx
movq %rax, (%rcx)
movq %rax, -0x40(%rbp)
jmp 0x3f1a
movl -0x48(%rbp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x400f
movq -0x50(%rbp), %rax
shlq %rax
movq %rax, -0x50(%rbp)
movq -0x58(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x3420
movq %rax, -0x58(%rbp)
jmp 0x3f1a
cmpl $0x0, -0x30(%rbp)
je 0x4021
movl $0x0, -0x30(%rbp)
jmp 0x3f1a
jmp 0x4023
jmp 0x4025
movl -0x70(%rbp), %eax
cmpq $0xc, %rax
je 0x405a
movq -0x58(%rbp), %rdi
callq 0x3070
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x3070
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movl $0xffffffed, -0x4(%rbp) # imm = 0xFFFFFFED
jmp 0x411f
cmpq $0x10, -0x50(%rbp)
jb 0x406e
movq -0x58(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x4079
xorl %eax, %eax
movq %rax, -0x88(%rbp)
jmp 0x4079
movq -0x88(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
je 0x40e7
movq -0x80(%rbp), %rax
cmpl $0x1, 0x8(%rax)
jne 0x40d2
movq -0x80(%rbp), %rax
cmpl $0x2, 0xc(%rax)
jne 0x40d2
movl $0x1, %edi
movl $0xc, %esi
callq 0x32c0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq -0x80(%rbp), %rcx
movq 0x10(%rcx), %rdx
movq %rdx, (%rax)
movl 0x18(%rcx), %ecx
movl %ecx, 0x8(%rax)
jmp 0x40e7
jmp 0x40d4
movq -0x80(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x3660
movq %rax, -0x80(%rbp)
jmp 0x4084
movq -0x58(%rbp), %rdi
callq 0x3070
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x411f
movq -0x58(%rbp), %rdi
callq 0x3070
movq -0x20(%rbp), %rax
movq (%rax), %rdi
callq 0x3070
movq -0x20(%rbp), %rax
movq $0x0, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)