#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 nlmsghdr {
  int /*<<< orphan*/ nlmsg_pid;
  int /*<<< orphan*/ nlmsg_len;
};

/* Variables and functions */
int NLMSG_HDRLEN;
int /*<<< orphan*/ NLMSG_SPACE(int);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ memset(struct nlmsghdr *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
unsigned char *set_nl_header(unsigned char *data, int size) {
  struct nlmsghdr *nlh = (struct nlmsghdr *)data;
  memset(nlh, 0, NLMSG_SPACE(size));
  nlh->nlmsg_len = NLMSG_SPACE(size);
  nlh->nlmsg_pid = getpid();
  return data + NLMSG_HDRLEN;
}


x86 assembly (clang, -O0):
<set_nl_header>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
call   1050 <NLMSG_SPACE@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0xc(%rbp),%edi
call   1050 <NLMSG_SPACE@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x2e61(%rip),%rcx
movslq (%rcx),%rcx
add    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_nl_header>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,%edi
call   1050 <NLMSG_SPACE@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1040 <memset@plt>
mov    %ebp,%edi
call   1050 <NLMSG_SPACE@plt>
mov    %eax,0x4(%rbx)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,(%rbx)
mov    0x2e8b(%rip),%rax
movslq (%rax),%rax
add    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.nlmsghdr = type { i32, i32 }
@NLMSG_HDRLEN = global i32 0
define i8* @set_nl_header(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.nlmsghdr*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = bitcast i8* %6 to %struct.nlmsghdr*
store %struct.nlmsghdr* %7, %struct.nlmsghdr** %5
%8 = load %struct.nlmsghdr*, %struct.nlmsghdr** %5
%9 = load i32, i32* %4
%10 = call i32 @NLMSG_SPACE(i32 %9)
%11 = call i32 @memset(%struct.nlmsghdr* %8, i32 0, i32 %10)
%12 = load i32, i32* %4
%13 = call i32 @NLMSG_SPACE(i32 %12)
%14 = load %struct.nlmsghdr*, %struct.nlmsghdr** %5
%15 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %14, i32 0, i32 1
store i32 %13, i32* %15
%16 = call i32 (...) @getpid()
%17 = load %struct.nlmsghdr*, %struct.nlmsghdr** %5
%18 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %17, i32 0, i32 0
store i32 %16, i32* %18
%19 = load i8*, i8** %3
%20 = load i32, i32* @NLMSG_HDRLEN
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %19, i64 %21
ret i8* %22
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i32, i32 }
@NLMSG_HDRLEN = global i32 0
define i8* @set_nl_header(i8* %0, i32 %1) {
%3 = bitcast i8* %0 to %struct.nlmsghdr*
%4 = tail call i32 @NLMSG_SPACE(i32 %1)
%5 = tail call i32 @memset(%struct.nlmsghdr* %3, i32 0, i32 %4)
%6 = tail call i32 @NLMSG_SPACE(i32 %1)
%7 = getelementptr inbounds i8, i8* %0, i64 4
%8 = bitcast i8* %7 to i32*
store i32 %6, i32* %8
%9 = tail call i32 (...) @getpid()
%10 = bitcast i8* %0 to i32*
store i32 %9, i32* %10
%11 = load i32, i32* @NLMSG_HDRLEN
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds i8, i8* %0, i64 %12
ret i8* %13
}