#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_pid;
  int nlmsg_len;
  int nlmsg_pid;
  int msg_namelen;
  int msg_iovlen;
  struct iovec *msg_iov;
  void *msg_name;
  scalar_t__ nlmsg_flags;
  scalar_t__ nl_groups;
  void *nl_family;
};
struct sockaddr {
  int dummy;
};
struct nlmsghdr {
  int nl_pid;
  int nlmsg_len;
  int nlmsg_pid;
  int msg_namelen;
  int msg_iovlen;
  struct iovec *msg_iov;
  void *msg_name;
  scalar_t__ nlmsg_flags;
  scalar_t__ nl_groups;
  void *nl_family;
};
struct msghdr {
  int nl_pid;
  int nlmsg_len;
  int nlmsg_pid;
  int msg_namelen;
  int msg_iovlen;
  struct iovec *msg_iov;
  void *msg_name;
  scalar_t__ nlmsg_flags;
  scalar_t__ nl_groups;
  void *nl_family;
};
struct iovec {
  int iov_len;
  void *iov_base;
};
typedef int /*<<< orphan*/ src_addr;
typedef int /*<<< orphan*/ msg;
typedef int /*<<< orphan*/ dest_addr;

/* Variables and functions */
void *AF_NETLINK;
scalar_t__ NLMSG_DATA(struct sockaddr_nl *);
int NLMSG_SPACE(int);
int /*<<< orphan*/ SOCK_RAW;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(struct sockaddr_nl *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int recvmsg(int, struct sockaddr_nl *, int /*<<< orphan*/);
int sendmsg(int, struct sockaddr_nl *, int /*<<< orphan*/);
int socket(void *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcpy(scalar_t__, char *);
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int state;
  struct sockaddr_nl src_addr, dest_addr;
  struct nlmsghdr *nlh = NULL;
  struct iovec iov;
  struct msghdr msg;
  int sock_fd, retval;
  int state_smg = 0;
  sock_fd = socket(AF_NETLINK, SOCK_RAW, 25);
  if (sock_fd == -1) {
    printf("error getting socket: %s", strerror(errno));
    return -1;
  }
  memset(&src_addr, 0, sizeof(src_addr));
  src_addr.nl_family = AF_NETLINK;
  src_addr.nl_pid = 100;
  src_addr.nl_groups = 0;
  retval = bind(sock_fd, (struct sockaddr *)&src_addr, sizeof(src_addr));
  if (retval < 0) {
    printf("bind failed: %s", strerror(errno));
    close(sock_fd);
    return -1;
  }
  nlh = (struct nlmsghdr *)malloc(NLMSG_SPACE(1024));
  if (!nlh) {
    printf("malloc nlmsghdr error!\n");
    close(sock_fd);
    return -1;
  }
  memset(&dest_addr, 0, sizeof(dest_addr));
  dest_addr.nl_family = AF_NETLINK;
  dest_addr.nl_pid = 0;
  dest_addr.nl_groups = 0;
  nlh->nlmsg_len = NLMSG_SPACE(1024);
  nlh->nlmsg_pid = 100;
  nlh->nlmsg_flags = 0;
  strcpy(NLMSG_DATA(nlh), "Hello from client!");
  iov.iov_base = (void *)nlh;
  iov.iov_len = NLMSG_SPACE(1024);
  memset(&msg, 0, sizeof(msg));
  msg.msg_name = (void *)&dest_addr;
  msg.msg_namelen = sizeof(dest_addr);
  msg.msg_iov = &iov;
  msg.msg_iovlen = 1;
  printf("state_smg\n");
  state_smg = sendmsg(sock_fd, &msg, 0);
  if (state_smg == -1) {
    printf("get error sendmsg = %s\n", strerror(errno));
  }
  memset(nlh, 0, NLMSG_SPACE(1024));
  printf("waiting received!\n");
  state = recvmsg(sock_fd, &msg, 0);
  if (state < 0) {
    printf("state<1");
  }
  printf("Received message: %s\n", (char *)NLMSG_DATA(nlh));
  close(sock_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0xa0(%rbp)
movl   $0x0,-0xfc(%rbp)
mov    0x2deb(%rip),%rax
mov    (%rax),%rdi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
mov    $0x19,%edx
call   10e0 <socket@plt>
mov    %eax,-0xf4(%rbp)
cmpl   $0xffffffff,-0xf4(%rbp)
jne    1249 <main+0x89>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xdca(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14e8 <main+0x328>
lea    -0x58(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
mov    0x2d80(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x64,-0x58(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0xf4(%rbp),%edi
lea    -0x58(%rbp),%rsi
mov    $0x40,%edx
call   10c0 <bind@plt>
mov    %eax,-0xf8(%rbp)
cmpl   $0x0,-0xf8(%rbp)
jge    12d3 <main+0x113>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xf4(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14e8 <main+0x328>
mov    $0x400,%edi
call   1080 <NLMSG_SPACE@plt>
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0xa0(%rbp)
cmpq   $0x0,-0xa0(%rbp)
jne    131e <main+0x15e>
lea    0xd29(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xf4(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    14e8 <main+0x328>
lea    -0x98(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
mov    0x2ca8(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
movl   $0x0,-0x98(%rbp)
movq   $0x0,-0x68(%rbp)
mov    $0x400,%edi
call   1080 <NLMSG_SPACE@plt>
mov    %eax,%ecx
mov    -0xa0(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0xa0(%rbp),%rax
movl   $0x64,0x8(%rax)
mov    -0xa0(%rbp),%rax
movq   $0x0,0x28(%rax)
mov    -0xa0(%rbp),%rdi
call   1090 <NLMSG_DATA@plt>
mov    %rax,%rdi
lea    0xca7(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0xa0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    $0x400,%edi
call   1080 <NLMSG_SPACE@plt>
mov    %eax,-0xb0(%rbp)
lea    -0xf0(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1060 <memset@plt>
lea    -0x98(%rbp),%rax
mov    %rax,-0xd0(%rbp)
movl   $0x40,-0xe4(%rbp)
lea    -0xb0(%rbp),%rax
mov    %rax,-0xd8(%rbp)
movl   $0x1,-0xe0(%rbp)
lea    0xc4d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xf4(%rbp),%edi
lea    -0xf0(%rbp),%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
mov    %eax,-0xfc(%rbp)
cmpl   $0xffffffff,-0xfc(%rbp)
jne    1454 <main+0x294>
mov    0x2b94(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    %rax,%rsi
lea    0xc12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xa0(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    $0x400,%edi
call   1080 <NLMSG_SPACE@plt>
mov    -0x108(%rbp),%rdi
mov    %eax,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0xbf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xf4(%rbp),%edi
lea    -0xf0(%rbp),%rsi
xor    %edx,%edx
call   10b0 <recvmsg@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    14b9 <main+0x2f9>
lea    0xbd8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xa0(%rbp),%rdi
call   1090 <NLMSG_DATA@plt>
mov    %rax,%rsi
lea    0xbc3(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0xf4(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0xd0,%rsp
mov    0x2dfa(%rip),%r12
mov    (%r12),%rdi
mov    0x2df7(%rip),%rax
mov    (%rax),%esi
mov    $0x19,%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     13c3 <main+0x1f3>
mov    %eax,%ebx
lea    0x90(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
mov    (%r12),%rax
mov    %rax,0xc8(%rsp)
movl   $0x64,0x90(%rsp)
movq   $0x0,0xc0(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x40,%edx
call   10d0 <bind@plt>
test   %eax,%eax
js     13e4 <main+0x214>
mov    $0x400,%edi
call   1090 <NLMSG_SPACE@plt>
mov    %eax,%edi
call   10b0 <malloc@plt>
test   %rax,%rax
je     1405 <main+0x235>
mov    %rax,%r14
lea    0x50(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
mov    (%r12),%rax
mov    %rax,0x88(%rsp)
movl   $0x0,0x50(%rsp)
movq   $0x0,0x80(%rsp)
mov    $0x400,%edi
call   1090 <NLMSG_SPACE@plt>
mov    %eax,0x4(%r14)
movl   $0x64,0x8(%r14)
movq   $0x0,0x28(%r14)
mov    %r14,%rdi
call   10a0 <NLMSG_DATA@plt>
lea    0xd52(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %r14,0x8(%rsp)
mov    $0x400,%edi
call   1090 <NLMSG_SPACE@plt>
mov    %eax,(%rsp)
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1070 <memset@plt>
mov    %r15,0x30(%rsp)
movabs $0x100000040,%rax
mov    %rax,0x1c(%rsp)
mov    %rsp,%rax
mov    %rax,0x28(%rsp)
lea    0xd61(%rip),%rdi
call   1050 <puts@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
xor    %edx,%edx
call   1040 <sendmsg@plt>
cmp    $0xffffffff,%eax
jne    135d <main+0x18d>
mov    0x2c8b(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xce9(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x400,%edi
call   1090 <NLMSG_SPACE@plt>
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
mov    %eax,%edx
call   1070 <memset@plt>
lea    0xd17(%rip),%rdi
call   1050 <puts@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
xor    %edx,%edx
call   10c0 <recvmsg@plt>
test   %eax,%eax
jns    13a1 <main+0x1d1>
lea    0xcba(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
call   10a0 <NLMSG_DATA@plt>
lea    0xcac(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%edi
call   1080 <close@plt>
jmp    141d <main+0x24d>
mov    0x2c06(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xc28(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1418 <main+0x248>
mov    0x2be5(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
lea    0xc20(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1411 <main+0x241>
lea    0xc66(%rip),%rdi
call   1050 <puts@plt>
mov    %ebx,%edi
call   1080 <close@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0xd0,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_nl = type { i32, i32, i32, i32, i32, %struct.iovec*, i8*, i64, i64, i8* }
%struct.iovec = type { i32, i8* }
%struct.nlmsghdr = type { i32, i32, i32, i32, i32, %struct.iovec*, i8*, i64, i64, i8* }
%struct.msghdr = type { i32, i32, i32, i32, i32, %struct.iovec*, i8*, i64, i64, i8* }
%struct.sockaddr = type { i32 }
@AF_NETLINK = global i8* null
@SOCK_RAW = global i32 0
@.str = [25 x i8] c"error getting socket: %s\00"
@errno = global i32 0
@.str.1 = [16 x i8] c"bind failed: %s\00"
@.str.2 = [24 x i8] c"malloc nlmsghdr error!\0A\00"
@.str.3 = [19 x i8] c"Hello from client!\00"
@.str.4 = [11 x i8] c"state_smg\0A\00"
@.str.5 = [24 x i8] c"get error sendmsg = %s\0A\00"
@.str.6 = [19 x i8] c"waiting received!\0A\00"
@.str.7 = [8 x i8] c"state<1\00"
@.str.8 = [22 x i8] c"Received message: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_nl
%8 = alloca %struct.sockaddr_nl
%9 = alloca %struct.nlmsghdr*
%10 = alloca %struct.iovec
%11 = alloca %struct.msghdr
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.nlmsghdr* null, %struct.nlmsghdr** %9
store i32 0, i32* %14
%15 = load i8*, i8** @AF_NETLINK
%16 = load i32, i32* @SOCK_RAW
%17 = call i32 @socket(i8* %15, i32 %16, i32 25)
store i32 %17, i32* %12
%18 = load i32, i32* %12
%19 = icmp eq i32 %18, -1
br i1 %19, label %20, label %24
20: ; preds = %2
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %22)
store i32 -1, i32* %3
br label %111
24: ; preds = %2
%25 = call i32 @memset(%struct.sockaddr_nl* %7, i32 0, i32 64)
%26 = load i8*, i8** @AF_NETLINK
%27 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %7, i32 0, i32 9
store i8* %26, i8** %27
%28 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %7, i32 0, i32 0
store i32 100, i32* %28
%29 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %7, i32 0, i32 8
store i64 0, i64* %29
%30 = load i32, i32* %12
%31 = bitcast %struct.sockaddr_nl* %7 to %struct.sockaddr*
%32 = call i32 @bind(i32 %30, %struct.sockaddr* %31, i32 64)
store i32 %32, i32* %13
%33 = load i32, i32* %13
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %41
35: ; preds = %24
%36 = load i32, i32* @errno
%37 = call i8* @strerror(i32 %36)
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %37)
%39 = load i32, i32* %12
%40 = call i32 @close(i32 %39)
store i32 -1, i32* %3
br label %111
41: ; preds = %24
%42 = call i32 @NLMSG_SPACE(i32 1024)
%43 = call i64 @malloc(i32 %42)
%44 = inttoptr i64 %43 to %struct.nlmsghdr*
store %struct.nlmsghdr* %44, %struct.nlmsghdr** %9
%45 = load %struct.nlmsghdr*, %struct.nlmsghdr** %9
%46 = icmp ne %struct.nlmsghdr* %45, null
br i1 %46, label %51, label %47
47: ; preds = %41
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%49 = load i32, i32* %12
%50 = call i32 @close(i32 %49)
store i32 -1, i32* %3
br label %111
51: ; preds = %41
%52 = call i32 @memset(%struct.sockaddr_nl* %8, i32 0, i32 64)
%53 = load i8*, i8** @AF_NETLINK
%54 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %8, i32 0, i32 9
store i8* %53, i8** %54
%55 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %8, i32 0, i32 0
store i32 0, i32* %55
%56 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %8, i32 0, i32 8
store i64 0, i64* %56
%57 = call i32 @NLMSG_SPACE(i32 1024)
%58 = load %struct.nlmsghdr*, %struct.nlmsghdr** %9
%59 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %58, i32 0, i32 1
store i32 %57, i32* %59
%60 = load %struct.nlmsghdr*, %struct.nlmsghdr** %9
%61 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %60, i32 0, i32 2
store i32 100, i32* %61
%62 = load %struct.nlmsghdr*, %struct.nlmsghdr** %9
%63 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %62, i32 0, i32 7
store i64 0, i64* %63
%64 = load %struct.nlmsghdr*, %struct.nlmsghdr** %9
%65 = bitcast %struct.nlmsghdr* %64 to %struct.sockaddr_nl*
%66 = call i64 @NLMSG_DATA(%struct.sockaddr_nl* %65)
%67 = call i32 @strcpy(i64 %66, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%68 = load %struct.nlmsghdr*, %struct.nlmsghdr** %9
%69 = bitcast %struct.nlmsghdr* %68 to i8*
%70 = getelementptr inbounds %struct.iovec, %struct.iovec* %10, i32 0, i32 1
store i8* %69, i8** %70
%71 = call i32 @NLMSG_SPACE(i32 1024)
%72 = getelementptr inbounds %struct.iovec, %struct.iovec* %10, i32 0, i32 0
store i32 %71, i32* %72
%73 = bitcast %struct.msghdr* %11 to %struct.sockaddr_nl*
%74 = call i32 @memset(%struct.sockaddr_nl* %73, i32 0, i32 64)
%75 = bitcast %struct.sockaddr_nl* %8 to i8*
%76 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %11, i32 0, i32 6
store i8* %75, i8** %76
%77 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %11, i32 0, i32 3
store i32 64, i32* %77
%78 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %11, i32 0, i32 5
store %struct.iovec* %10, %struct.iovec** %78
%79 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %11, i32 0, i32 4
store i32 1, i32* %79
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0))
%81 = load i32, i32* %12
%82 = bitcast %struct.msghdr* %11 to %struct.sockaddr_nl*
%83 = call i32 @sendmsg(i32 %81, %struct.sockaddr_nl* %82, i32 0)
store i32 %83, i32* %14
%84 = load i32, i32* %14
%85 = icmp eq i32 %84, -1
br i1 %85, label %86, label %90
86: ; preds = %51
%87 = load i32, i32* @errno
%88 = call i8* @strerror(i32 %87)
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %88)
br label %90
90: ; preds = %86, %51
%91 = load %struct.nlmsghdr*, %struct.nlmsghdr** %9
%92 = bitcast %struct.nlmsghdr* %91 to %struct.sockaddr_nl*
%93 = call i32 @NLMSG_SPACE(i32 1024)
%94 = call i32 @memset(%struct.sockaddr_nl* %92, i32 0, i32 %93)
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
%96 = load i32, i32* %12
%97 = bitcast %struct.msghdr* %11 to %struct.sockaddr_nl*
%98 = call i32 @recvmsg(i32 %96, %struct.sockaddr_nl* %97, i32 0)
store i32 %98, i32* %6
%99 = load i32, i32* %6
%100 = icmp slt i32 %99, 0
br i1 %100, label %101, label %103
101: ; preds = %90
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %103
103: ; preds = %101, %90
%104 = load %struct.nlmsghdr*, %struct.nlmsghdr** %9
%105 = bitcast %struct.nlmsghdr* %104 to %struct.sockaddr_nl*
%106 = call i64 @NLMSG_DATA(%struct.sockaddr_nl* %105)
%107 = inttoptr i64 %106 to i8*
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %107)
%109 = load i32, i32* %12
%110 = call i32 @close(i32 %109)
store i32 0, i32* %3
br label %111
111: ; preds = %103, %47, %35, %20
%112 = load i32, i32* %3
ret i32 %112
}

LLVM IR (-O2):
%struct.sockaddr_nl = type { i32, i32, i32, i32, i32, %struct.iovec*, i8*, i64, i64, i8* }
%struct.iovec = type { i32, i8* }
%struct.msghdr = type { i32, i32, i32, i32, i32, %struct.iovec*, i8*, i64, i64, i8* }
%struct.nlmsghdr = type { i32, i32, i32, i32, i32, %struct.iovec*, i8*, i64, i64, i8* }
%struct.sockaddr = type { i32 }
@AF_NETLINK = global i8* null
@SOCK_RAW = global i32 0
@.str = [25 x i8] c"error getting socket: %s\00"
@errno = global i32 0
@.str.1 = [16 x i8] c"bind failed: %s\00"
@.str.3 = [19 x i8] c"Hello from client!\00"
@.str.5 = [24 x i8] c"get error sendmsg = %s\0A\00"
@.str.7 = [8 x i8] c"state<1\00"
@.str.8 = [22 x i8] c"Received message: %s\0A\00"
@str = [23 x i8] c"malloc nlmsghdr error!\00"
@str.9 = [10 x i8] c"state_smg\00"
@str.10 = [18 x i8] c"waiting received!\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_nl
%4 = alloca %struct.sockaddr_nl
%5 = alloca %struct.iovec
%6 = alloca %struct.msghdr
%7 = bitcast %struct.sockaddr_nl* %3 to i8*
%8 = bitcast %struct.sockaddr_nl* %4 to i8*
%9 = bitcast %struct.iovec* %5 to i8*
%10 = bitcast %struct.msghdr* %6 to i8*
%11 = load i8*, i8** @AF_NETLINK
%12 = load i32, i32* @SOCK_RAW
%13 = tail call i32 @socket(i8* %11, i32 %12, i32 25)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %19
15: ; preds = %2
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %85
19: ; preds = %2
%20 = call i32 @memset(%struct.sockaddr_nl* %3, i32 0, i32 64)
%21 = load i8*, i8** @AF_NETLINK
%22 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %3, i64 0, i32 9
store i8* %21, i8** %22
%23 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %3, i64 0, i32 0
store i32 100, i32* %23
%24 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %3, i64 0, i32 8
store i64 0, i64* %24
%25 = bitcast %struct.sockaddr_nl* %3 to %struct.sockaddr*
%26 = call i32 @bind(i32 %13, %struct.sockaddr* %25, i32 64)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %19
%29 = load i32, i32* @errno
%30 = call i8* @strerror(i32 %29)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32 @close(i32 %13)
br label %85
33: ; preds = %19
%34 = call i32 @NLMSG_SPACE(i32 1024)
%35 = call i64 @malloc(i32 %34)
%36 = inttoptr i64 %35 to %struct.nlmsghdr*
%37 = icmp eq i64 %35, 0
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str, i64 0, i64 0))
%40 = call i32 @close(i32 %13)
br label %85
41: ; preds = %33
%42 = call i32 @memset(%struct.sockaddr_nl* %4, i32 0, i32 64)
%43 = load i8*, i8** @AF_NETLINK
%44 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %4, i64 0, i32 9
store i8* %43, i8** %44
%45 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %4, i64 0, i32 0
store i32 0, i32* %45
%46 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %4, i64 0, i32 8
store i64 0, i64* %46
%47 = call i32 @NLMSG_SPACE(i32 1024)
%48 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %36, i64 0, i32 1
store i32 %47, i32* %48
%49 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %36, i64 0, i32 2
store i32 100, i32* %49
%50 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %36, i64 0, i32 7
store i64 0, i64* %50
%51 = inttoptr i64 %35 to %struct.sockaddr_nl*
%52 = call i64 @NLMSG_DATA(%struct.sockaddr_nl* %51)
%53 = call i32 @strcpy(i64 %52, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
%54 = inttoptr i64 %35 to i8*
%55 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i64 0, i32 1
store i8* %54, i8** %55
%56 = call i32 @NLMSG_SPACE(i32 1024)
%57 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i64 0, i32 0
store i32 %56, i32* %57
%58 = bitcast %struct.msghdr* %6 to %struct.sockaddr_nl*
%59 = call i32 @memset(%struct.sockaddr_nl* %58, i32 0, i32 64)
%60 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 6
%61 = bitcast i8** %60 to %struct.sockaddr_nl**
store %struct.sockaddr_nl* %4, %struct.sockaddr_nl** %61
%62 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 3
store i32 64, i32* %62
%63 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 5
store %struct.iovec* %5, %struct.iovec** %63
%64 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %6, i64 0, i32 4
store i32 1, i32* %64
%65 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.9, i64 0, i64 0))
%66 = call i32 @sendmsg(i32 %13, %struct.sockaddr_nl* %58, i32 0)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %72
68: ; preds = %41
%69 = load i32, i32* @errno
%70 = call i8* @strerror(i32 %69)
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %68, %41
%73 = call i32 @NLMSG_SPACE(i32 1024)
%74 = call i32 @memset(%struct.sockaddr_nl* %51, i32 0, i32 %73)
%75 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.10, i64 0, i64 0))
%76 = call i32 @recvmsg(i32 %13, %struct.sockaddr_nl* %58, i32 0)
%77 = icmp slt i32 %76, 0
br i1 %77, label %78, label %80
78: ; preds = %72
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
br label %80
80: ; preds = %78, %72
%81 = call i64 @NLMSG_DATA(%struct.sockaddr_nl* %51)
%82 = inttoptr i64 %81 to i8*
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.8, i64 0, i64 0), i8* %82)
%84 = call i32 @close(i32 %13)
br label %85
85: ; preds = %80, %38, %28, %15
%86 = phi i32 [ -1, %15 ], [ -1, %28 ], [ 0, %80 ], [ -1, %38 ]
ret i32 %86
}