#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 /*<<< orphan*/ nl_groups;
  int /*<<< orphan*/ nl_pid;
  int /*<<< orphan*/ nl_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_NETLINK;
int /*<<< orphan*/ NETLINK_ROUTE;
int /*<<< orphan*/ PF_NETLINK;
int /*<<< orphan*/ RTMGRP_IPV4_ROUTE;
int /*<<< orphan*/ SOCK_RAW;
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int /*<<< orphan*/ read_event(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int nls = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
  struct sockaddr_nl addr;
  memset((void *)&addr, 0, sizeof(addr));
  addr.nl_family = AF_NETLINK;
  addr.nl_pid = getpid();
  addr.nl_groups = RTMGRP_IPV4_ROUTE;
  bind(nls, (struct sockaddr *)&addr, sizeof(addr));
  while (1)
    read_event(nls);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    0x2e72(%rip),%rax
mov    (%rax),%esi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1060 <bind@plt>
mov    -0x14(%rbp),%edi
call   1050 <read_event@plt>
jmp    11cc <main+0x7c>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    0x2e6a(%rip),%rax
mov    (%rax),%edi
mov    0x2e81(%rip),%rax
mov    (%rax),%esi
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
mov    %eax,%ebx
lea    0x8(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1040 <memset@plt>
mov    0x2e4c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,0xc(%rsp)
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1060 <bind@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1050 <read_event@plt>
jmp    11d0 <main+0x80>

LLVM IR (-O0):
%struct.sockaddr_nl = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_NETLINK = global i32 0
@SOCK_RAW = global i32 0
@NETLINK_ROUTE = global i32 0
@AF_NETLINK = global i32 0
@RTMGRP_IPV4_ROUTE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.sockaddr_nl
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* @PF_NETLINK
%9 = load i32, i32* @SOCK_RAW
%10 = load i32, i32* @NETLINK_ROUTE
%11 = call i32 @socket(i32 %8, i32 %9, i32 %10)
store i32 %11, i32* %6
%12 = bitcast %struct.sockaddr_nl* %7 to i8*
%13 = call i32 @memset(i8* %12, i32 0, i32 12)
%14 = load i32, i32* @AF_NETLINK
%15 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %7, i32 0, i32 2
store i32 %14, i32* %15
%16 = call i32 (...) @getpid()
%17 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %7, i32 0, i32 1
store i32 %16, i32* %17
%18 = load i32, i32* @RTMGRP_IPV4_ROUTE
%19 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %7, i32 0, i32 0
store i32 %18, i32* %19
%20 = load i32, i32* %6
%21 = bitcast %struct.sockaddr_nl* %7 to %struct.sockaddr*
%22 = call i32 @bind(i32 %20, %struct.sockaddr* %21, i32 12)
br label %23
23: ; preds = %2, %23
%24 = load i32, i32* %6
%25 = call i32 @read_event(i32 %24)
br label %23
}

LLVM IR (-O2):
%struct.sockaddr_nl = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_NETLINK = global i32 0
@SOCK_RAW = global i32 0
@NETLINK_ROUTE = global i32 0
@AF_NETLINK = global i32 0
@RTMGRP_IPV4_ROUTE = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_nl
%4 = load i32, i32* @PF_NETLINK
%5 = load i32, i32* @SOCK_RAW
%6 = load i32, i32* @NETLINK_ROUTE
%7 = tail call i32 @socket(i32 %4, i32 %5, i32 %6)
%8 = bitcast %struct.sockaddr_nl* %3 to i8*
%9 = call i32 @memset(i8* %8, i32 0, i32 12)
%10 = load i32, i32* @AF_NETLINK
%11 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %3, i64 0, i32 2
store i32 %10, i32* %11
%12 = call i32 (...) @getpid()
%13 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %3, i64 0, i32 1
store i32 %12, i32* %13
%14 = load i32, i32* @RTMGRP_IPV4_ROUTE
%15 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %3, i64 0, i32 0
store i32 %14, i32* %15
%16 = bitcast %struct.sockaddr_nl* %3 to %struct.sockaddr*
%17 = call i32 @bind(i32 %7, %struct.sockaddr* %16, i32 12)
br label %18
18: ; preds = %18, %2
%19 = call i32 @read_event(i32 %7)
br label %18
}