#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 nlmsghdr {
  int nlmsg_type;
};
struct msghdr {
  void *member_0;
  int member_1;
  int member_3;
  int msg_namelen;
  int /*<<< orphan*/ member_6;
  int /*<<< orphan*/ member_5;
  int /*<<< orphan*/ *member_4;
  struct iovec *member_2;
};
struct iovec {
  char *member_0;
  int member_1;
};
typedef int /*<<< orphan*/ nladdr;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ NLMSG_DATA(struct nlmsghdr *);
struct nlmsghdr *NLMSG_NEXT(struct nlmsghdr *, int);
scalar_t__ NLMSG_OK(struct nlmsghdr *, int);
#define RTM_DELADDR 129
#define RTM_NEWADDR 128
int recvmsg(int, struct msghdr *, int /*<<< orphan*/);
int /*<<< orphan*/ rtnl_address_event(struct nlmsghdr *, int /*<<< orphan*/);
void rtnl_process(int fd) {
  char buf[8192];
  struct sockaddr_nl nladdr;
  struct iovec iov = {buf, sizeof(buf)};
  int status;
  struct nlmsghdr *h;
  struct msghdr msg = {(void *)&nladdr, sizeof(nladdr), &iov, 1, NULL, 0, 0};
  for (;;) {
    status = recvmsg(fd, &msg, 0);
    if (status <= 0)
      break;
    if (msg.msg_namelen != sizeof(nladdr))
      continue;
    h = (struct nlmsghdr *)buf;
    while (NLMSG_OK(h, status)) {
      switch (h->nlmsg_type) {
      case RTM_NEWADDR:
      case RTM_DELADDR:
        rtnl_address_event(h, NLMSG_DATA(h));
        break;
      }
      h = NLMSG_NEXT(h, status);
    }
  }
}


