#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 rtattr {
  int rta_len;
  int /*<<< orphan*/ rta_type;
};
struct nlmsghdr {
  int dummy;
};
struct genlmsghdr {
  int dummy;
};
typedef int /*<<< orphan*/ data;

/* Variables and functions */
int /*<<< orphan*/ CTRL_ATTR_FAMILY_NAME;
int /*<<< orphan*/ CTRL_CMD_GETFAMILY;
int /*<<< orphan*/ GENL_ID_CTRL;
scalar_t__ NLMSG_ALIGN(int);
int /*<<< orphan*/ RTA_DATA(struct rtattr *);
int RTA_LENGTH(int);
int /*<<< orphan*/ do_nl_req(int, struct nlmsghdr *, int, int);
int genl_parse_getfamily(void *);
int init_genl_req(char *, int /*<<< orphan*/, int /*<<< orphan*/,
                  int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int strlen(char *);
int resolve_mptcp_pm_netlink(int fd) {
  char data[NLMSG_ALIGN(sizeof(struct nlmsghdr)) +
            NLMSG_ALIGN(sizeof(struct genlmsghdr)) + 1024];
  struct nlmsghdr *nh;
  struct rtattr *rta;
  int namelen;
  int off = 0;
  memset(data, 0, sizeof(data));
  nh = (void *)data;
  off = init_genl_req(data, GENL_ID_CTRL, CTRL_CMD_GETFAMILY, 0);
  rta = (void *)(data + off);
  namelen = strlen("mptcp_pm") + 1;
  rta->rta_type = CTRL_ATTR_FAMILY_NAME;
  rta->rta_len = RTA_LENGTH(namelen);
  memcpy(RTA_DATA(rta), "mptcp_pm", namelen);
  off += NLMSG_ALIGN(rta->rta_len);
  do_nl_req(fd, nh, off, sizeof(data));
  return genl_parse_getfamily((void *)data);
}


x86 assembly (clang, -O0):
<resolve_mptcp_pm_netlink>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x4,%edi
mov    %edi,-0x4c(%rbp)
call   1050 <NLMSG_ALIGN@plt>
mov    -0x4c(%rbp),%edi
mov    %rax,-0x48(%rbp)
call   1050 <NLMSG_ALIGN@plt>
mov    -0x48(%rbp),%rcx
mov    %rax,%rdx
lea    0x400(%rcx,%rdx,1),%rax
mov    %rax,-0x40(%rbp)
mov    %rsp,%rsi
mov    %rsi,-0x10(%rbp)
lea    0x40f(%rcx,%rdx,1),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x30(%rbp)
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x38(%rbp),%rdi
mov    %rdi,%rax
mov    %rax,-0x20(%rbp)
mov    0x2dcb(%rip),%rax
mov    (%rax),%esi
mov    0x2dca(%rip),%rax
mov    (%rax),%edx
xor    %ecx,%ecx
call   1090 <init_genl_req@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,-0x30(%rbp)
movslq -0x30(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
lea    0xdc6(%rip),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    0x2d84(%rip),%rax
mov    (%rax),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x2c(%rbp),%edi
call   10b0 <RTA_LENGTH@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%rdi
call   10a0 <RTA_DATA@plt>
mov    %eax,%edi
mov    -0x2c(%rbp),%edx
lea    0xd86(%rip),%rsi
call   1070 <memcpy@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1050 <NLMSG_ALIGN@plt>
mov    %rax,%rdx
mov    -0x40(%rbp),%rax
movslq -0x30(%rbp),%rcx
add    %rdx,%rcx
mov    %ecx,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%edx
mov    %eax,%ecx
call   1030 <do_nl_req@plt>
mov    -0x38(%rbp),%rdi
call   1080 <genl_parse_getfamily@plt>
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve_mptcp_pm_netlink>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,-0x2c(%rbp)
mov    $0x4,%edi
call   1050 <NLMSG_ALIGN@plt>
mov    %rax,%rbx
mov    $0x4,%edi
call   1050 <NLMSG_ALIGN@plt>
lea    (%rbx,%rax,1),%r15
add    $0x400,%r15d
add    %rbx,%rax
add    $0x40f,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1060 <memset@plt>
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
mov    0x2dea(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %ecx,%ecx
call   1090 <init_genl_req@plt>
movslq %eax,%r12
lea    (%rbx,%r12,1),%r13
lea    0xdf0(%rip),%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%r14d
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%r12,%rbx,1)
mov    %r14d,%edi
call   10b0 <RTA_LENGTH@plt>
mov    %eax,(%r12,%rbx,1)
mov    %r13,%rdi
call   10a0 <RTA_DATA@plt>
mov    %eax,%edi
lea    0xdbc(%rip),%rsi
mov    %r14d,%edx
call   1070 <memcpy@plt>
mov    (%r12,%rbx,1),%edi
call   1050 <NLMSG_ALIGN@plt>
add    %eax,%r12d
mov    -0x2c(%rbp),%edi
mov    %rbx,%rsi
mov    %r12d,%edx
mov    %r15d,%ecx
call   1030 <do_nl_req@plt>
mov    %rbx,%rdi
call   1080 <genl_parse_getfamily@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.nlmsghdr = type { i32 }
%struct.rtattr = type { i32, i32 }
@GENL_ID_CTRL = global i32 0
@CTRL_CMD_GETFAMILY = global i32 0
@.str = [9 x i8] c"mptcp_pm\00"
@CTRL_ATTR_FAMILY_NAME = global i32 0
define i32 @resolve_mptcp_pm_netlink(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.nlmsghdr*
%6 = alloca %struct.rtattr*
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %2
%9 = call i64 @NLMSG_ALIGN(i32 4)
%10 = call i64 @NLMSG_ALIGN(i32 4)
%11 = add nsw i64 %9, %10
%12 = add nsw i64 %11, 1024
%13 = call i8* @llvm.stacksave()
store i8* %13, i8** %3
%14 = alloca i8, i64 %12
store i64 %12, i64* %4
store i32 0, i32* %8
%15 = trunc i64 %12 to i32
%16 = call i32 @memset(i8* %14, i32 0, i32 %15)
%17 = bitcast i8* %14 to %struct.nlmsghdr*
store %struct.nlmsghdr* %17, %struct.nlmsghdr** %5
%18 = load i32, i32* @GENL_ID_CTRL
%19 = load i32, i32* @CTRL_CMD_GETFAMILY
%20 = call i32 @init_genl_req(i8* %14, i32 %18, i32 %19, i32 0)
store i32 %20, i32* %8
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %14, i64 %22
%24 = bitcast i8* %23 to %struct.rtattr*
store %struct.rtattr* %24, %struct.rtattr** %6
%25 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%26 = add nsw i32 %25, 1
store i32 %26, i32* %7
%27 = load i32, i32* @CTRL_ATTR_FAMILY_NAME
%28 = load %struct.rtattr*, %struct.rtattr** %6
%29 = getelementptr inbounds %struct.rtattr, %struct.rtattr* %28, i32 0, i32 1
store i32 %27, i32* %29
%30 = load i32, i32* %7
%31 = call i32 @RTA_LENGTH(i32 %30)
%32 = load %struct.rtattr*, %struct.rtattr** %6
%33 = getelementptr inbounds %struct.rtattr, %struct.rtattr* %32, i32 0, i32 0
store i32 %31, i32* %33
%34 = load %struct.rtattr*, %struct.rtattr** %6
%35 = call i32 @RTA_DATA(%struct.rtattr* %34)
%36 = load i32, i32* %7
%37 = call i32 @memcpy(i32 %35, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %36)
%38 = load %struct.rtattr*, %struct.rtattr** %6
%39 = getelementptr inbounds %struct.rtattr, %struct.rtattr* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i64 @NLMSG_ALIGN(i32 %40)
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = add nsw i64 %43, %41
%45 = trunc i64 %44 to i32
store i32 %45, i32* %8
%46 = load i32, i32* %2
%47 = load %struct.nlmsghdr*, %struct.nlmsghdr** %5
%48 = load i32, i32* %8
%49 = trunc i64 %12 to i32
%50 = call i32 @do_nl_req(i32 %46, %struct.nlmsghdr* %47, i32 %48, i32 %49)
%51 = call i32 @genl_parse_getfamily(i8* %14)
%52 = load i8*, i8** %3
ret i32 %51
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i32 }
%struct.rtattr = type { i32, i32 }
@GENL_ID_CTRL = global i32 0
@CTRL_CMD_GETFAMILY = global i32 0
@.str = [9 x i8] c"mptcp_pm\00"
@CTRL_ATTR_FAMILY_NAME = global i32 0
define i32 @resolve_mptcp_pm_netlink(i32 %0) {
%2 = tail call i64 @NLMSG_ALIGN(i32 4)
%3 = tail call i64 @NLMSG_ALIGN(i32 4)
%4 = add i64 %2, 1024
%5 = add i64 %4, %3
%6 = alloca i8, i64 %5
%7 = trunc i64 %5 to i32
%8 = call i32 @memset(i8* %6, i32 0, i32 %7)
%9 = bitcast i8* %6 to %struct.nlmsghdr*
%10 = load i32, i32* @GENL_ID_CTRL
%11 = load i32, i32* @CTRL_CMD_GETFAMILY
%12 = call i32 @init_genl_req(i8* %6, i32 %10, i32 %11, i32 0)
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %6, i64 %13
%15 = bitcast i8* %14 to %struct.rtattr*
%16 = call i32 @strlen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%17 = add nsw i32 %16, 1
%18 = load i32, i32* @CTRL_ATTR_FAMILY_NAME
%19 = getelementptr inbounds i8, i8* %14, i64 4
%20 = bitcast i8* %19 to i32*
store i32 %18, i32* %20
%21 = call i32 @RTA_LENGTH(i32 %17)
%22 = bitcast i8* %14 to i32*
store i32 %21, i32* %22
%23 = call i32 @RTA_DATA(%struct.rtattr* %15)
%24 = call i32 @memcpy(i32 %23, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %17)
%25 = load i32, i32* %22
%26 = call i64 @NLMSG_ALIGN(i32 %25)
%27 = trunc i64 %26 to i32
%28 = add i32 %12, %27
%29 = call i32 @do_nl_req(i32 %0, %struct.nlmsghdr* %9, i32 %28, i32 %7)
%30 = call i32 @genl_parse_getfamily(i8* %6)
ret i32 %30
}