#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sock;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int, char *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int listen(int, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ ntohs(int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int chat_server_init(int port) {
  int listen_fd = -1;
  int ret = -1;
  int yes = 1;
  struct sockaddr_in sock;
  if ((listen_fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
    fprintf(stderr, "%s:%d >> Error: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/dorneanu/rsachat/refs/heads/master/src/"
            "server.c",
            72, "Can't create listening socket");
    exit(EXIT_FAILURE);
  };
  if ((ret = setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &yes,
                        sizeof(int))) < 0) {
    fprintf(stderr, "%s:%d >> Error: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/dorneanu/rsachat/refs/heads/master/src/"
            "server.c",
            77, "Can't reuse port");
    exit(EXIT_FAILURE);
  };
  memset((char *)&sock, 0, sizeof(sock));
  sock.sin_family = AF_INET;
  sock.sin_addr.s_addr = htonl(INADDR_ANY);
  sock.sin_port = ntohs(port);
  if ((ret = bind(listen_fd, (struct sockaddr *)&sock, sizeof(sock))) < 0) {
    fprintf(stderr, "%s:%d >> Error: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/dorneanu/rsachat/refs/heads/master/src/"
            "server.c",
            89, "Can't bind to port");
    exit(EXIT_FAILURE);
  };
  if ((ret = listen(listen_fd, 5)) < 0) {
    fprintf(stderr, "%s:%d >> Error: %s\n",
            "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
            "2022-01-22/02-19-57/repos/dorneanu/rsachat/refs/heads/master/src/"
            "server.c",
            96, "Can't listen to connections");
    exit(EXIT_FAILURE);
  };
  return listen_fd;
}


