#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ uint8_t;
struct nlmsghdr {
  int dummy;
};
struct nduseroptmsg {
  scalar_t__ nduseropt_family;
  scalar_t__ nduseropt_icmp_type;
  scalar_t__ nduseropt_icmp_code;
  int nduseropt_opts_len;
  int /*<<< orphan*/ nduseropt_ifindex;
};
struct nd_opt_hdr {
  int dummy;
};
struct icmp6_hdr {
  int dummy;
};

/* Variables and functions */
scalar_t__ AF_INET6;
scalar_t__ ND_ROUTER_ADVERT;
scalar_t__ NLMSG_DATA(struct nlmsghdr *);
size_t NLMSG_SPACE(int);
int /*<<< orphan*/ memset(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          unsigned int);
int parse_nd_opts(struct nd_opt_hdr *, int, int /*<<< orphan*/);
size_t recv(int, int /*<<< orphan*/ *, unsigned int, int /*<<< orphan*/);
int nl_recv(int fd) {
  unsigned int buf_size = NLMSG_SPACE(65536 - sizeof(struct icmp6_hdr));
  uint8_t buf[buf_size];
  size_t msg_size;
  struct nduseroptmsg *ndmsg;
  memset(buf, 0, buf_size);
  msg_size = recv(fd, buf, buf_size, 0);
  if (msg_size == (size_t)(-1))
    return -1;
  if (msg_size < NLMSG_SPACE(sizeof(struct nduseroptmsg)))
    return -1;
  ndmsg = (struct nduseroptmsg *)NLMSG_DATA((struct nlmsghdr *)buf);
  if (ndmsg->nduseropt_family != AF_INET6 ||
      ndmsg->nduseropt_icmp_type != ND_ROUTER_ADVERT ||
      ndmsg->nduseropt_icmp_code != 0)
    return 0;
  if (msg_size <
      NLMSG_SPACE(sizeof(struct nduseroptmsg) + ndmsg->nduseropt_opts_len))
    return -1;
  return parse_nd_opts((struct nd_opt_hdr *)(ndmsg + 1),
                       ndmsg->nduseropt_opts_len, ndmsg->nduseropt_ifindex);
}


