#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 setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int creer_serveur(int port) {
  int socket_serveur;
  socket_serveur = socket(AF_INET, SOCK_STREAM, 0);
  if (socket_serveur == -1) {
    perror("socket_serveur");
  }
  struct sockaddr_in saddr;
  saddr.sin_family = AF_INET;
  saddr.sin_port = htons(port);
  saddr.sin_addr.s_addr = INADDR_ANY;
  int optval = 1;
  if (setsockopt(socket_serveur, SOL_SOCKET, SO_REUSEADDR, &optval,
                 sizeof(int)) == -1) {
    perror("Can not set SO_REUSEADDR option");
  }
  if (bind(socket_serveur, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) {
    perror("Bind socker_serveur probleme ");
    return -1;
  }
  int a = listen(socket_serveur, 10);
  if (a == -1) {
    perror(" listen socket_serveur ");
    return -1;
  }
  return socket_serveur;
}


x86 assembly (clang, -O0):
<creer_serveur>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    119d <creer_serveur+0x3d>
lea    0xe68(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e3c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e1d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
mov    0x2de6(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1200 <creer_serveur+0xa0>
lea    0xe14(%rip),%rdi
call   1070 <perror@plt>
mov    -0xc(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   1060 <bind@plt>
cmp    $0xffffffff,%eax
jne    1232 <creer_serveur+0xd2>
lea    0xe0e(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126a <creer_serveur+0x10a>
mov    -0xc(%rbp),%edi
mov    $0xa,%esi
call   1050 <listen@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    1264 <creer_serveur+0x104>
lea    0xdfa(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    126a <creer_serveur+0x10a>
mov    -0xc(%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   %r14
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebp
mov    0x2e6f(%rip),%r14
mov    (%r14),%edi
mov    0x2e4d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1211 <creer_serveur+0xb1>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    %ebp,%edi
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2e30(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
movl   $0x1,0xc(%rsp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
mov    0x2dfa(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1222 <creer_serveur+0xc2>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1060 <bind@plt>
cmp    $0xffffffff,%eax
je     1230 <creer_serveur+0xd0>
mov    %ebx,%edi
mov    $0xa,%esi
call   1050 <listen@plt>
cmp    $0xffffffff,%eax
je     1239 <creer_serveur+0xd9>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xde8(%rip),%rdi
call   1070 <perror@plt>
jmp    118f <creer_serveur+0x2f>
lea    0xde6(%rip),%rdi
call   1070 <perror@plt>
jmp    11df <creer_serveur+0x7f>
lea    0xdf8(%rip),%rdi
jmp    1240 <creer_serveur+0xe0>
lea    0xe0d(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%ebx
jmp    1206 <creer_serveur+0xa6>

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"
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [32 x i8] c"Can not set SO_REUSEADDR option\00"
@.str.2 = [30 x i8] c"Bind socker_serveur probleme \00"
@.str.3 = [24 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
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %3
%8 = load i32, i32* @AF_INET
%9 = load i32, i32* @SOCK_STREAM
%10 = call i32 @socket(i32 %8, i32 %9, i32 0)
store i32 %10, i32* %4
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %1
%16 = load i32, i32* @AF_INET
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 2
store i32 %16, i32* %17
%18 = load i32, i32* %3
%19 = call i32 @htons(i32 %18)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 1
store i32 %19, i32* %20
%21 = load i32, i32* @INADDR_ANY
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i32 0, i32 0
%23 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %22, i32 0, i32 0
store i32 %21, i32* %23
store i32 1, i32* %6
%24 = load i32, i32* %4
%25 = load i32, i32* @SOL_SOCKET
%26 = load i32, i32* @SO_REUSEADDR
%27 = call i32 @setsockopt(i32 %24, i32 %25, i32 %26, i32* %6, i32 4)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %31
29: ; preds = %15
%30 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %31
31: ; preds = %29, %15
%32 = load i32, i32* %4
%33 = bitcast %struct.sockaddr_in* %5 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 ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %47
38: ; preds = %31
%39 = load i32, i32* %4
%40 = call i32 @listen(i32 %39, i32 10)
store i32 %40, i32* %7
%41 = load i32, i32* %7
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %45
43: ; preds = %38
%44 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %47
45: ; preds = %38
%46 = load i32, i32* %4
store i32 %46, i32* %2
br label %47
47: ; preds = %45, %43, %36
%48 = load i32, i32* %2
ret i32 %48
}

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"
@INADDR_ANY = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [32 x i8] c"Can not set SO_REUSEADDR option\00"
@.str.2 = [30 x i8] c"Bind socker_serveur probleme \00"
@.str.3 = [24 x i8] c" listen socket_serveur \00"
define i32 @creer_serveur(i32 %0) {
%2 = alloca %struct.sockaddr_in
%3 = alloca i32
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = tail call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %1
%11 = bitcast %struct.sockaddr_in* %2 to i8*
%12 = load i32, i32* @AF_INET
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 2
store i32 %12, i32* %13
%14 = tail call i32 @htons(i32 %0)
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 1
store i32 %14, i32* %15
%16 = load i32, i32* @INADDR_ANY
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %2, i64 0, i32 0, i32 0
store i32 %16, i32* %17
%18 = bitcast i32* %3 to i8*
store i32 1, i32* %3
%19 = load i32, i32* @SOL_SOCKET
%20 = load i32, i32* @SO_REUSEADDR
%21 = call i32 @setsockopt(i32 %6, i32 %19, i32 %20, i32* %3, i32 4)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %10
%24 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %10
%26 = bitcast %struct.sockaddr_in* %2 to %struct.sockaddr*
%27 = call i32 @bind(i32 %6, %struct.sockaddr* %26, i32 12)
%28 = icmp eq i32 %27, -1
br i1 %28, label %32, label %29
29: ; preds = %25
%30 = call i32 @listen(i32 %6, i32 10)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %29, %25
%33 = phi i8* [ getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0), %25 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0), %29 ]
%34 = call i32 @perror(i8* %33)
br label %35
35: ; preds = %32, %29
%36 = phi i32 [ %6, %29 ], [ -1, %32 ]
ret i32 %36
}