x86 assembly (clang, -O0):
<chat_server_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0xffffffff,-0x8(%rbp)
movl   $0xffffffff,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    120b <chat_server_init+0x7b>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
lea    0xe1b(%rip),%rsi
lea    0xe28(%rip),%rdx
mov    $0x48,%ecx
lea    0xea6(%rip),%r8
call   1060 <fprintf@plt>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
mov    0x2d8a(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    1271 <chat_server_init+0xe1>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
lea    0xdb5(%rip),%rsi
lea    0xdc2(%rip),%rdx
mov    $0x4d,%ecx
lea    0xe5e(%rip),%r8
call   1060 <fprintf@plt>
mov    0x2d46(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2d58(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
call   1080 <ntohs@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    12fc <chat_server_init+0x16c>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
lea    0xd2a(%rip),%rsi
lea    0xd37(%rip),%rdx
mov    $0x59,%ecx
lea    0xde4(%rip),%r8
call   1060 <fprintf@plt>
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   1070 <listen@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jge    134b <chat_server_init+0x1bb>
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
lea    0xcdb(%rip),%rsi
lea    0xce8(%rip),%rdx
mov    $0x60,%ecx
lea    0xda8(%rip),%r8
call   1060 <fprintf@plt>
mov    0x2c6c(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chat_server_init>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%r14d
movl   $0x1,0xc(%rsp)
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    0x2e0d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
test   %eax,%eax
js     125f <chat_server_init+0xcf>
mov    %eax,%ebx
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
mov    0x2dd2(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
test   %eax,%eax
js     1284 <chat_server_init+0xf4>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1050 <memset@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   1040 <htonl@plt>
mov    %eax,0x14(%rsp)
mov    %r14d,%edi
call   1080 <ntohs@plt>
mov    %eax,0x10(%rsp)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1090 <bind@plt>
test   %eax,%eax
js     12a9 <chat_server_init+0x119>
mov    %ebx,%edi
mov    $0x5,%esi
call   1070 <listen@plt>
test   %eax,%eax
js     12ce <chat_server_init+0x13e>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d62(%rip),%rax
mov    (%rax),%edi
lea    0xd91(%rip),%rsi
lea    0xd9e(%rip),%rdx
lea    0xe21(%rip),%r8
mov    $0x48,%ecx
jmp    12f1 <chat_server_init+0x161>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
lea    0xd6c(%rip),%rsi
lea    0xd79(%rip),%rdx
lea    0xe1a(%rip),%r8
mov    $0x4d,%ecx
jmp    12f1 <chat_server_init+0x161>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
lea    0xd47(%rip),%rsi
lea    0xd54(%rip),%rdx
lea    0xe06(%rip),%r8
mov    $0x59,%ecx
jmp    12f1 <chat_server_init+0x161>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
lea    0xd22(%rip),%rsi
lea    0xd2f(%rip),%rdx
lea    0xdf4(%rip),%r8
mov    $0x60,%ecx
call   1060 <fprintf@plt>
mov    0x2cb3(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"%s:%d >> Error: %s\0A\00"
@.str.1 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dorneanu/rsachat/refs/heads/master/src/server.c\00"
@.str.2 = [30 x i8] c"Can't create listening socket\00"
@EXIT_FAILURE = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [17 x i8] c"Can't reuse port\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.4 = [19 x i8] c"Can't bind to port\00"
@.str.5 = [28 x i8] c"Can't listen to connections\00"
define i32 @chat_server_init(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.sockaddr_in
store i32 %0, i32* %2
store i32 -1, i32* %3
store i32 -1, i32* %4
store i32 1, i32* %5
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = call i32 @socket(i32 %7, i32 %8, i32 0)
store i32 %9, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 72, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %1
%17 = load i32, i32* %3
%18 = load i32, i32* @SOL_SOCKET
%19 = load i32, i32* @SO_REUSEADDR
%20 = call i32 @setsockopt(i32 %17, i32 %18, i32 %19, i32* %5, i32 4)
store i32 %20, i32* %4
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %27
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 77, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32, i32* @EXIT_FAILURE
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %16
%28 = bitcast %struct.sockaddr_in* %6 to i8*
%29 = call i32 @memset(i8* %28, i32 0, i32 12)
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %30, i32* %31
%32 = load i32, i32* @INADDR_ANY
%33 = call i32 @htonl(i32 %32)
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
store i32 %33, i32* %35
%36 = load i32, i32* %2
%37 = call i32 @ntohs(i32 %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
store i32 %37, i32* %38
%39 = load i32, i32* %3
%40 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%41 = call i32 @bind(i32 %39, %struct.sockaddr* %40, i32 12)
store i32 %41, i32* %4
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %48
43: ; preds = %27
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 89, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %27
%49 = load i32, i32* %3
%50 = call i32 @listen(i32 %49, i32 5)
store i32 %50, i32* %4
%51 = icmp slt i32 %50, 0
br i1 %51, label %52, label %57
52: ; preds = %48
%53 = load i32, i32* @stderr
%54 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 96, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%55 = load i32, i32* @EXIT_FAILURE
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %48
%58 = load i32, i32* %3
ret i32 %58
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [20 x i8] c"%s:%d >> Error: %s\0A\00"
@.str.1 = [138 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/dorneanu/rsachat/refs/heads/master/src/server.c\00"
@.str.2 = [30 x i8] c"Can't create listening socket\00"
@EXIT_FAILURE = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.3 = [17 x i8] c"Can't reuse port\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.4 = [19 x i8] c"Can't bind to port\00"
@.str.5 = [28 x i8] c"Can't listen to connections\00"
define i32 @chat_server_init(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = load i32, i32* @PF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 72, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = load i32, i32* @SOL_SOCKET
%17 = load i32, i32* @SO_REUSEADDR
%18 = call i32 @setsockopt(i32 %8, i32 %16, i32 %17, i32* %2, i32 4)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %15
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 77, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %15
%26 = call i32 @memset(i8* %5, i32 0, i32 12)
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %27, i32* %28
%29 = load i32, i32* @INADDR_ANY
%30 = call i32 @htonl(i32 %29)
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %30, i32* %31
%32 = call i32 @ntohs(i32 %0)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %32, i32* %33
%34 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%35 = call i32 @bind(i32 %8, %struct.sockaddr* %34, i32 12)
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %42
37: ; preds = %25
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 89, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%40 = load i32, i32* @EXIT_FAILURE
%41 = call i32 @exit(i32 %40)
unreachable
42: ; preds = %25
%43 = call i32 @listen(i32 %8, i32 5)
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %50
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([138 x i8], [138 x i8]* @.str.1, i64 0, i64 0), i32 96, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %42
ret i32 %8
}