x86 assembly (clang, -O0):
<nl_recv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    $0xfffc,%edi
call   1050 <NLMSG_SPACE@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x40(%rbp),%rsi
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xffffffffffffffff,-0x28(%rbp)
jne    11cc <nl_recv+0x7c>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    12c2 <nl_recv+0x172>
mov    -0x28(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    $0x20,%edi
call   1050 <NLMSG_SPACE@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
cmp    %rcx,%rax
jae    1201 <nl_recv+0xb1>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    12c2 <nl_recv+0x172>
mov    -0x40(%rbp),%rdi
call   1060 <NLMSG_DATA@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    0x2dcc(%rip),%rcx
cmp    (%rcx),%rax
jne    124c <nl_recv+0xfc>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2da4(%rip),%rcx
cmp    (%rcx),%rax
jne    124c <nl_recv+0xfc>
mov    -0x30(%rbp),%rax
cmpq   $0x0,0x10(%rax)
je     125f <nl_recv+0x10f>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    12c2 <nl_recv+0x172>
mov    -0x28(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x30(%rbp),%rax
movslq 0x18(%rax),%rax
add    $0x20,%rax
mov    %eax,%edi
call   1050 <NLMSG_SPACE@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
cmp    %rcx,%rax
jae    129d <nl_recv+0x14d>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    12c2 <nl_recv+0x172>
mov    -0x30(%rbp),%rdi
add    $0x20,%rdi
mov    -0x30(%rbp),%rax
mov    0x18(%rax),%esi
mov    -0x30(%rbp),%rax
mov    0x1c(%rax),%edx
call   1070 <parse_nd_opts@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nl_recv>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%r14d
mov    $0xfffc,%edi
call   1050 <NLMSG_SPACE@plt>
mov    %rax,%r15
mov    %r15d,%eax
mov    %rsp,%rbx
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1040 <memset@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    $0xffffffff,%r14d
cmp    $0xffffffffffffffff,%rax
je     1220 <nl_recv+0xd0>
mov    %rax,%r12
mov    $0x20,%edi
call   1050 <NLMSG_SPACE@plt>
cmp    %rax,%r12
jb     1220 <nl_recv+0xd0>
mov    %rbx,%rdi
call   1060 <NLMSG_DATA@plt>
mov    %rax,%r15
mov    (%rax),%rax
mov    0x2e15(%rip),%rcx
xor    %r14d,%r14d
cmp    (%rcx),%rax
jne    1220 <nl_recv+0xd0>
mov    0x8(%r15),%rax
mov    0x2df2(%rip),%rcx
cmp    (%rcx),%rax
jne    1220 <nl_recv+0xd0>
cmpq   $0x0,0x10(%r15)
jne    1220 <nl_recv+0xd0>
mov    0x18(%r15),%edi
add    $0x20,%edi
call   1050 <NLMSG_SPACE@plt>
mov    $0xffffffff,%r14d
cmp    %rax,%r12
jb     1220 <nl_recv+0xd0>
mov    %r15,%rdi
add    $0x20,%rdi
mov    0x18(%r15),%esi
mov    0x1c(%r15),%edx
call   1070 <parse_nd_opts@plt>
mov    %eax,%r14d
mov    %r14d,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.nduseroptmsg = type { i64, i64, i64, i32, i32 }
%struct.nlmsghdr = type { i32 }
%struct.nd_opt_hdr = type { i32 }
@AF_INET6 = global i64 0
@ND_ROUTER_ADVERT = global i64 0
define i32 @nl_recv(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca %struct.nduseroptmsg*
%9 = alloca i32
store i32 %0, i32* %3
%10 = call i64 @NLMSG_SPACE(i32 65532)
%11 = trunc i64 %10 to i32
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %5
%15 = alloca i32, i64 %13
store i64 %13, i64* %6
%16 = load i32, i32* %4
%17 = call i32 @memset(i32* %15, i32 0, i32 %16)
%18 = load i32, i32* %3
%19 = load i32, i32* %4
%20 = call i64 @recv(i32 %18, i32* %15, i32 %19, i32 0)
store i64 %20, i64* %7
%21 = load i64, i64* %7
%22 = icmp eq i64 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %1
store i32 -1, i32* %2
store i32 1, i32* %9
br label %72
24: ; preds = %1
%25 = load i64, i64* %7
%26 = call i64 @NLMSG_SPACE(i32 32)
%27 = icmp ult i64 %25, %26
br i1 %27, label %28, label %29
28: ; preds = %24
store i32 -1, i32* %2
store i32 1, i32* %9
br label %72
29: ; preds = %24
%30 = bitcast i32* %15 to %struct.nlmsghdr*
%31 = call i64 @NLMSG_DATA(%struct.nlmsghdr* %30)
%32 = inttoptr i64 %31 to %struct.nduseroptmsg*
store %struct.nduseroptmsg* %32, %struct.nduseroptmsg** %8
%33 = load %struct.nduseroptmsg*, %struct.nduseroptmsg** %8
%34 = getelementptr inbounds %struct.nduseroptmsg, %struct.nduseroptmsg* %33, i32 0, i32 0
%35 = load i64, i64* %34
%36 = load i64, i64* @AF_INET6
%37 = icmp ne i64 %35, %36
br i1 %37, label %49, label %38
38: ; preds = %29
%39 = load %struct.nduseroptmsg*, %struct.nduseroptmsg** %8
%40 = getelementptr inbounds %struct.nduseroptmsg, %struct.nduseroptmsg* %39, i32 0, i32 1
%41 = load i64, i64* %40
%42 = load i64, i64* @ND_ROUTER_ADVERT
%43 = icmp ne i64 %41, %42
br i1 %43, label %49, label %44
44: ; preds = %38
%45 = load %struct.nduseroptmsg*, %struct.nduseroptmsg** %8
%46 = getelementptr inbounds %struct.nduseroptmsg, %struct.nduseroptmsg* %45, i32 0, i32 2
%47 = load i64, i64* %46
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %50
49: ; preds = %44, %38, %29
store i32 0, i32* %2
store i32 1, i32* %9
br label %72
50: ; preds = %44
%51 = load i64, i64* %7
%52 = load %struct.nduseroptmsg*, %struct.nduseroptmsg** %8
%53 = getelementptr inbounds %struct.nduseroptmsg, %struct.nduseroptmsg* %52, i32 0, i32 3
%54 = load i32, i32* %53
%55 = sext i32 %54 to i64
%56 = add i64 32, %55
%57 = trunc i64 %56 to i32
%58 = call i64 @NLMSG_SPACE(i32 %57)
%59 = icmp ult i64 %51, %58
br i1 %59, label %60, label %61
60: ; preds = %50
store i32 -1, i32* %2
store i32 1, i32* %9
br label %72
61: ; preds = %50
%62 = load %struct.nduseroptmsg*, %struct.nduseroptmsg** %8
%63 = getelementptr inbounds %struct.nduseroptmsg, %struct.nduseroptmsg* %62, i64 1
%64 = bitcast %struct.nduseroptmsg* %63 to %struct.nd_opt_hdr*
%65 = load %struct.nduseroptmsg*, %struct.nduseroptmsg** %8
%66 = getelementptr inbounds %struct.nduseroptmsg, %struct.nduseroptmsg* %65, i32 0, i32 3
%67 = load i32, i32* %66
%68 = load %struct.nduseroptmsg*, %struct.nduseroptmsg** %8
%69 = getelementptr inbounds %struct.nduseroptmsg, %struct.nduseroptmsg* %68, i32 0, i32 4
%70 = load i32, i32* %69
%71 = call i32 @parse_nd_opts(%struct.nd_opt_hdr* %64, i32 %67, i32 %70)
store i32 %71, i32* %2
store i32 1, i32* %9
br label %72
72: ; preds = %61, %60, %49, %28, %23
%73 = load i8*, i8** %5
%74 = load i32, i32* %2
ret i32 %74
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i32 }
%struct.nduseroptmsg = type { i64, i64, i64, i32, i32 }
%struct.nd_opt_hdr = type { i32 }
@AF_INET6 = global i64 0
@ND_ROUTER_ADVERT = global i64 0
define i32 @nl_recv(i32 %0) {
%2 = tail call i64 @NLMSG_SPACE(i32 65532)
%3 = trunc i64 %2 to i32
%4 = and i64 %2, 4294967295
%5 = alloca i32, i64 %4
%6 = call i32 @memset(i32* %5, i32 0, i32 %3)
%7 = call i64 @recv(i32 %0, i32* %5, i32 %3, i32 0)
%8 = icmp eq i64 %7, -1
br i1 %8, label %42, label %9
9: ; preds = %1
%10 = call i64 @NLMSG_SPACE(i32 32)
%11 = icmp ult i64 %7, %10
br i1 %11, label %42, label %12
12: ; preds = %9
%13 = bitcast i32* %5 to %struct.nlmsghdr*
%14 = call i64 @NLMSG_DATA(%struct.nlmsghdr* %13)
%15 = inttoptr i64 %14 to %struct.nduseroptmsg*
%16 = getelementptr inbounds %struct.nduseroptmsg, %struct.nduseroptmsg* %15, i64 0, i32 0
%17 = load i64, i64* %16
%18 = load i64, i64* @AF_INET6
%19 = icmp eq i64 %17, %18
br i1 %19, label %20, label %42
20: ; preds = %12
%21 = getelementptr inbounds %struct.nduseroptmsg, %struct.nduseroptmsg* %15, i64 0, i32 1
%22 = load i64, i64* %21
%23 = load i64, i64* @ND_ROUTER_ADVERT
%24 = icmp eq i64 %22, %23
br i1 %24, label %25, label %42
25: ; preds = %20
%26 = getelementptr inbounds %struct.nduseroptmsg, %struct.nduseroptmsg* %15, i64 0, i32 2
%27 = load i64, i64* %26
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %42
29: ; preds = %25
%30 = getelementptr inbounds %struct.nduseroptmsg, %struct.nduseroptmsg* %15, i64 0, i32 3
%31 = load i32, i32* %30
%32 = add i32 %31, 32
%33 = call i64 @NLMSG_SPACE(i32 %32)
%34 = icmp ult i64 %7, %33
br i1 %34, label %42, label %35
35: ; preds = %29
%36 = getelementptr inbounds %struct.nduseroptmsg, %struct.nduseroptmsg* %15, i64 1
%37 = bitcast %struct.nduseroptmsg* %36 to %struct.nd_opt_hdr*
%38 = load i32, i32* %30
%39 = getelementptr inbounds %struct.nduseroptmsg, %struct.nduseroptmsg* %15, i64 0, i32 4
%40 = load i32, i32* %39
%41 = call i32 @parse_nd_opts(%struct.nd_opt_hdr* %37, i32 %38, i32 %40)
br label %42
42: ; preds = %29, %12, %20, %25, %9, %1, %35
%43 = phi i32 [ %41, %35 ], [ -1, %1 ], [ -1, %9 ], [ 0, %25 ], [ 0, %20 ], [ 0, %12 ], [ -1, %29 ]
ret i32 %43
}