#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 */
typedef scalar_t__ uint32_t;
struct sockaddr_nl {
  int /*<<< orphan*/ nl_family;
};
typedef int /*<<< orphan*/ sa;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ AF_NETLINK;
int /*<<< orphan*/ NETLINK_ROUTE;
scalar_t__ NLMSG_DONE;
scalar_t__ NLMSG_ERROR;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ check(int);
int get_ip(int, struct sockaddr_nl *, int /*<<< orphan*/);
int get_msg(int, struct sockaddr_nl *, char *, int);
int /*<<< orphan*/ memset(struct sockaddr_nl *, int /*<<< orphan*/, int);
scalar_t__ parse_nl_msg(char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(void) {
  int fd = 0, len = 0;
  fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  check(fd);
  struct sockaddr_nl sa;
  memset(&sa, 0, sizeof(sa));
  sa.nl_family = AF_NETLINK;
  len = get_ip(fd, &sa, AF_INET);
  check(len);
  char buf[4096];
  uint32_t nl_msg_type;
  do {
    len = get_msg(fd, &sa, buf, 4096);
    check(len);
    nl_msg_type = parse_nl_msg(buf, len);
  } while (nl_msg_type != NLMSG_DONE && nl_msg_type != NLMSG_ERROR);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1020,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
mov    0x2e17(%rip),%rax
mov    (%rax),%edx
call   1080 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
call   1070 <check@plt>
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e17(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rsi
call   1060 <get_ip@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <check@plt>
mov    -0x8(%rbp),%edi
lea    -0x1010(%rbp),%rdx
lea    -0x10(%rbp),%rsi
mov    $0x1000,%ecx
call   1050 <get_msg@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
call   1070 <check@plt>
lea    -0x1010(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <parse_nl_msg@plt>
mov    %rax,-0x1018(%rbp)
mov    -0x1018(%rbp),%rcx
xor    %eax,%eax
mov    0x2d90(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x1019(%rbp)
je     1259 <main+0xf9>
mov    -0x1018(%rbp),%rax
mov    0x2d8b(%rip),%rcx
cmp    (%rcx),%rax
setne  %al
mov    %al,-0x1019(%rbp)
mov    -0x1019(%rbp),%al
test   $0x1,%al
jne    11e7 <main+0x87>
xor    %eax,%eax
add    $0x1020,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    0x2e58(%rip),%rbx
mov    (%rbx),%edi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
call   1080 <socket@plt>
mov    %eax,%r15d
mov    %eax,%edi
call   1070 <check@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1030 <memset@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    0x2e2c(%rip),%rax
mov    (%rax),%edx
mov    %r15d,%edi
mov    %r14,%rsi
call   1060 <get_ip@plt>
mov    %eax,%edi
call   1070 <check@plt>
lea    0x10(%rsp),%rbx
mov    0x2de4(%rip),%r12
mov    0x2df5(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15d,%edi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    $0x1000,%ecx
call   1050 <get_msg@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1070 <check@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <parse_nl_msg@plt>
cmp    (%r12),%rax
je     1222 <main+0xc2>
cmp    0x0(%r13),%rax
jne    11f0 <main+0x90>
xor    %eax,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_nl = type { i32 }
@AF_NETLINK = global i32 0
@SOCK_RAW = global i32 0
@NETLINK_ROUTE = global i32 0
@AF_INET = global i32 0
@NLMSG_DONE = global i64 0
@NLMSG_ERROR = global i64 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_nl
%5 = alloca [4096 x i8]
%6 = alloca i64
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%7 = load i32, i32* @AF_NETLINK
%8 = load i32, i32* @SOCK_RAW
%9 = load i32, i32* @NETLINK_ROUTE
%10 = call i32 @socket(i32 %7, i32 %8, i32 %9)
store i32 %10, i32* %2
%11 = load i32, i32* %2
%12 = call i32 @check(i32 %11)
%13 = call i32 @memset(%struct.sockaddr_nl* %4, i32 0, i32 4)
%14 = load i32, i32* @AF_NETLINK
%15 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %4, i32 0, i32 0
store i32 %14, i32* %15
%16 = load i32, i32* %2
%17 = load i32, i32* @AF_INET
%18 = call i32 @get_ip(i32 %16, %struct.sockaddr_nl* %4, i32 %17)
store i32 %18, i32* %3
%19 = load i32, i32* %3
%20 = call i32 @check(i32 %19)
br label %21
21: ; preds = %38, %0
%22 = load i32, i32* %2
%23 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%24 = call i32 @get_msg(i32 %22, %struct.sockaddr_nl* %4, i8* %23, i32 4096)
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = call i32 @check(i32 %25)
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%28 = load i32, i32* %3
%29 = call i64 @parse_nl_msg(i8* %27, i32 %28)
store i64 %29, i64* %6
br label %30
30: ; preds = %21
%31 = load i64, i64* %6
%32 = load i64, i64* @NLMSG_DONE
%33 = icmp ne i64 %31, %32
br i1 %33, label %34, label %38
34: ; preds = %30
%35 = load i64, i64* %6
%36 = load i64, i64* @NLMSG_ERROR
%37 = icmp ne i64 %35, %36
br label %38
38: ; preds = %34, %30
%39 = phi i1 [ false, %30 ], [ %37, %34 ]
br i1 %39, label %21, label %40
40: ; preds = %38
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_nl = type { i32 }
@AF_NETLINK = global i32 0
@SOCK_RAW = global i32 0
@NETLINK_ROUTE = global i32 0
@AF_INET = global i32 0
@NLMSG_DONE = global i64 0
@NLMSG_ERROR = global i64 0
define i32 @main() {
%1 = alloca %struct.sockaddr_nl
%2 = alloca [4096 x i8]
%3 = load i32, i32* @AF_NETLINK
%4 = load i32, i32* @SOCK_RAW
%5 = load i32, i32* @NETLINK_ROUTE
%6 = tail call i32 @socket(i32 %3, i32 %4, i32 %5)
%7 = tail call i32 @check(i32 %6)
%8 = bitcast %struct.sockaddr_nl* %1 to i8*
%9 = call i32 @memset(%struct.sockaddr_nl* %1, i32 0, i32 4)
%10 = load i32, i32* @AF_NETLINK
%11 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %1, i64 0, i32 0
store i32 %10, i32* %11
%12 = load i32, i32* @AF_INET
%13 = call i32 @get_ip(i32 %6, %struct.sockaddr_nl* %1, i32 %12)
%14 = call i32 @check(i32 %13)
%15 = getelementptr inbounds [4096 x i8], [4096 x i8]* %2, i64 0, i64 0
br label %16
16: ; preds = %16, %0
%17 = call i32 @get_msg(i32 %6, %struct.sockaddr_nl* %1, i8* %15, i32 4096)
%18 = call i32 @check(i32 %17)
%19 = call i64 @parse_nl_msg(i8* %15, i32 %17)
%20 = load i64, i64* @NLMSG_DONE
%21 = icmp ne i64 %19, %20
%22 = load i64, i64* @NLMSG_ERROR
%23 = icmp ne i64 %19, %22
%24 = select i1 %21, i1 %23, i1 false
br i1 %24, label %16, label %25
25: ; preds = %16
ret i32 0
}