#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 sockaddr_nl {
  int /*<<< orphan*/ nl_family;
};
struct nlmsghdr {
  int nlmsg_seq;
  int /*<<< orphan*/ nlmsg_flags;
  scalar_t__ nlmsg_pid;
  int /*<<< orphan*/ nlmsg_len;
};
struct msghdr {
  void *member_0;
  int member_1;
  int member_3;
  int /*<<< orphan*/ member_6;
  int /*<<< orphan*/ member_5;
  int /*<<< orphan*/ *member_4;
  struct iovec *member_2;
};
struct iovec {
  void *member_0;
  int /*<<< orphan*/ member_1;
};
typedef int /*<<< orphan*/ sa;

/* Variables and functions */
int /*<<< orphan*/ AF_NETLINK;
int /*<<< orphan*/ NLM_F_ACK;
int /*<<< orphan*/ memset(struct sockaddr_nl *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int sendmsg(int, struct msghdr *, int /*<<< orphan*/);
int nltest_sendmsg(int sock, struct nlmsghdr *nh) {
  struct sockaddr_nl sa;
  struct iovec iov = {(void *)nh, nh->nlmsg_len};
  struct msghdr msg = {(void *)&sa, sizeof(sa), &iov, 1, NULL, 0, 0};
  static int sequence_number = 0;
  memset(&sa, 0, sizeof(sa));
  sa.nl_family = AF_NETLINK;
  nh->nlmsg_pid = 0;
  nh->nlmsg_seq = ++sequence_number;
  nh->nlmsg_flags |= NLM_F_ACK;
  printf("Sending message\n");
  return sendmsg(sock, &msg, 0);
}


x86 assembly (clang, -O0):
<nltest_sendmsg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%eax
mov    %eax,-0x20(%rbp)
lea    -0x18(%rbp),%rax
mov    %rax,-0x50(%rbp)
movl   $0x4,-0x48(%rbp)
lea    -0x28(%rbp),%rax
mov    %eax,-0x44(%rbp)
movl   $0x1,-0x40(%rbp)
movl   $0x0,-0x3c(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x2e44(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,0x8(%rax)
mov    0x2e89(%rip),%ecx
add    $0x1,%ecx
mov    %ecx,0x2e80(%rip)
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    0x2e1f(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
or     0x4(%rax),%ecx
mov    %ecx,0x4(%rax)
lea    0xe24(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
xor    %edx,%edx
call   1030 <sendmsg@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nltest_sendmsg>:
push   %rbp
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rsi,0x10(%rsp)
mov    0x10(%rsi),%eax
mov    %eax,0x18(%rsp)
lea    0x8(%rsp),%rdi
mov    %rdi,0x20(%rsp)
movl   $0x4,0x28(%rsp)
lea    0x10(%rsp),%rax
mov    %eax,0x2c(%rsp)
movl   $0x1,0x30(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x34(%rsp)
movl   $0x0,0x44(%rsp)
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
movq   $0x0,0x8(%rbx)
mov    0x2e9b(%rip),%eax
add    $0x1,%eax
mov    %eax,0x2e92(%rip)
mov    %eax,(%rbx)
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
or     %eax,0x4(%rbx)
lea    0xe41(%rip),%rdi
call   1040 <puts@plt>
lea    0x20(%rsp),%rsi
mov    %ebp,%edi
xor    %edx,%edx
call   1030 <sendmsg@plt>
add    $0x48,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.nlmsghdr = type { i32, i32, i64, i32 }
%struct.sockaddr_nl = type { i32 }
%struct.iovec = type { i8*, i32 }
%struct.msghdr = type { i8*, i32, i32, i32, i32, i32*, %struct.iovec* }
@nltest_sendmsg.sequence_number = internal global i32 0
@AF_NETLINK = global i32 0
@NLM_F_ACK = global i32 0
@.str = [17 x i8] c"Sending message\0A\00"
define i32 @nltest_sendmsg(i32 %0, %struct.nlmsghdr* %1) {
%3 = alloca i32
%4 = alloca %struct.nlmsghdr*
%5 = alloca %struct.sockaddr_nl
%6 = alloca %struct.iovec
%7 = alloca %struct.msghdr
store i32 %0, i32* %3
store %struct.nlmsghdr* %1, %struct.nlmsghdr** %4
%8 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i32 0, i32 0
%9 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%10 = bitcast %struct.nlmsghdr* %9 to i8*
store i8* %10, i8** %8
%11 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i32 0, i32 1
%12 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%13 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %12, i32 0, i32 3
%14 = load i32, i32* %13
store i32 %14, i32* %11
%15 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i32 0, i32 0
%16 = bitcast %struct.sockaddr_nl* %5 to i8*
store i8* %16, i8** %15
%17 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i32 0, i32 1
store i32 4, i32* %17
%18 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i32 0, i32 2
%19 = ptrtoint %struct.iovec* %6 to i32
store i32 %19, i32* %18
%20 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i32 0, i32 3
store i32 1, i32* %20
%21 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i32 0, i32 4
store i32 0, i32* %21
%22 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i32 0, i32 5
store i32* null, i32** %22
%23 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %7, i32 0, i32 6
store %struct.iovec* null, %struct.iovec** %23
%24 = call i32 @memset(%struct.sockaddr_nl* %5, i32 0, i32 4)
%25 = load i32, i32* @AF_NETLINK
%26 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %5, i32 0, i32 0
store i32 %25, i32* %26
%27 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%28 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %27, i32 0, i32 2
store i64 0, i64* %28
%29 = load i32, i32* @nltest_sendmsg.sequence_number
%30 = add nsw i32 %29, 1
store i32 %30, i32* @nltest_sendmsg.sequence_number
%31 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%32 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %31, i32 0, i32 0
store i32 %30, i32* %32
%33 = load i32, i32* @NLM_F_ACK
%34 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%35 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %34, i32 0, i32 1
%36 = load i32, i32* %35
%37 = or i32 %36, %33
store i32 %37, i32* %35
%38 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%39 = load i32, i32* %3
%40 = call i32 @sendmsg(i32 %39, %struct.msghdr* %7, i32 0)
ret i32 %40
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i32, i32, i64, i32 }
%struct.sockaddr_nl = type { i32 }
%struct.iovec = type { i8*, i32 }
%struct.msghdr = type { i8*, i32, i32, i32, i32, i32*, %struct.iovec* }
@nltest_sendmsg.sequence_number = internal unnamed_addr global i32 0
@AF_NETLINK = global i32 0
@NLM_F_ACK = global i32 0
@str = [16 x i8] c"Sending message\00"
define i32 @nltest_sendmsg(i32 %0, %struct.nlmsghdr* %1) {
%3 = alloca %struct.sockaddr_nl
%4 = alloca %struct.iovec
%5 = alloca %struct.msghdr
%6 = bitcast %struct.sockaddr_nl* %3 to i8*
%7 = bitcast %struct.iovec* %4 to i8*
%8 = bitcast %struct.iovec* %4 to %struct.nlmsghdr**
store %struct.nlmsghdr* %1, %struct.nlmsghdr** %8
%9 = getelementptr inbounds %struct.iovec, %struct.iovec* %4, i64 0, i32 1
%10 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %1, i64 0, i32 3
%11 = load i32, i32* %10
store i32 %11, i32* %9
%12 = bitcast %struct.msghdr* %5 to i8*
%13 = bitcast %struct.msghdr* %5 to %struct.sockaddr_nl**
store %struct.sockaddr_nl* %3, %struct.sockaddr_nl** %13
%14 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 1
store i32 4, i32* %14
%15 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 2
%16 = ptrtoint %struct.iovec* %4 to i64
%17 = trunc i64 %16 to i32
store i32 %17, i32* %15
%18 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 3
store i32 1, i32* %18
%19 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 4
%20 = bitcast i32* %19 to i8*
%21 = call i32 @memset(%struct.sockaddr_nl* %3, i32 0, i32 4)
%22 = load i32, i32* @AF_NETLINK
%23 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %3, i64 0, i32 0
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %1, i64 0, i32 2
store i64 0, i64* %24
%25 = load i32, i32* @nltest_sendmsg.sequence_number
%26 = add nsw i32 %25, 1
store i32 %26, i32* @nltest_sendmsg.sequence_number
%27 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %1, i64 0, i32 0
store i32 %26, i32* %27
%28 = load i32, i32* @NLM_F_ACK
%29 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %1, i64 0, i32 1
%30 = load i32, i32* %29
%31 = or i32 %30, %28
store i32 %31, i32* %29
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%33 = call i32 @sendmsg(i32 %0, %struct.msghdr* %5, i32 0)
ret i32 %33
}