#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_type;
  size_t rta_len;
};
struct nlmsghdr {
  int nlmsg_len;
};

/* Variables and functions */
int NLMSG_ALIGN(int);
int RTA_ALIGN(size_t);
int /*<<< orphan*/ RTA_DATA(struct rtattr *);
size_t RTA_LENGTH(size_t);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, void *, size_t);
void _nlmsg_put(struct nlmsghdr *nlmsg, int type, void *data, size_t len) {
  struct rtattr *rta;
  size_t rtalen = RTA_LENGTH(len);
  rta =
      ((struct rtattr *)(((void *)(nlmsg)) + NLMSG_ALIGN((nlmsg)->nlmsg_len)));
  rta->rta_type = type;
  rta->rta_len = rtalen;
  if (data)
    memcpy(RTA_DATA(rta), data, len);
  nlmsg->nlmsg_len = NLMSG_ALIGN(nlmsg->nlmsg_len) + RTA_ALIGN(rtalen);
}


x86 assembly (clang, -O0):
<_nlmsg_put>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1070 <RTA_LENGTH@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1040 <NLMSG_ALIGN@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%rax
mov    %rcx,0x8(%rax)
cmpq   $0x0,-0x18(%rbp)
je     11cf <_nlmsg_put+0x7f>
mov    -0x28(%rbp),%rdi
call   1060 <RTA_DATA@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1040 <NLMSG_ALIGN@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x30(%rbp),%rdi
call   1030 <RTA_ALIGN@plt>
mov    -0x3c(%rbp),%ecx
add    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_nlmsg_put>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %rdx,%r12
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rcx,%rdi
call   1070 <RTA_LENGTH@plt>
mov    %rax,%r14
mov    (%rbx),%edi
call   1040 <NLMSG_ALIGN@plt>
movslq %eax,%rdi
mov    %ebp,(%rbx,%rdi,1)
mov    %r14,0x8(%rbx,%rdi,1)
test   %r12,%r12
je     119a <_nlmsg_put+0x4a>
add    %rbx,%rdi
call   1060 <RTA_DATA@plt>
mov    %eax,%edi
mov    %r12,%rsi
mov    %r15,%rdx
call   1050 <memcpy@plt>
mov    (%rbx),%edi
call   1040 <NLMSG_ALIGN@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1030 <RTA_ALIGN@plt>
add    %ebp,%eax
mov    %eax,(%rbx)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.nlmsghdr = type { i32 }
%struct.rtattr = type { i32, i64 }
define void @_nlmsg_put(%struct.nlmsghdr* %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca %struct.nlmsghdr*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca %struct.rtattr*
%10 = alloca i64
store %struct.nlmsghdr* %0, %struct.nlmsghdr** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%11 = load i64, i64* %8
%12 = call i64 @RTA_LENGTH(i64 %11)
store i64 %12, i64* %10
%13 = load %struct.nlmsghdr*, %struct.nlmsghdr** %5
%14 = bitcast %struct.nlmsghdr* %13 to i8*
%15 = load %struct.nlmsghdr*, %struct.nlmsghdr** %5
%16 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %15, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i32 @NLMSG_ALIGN(i32 %17)
%19 = sext i32 %18 to i64
%20 = getelementptr i8, i8* %14, i64 %19
%21 = bitcast i8* %20 to %struct.rtattr*
store %struct.rtattr* %21, %struct.rtattr** %9
%22 = load i32, i32* %6
%23 = load %struct.rtattr*, %struct.rtattr** %9
%24 = getelementptr inbounds %struct.rtattr, %struct.rtattr* %23, i32 0, i32 0
store i32 %22, i32* %24
%25 = load i64, i64* %10
%26 = load %struct.rtattr*, %struct.rtattr** %9
%27 = getelementptr inbounds %struct.rtattr, %struct.rtattr* %26, i32 0, i32 1
store i64 %25, i64* %27
%28 = load i8*, i8** %7
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %36
30: ; preds = %4
%31 = load %struct.rtattr*, %struct.rtattr** %9
%32 = call i32 @RTA_DATA(%struct.rtattr* %31)
%33 = load i8*, i8** %7
%34 = load i64, i64* %8
%35 = call i32 @memcpy(i32 %32, i8* %33, i64 %34)
br label %36
36: ; preds = %30, %4
%37 = load %struct.nlmsghdr*, %struct.nlmsghdr** %5
%38 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %37, i32 0, i32 0
%39 = load i32, i32* %38
%40 = call i32 @NLMSG_ALIGN(i32 %39)
%41 = load i64, i64* %10
%42 = call i32 @RTA_ALIGN(i64 %41)
%43 = add nsw i32 %40, %42
%44 = load %struct.nlmsghdr*, %struct.nlmsghdr** %5
%45 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %44, i32 0, i32 0
store i32 %43, i32* %45
ret void
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i32 }
%struct.rtattr = type { i32, i64 }
define void @_nlmsg_put(%struct.nlmsghdr* %0, i32 %1, i8* %2, i64 %3) {
%5 = tail call i64 @RTA_LENGTH(i64 %3)
%6 = bitcast %struct.nlmsghdr* %0 to i8*
%7 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %0, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i32 @NLMSG_ALIGN(i32 %8)
%10 = sext i32 %9 to i64
%11 = getelementptr i8, i8* %6, i64 %10
%12 = bitcast i8* %11 to i32*
store i32 %1, i32* %12
%13 = getelementptr inbounds i8, i8* %11, i64 8
%14 = bitcast i8* %13 to i64*
store i64 %5, i64* %14
%15 = icmp eq i8* %2, null
br i1 %15, label %20, label %16
16: ; preds = %4
%17 = bitcast i8* %11 to %struct.rtattr*
%18 = tail call i32 @RTA_DATA(%struct.rtattr* %17)
%19 = tail call i32 @memcpy(i32 %18, i8* %2, i64 %3)
br label %20
20: ; preds = %16, %4
%21 = load i32, i32* %7
%22 = tail call i32 @NLMSG_ALIGN(i32 %21)
%23 = tail call i32 @RTA_ALIGN(i64 %5)
%24 = add nsw i32 %23, %22
store i32 %24, i32* %7
ret void
}