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

/* Variables and functions */
int /*<<< orphan*/ AF_NETLINK;
int /*<<< orphan*/ LOG_ERR;
int /*<<< orphan*/ NETLINK_ROUTE;
int /*<<< orphan*/ SOCK_DGRAM;
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *, int,
                          int /*<<< orphan*/);
int get_socket() {
  int fd;
  struct sockaddr_nl sa = {AF_NETLINK, 0, 0, 0};
  fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
  if (fd < 0) {
    do {
      syslog(LOG_ERR,
             "%s(%d): "
             "%s",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/Ongy/ip-notify/refs/heads/master/src/"
             "ip-notify.c",
             49, strerror(errno));
      exit(-1);
    } while (0);
  }
  if (bind(fd, (struct sockaddr *)&sa, sizeof(sa)) < 0) {
    do {
      syslog(LOG_ERR,
             "%s(%d): "
             "%s",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/Ongy/ip-notify/refs/heads/master/src/"
             "ip-notify.c",
             53, strerror(errno));
      exit(-1);
    } while (0);
  }
  return fd;
}


x86 assembly (clang, -O0):
<get_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
mov    0x2e5f(%rip),%rax
mov    (%rax),%esi
mov    0x2e26(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jge    11ed <get_socket+0x9d>
jmp    11ab <get_socket+0x5b>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%r8d
lea    0xe2e(%rip),%rsi
lea    0xe32(%rip),%rdx
mov    $0x31,%ecx
call   1030 <syslog@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x10,%edx
call   1040 <bind@plt>
cmp    $0x0,%rax
jge    124f <get_socket+0xff>
jmp    120d <get_socket+0xbd>
mov    0x2dac(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%edi
mov    %eax,%r8d
lea    0xdcc(%rip),%rsi
lea    0xdd0(%rip),%rdx
mov    $0x35,%ecx
call   1030 <syslog@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_socket>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    %edi,(%rsp)
movq   $0x0,0x4(%rsp)
movl   $0x0,0xc(%rsp)
mov    0x2e6f(%rip),%rax
mov    (%rax),%esi
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
call   1070 <socket@plt>
test   %eax,%eax
js     11ab <get_socket+0x5b>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x10,%edx
call   1040 <bind@plt>
test   %rax,%rax
js     11d9 <get_socket+0x89>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e0e(%rip),%rax
mov    (%rax),%ebx
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe37(%rip),%rsi
lea    0xe3b(%rip),%rdx
mov    %ebx,%edi
mov    $0x31,%ecx
jmp    1205 <get_socket+0xb5>
mov    0x2de0(%rip),%rax
mov    (%rax),%ebx
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe09(%rip),%rsi
lea    0xe0d(%rip),%rdx
mov    %ebx,%edi
mov    $0x35,%ecx
mov    %eax,%r8d
call   1030 <syslog@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_nl = type { i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_NETLINK = global i32 0
@SOCK_DGRAM = global i32 0
@NETLINK_ROUTE = global i32 0
@LOG_ERR = global i32 0
@.str = [11 x i8] c"%s(%d): %s\00"
@.str.1 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Ongy/ip-notify/refs/heads/master/src/ip-notify.c\00"
@errno = global i32 0
define i32 @get_socket() {
%1 = alloca i32
%2 = alloca %struct.sockaddr_nl
%3 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %2, i32 0, i32 0
%4 = load i32, i32* @AF_NETLINK
store i32 %4, i32* %3
%5 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %2, i32 0, i32 1
store i32 0, i32* %5
%6 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %2, i32 0, i32 2
store i32 0, i32* %6
%7 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %2, i32 0, i32 3
store i32 0, i32* %7
%8 = load i32, i32* @AF_NETLINK
%9 = load i32, i32* @SOCK_DGRAM
%10 = load i32, i32* @NETLINK_ROUTE
%11 = call i32 @socket(i32 %8, i32 %9, i32 %10)
store i32 %11, i32* %1
%12 = load i32, i32* %1
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %0
br label %15
15: ; preds = %14
%16 = load i32, i32* @LOG_ERR
%17 = load i32, i32* @errno
%18 = call i32 @strerror(i32 %17)
%19 = call i32 @syslog(i32 %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 49, i32 %18)
%20 = call i32 @exit(i32 -1)
unreachable
21: ; No predecessors!
br label %22
22: ; preds = %21, %0
%23 = load i32, i32* %1
%24 = bitcast %struct.sockaddr_nl* %2 to %struct.sockaddr*
%25 = call i64 @bind(i32 %23, %struct.sockaddr* %24, i32 16)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %35
27: ; preds = %22
br label %28
28: ; preds = %27
%29 = load i32, i32* @LOG_ERR
%30 = load i32, i32* @errno
%31 = call i32 @strerror(i32 %30)
%32 = call i32 @syslog(i32 %29, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 53, i32 %31)
%33 = call i32 @exit(i32 -1)
unreachable
34: ; No predecessors!
br label %35
35: ; preds = %34, %22
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
%struct.sockaddr_nl = type { i32, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_NETLINK = global i32 0
@SOCK_DGRAM = global i32 0
@NETLINK_ROUTE = global i32 0
@LOG_ERR = global i32 0
@.str = [11 x i8] c"%s(%d): %s\00"
@.str.1 = [139 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Ongy/ip-notify/refs/heads/master/src/ip-notify.c\00"
@errno = global i32 0
define i32 @get_socket() {
%1 = alloca %struct.sockaddr_nl
%2 = bitcast %struct.sockaddr_nl* %1 to i8*
%3 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %1, i64 0, i32 0
%4 = load i32, i32* @AF_NETLINK
store i32 %4, i32* %3
%5 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %1, i64 0, i32 1
store i32 0, i32* %5
%6 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %1, i64 0, i32 2
store i32 0, i32* %6
%7 = getelementptr inbounds %struct.sockaddr_nl, %struct.sockaddr_nl* %1, i64 0, i32 3
store i32 0, i32* %7
%8 = load i32, i32* @SOCK_DGRAM
%9 = load i32, i32* @NETLINK_ROUTE
%10 = tail call i32 @socket(i32 %4, i32 %8, i32 %9)
%11 = icmp slt i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %0
%13 = load i32, i32* @LOG_ERR
%14 = load i32, i32* @errno
%15 = tail call i32 @strerror(i32 %14)
%16 = tail call i32 @syslog(i32 %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 49, i32 %15)
%17 = tail call i32 @exit(i32 -1)
unreachable
18: ; preds = %0
%19 = bitcast %struct.sockaddr_nl* %1 to %struct.sockaddr*
%20 = call i64 @bind(i32 %10, %struct.sockaddr* %19, i32 16)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %18
%23 = load i32, i32* @LOG_ERR
%24 = load i32, i32* @errno
%25 = call i32 @strerror(i32 %24)
%26 = call i32 @syslog(i32 %23, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([139 x i8], [139 x i8]* @.str.1, i64 0, i64 0), i32 53, i32 %25)
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %18
ret i32 %10
}