x86 assembly (clang, -O0):
<rtnl_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2070,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x2010(%rbp),%rax
mov    %rax,-0x2028(%rbp)
movl   $0x2000,-0x2020(%rbp)
lea    -0x2018(%rbp),%rax
mov    %rax,-0x2068(%rbp)
movl   $0x4,-0x2060(%rbp)
lea    -0x2028(%rbp),%rax
mov    %eax,-0x205c(%rbp)
movl   $0x1,-0x2058(%rbp)
movl   $0x0,-0x2054(%rbp)
movl   $0x0,-0x2050(%rbp)
movq   $0x0,-0x2048(%rbp)
movq   $0x0,-0x2040(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x2068(%rbp),%rsi
xor    %edx,%edx
call   1050 <recvmsg@plt>
mov    %eax,-0x202c(%rbp)
cmpl   $0x0,-0x202c(%rbp)
jg     11f8 <rtnl_process+0xa8>
jmp    129d <rtnl_process+0x14d>
movslq -0x2058(%rbp),%rax
cmp    $0x4,%rax
je     120e <rtnl_process+0xbe>
jmp    11cf <rtnl_process+0x7f>
lea    -0x2010(%rbp),%rax
mov    %rax,-0x2038(%rbp)
mov    -0x2038(%rbp),%rdi
mov    -0x202c(%rbp),%esi
call   1030 <NLMSG_OK@plt>
cmp    $0x0,%rax
je     1298 <rtnl_process+0x148>
mov    -0x2038(%rbp),%rax
mov    (%rax),%eax
add    $0xffffff80,%eax
sub    $0x1,%eax
ja     127a <rtnl_process+0x12a>
jmp    1252 <rtnl_process+0x102>
mov    -0x2038(%rbp),%rax
mov    %rax,-0x2070(%rbp)
mov    -0x2038(%rbp),%rdi
call   1040 <NLMSG_DATA@plt>
mov    -0x2070(%rbp),%rdi
mov    %eax,%esi
call   1060 <rtnl_address_event@plt>
mov    -0x2038(%rbp),%rdi
mov    -0x202c(%rbp),%esi
call   1070 <NLMSG_NEXT@plt>
mov    %rax,-0x2038(%rbp)
jmp    121c <rtnl_process+0xcc>
jmp    11cf <rtnl_process+0x7f>
add    $0x2070,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtnl_process>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2050,%rsp
mov    %edi,%r12d
lea    0x50(%rsp),%r14
mov    %r14,0x40(%rsp)
movl   $0x2000,0x48(%rsp)
lea    0x8(%rsp),%rax
mov    %rax,0x10(%rsp)
movl   $0x4,0x18(%rsp)
lea    0x40(%rsp),%rax
mov    %eax,0x1c(%rsp)
movq   $0x1,0x20(%rsp)
movl   $0x0,0x28(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x30(%rsp)
lea    0x10(%rsp),%rsi
xor    %edx,%edx
call   1050 <recvmsg@plt>
test   %eax,%eax
jle    123c <rtnl_process+0xec>
mov    %eax,%ebp
lea    0x10(%rsp),%r15
jmp    11e3 <rtnl_process+0x93>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12d,%edi
mov    %r15,%rsi
xor    %edx,%edx
call   1050 <recvmsg@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    123c <rtnl_process+0xec>
cmpl   $0x4,0x20(%rsp)
jne    11d0 <rtnl_process+0x80>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <NLMSG_OK@plt>
test   %rax,%rax
je     11d0 <rtnl_process+0x80>
mov    %r14,%rbx
jmp    121c <rtnl_process+0xcc>
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <NLMSG_NEXT@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %ebp,%esi
call   1030 <NLMSG_OK@plt>
test   %rax,%rax
je     11d0 <rtnl_process+0x80>
mov    (%rbx),%eax
and    $0xfffffffe,%eax
cmp    $0x80,%eax
jne    1200 <rtnl_process+0xb0>
mov    %rbx,%rdi
call   1040 <NLMSG_DATA@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1060 <rtnl_address_event@plt>
jmp    1200 <rtnl_process+0xb0>
add    $0x2050,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_nl = type { i32 }
%struct.iovec = type { i8*, i32 }
%struct.nlmsghdr = type { i32 }
%struct.msghdr = type { i8*, i32, i32, i32, i32, i32, i32*, %struct.iovec* }
define void @rtnl_process(i32 %0) {
%2 = alloca i32
%3 = alloca [8192 x i8]
%4 = alloca %struct.sockaddr_nl
%5 = alloca %struct.iovec
%6 = alloca i32
%7 = alloca %struct.nlmsghdr*
%8 = alloca %struct.msghdr
store i32 %0, i32* %2
%9 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i32 0, i32 0
%10 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
store i8* %10, i8** %9
%11 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i32 0, i32 1
store i32 8192, i32* %11
%12 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 0
%13 = bitcast %struct.sockaddr_nl* %4 to i8*
store i8* %13, i8** %12
%14 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 1
store i32 4, i32* %14
%15 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 2
%16 = ptrtoint %struct.iovec* %5 to i32
store i32 %16, i32* %15
%17 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 3
store i32 1, i32* %17
%18 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 4
store i32 0, i32* %18
%19 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 5
store i32 0, i32* %19
%20 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 6
store i32* null, i32** %20
%21 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 7
store %struct.iovec* null, %struct.iovec** %21
br label %22
22: ; preds = %55, %33, %1
%23 = load i32, i32* %2
%24 = call i32 @recvmsg(i32 %23, %struct.msghdr* %8, i32 0)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp sle i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %22
br label %56
28: ; preds = %22
%29 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %8, i32 0, i32 3
%30 = load i32, i32* %29
%31 = sext i32 %30 to i64
%32 = icmp ne i64 %31, 4
br i1 %32, label %33, label %34
33: ; preds = %28
br label %22
34: ; preds = %28
%35 = getelementptr inbounds [8192 x i8], [8192 x i8]* %3, i64 0, i64 0
%36 = bitcast i8* %35 to %struct.nlmsghdr*
store %struct.nlmsghdr* %36, %struct.nlmsghdr** %7
br label %37
37: ; preds = %51, %34
%38 = load %struct.nlmsghdr*, %struct.nlmsghdr** %7
%39 = load i32, i32* %6
%40 = call i64 @NLMSG_OK(%struct.nlmsghdr* %38, i32 %39)
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %55
42: ; preds = %37
%43 = load %struct.nlmsghdr*, %struct.nlmsghdr** %7
%44 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %43, i32 0, i32 0
%45 = load i32, i32* %44
switch i32 %45, label %51 [
i32 128, label %46
i32 129, label %46
]
46: ; preds = %42, %42
%47 = load %struct.nlmsghdr*, %struct.nlmsghdr** %7
%48 = load %struct.nlmsghdr*, %struct.nlmsghdr** %7
%49 = call i32 @NLMSG_DATA(%struct.nlmsghdr* %48)
%50 = call i32 @rtnl_address_event(%struct.nlmsghdr* %47, i32 %49)
br label %51
51: ; preds = %42, %46
%52 = load %struct.nlmsghdr*, %struct.nlmsghdr** %7
%53 = load i32, i32* %6
%54 = call %struct.nlmsghdr* @NLMSG_NEXT(%struct.nlmsghdr* %52, i32 %53)
store %struct.nlmsghdr* %54, %struct.nlmsghdr** %7
br label %37
55: ; preds = %37
br label %22
56: ; preds = %27
ret void
}

LLVM IR (-O2):
%struct.sockaddr_nl = type { i32 }
%struct.iovec = type { i8*, i32 }
%struct.msghdr = type { i8*, i32, i32, i32, i32, i32, i32*, %struct.iovec* }
%struct.nlmsghdr = type { i32 }
define void @rtnl_process(i32 %0) {
%2 = alloca [8192 x i8]
%3 = alloca %struct.sockaddr_nl
%4 = alloca %struct.iovec
%5 = alloca %struct.msghdr
%6 = getelementptr inbounds [8192 x i8], [8192 x i8]* %2, i64 0, i64 0
%7 = bitcast %struct.sockaddr_nl* %3 to i8*
%8 = bitcast %struct.iovec* %4 to i8*
%9 = getelementptr inbounds %struct.iovec, %struct.iovec* %4, i64 0, i32 0
store i8* %6, i8** %9
%10 = getelementptr inbounds %struct.iovec, %struct.iovec* %4, i64 0, i32 1
store i32 8192, i32* %10
%11 = bitcast %struct.msghdr* %5 to i8*
%12 = bitcast %struct.msghdr* %5 to %struct.sockaddr_nl**
store %struct.sockaddr_nl* %3, %struct.sockaddr_nl** %12
%13 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 1
store i32 4, i32* %13
%14 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 2
%15 = ptrtoint %struct.iovec* %4 to i64
%16 = trunc i64 %15 to i32
store i32 %16, i32* %14
%17 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 3
store i32 1, i32* %17
%18 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 4
store i32 0, i32* %18
%19 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 5
store i32 0, i32* %19
%20 = getelementptr inbounds %struct.msghdr, %struct.msghdr* %5, i64 0, i32 6
%21 = bitcast i32** %20 to i8*
%22 = call i32 @recvmsg(i32 %0, %struct.msghdr* %5, i32 0)
%23 = icmp slt i32 %22, 1
br i1 %23, label %51, label %24
24: ; preds = %1
%25 = bitcast [8192 x i8]* %2 to %struct.nlmsghdr*
%26 = bitcast [8192 x i8]* %2 to i32*
br label %27
27: ; preds = %24, %31
%28 = phi i32 [ %22, %24 ], [ %32, %31 ]
%29 = load i32, i32* %17
%30 = icmp eq i32 %29, 4
br i1 %30, label %34, label %31
31: ; preds = %46, %34, %27
%32 = call i32 @recvmsg(i32 %0, %struct.msghdr* %5, i32 0)
%33 = icmp slt i32 %32, 1
br i1 %33, label %51, label %27
34: ; preds = %27
%35 = call i64 @NLMSG_OK(%struct.nlmsghdr* %25, i32 %28)
%36 = icmp eq i64 %35, 0
br i1 %36, label %31, label %37
37: ; preds = %34, %46
%38 = phi %struct.nlmsghdr* [ %47, %46 ], [ %25, %34 ]
%39 = phi i32* [ %48, %46 ], [ %26, %34 ]
%40 = load i32, i32* %39
%41 = and i32 %40, -2
%42 = icmp eq i32 %41, 128
br i1 %42, label %43, label %46
43: ; preds = %37
%44 = call i32 @NLMSG_DATA(%struct.nlmsghdr* %38)
%45 = call i32 @rtnl_address_event(%struct.nlmsghdr* %38, i32 %44)
br label %46
46: ; preds = %37, %43
%47 = call %struct.nlmsghdr* @NLMSG_NEXT(%struct.nlmsghdr* %38, i32 %28)
%48 = getelementptr inbounds %struct.nlmsghdr, %struct.nlmsghdr* %47, i64 0, i32 0
%49 = call i64 @NLMSG_OK(%struct.nlmsghdr* %47, i32 %28)
%50 = icmp eq i64 %49, 0
br i1 %50, label %31, label %37
51: ; preds = %31, %1
ret void
}