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

/* Variables and functions */
int /*<<< orphan*/ AF_NETLINK;
int /*<<< orphan*/ PF_NETLINK;
int /*<<< orphan*/ SOCK_RAW;
int bind(int, struct sockaddr *, int);
int errno;
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ memset(void *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ read_event(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int);
int main(int argc, char *argv[]) {
  struct sockaddr_nl addr;
  int nls;
  int rc;
  nls = socket(PF_NETLINK, SOCK_RAW, 19);
  printf("nls=%d\n", nls);
  memset((void *)&addr, 0, sizeof(addr));
  addr.nl_family = AF_NETLINK;
  addr.nl_pid = getpid();
  addr.nl_groups = 1;
  rc = bind(nls, (struct sockaddr *)&addr, sizeof(addr));
  printf("errno=%d\n", errno);
  perror("bind");
  printf("rc from bind = %d\n", rc);
  while (1)
    read_event(nls);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    $0x13,%edx
call   1090 <socket@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xe51(%rip),%rdi
call   1040 <printf@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x24(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
mov    %eax,-0x28(%rbp)
mov    0x2dcc(%rip),%rax
mov    (%rax),%esi
lea    0xe03(%rip),%rdi
call   1040 <printf@plt>
lea    0xe01(%rip),%rdi
call   1080 <perror@plt>
mov    -0x28(%rbp),%esi
lea    0xdf7(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%edi
call   1060 <read_event@plt>
jmp    1225 <main+0xb5>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    0x2e60(%rip),%rax
mov    (%rax),%esi
mov    $0x13,%edx
call   1090 <socket@plt>
mov    %eax,%ebx
lea    0xe63(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,0x4(%rsp)
movl   $0x1,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
mov    %eax,%ebp
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
lea    0xe12(%rip),%rdi
call   1040 <printf@plt>
lea    0xe10(%rip),%rdi
call   1080 <perror@plt>
lea    0xe09(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebx,%edi
call   1060 <read_event@plt>
jmp    1220 <main+0xb0>

LLVM IR (-O0):
%struct.sockaddr_nl = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_NETLINK = global i32 0
@SOCK_RAW = global i32 0
@.str = [8 x i8] c"nls=%d\0A\00"
@AF_NETLINK = global i32 0
@.str.1 = [10 x i8] c"errno=%d\0A\00"
@errno = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [19 x i8] c"rc from bind = %d\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_nl
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @PF_NETLINK
%10 = load i32, i32* @SOCK_RAW
%11 = call i32 @socket(i32 %9, i32 %10, i32 19)
store i32 %11, i32* %7
%12 = load i32, i32* %7
%13 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = bitcast %struct.sockaddr_nl* %6 to i8*
%15 = call i32 @memset(i8* %14, i32 0, i32 12)
%16 = load i32, i32* @AF_NETLINK
%17 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %6, i32 0, i32 2
store i32 %16, i32* %17
%18 = call i32 (...) @getpid()
%19 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %6, i32 0, i32 1
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %6, i32 0, i32 0
store i32 1, i32* %20
%21 = load i32, i32* %7
%22 = bitcast %struct.sockaddr_nl* %6 to %struct.sockaddr*
%23 = call i32 @bind(i32 %21, %struct.sockaddr* %22, i32 12)
store i32 %23, i32* %8
%24 = load i32, i32* @errno
%25 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%27 = load i32, i32* %8
%28 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %27)
br label %29
29: ; preds = %2, %29
%30 = load i32, i32* %7
%31 = call i32 @read_event(i32 %30)
br label %29
}

LLVM IR (-O2):
%struct.sockaddr_nl = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@PF_NETLINK = global i32 0
@SOCK_RAW = global i32 0
@.str = [8 x i8] c"nls=%d\0A\00"
@AF_NETLINK = global i32 0
@.str.1 = [10 x i8] c"errno=%d\0A\00"
@errno = global i32 0
@.str.2 = [5 x i8] c"bind\00"
@.str.3 = [19 x i8] c"rc from bind = %d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_nl
%4 = bitcast %struct.sockaddr_nl* %3 to i8*
%5 = load i32, i32* @PF_NETLINK
%6 = load i32, i32* @SOCK_RAW
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 19)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = call i32 @memset(i8* %4, 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 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %3, i64 0, i32 0
store i32 1, i32* %14
%15 = bitcast %struct.sockaddr_nl* %3 to %struct.sockaddr*
%16 = call i32 @bind(i32 %7, %struct.sockaddr* %15, i32 12)
%17 = load i32, i32* @errno
%18 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %16)
br label %21
21: ; preds = %21, %2
%22 = call i32 @read_event(i32 %7)
br label %21
}