#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;
};

/* Variables and functions */
int NLMSG_ALIGN(int);
int RTA_ALIGN(int);
void *RTA_DATA(struct rtattr *);
int RTA_LENGTH(int);
__attribute__((visibility("hidden"))) void *rta_put(struct nlmsghdr *m,
                                                    int type, int len) {
  struct rtattr *rta = (void *)m + NLMSG_ALIGN(m->nlmsg_len);
  int rtalen = RTA_LENGTH(len);
  rta->rta_type = type;
  rta->rta_len = rtalen;
  m->nlmsg_len = NLMSG_ALIGN(m->nlmsg_len) + RTA_ALIGN(rtalen);
  return RTA_DATA(rta);
}


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

x86 assembly (clang, -O2):
<rta_put>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %esi,%r14d
mov    %rdi,%rbp
mov    (%rdi),%edi
call   1040 <NLMSG_ALIGN@plt>
movslq %eax,%rbx
lea    (%rbx,%rbp,1),%r15
mov    %r12d,%edi
call   1060 <RTA_LENGTH@plt>
mov    %eax,%r12d
mov    %r14d,0x0(%rbp,%rbx,1)
mov    %eax,0x4(%rbp,%rbx,1)
mov    0x0(%rbp),%edi
call   1040 <NLMSG_ALIGN@plt>
mov    %eax,%r14d
mov    %r12d,%edi
call   1030 <RTA_ALIGN@plt>
add    %r14d,%eax
mov    %eax,0x0(%rbp)
mov    %r15,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <RTA_DATA@plt>

LLVM IR (-O0):
%struct.nlmsghdr = type { i32 }
%struct.rtattr = type { i32, i32 }
define hidden i8* @rta_put(%struct.nlmsghdr* %0, i32 %1, i32 %2) {
%4 = alloca %struct.nlmsghdr*
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.rtattr*
%8 = alloca i32
store %struct.nlmsghdr* %0, %struct.nlmsghdr** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%10 = bitcast %struct.nlmsghdr* %9 to i8*
%11 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%12 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %11, i32 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @NLMSG_ALIGN(i32 %13)
%15 = sext i32 %14 to i64
%16 = getelementptr i8, i8* %10, i64 %15
%17 = bitcast i8* %16 to %struct.rtattr*
store %struct.rtattr* %17, %struct.rtattr** %7
%18 = load i32, i32* %6
%19 = call i32 @RTA_LENGTH(i32 %18)
store i32 %19, i32* %8
%20 = load i32, i32* %5
%21 = load %struct.rtattr*, %struct.rtattr** %7
%22 = getelementptr inbounds %struct.rtattr, %struct.rtattr* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = load i32, i32* %8
%24 = load %struct.rtattr*, %struct.rtattr** %7
%25 = getelementptr inbounds %struct.rtattr, %struct.rtattr* %24, i32 0, i32 1
store i32 %23, i32* %25
%26 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%27 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @NLMSG_ALIGN(i32 %28)
%30 = load i32, i32* %8
%31 = call i32 @RTA_ALIGN(i32 %30)
%32 = add nsw i32 %29, %31
%33 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%34 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %33, i32 0, i32 0
store i32 %32, i32* %34
%35 = load %struct.rtattr*, %struct.rtattr** %7
%36 = call i8* @RTA_DATA(%struct.rtattr* %35)
ret i8* %36
}

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