#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 dummy;
};
struct msghdr {
  int msg_namelen;
  int msg_iovlen;
  struct iovec *msg_iov;
  struct sockaddr_nl *msg_name;
};
struct iovec {
  size_t iov_len;
  void *iov_base;
};
typedef int /*<<< orphan*/ msg;

/* Variables and functions */
int /*<<< orphan*/ memset(struct msghdr *, int /*<<< orphan*/, int);
int recvmsg(int, struct msghdr *, int /*<<< orphan*/);
int get_msg(int fd, struct sockaddr_nl *sa, void *buf, size_t len) {
  struct iovec iov;
  struct msghdr msg;
  iov.iov_base = buf;
  iov.iov_len = len;
  memset(&msg, 0, sizeof(msg));
  msg.msg_name = sa;
  msg.msg_namelen = sizeof(*sa);
  msg.msg_iov = &iov;
  msg.msg_iovlen = 1;
  return recvmsg(fd, &msg, 0);
}


x86 assembly (clang, -O0):
<get_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
movl   $0x4,-0x48(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x1,-0x44(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x48(%rbp),%rsi
xor    %edx,%edx
call   1040 <recvmsg@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_msg>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    %rdx,0x10(%rsp)
mov    %rcx,0x8(%rsp)
lea    0x18(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
mov    %rbx,0x28(%rsp)
movabs $0x100000004,%rax
mov    %rax,0x18(%rsp)
lea    0x8(%rsp),%rax
mov    %rax,0x20(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1040 <recvmsg@plt>
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_nl = type { i32 }
%struct.iovec = type { i64, i8* }
%struct.msghdr = type { i32, i32, %struct.iovec*, %struct.sockaddr_nl* }
define i32 @get_msg(i32 %0, %struct.sockaddr_nl* %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca %struct.sockaddr_nl*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca %struct.iovec
%10 = alloca %struct.msghdr
store i32 %0, i32* %5
store %struct.sockaddr_nl* %1, %struct.sockaddr_nl** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
%11 = load i8*, i8** %7
%12 = getelementptr inbounds %struct.iovec, %struct.iovec* %9, i32 0, i32 1
store i8* %11, i8** %12
%13 = load i64, i64* %8
%14 = getelementptr inbounds %struct.iovec, %struct.iovec* %9, i32 0, i32 0
store i64 %13, i64* %14
%15 = call i32 @memset(%struct.msghdr* %10, i32 0, i32 24)
%16 = load %struct.sockaddr_nl*, %struct.sockaddr_nl** %6
%17 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %10, i32 0, i32 3
store %struct.sockaddr_nl* %16, %struct.sockaddr_nl** %17
%18 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %10, i32 0, i32 0
store i32 4, i32* %18
%19 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %10, i32 0, i32 2
store %struct.iovec* %9, %struct.iovec** %19
%20 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %10, i32 0, i32 1
store i32 1, i32* %20
%21 = load i32, i32* %5
%22 = call i32 @recvmsg(i32 %21, %struct.msghdr* %10, i32 0)
ret i32 %22
}

LLVM IR (-O2):
%struct.sockaddr_nl = type { i32 }
%struct.iovec = type { i64, i8* }
%struct.msghdr = type { i32, i32, %struct.iovec*, %struct.sockaddr_nl* }
define i32 @get_msg(i32 %0, %struct.sockaddr_nl* %1, i8* %2, i64 %3) {
%5 = alloca %struct.iovec
%6 = alloca %struct.msghdr
%7 = bitcast %struct.iovec* %5 to i8*
%8 = bitcast %struct.msghdr* %6 to i8*
%9 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i64 0, i32 1
store i8* %2, i8** %9
%10 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i64 0, i32 0
store i64 %3, i64* %10
%11 = call i32 @memset(%struct.msghdr* %6, i32 0, i32 24)
%12 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 3
store %struct.sockaddr_nl* %1, %struct.sockaddr_nl** %12
%13 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 0
store i32 4, i32* %13
%14 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 2
store %struct.iovec* %5, %struct.iovec** %14
%15 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 1
store i32 1, i32* %15
%16 = call i32 @recvmsg(i32 %0, %struct.msghdr* %6, i32 0)
ret i32 %16
}