#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 nlattr {
  int nla_type;
  int /*<<< orphan*/ nla_len;
};

/* Variables and functions */
int /*<<< orphan*/ nla_attr_size(size_t);
void *nla_data(struct nlattr *);
int /*<<< orphan*/ nla_total_size(size_t);
void *nla_reserve(void **ctx, int type, size_t len) {
  struct nlattr *nla = (struct nlattr *)(*ctx);
  *(char **)ctx += nla_total_size(len);
  nla->nla_type = type;
  nla->nla_len = nla_attr_size(len);
  return nla_data(nla);
}


x86 assembly (clang, -O0):
<nla_reserve>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <nla_total_size@plt>
mov    %eax,%edx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
movslq %edx,%rdx
add    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0xc(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rdi
call   1040 <nla_attr_size@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <nla_data@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nla_reserve>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%r14d
mov    %rdi,%rbp
mov    (%rdi),%rbx
mov    %rdx,%rdi
call   1050 <nla_total_size@plt>
cltq
add    %rax,0x0(%rbp)
mov    %r14d,(%rbx)
mov    %r15,%rdi
call   1040 <nla_attr_size@plt>
mov    %eax,0x4(%rbx)
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <nla_data@plt>

LLVM IR (-O0):
%struct.nlattr = type { i32, i32 }
define i8* @nla_reserve(i8** %0, i32 %1, i64 %2) {
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i64
%7 = alloca %struct.nlattr*
store i8** %0, i8*** %4
store i32 %1, i32* %5
store i64 %2, i64* %6
%8 = load i8**, i8*** %4
%9 = load i8*, i8** %8
%10 = bitcast i8* %9 to %struct.nlattr*
store %struct.nlattr* %10, %struct.nlattr** %7
%11 = load i64, i64* %6
%12 = call i32 @nla_total_size(i64 %11)
%13 = load i8**, i8*** %4
%14 = load i8*, i8** %13
%15 = sext i32 %12 to i64
%16 = getelementptr inbounds i8, i8* %14, i64 %15
store i8* %16, i8** %13
%17 = load i32, i32* %5
%18 = load %struct.nlattr*, %struct.nlattr** %7
%19 = getelementptr inbounds %struct.nlattr, %struct.nlattr* %18, i32 0, i32 0
store i32 %17, i32* %19
%20 = load i64, i64* %6
%21 = call i32 @nla_attr_size(i64 %20)
%22 = load %struct.nlattr*, %struct.nlattr** %7
%23 = getelementptr inbounds %struct.nlattr, %struct.nlattr* %22, i32 0, i32 1
store i32 %21, i32* %23
%24 = load %struct.nlattr*, %struct.nlattr** %7
%25 = call i8* @nla_data(%struct.nlattr* %24)
ret i8* %25
}

LLVM IR (-O2):
%struct.nlattr = type { i32, i32 }
define i8* @nla_reserve(i8** nocapture %0, i32 %1, i64 %2) {
%4 = bitcast i8** %0 to %struct.nlattr**
%5 = load %struct.nlattr*, %struct.nlattr** %4
%6 = tail call i32 @nla_total_size(i64 %2)
%7 = load i8*, i8** %0
%8 = sext i32 %6 to i64
%9 = getelementptr inbounds i8, i8* %7, i64 %8
store i8* %9, i8** %0
%10 = getelementptr inbounds %struct.nlattr, %struct.nlattr* %5, i64 0, i32 0
store i32 %1, i32* %10
%11 = tail call i32 @nla_attr_size(i64 %2)
%12 = getelementptr inbounds %struct.nlattr, %struct.nlattr* %5, i64 0, i32 1
store i32 %11, i32* %12
%13 = tail call i8* @nla_data(%struct.nlattr* %5)
ret i8* %13
}