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

/* Variables and functions */
int /*<<< orphan*/ AF_NETLINK;
int RTMGRP_IPV6_IFADDR;
int RTMGRP_LINK;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ memset(struct sockaddr_nl *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int ifup_start_listening(int fd) {
  struct sockaddr_nl sa;
  memset(&sa, 0, sizeof(sa));
  sa.nl_family = AF_NETLINK;
  sa.nl_groups = RTMGRP_LINK | RTMGRP_IPV6_IFADDR;
  if (bind(fd, (struct sockaddr *)&sa, sizeof(sa))) {
    perror("bind");
    return 0;
  }
  return 1;
}


x86 assembly (clang, -O0):
<ifup_start_listening>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e86(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%eax
mov    0x2e79(%rip),%rcx
or     (%rcx),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1040 <bind@plt>
cmp    $0x0,%rax
je     119f <ifup_start_listening+0x6f>
lea    0xe72(%rip),%rdi
call   1050 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11a6 <ifup_start_listening+0x76>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ifup_start_listening>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebx
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    0x2e89(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    0x2e9c(%rip),%rax
mov    0x2e7d(%rip),%rcx
mov    (%rcx),%ecx
or     (%rax),%ecx
mov    %ecx,(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1040 <bind@plt>
mov    %rax,%rcx
mov    $0x1,%eax
test   %rcx,%rcx
jne    118e <ifup_start_listening+0x5e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe6b(%rip),%rdi
call   1050 <perror@plt>
xor    %eax,%eax
jmp    1186 <ifup_start_listening+0x56>

LLVM IR (-O0):
%struct.sockaddr_nl = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_NETLINK = global i32 0
@RTMGRP_LINK = global i32 0
@RTMGRP_IPV6_IFADDR = global i32 0
@.str = [5 x i8] c"bind\00"
define i32 @ifup_start_listening(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_nl
store i32 %0, i32* %3
%5 = call i32 @memset(%struct.sockaddr_nl* %4, i32 0, i32 8)
%6 = load i32, i32* @AF_NETLINK
%7 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %4, i32 0, i32 1
store i32 %6, i32* %7
%8 = load i32, i32* @RTMGRP_LINK
%9 = load i32, i32* @RTMGRP_IPV6_IFADDR
%10 = or i32 %8, %9
%11 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %4, i32 0, i32 0
store i32 %10, i32* %11
%12 = load i32, i32* %3
%13 = bitcast %struct.sockaddr_nl* %4 to %struct.sockaddr*
%14 = call i64 @bind(i32 %12, %struct.sockaddr* %13, i32 8)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %2
br label %19
18: ; preds = %1
store i32 1, i32* %2
br label %19
19: ; preds = %18, %16
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
%struct.sockaddr_nl = type { i32, i32 }
%struct.sockaddr = type { i32 }
@AF_NETLINK = global i32 0
@RTMGRP_LINK = global i32 0
@RTMGRP_IPV6_IFADDR = global i32 0
@.str = [5 x i8] c"bind\00"
define i32 @ifup_start_listening(i32 %0) {
%2 = alloca %struct.sockaddr_nl
%3 = bitcast %struct.sockaddr_nl* %2 to i8*
%4 = call i32 @memset(%struct.sockaddr_nl* %2, i32 0, i32 8)
%5 = load i32, i32* @AF_NETLINK
%6 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %2, i64 0, i32 1
store i32 %5, i32* %6
%7 = load i32, i32* @RTMGRP_LINK
%8 = load i32, i32* @RTMGRP_IPV6_IFADDR
%9 = or i32 %8, %7
%10 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %2, i64 0, i32 0
store i32 %9, i32* %10
%11 = bitcast %struct.sockaddr_nl* %2 to %struct.sockaddr*
%12 = call i64 @bind(i32 %0, %struct.sockaddr* %11, i32 8)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %1
%15 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %1, %14
%17 = phi i32 [ 0, %14 ], [ 1, %1 ]
ret i32 %17
}