#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*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ htons(int);
int listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int);
int setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int creer_serveur(int port) {
  struct sockaddr_in saddr;
  saddr.sin_family = AF_INET;
  saddr.sin_port = htons(8080);
  saddr.sin_addr.s_addr = INADDR_ANY;
  int socket_serveur = socket(AF_INET, SOCK_STREAM, 0);
  int optval = 1;
  if (setsockopt(socket_serveur, SOL_SOCKET, SO_REUSEADDR, &optval,
                 sizeof(int)) == -1)
    perror(" Cannot set SO_REUSEADDR option ");
  printf("Port : %d\n", port);
  if (socket_serveur == -1) {
    perror("Problème de création de socket dans la fonction creer_serveur");
    return -1;
  } else {
    if (bind(socket_serveur, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) {
      perror("Problème dans le deuxième if de creer_serveur");
      return -1;
    } else {
      if (listen(socket_serveur, 10) == -1) {
        perror("Problème dans le troisième if de creer_serveur");
        return -1;
      } else {
        return socket_serveur;
      }
    }
  }
}


x86 assembly (clang, -O0):
<creer_serveur>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    $0x1f90,%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    0x2e18(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0x1c(%rbp)
movl   $0x1,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2e1b(%rip),%rax
mov    (%rax),%esi
mov    0x2dea(%rip),%rax
mov    (%rax),%edx
lea    -0x20(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    11fc <creer_serveur+0x8c>
lea    0xe09(%rip),%rdi
call   1080 <perror@plt>
mov    -0x8(%rbp),%esi
lea    0xe1b(%rip),%rdi
call   1050 <printf@plt>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    122d <creer_serveur+0xbd>
lea    0xe10(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1293 <creer_serveur+0x123>
mov    -0x1c(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
jne    125f <creer_serveur+0xef>
lea    0xe1e(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1293 <creer_serveur+0x123>
mov    -0x1c(%rbp),%edi
mov    $0xa,%esi
call   1060 <listen@plt>
cmp    $0xffffffff,%eax
jne    128d <creer_serveur+0x11d>
lea    0xe20(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1293 <creer_serveur+0x123>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<creer_serveur>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %edi,%ebp
mov    0x2e61(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x10(%rsp)
mov    $0x1f90,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
mov    0x2e3e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    (%rbx),%edi
mov    0x2e1f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebx
movl   $0x1,0x4(%rsp)
mov    0x2e25(%rip),%rax
mov    (%rax),%esi
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1228 <creer_serveur+0xb8>
lea    0xe35(%rip),%rdi
mov    %ebp,%esi
call   1050 <printf@plt>
cmp    $0xffffffff,%ebx
je     1236 <creer_serveur+0xc6>
lea    0x8(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
je     123f <creer_serveur+0xcf>
mov    %ebx,%edi
mov    $0xa,%esi
call   1060 <listen@plt>
cmp    $0xffffffff,%eax
je     1248 <creer_serveur+0xd8>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdd1(%rip),%rdi
call   1080 <perror@plt>
jmp    11e5 <creer_serveur+0x75>
lea    0xdef(%rip),%rdi
jmp    124f <creer_serveur+0xdf>
lea    0xe26(%rip),%rdi
jmp    124f <creer_serveur+0xdf>
lea    0xe4d(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%ebx
jmp    121f <creer_serveur+0xaf>

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
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str = [33 x i8] c" Cannot set SO_REUSEADDR option \00"
@.str.1 = [11 x i8] c"Port : %d\0A\00"
@.str.2 = [64 x i8] c"Probl\C3\A8me de cr\C3\A9ation de socket dans la fonction creer_serveur\00"
@.str.3 = [48 x i8] c"Probl\C3\A8me dans le deuxi\C3\A8me if de creer_serveur\00"
@.str.4 = [49 x i8] c"Probl\C3\A8me dans le troisi\C3\A8me if de creer_serveur\00"
define i32 @creer_serveur(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
%7 = load i32, i32* @AF_INET
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %7, i32* %8
%9 = call i32 @htons(i32 8080)
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
store i32 %9, i32* %10
%11 = load i32, i32* @INADDR_ANY
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
%13 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %12, i32 0, i32 0
store i32 %11, i32* %13
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = call i32 @socket(i32 %14, i32 %15, i32 0)
store i32 %16, i32* %5
store i32 1, i32* %6
%17 = load i32, i32* %5
%18 = load i32, i32* @SOL_SOCKET
%19 = load i32, i32* @SO_REUSEADDR
%20 = call i32 @setsockopt(i32 %17, i32 %18, i32 %19, i32* %6, i32 4)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %1
%23 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %24
24: ; preds = %22, %1
%25 = load i32, i32* %3
%26 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = load i32, i32* %5
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 @perror(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %46
31: ; preds = %24
%32 = load i32, i32* %5
%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 = %31
%37 = call i32 @perror(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %46
38: ; preds = %31
%39 = load i32, i32* %5
%40 = call i32 @listen(i32 %39, i32 10)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = call i32 @perror(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %2
br label %46
44: ; preds = %38
%45 = load i32, i32* %5
store i32 %45, i32* %2
br label %46
46: ; preds = %44, %42, %36, %29
%47 = load i32, i32* %2
ret i32 %47
}

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
@INADDR_ANY = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str = [33 x i8] c" Cannot set SO_REUSEADDR option \00"
@.str.1 = [11 x i8] c"Port : %d\0A\00"
@.str.2 = [64 x i8] c"Probl\C3\A8me de cr\C3\A9ation de socket dans la fonction creer_serveur\00"
@.str.3 = [48 x i8] c"Probl\C3\A8me dans le deuxi\C3\A8me if de creer_serveur\00"
@.str.4 = [49 x i8] c"Probl\C3\A8me dans le troisi\C3\A8me if de creer_serveur\00"
define i32 @creer_serveur(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = bitcast %struct.sockaddr_in* %2 to i8*
%5 = load i32, i32* @AF_INET
%6 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %5, i32* %6
%7 = tail call i32 @htons(i32 8080)
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %7, i32* %8
%9 = load i32, i32* @INADDR_ANY
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %9, i32* %10
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%15 = load i32, i32* @SOL_SOCKET
%16 = load i32, i32* @SO_REUSEADDR
%17 = call i32 @setsockopt(i32 %13, i32 %15, i32 %16, i32* %3, i32 4)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %21
19: ; preds = %1
%20 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %21
21: ; preds = %19, %1
%22 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%23 = icmp eq i32 %13, -1
br i1 %23, label %31, label %24
24: ; preds = %21
%25 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%26 = call i32 @bind(i32 %13, %struct.sockaddr* %25, i32 12)
%27 = icmp eq i32 %26, -1
br i1 %27, label %31, label %28
28: ; preds = %24
%29 = call i32 @listen(i32 %13, i32 10)
%30 = icmp eq i32 %29, -1
br i1 %30, label %31, label %34
31: ; preds = %28, %24, %21
%32 = phi i8* [ getelementptr inbounds ([64 x i8], [64 x i8]* @.str.2, i64 0, i64 0), %21 ], [ getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), %24 ], [ getelementptr inbounds ([49 x i8], [49 x i8]* @.str.4, i64 0, i64 0), %28 ]
%33 = call i32 @perror(i8* %32)
br label %34
34: ; preds = %31, %28
%35 = phi i32 [ %13, %28 ], [ -1, %31 ]
ret i32 %35
}