#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 {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ one;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
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 const *, int);
int /*<<< orphan*/ fatal_error(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int /*<<< orphan*/, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int cree_socket_ecoute(int port) {
  int listen_fd;
  struct sockaddr_in addr;
  int one = 1;
  listen_fd = socket(PF_INET, SOCK_STREAM, 0);
  if (listen_fd == -1)
    fatal_error("echec de socket");
  if (setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) == -1)
    fatal_error("echec de setsockopt(SO_REUSEADDR)");
  memset(&addr, 0, sizeof(addr));
  addr.sin_family = AF_INET;
  addr.sin_port = htons(port);
  addr.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(listen_fd, (const struct sockaddr *)&addr, sizeof(addr)) == -1)
    fatal_error("echec de bind");
  if (listen(listen_fd, 15) == -1)
    fatal_error("echec de listen");
  fprintf(stderr, "Serveur actif sur le port %i\n", port);
  return listen_fd;
}


x86 assembly (clang, -O0):
<cree_socket_ecoute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    0x2e0e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11d4 <cree_socket_ecoute+0x44>
lea    0xe31(%rip),%rdi
call   1080 <fatal_error@plt>
mov    -0x8(%rbp),%edi
mov    0x2e0a(%rip),%rax
mov    (%rax),%esi
mov    0x2dc9(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    120d <cree_socket_ecoute+0x7d>
lea    0xe08(%rip),%rdi
call   1080 <fatal_error@plt>
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2dbc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    126b <cree_socket_ecoute+0xdb>
lea    0xdcc(%rip),%rdi
call   1080 <fatal_error@plt>
mov    -0x8(%rbp),%edi
mov    $0xf,%esi
call   1090 <listen@plt>
cmp    $0xffffffff,%eax
jne    128d <cree_socket_ecoute+0xfd>
lea    0xdb8(%rip),%rdi
call   1080 <fatal_error@plt>
mov    0x2d34(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xdb0(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cree_socket_ecoute>:
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>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
jne    11cf <cree_socket_ecoute+0x3f>
lea    0xe36(%rip),%rdi
call   1080 <fatal_error@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
mov    0x2dd1(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1204 <cree_socket_ecoute+0x74>
lea    0xe11(%rip),%rdi
call   1080 <fatal_error@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
mov    0x2dc1(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    %r14d,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
call   1050 <htonl@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10a0 <bind@plt>
cmp    $0xffffffff,%eax
jne    1263 <cree_socket_ecoute+0xd3>
lea    0xdd4(%rip),%rdi
call   1080 <fatal_error@plt>
mov    %ebp,%edi
mov    $0xf,%esi
call   1090 <listen@plt>
cmp    $0xffffffff,%eax
jne    1280 <cree_socket_ecoute+0xf0>
lea    0xdc5(%rip),%rdi
call   1080 <fatal_error@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
lea    0xdc0(%rip),%rsi
mov    %r14d,%edx
call   1070 <fprintf@plt>
mov    %ebp,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [16 x i8] c"echec de socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [34 x i8] c"echec de setsockopt(SO_REUSEADDR)\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [14 x i8] c"echec de bind\00"
@.str.3 = [16 x i8] c"echec de listen\00"
@stderr = global i32 0
@.str.4 = [30 x i8] c"Serveur actif sur le port %i\0A\00"
define i32 @cree_socket_ecoute(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
store i32 %0, i32* %2
store i32 1, i32* %5
%6 = load i32, i32* @PF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = call i32 @socket(i32 %6, i32 %7, i32 0)
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = call i32 @fatal_error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
%14 = load i32, i32* %3
%15 = load i32, i32* @SOL_SOCKET
%16 = load i32, i32* @SO_REUSEADDR
%17 = call i32 @setsockopt(i32 %14, i32 %15, i32 %16, i32* %5, i32 4)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %13
%20 = call i32 @fatal_error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %21
21: ; preds = %19, %13
%22 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 12)
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* %2
%26 = call i32 @htons(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %26, i32* %27
%28 = load i32, i32* @INADDR_ANY
%29 = call i32 @htonl(i32 %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 0
store i32 %29, i32* %31
%32 = load i32, i32* %3
%33 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%34 = call i32 @bind(i32 %32, %struct.sockaddr* %33, i32 12)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %21
%37 = call i32 @fatal_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %38
38: ; preds = %36, %21
%39 = load i32, i32* %3
%40 = call i32 @listen(i32 %39, i32 15)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 @fatal_error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %42, %38
%45 = load i32, i32* @stderr
%46 = load i32, i32* %2
%47 = call i32 @fprintf(i32 %45, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %46)
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [16 x i8] c"echec de socket\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [34 x i8] c"echec de setsockopt(SO_REUSEADDR)\00"
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.2 = [14 x i8] c"echec de bind\00"
@.str.3 = [16 x i8] c"echec de listen\00"
@stderr = global i32 0
@.str.4 = [30 x i8] c"Serveur actif sur le port %i\0A\00"
define i32 @cree_socket_ecoute(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%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 eq i32 %8, -1
br i1 %9, label %10, label %12
10: ; preds = %1
%11 = tail call i32 @fatal_error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
%13 = load i32, i32* @SOL_SOCKET
%14 = load i32, i32* @SO_REUSEADDR
%15 = call i32 @setsockopt(i32 %8, i32 %13, i32 %14, i32* %3, i32 4)
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @fatal_error(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %12
%20 = call i32 @memset(%struct.sockaddr_in* %2, i32 0, i32 12)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %21, i32* %22
%23 = call i32 @htons(i32 %0)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = call i32 @htonl(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %26, i32* %27
%28 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%29 = call i32 @bind(i32 %8, %struct.sockaddr* %28, i32 12)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %33
31: ; preds = %19
%32 = call i32 @fatal_error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %19
%34 = call i32 @listen(i32 %8, i32 15)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %38
36: ; preds = %33
%37 = call i32 @fatal_error(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
br label %38
38: ; preds = %36, %33
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0), i32 %0)
ret i32 %8
}