#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*/ saddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ INADDR_ANY;
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 *);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ perror(char *);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int creer_serveur(int port) {
  int socket_serveur;
  int optval = 1;
  socket_serveur = socket(AF_INET, SOCK_STREAM, 0);
  if (socket_serveur == -1) {
    perror("socket_serveur");
    fprintf(stderr, "erreur a la creation du socket");
    exit(EXIT_FAILURE);
  }
  struct sockaddr_in saddr;
  saddr.sin_family = AF_INET;
  saddr.sin_port = htons(port);
  saddr.sin_addr.s_addr = INADDR_ANY;
  if (setsockopt(socket_serveur, SOL_SOCKET, SO_REUSEADDR, &optval,
                 sizeof(int)) == -1) {
    perror("Can not see SO_REUSEADDR option");
    exit(EXIT_FAILURE);
  }
  if (bind(socket_serveur, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) {
    perror("bind socket");
    fprintf(stderr, "erreur au bind du socket");
    exit(EXIT_FAILURE);
  }
  if (listen(socket_serveur, 10) == -1) {
    perror("listen socket_serveur");
    exit(EXIT_FAILURE);
  }
  return socket_serveur;
}


x86 assembly (clang, -O0):
<creer_serveur>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x1,-0xc(%rbp)
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
mov    0x2e1e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    11e7 <creer_serveur+0x67>
lea    0xeac(%rip),%rdi
call   1080 <perror@plt>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2dd4(%rip),%rax
mov    (%rax),%esi
mov    0x2d93(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1251 <creer_serveur+0xd1>
lea    0xde1(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d6e(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
jne    129a <creer_serveur+0x11a>
lea    0xdcd(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d4a(%rip),%rax
mov    (%rax),%edi
lea    0xdc4(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%edi
mov    $0xa,%esi
call   1060 <listen@plt>
cmp    $0xffffffff,%eax
jne    12ca <creer_serveur+0x14a>
lea    0xdad(%rip),%rdi
call   1080 <perror@plt>
mov    0x2cf5(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x8(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<creer_serveur>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebp
movl   $0x1,0xc(%rsp)
mov    0x2e47(%rip),%r14
mov    (%r14),%edi
mov    0x2e1d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10a0 <socket@plt>
cmp    $0xffffffff,%eax
je     122d <creer_serveur+0xad>
mov    %eax,%ebx
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    %ebp,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2e0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    0x2e0f(%rip),%rax
mov    (%rax),%esi
mov    0x2dce(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     124b <creer_serveur+0xcb>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
je     1254 <creer_serveur+0xd4>
mov    %ebx,%edi
mov    $0xa,%esi
call   1060 <listen@plt>
cmp    $0xffffffff,%eax
je     1277 <creer_serveur+0xf7>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe37(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xdb7(%rip),%rsi
jmp    1270 <creer_serveur+0xf0>
lea    0xdcd(%rip),%rdi
jmp    127e <creer_serveur+0xfe>
lea    0xde4(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
lea    0xddb(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1283 <creer_serveur+0x103>
lea    0xde6(%rip),%rdi
call   1080 <perror@plt>
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [15 x i8] c"socket_serveur\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"erreur a la creation du socket\00"
@EXIT_FAILURE = global i32 0
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [32 x i8] c"Can not see SO_REUSEADDR option\00"
@.str.3 = [12 x i8] c"bind socket\00"
@.str.4 = [25 x i8] c"erreur au bind du socket\00"
@.str.5 = [22 x i8] c"listen socket_serveur\00"
define i32 @creer_serveur(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in
store i32 %0, i32* %2
store i32 1, i32* %4
%6 = load i32, i32* @AF_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 %17
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %1
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %18, i32* %19
%20 = load i32, i32* %2
%21 = call i32 @htons(i32 %20)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* @INADDR_ANY
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
store i32 %23, i32* %25
%26 = load i32, i32* %3
%27 = load i32, i32* @SOL_SOCKET
%28 = load i32, i32* @SO_REUSEADDR
%29 = call i32 @setsockopt(i32 %26, i32 %27, i32 %28, i32* %4, i32 4)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %17
%32 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %17
%36 = load i32, i32* %3
%37 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%38 = call i32 @bind(i32 %36, %struct.sockaddr* %37, i32 12)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %46
40: ; preds = %35
%41 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%42 = load i32, i32* @stderr
%43 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %35
%47 = load i32, i32* %3
%48 = call i32 @listen(i32 %47, i32 10)
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %54
50: ; preds = %46
%51 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %46
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [15 x i8] c"socket_serveur\00"
@stderr = global i32 0
@.str.1 = [31 x i8] c"erreur a la creation du socket\00"
@EXIT_FAILURE = global i32 0
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.2 = [32 x i8] c"Can not see SO_REUSEADDR option\00"
@.str.3 = [12 x i8] c"bind socket\00"
@.str.4 = [25 x i8] c"erreur au bind du socket\00"
@.str.5 = [22 x i8] c"listen socket_serveur\00"
define i32 @creer_serveur(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %15
9: ; preds = %1
%10 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = bitcast %struct.sockaddr_in* %3 to i8*
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %17, i32* %18
%19 = tail call i32 @htons(i32 %0)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %21, i32* %22
%23 = load i32, i32* @SOL_SOCKET
%24 = load i32, i32* @SO_REUSEADDR
%25 = call i32 @setsockopt(i32 %7, i32 %23, i32 %24, i32* %2, i32 4)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %31
27: ; preds = %15
%28 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %15
%32 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%33 = call i32 @bind(i32 %7, %struct.sockaddr* %32, i32 12)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %41
35: ; preds = %31
%36 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
%40 = call i32 @exit(i32 %39)
unreachable
41: ; preds = %31
%42 = call i32 @listen(i32 %7, i32 10)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %41
ret i32 %7
}