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

/* Variables and functions */
scalar_t__ NLMSG_DATA(struct nlmsghdr *);
int /*<<< orphan*/ NLMSG_SPACE(int);
struct nlmsghdr *malloc(int /*<<< orphan*/);
int /*<<< orphan*/ memset(struct nlmsghdr *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int, char *);
int recv(int, void *, int /*<<< orphan*/, int /*<<< orphan*/);
int read_event(int sock) {
  int ret;
  struct nlmsghdr *nlh;
  nlh = malloc(NLMSG_SPACE(1024));
  memset(nlh, 0, NLMSG_SPACE(1024));
  ret = recv(sock, (void *)nlh, NLMSG_SPACE(1024), 0);
  printf("Message size: %d , Message: %s\n", ret, (char *)NLMSG_DATA(nlh));
  return 0;
}


x86 assembly (clang, -O0):
<read_event>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x400,%edi
call   1060 <NLMSG_SPACE@plt>
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x400,%edi
call   1060 <NLMSG_SPACE@plt>
mov    -0x30(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x400,%edi
call   1060 <NLMSG_SPACE@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <NLMSG_DATA@plt>
mov    -0x14(%rbp),%esi
mov    %rax,%rdx
lea    0xe1a(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_event>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    $0x400,%edi
call   1060 <NLMSG_SPACE@plt>
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    $0x400,%edi
call   1060 <NLMSG_SPACE@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1050 <memset@plt>
mov    $0x400,%edi
call   1060 <NLMSG_SPACE@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1070 <NLMSG_DATA@plt>
lea    0xe48(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.nlmsghdr = type { i32 }
@.str = [32 x i8] c"Message size: %d , Message: %s\0A\00"
define i32 @read_event(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.nlmsghdr*
store i32 %0, i32* %2
%5 = call i32 @NLMSG_SPACE(i32 1024)
%6 = call %struct.nlmsghdr* @malloc(i32 %5)
store %struct.nlmsghdr* %6, %struct.nlmsghdr** %4
%7 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%8 = call i32 @NLMSG_SPACE(i32 1024)
%9 = call i32 @memset(%struct.nlmsghdr* %7, i32 0, i32 %8)
%10 = load i32, i32* %2
%11 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%12 = bitcast %struct.nlmsghdr* %11 to i8*
%13 = call i32 @NLMSG_SPACE(i32 1024)
%14 = call i32 @recv(i32 %10, i8* %12, i32 %13, i32 0)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = load %struct.nlmsghdr*, %struct.nlmsghdr** %4
%17 = call i64 @NLMSG_DATA(%struct.nlmsghdr* %16)
%18 = inttoptr i64 %17 to i8*
%19 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %15, i8* %18)
ret i32 0
}

LLVM IR (-O2):
%struct.nlmsghdr = type { i32 }
@.str = [32 x i8] c"Message size: %d , Message: %s\0A\00"
define i32 @read_event(i32 %0) {
%2 = tail call i32 @NLMSG_SPACE(i32 1024)
%3 = tail call %struct.nlmsghdr* @malloc(i32 %2)
%4 = tail call i32 @NLMSG_SPACE(i32 1024)
%5 = tail call i32 @memset(%struct.nlmsghdr* %3, i32 0, i32 %4)
%6 = bitcast %struct.nlmsghdr* %3 to i8*
%7 = tail call i32 @NLMSG_SPACE(i32 1024)
%8 = tail call i32 @recv(i32 %0, i8* %6, i32 %7, i32 0)
%9 = tail call i64 @NLMSG_DATA(%struct.nlmsghdr* %3)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %10)
ret i32 0
}