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

/* Variables and functions */
unsigned int RTA_ALIGN(int);
int /*<<< orphan*/ RTA_DATA(struct rtattr *);
int RTA_LENGTH(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/, void const *, int);
void addrta(struct nlmsghdr *n, int type, const void *data, int alen) {
  int len = RTA_LENGTH(alen);
  struct rtattr *rta;
  rta = ((struct rtattr *)(((void *)(n)) +
                           ((((n)->nlmsg_len) + 4U - 1) & ~(4U - 1))));
  rta->rta_type = type;
  rta->rta_len = len;
  memcpy(RTA_DATA(rta), data, alen);
  n->nlmsg_len = (((n->nlmsg_len) + 4U - 1) & ~(4U - 1)) + RTA_ALIGN(len);
}


x86 assembly (clang, -O0):
<addrta>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1060 <RTA_LENGTH@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%ecx
add    $0x4,%ecx
sub    $0x1,%ecx
and    $0xfffffffc,%ecx
mov    %ecx,%ecx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x28(%rbp),%rdi
call   1050 <RTA_DATA@plt>
mov    %eax,%edi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
add    $0x4,%eax
sub    $0x1,%eax
and    $0xfffffffc,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <RTA_ALIGN@plt>
mov    -0x2c(%rbp),%ecx
add    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addrta>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
mov    %ecx,%edi
call   1060 <RTA_LENGTH@plt>
mov    %eax,%r12d
mov    (%rbx),%eax
add    $0x3,%eax
and    $0xfffffffc,%eax
lea    (%rbx,%rax,1),%rdi
mov    %r15d,(%rbx,%rax,1)
mov    %r12d,0x4(%rbx,%rax,1)
call   1050 <RTA_DATA@plt>
mov    %eax,%edi
mov    %r14,%rsi
mov    %ebp,%edx
call   1040 <memcpy@plt>
mov    (%rbx),%ebp
add    $0x3,%ebp
and    $0xfffffffc,%ebp
mov    %r12d,%edi
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, i32 }
define void @addrta(%struct.nlmsghdr* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca %struct.nlmsghdr*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca %struct.rtattr*
store %struct.nlmsghdr* %0, %struct.nlmsghdr** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%11 = load i32, i32* %8
%12 = call i32 @RTA_LENGTH(i32 %11)
store i32 %12, i32* %9
%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 = add i32 %17, 4
%19 = sub i32 %18, 1
%20 = and i32 %19, -4
%21 = zext i32 %20 to i64
%22 = getelementptr i8, i8* %14, i64 %21
%23 = bitcast i8* %22 to %struct.rtattr*
store %struct.rtattr* %23, %struct.rtattr** %10
%24 = load i32, i32* %6
%25 = load %struct.rtattr*, %struct.rtattr** %10
%26 = getelementptr inbounds %struct.rtattr, %struct.rtattr* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = load i32, i32* %9
%28 = load %struct.rtattr*, %struct.rtattr** %10
%29 = getelementptr inbounds %struct.rtattr, %struct.rtattr* %28, i32 0, i32 1
store i32 %27, i32* %29
%30 = load %struct.rtattr*, %struct.rtattr** %10
%31 = call i32 @RTA_DATA(%struct.rtattr* %30)
%32 = load i8*, i8** %7
%33 = load i32, i32* %8
%34 = call i32 @memcpy(i32 %31, i8* %32, i32 %33)
%35 = load %struct.nlmsghdr*, %struct.nlmsghdr** %5
%36 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = add i32 %37, 4
%39 = sub i32 %38, 1
%40 = and i32 %39, -4
%41 = load i32, i32* %9
%42 = call i32 @RTA_ALIGN(i32 %41)
%43 = add 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, i32 }
define void @addrta(%struct.nlmsghdr* %0, i32 %1, i8* %2, i32 %3) {
%5 = tail call i32 @RTA_LENGTH(i32 %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 = add i32 %8, 3
%10 = and i32 %9, -4
%11 = zext i32 %10 to i64
%12 = getelementptr i8, i8* %6, i64 %11
%13 = bitcast i8* %12 to %struct.rtattr*
%14 = bitcast i8* %12 to i32*
store i32 %1, i32* %14
%15 = getelementptr inbounds i8, i8* %12, i64 4
%16 = bitcast i8* %15 to i32*
store i32 %5, i32* %16
%17 = tail call i32 @RTA_DATA(%struct.rtattr* %13)
%18 = tail call i32 @memcpy(i32 %17, i8* %2, i32 %3)
%19 = load i32, i32* %7
%20 = add i32 %19, 3
%21 = and i32 %20, -4
%22 = tail call i32 @RTA_ALIGN(i32 %5)
%23 = add i32 %21, %22
store i32 %23, i32* %7
ret void
}