#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 nl_groups;
  int /*<<< orphan*/ nl_family;
};
struct sockaddr {
  int dummy;
};
struct nlmsghdr {
  int dummy;
};
struct msghdr {
  int member_1;
  int member_3;
  int /*<<< orphan*/ member_6;
  int /*<<< orphan*/ member_5;
  int /*<<< orphan*/ *member_4;
  struct iovec *member_2;
  struct sockaddr_nl *member_0;
};
struct iovec {
  char *member_0;
  int member_1;
};
typedef int /*<<< orphan*/ sa;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AF_NETLINK;
char *NLMSG_DATA(char *);
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ memset(struct sockaddr_nl *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, char, char *);
int recvmsg(int, struct msghdr *, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int);
main() {
  int fd;
  struct sockaddr_nl sa;
  int len;
  char buf[4096];
  struct iovec iov = {buf, sizeof(buf)};
  struct nlmsghdr *nh;
  struct msghdr msg = {&sa, sizeof(sa), &iov, 1, NULL, 0, 0};
  char *data;
  memset(&sa, 0, sizeof(sa));
  sa.nl_family = AF_NETLINK;
  sa.nl_groups = 1;
  fd = socket(AF_NETLINK, SOCK_RAW, 31);
  bind(fd, (struct sockaddr *)&sa, sizeof(sa));
  while (1 == 1) {
    len = recvmsg(fd, &msg, 0);
    data = NLMSG_DATA(buf);
    printf("Sensor = %d %s\n", data[0], &data[1]);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1070,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1030(%rbp)
movl   $0x1000,-0x1028(%rbp)
lea    -0x10(%rbp),%rax
mov    %eax,-0x1060(%rbp)
movl   $0x8,-0x105c(%rbp)
lea    -0x1030(%rbp),%rax
mov    %eax,-0x1058(%rbp)
movl   $0x1,-0x1054(%rbp)
movq   $0x0,-0x1050(%rbp)
movq   $0x0,-0x1048(%rbp)
movq   $0x0,-0x1040(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
mov    $0x1f,%edx
call   1080 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1070 <bind@plt>
mov    -0x8(%rbp),%edi
lea    -0x1060(%rbp),%rsi
xor    %edx,%edx
call   1060 <recvmsg@plt>
mov    %eax,-0x14(%rbp)
lea    -0x1020(%rbp),%rdi
call   1050 <NLMSG_DATA@plt>
mov    %rax,-0x1068(%rbp)
mov    -0x1068(%rbp),%rax
mov    (%rax),%al
mov    -0x1068(%rbp),%rdx
add    $0x1,%rdx
mov    %rdx,-0x1070(%rbp)
lea    0xd8e(%rip),%rdi
movsbl %al,%esi
call   1030 <printf@plt>
jmp    1229 <main+0xc9>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x1048,%rsp
lea    0x40(%rsp),%r15
mov    %r15,0x8(%rsp)
movl   $0x1000,0x10(%rsp)
mov    %rsp,%r14
mov    %r14d,0x18(%rsp)
movl   $0x8,0x1c(%rsp)
lea    0x8(%rsp),%rax
mov    %eax,0x20(%rsp)
movl   $0x1,0x24(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x28(%rsp)
movq   $0x0,0x38(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
mov    %edi,0x4(%rsp)
movl   $0x1,(%rsp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
mov    $0x1f,%edx
call   1080 <socket@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1070 <bind@plt>
lea    0x18(%rsp),%r14
lea    0xdfc(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebp,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1060 <recvmsg@plt>
mov    %r15,%rdi
call   1050 <NLMSG_DATA@plt>
movsbl (%rax),%esi
lea    0x1(%rax),%rdx
mov    %rbx,%rdi
call   1030 <printf@plt>
jmp    1210 <main+0xb0>

LLVM IR (-O0):
%struct.sockaddr_nl = type { i32, i32 }
%struct.iovec = type { i8*, i32 }
%struct.nlmsghdr = type { i32 }
%struct.msghdr = type { i32, i32, i32, i32, i32*, %struct.iovec*, %struct.sockaddr_nl* }
%struct.sockaddr = type { i32 }
@AF_NETLINK = global i32 0
@SOCK_RAW = global i32 0
@.str = [16 x i8] c"Sensor = %d %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_nl
%4 = alloca i32
%5 = alloca [4096 x i8]
%6 = alloca %struct.iovec
%7 = alloca %struct.nlmsghdr*
%8 = alloca %struct.msghdr
%9 = alloca i8*
store i32 0, i32* %1
%10 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i32 0, i32 0
%11 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
store i8* %11, i8** %10
%12 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i32 0, i32 1
store i32 4096, i32* %12
%13 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 0
%14 = ptrtoint %struct.sockaddr_nl* %3 to i32
store i32 %14, i32* %13
%15 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 1
store i32 8, i32* %15
%16 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 2
%17 = ptrtoint %struct.iovec* %6 to i32
store i32 %17, i32* %16
%18 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 3
store i32 1, i32* %18
%19 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 4
store i32* null, i32** %19
%20 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 5
store %struct.iovec* null, %struct.iovec** %20
%21 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 6
store %struct.sockaddr_nl* null, %struct.sockaddr_nl** %21
%22 = call i32 @memset(%struct.sockaddr_nl* %3, i32 0, i32 8)
%23 = load i32, i32* @AF_NETLINK
%24 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %3, i32 0, i32 1
store i32 %23, i32* %24
%25 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %3, i32 0, i32 0
store i32 1, i32* %25
%26 = load i32, i32* @AF_NETLINK
%27 = load i32, i32* @SOCK_RAW
%28 = call i32 @socket(i32 %26, i32 %27, i32 31)
store i32 %28, i32* %2
%29 = load i32, i32* %2
%30 = bitcast %struct.sockaddr_nl* %3 to %struct.sockaddr*
%31 = call i32 @bind(i32 %29, %struct.sockaddr* %30, i32 8)
br label %32
32: ; preds = %0, %32
%33 = load i32, i32* %2
%34 = call i32 @recvmsg(i32 %33, %struct.msghdr* %8, i32 0)
store i32 %34, i32* %4
%35 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%36 = call i8* @NLMSG_DATA(i8* %35)
store i8* %36, i8** %9
%37 = load i8*, i8** %9
%38 = getelementptr inbounds i8, i8* %37, i64 0
%39 = load i8, i8* %38
%40 = load i8*, i8** %9
%41 = getelementptr inbounds i8, i8* %40, i64 1
%42 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8 signext %39, i8* %41)
br label %32
}

LLVM IR (-O2):
%struct.sockaddr_nl = type { i32, i32 }
%struct.iovec = type { i8*, i32 }
%struct.msghdr = type { i32, i32, i32, i32, i32*, %struct.iovec*, %struct.sockaddr_nl* }
%struct.nlmsghdr = type { i32 }
%struct.sockaddr = type { i32 }
@AF_NETLINK = global i32 0
@SOCK_RAW = global i32 0
@.str = [16 x i8] c"Sensor = %d %s\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_nl
%2 = alloca [4096 x i8]
%3 = alloca %struct.iovec
%4 = alloca %struct.msghdr
%5 = bitcast %struct.sockaddr_nl* %1 to i8*
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
%7 = bitcast %struct.iovec* %3 to i8*
%8 = getelementptr inbounds %struct.iovec, %struct.iovec* %3, i64 0, i32 0
store i8* %6, i8** %8
%9 = getelementptr inbounds %struct.iovec, %struct.iovec* %3, i64 0, i32 1
store i32 4096, i32* %9
%10 = bitcast %struct.msghdr* %4 to i8*
%11 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 0
%12 = ptrtoint %struct.sockaddr_nl* %1 to i64
%13 = trunc i64 %12 to i32
store i32 %13, i32* %11
%14 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 1
store i32 8, i32* %14
%15 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 2
%16 = ptrtoint %struct.iovec* %3 to i64
%17 = trunc i64 %16 to i32
store i32 %17, i32* %15
%18 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 3
store i32 1, i32* %18
%19 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %4, i64 0, i32 4
%20 = bitcast i32** %19 to i8*
%21 = call i32 @memset(%struct.sockaddr_nl* %1, i32 0, i32 8)
%22 = load i32, i32* @AF_NETLINK
%23 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %1, i64 0, i32 1
store i32 %22, i32* %23
%24 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %1, i64 0, i32 0
store i32 1, i32* %24
%25 = load i32, i32* @SOCK_RAW
%26 = call i32 @socket(i32 %22, i32 %25, i32 31)
%27 = bitcast %struct.sockaddr_nl* %1 to %struct.sockaddr*
%28 = call i32 @bind(i32 %26, %struct.sockaddr* %27, i32 8)
br label %29
29: ; preds = %29, %0
%30 = call i32 @recvmsg(i32 %26, %struct.msghdr* %4, i32 0)
%31 = call i8* @NLMSG_DATA(i8* %6)
%32 = load i8, i8* %31
%33 = getelementptr inbounds i8, i8* %31, i64 1
%34 = call i32 @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8 signext %32, i8* %33)
br label %29
}