#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 {
  int nlmsg_len;
};
typedef int len;

/* Variables and functions */
int NLMSG_ALIGN(int);
int /*<<< orphan*/ memcpy(void *, void const *, int);
void add_rtattr(struct nlmsghdr *n, int type, const void *data, int alen) {
  struct rtattr *rta =
      ((struct rtattr *)(((void *)(n)) + NLMSG_ALIGN((n)->nlmsg_len)));
  int len = ((((sizeof(struct rtattr)) + 4 - 1) & ~(4 - 1)) + (alen));
  rta->rta_type = type;
  rta->rta_len = len;
  memcpy(((void *)(((char *)(rta)) +
                   ((((sizeof(struct rtattr)) + 4 - 1) & ~(4 - 1)) + (0)))),
         data, alen);
  n->nlmsg_len = NLMSG_ALIGN(n->nlmsg_len) + (((len) + 4 - 1) & ~(4 - 1));
}


x86 assembly (clang, -O0):
<add_rtattr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <NLMSG_ALIGN@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
movslq -0x1c(%rbp),%rax
add    $0x8,%rax
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x28(%rbp),%rdi
add    $0x8,%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <NLMSG_ALIGN@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    $0x4,%eax
sub    $0x1,%eax
and    $0xfffffffc,%eax
add    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_rtattr>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebx
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%r14
mov    (%rdi),%edi
call   1030 <NLMSG_ALIGN@plt>
cltq
lea    0x8(%rbx),%ecx
mov    %ebp,(%r14,%rax,1)
mov    %ecx,0x4(%r14,%rax,1)
lea    (%r14,%rax,1),%rdi
add    $0x8,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1040 <memcpy@plt>
mov    (%r14),%edi
call   1030 <NLMSG_ALIGN@plt>
add    $0xb,%ebx
and    $0xfffffffc,%ebx
add    %eax,%ebx
mov    %ebx,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.nlmsghdr = type { i32 }
define void @add_rtattr(%struct.nlmsghdr* %0, i32 %1, i8* %2, i32 %3) {
%5 = bitcast %struct.nlmsghdr* %0 to i8*
%6 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %0, i64 0, i32 0
%7 = load i32, i32* %6
%8 = tail call i32 @NLMSG_ALIGN(i32 %7)
%9 = sext i32 %8 to i64
%10 = getelementptr i8, i8* %5, i64 %9
%11 = add i32 %3, 8
%12 = bitcast i8* %10 to i32*
store i32 %1, i32* %12
%13 = getelementptr inbounds i8, i8* %10, i64 4
%14 = bitcast i8* %13 to i32*
store i32 %11, i32* %14
%15 = getelementptr inbounds i8, i8* %10, i64 8
%16 = tail call i32 @memcpy(i8* %15, i8* %2, i32 %3)
%17 = load i32, i32* %6
%18 = tail call i32 @NLMSG_ALIGN(i32 %17)
%19 = add i32 %3, 11
%20 = and i32 %19, -4
%21 = add nsw i32 %18, %20
store i32 %21, i32* %6
ret void
}