#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 */
struct nlmsghdr {
  scalar_t__ nlmsg_len;
};
struct nlattr {
  int dummy;
};
struct nla_policy {
  int dummy;
};
typedef scalar_t__ __u32;

/* Variables and functions */
int EINVAL;
int nla_parse(struct nlattr **, int, int /*<<< orphan*/, int /*<<< orphan*/,
              struct nla_policy const *);
int /*<<< orphan*/ nlmsg_attrdata(struct nlmsghdr const *, int);
int /*<<< orphan*/ nlmsg_attrlen(struct nlmsghdr const *, int);
scalar_t__ nlmsg_msg_size(int);
int nlmsg_parse(const struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[],
                int maxtype, const struct nla_policy *policy) {
  if (nlh->nlmsg_len < (__u32)nlmsg_msg_size(hdrlen))
    return -EINVAL;
  return nla_parse(tb, maxtype, nlmsg_attrdata(nlh, hdrlen),
                   nlmsg_attrlen(nlh, hdrlen), policy);
}


x86 assembly (clang, -O0):
<nlmsg_parse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <nlmsg_msg_size@plt>
mov    %rax,%rcx
mov    -0x38(%rbp),%rax
cmp    %rcx,%rax
jge    1190 <nlmsg_parse+0x50>
xor    %eax,%eax
mov    0x2e5a(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11d1 <nlmsg_parse+0x91>
mov    -0x20(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1030 <nlmsg_attrdata@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <nlmsg_attrlen@plt>
mov    -0x48(%rbp),%rdi
mov    -0x40(%rbp),%esi
mov    -0x3c(%rbp),%edx
mov    %eax,%ecx
mov    -0x30(%rbp),%r8
call   1050 <nla_parse@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nlmsg_parse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8,%r14
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %esi,%ebp
mov    %rdi,%rbx
mov    (%rdi),%r13
mov    %esi,%edi
call   1060 <nlmsg_msg_size@plt>
cmp    %rax,%r13
jge    1182 <nlmsg_parse+0x42>
mov    0x2e71(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <nlmsg_attrdata@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <nlmsg_attrlen@plt>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %r13d,%edx
mov    %eax,%ecx
mov    %r14,%r8
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <nla_parse@plt>

LLVM IR (-O0):
%struct.nlmsghdr = type { i64 }
%struct.nlattr = type { i32 }
%struct.nla_policy = type { i32 }
@EINVAL = global i32 0
define i32 @nlmsg_parse(%struct.nlmsghdr* %0, i32 %1, %struct.nlattr** %2, i32 %3, %struct.nla_policy* %4) {
%6 = alloca i32
%7 = alloca %struct.nlmsghdr*
%8 = alloca i32
%9 = alloca %struct.nlattr**
%10 = alloca i32
%11 = alloca %struct.nla_policy*
store %struct.nlmsghdr* %0, %struct.nlmsghdr** %7
store i32 %1, i32* %8
store %struct.nlattr** %2, %struct.nlattr*** %9
store i32 %3, i32* %10
store %struct.nla_policy* %4, %struct.nla_policy** %11
%12 = load %struct.nlmsghdr*, %struct.nlmsghdr** %7
%13 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %12, i32 0, i32 0
%14 = load i64, i64* %13
%15 = load i32, i32* %8
%16 = call i64 @nlmsg_msg_size(i32 %15)
%17 = icmp slt i64 %14, %16
br i1 %17, label %18, label %21
18: ; preds = %5
%19 = load i32, i32* @EINVAL
%20 = sub nsw i32 0, %19
store i32 %20, i32* %6
br label %32
21: ; preds = %5
%22 = load %struct.nlattr**, %struct.nlattr*** %9
%23 = load i32, i32* %10
%24 = load %struct.nlmsghdr*, %struct.nlmsghdr** %7
%25 = load i32, i32* %8
%26 = call i32 @nlmsg_attrdata(%struct.nlmsghdr* %24, i32 %25)
%27 = load %struct.nlmsghdr*, %struct.nlmsghdr** %7
%28 = load i32, i32* %8
%29 = call i32 @nlmsg_attrlen(%struct.nlmsghdr* %27, i32 %28)
%30 = load %struct.nla_policy*, %struct.nla_policy** %11
%31 = call i32 @nla_parse(%struct.nlattr** %22, i32 %23, i32 %26, i32 %29, %struct.nla_policy* %30)
store i32 %31, i32* %6
br label %32
32: ; preds = %21, %18
%33 = load i32, i32* %6
ret i32 %33
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i64 }
%struct.nlattr = type { i32 }
%struct.nla_policy = type { i32 }
@EINVAL = global i32 0
define i32 @nlmsg_parse(%struct.nlmsghdr* %0, i32 %1, %struct.nlattr** %2, i32 %3, %struct.nla_policy* %4) {
%6 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %0, i64 0, i32 0
%7 = load i64, i64* %6
%8 = tail call i64 @nlmsg_msg_size(i32 %1)
%9 = icmp slt i64 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = load i32, i32* @EINVAL
%12 = sub nsw i32 0, %11
br label %17
13: ; preds = %5
%14 = tail call i32 @nlmsg_attrdata(%struct.nlmsghdr* %0, i32 %1)
%15 = tail call i32 @nlmsg_attrlen(%struct.nlmsghdr* %0, i32 %1)
%16 = tail call i32 @nla_parse(%struct.nlattr** %2, i32 %3, i32 %14, i32 %15, %struct.nla_policy* %4)
br label %17
17: ; preds = %13, %10
%18 = phi i32 [ %12, %10 ], [ %16, %13 ]
ret i32 %18
}