#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 /*<<< orphan*/ initialiser_signaux();
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) {
  initialiser_signaux();
  int socket_serveur = socket(AF_INET, SOCK_STREAM, 0);
  int option_value = 1;
  if (setsockopt(socket_serveur, SOL_SOCKET, SO_REUSEADDR, &option_value,
                 sizeof(int)) == -1) {
    perror("Can not set SO_REUSEADDR option");
    return -1;
  }
  if (socket_serveur == -1) {
    perror("socket_serveur");
    return -1;
  }
  struct sockaddr_in saddr;
  saddr.sin_family = AF_INET;
  saddr.sin_port = htons(port);
  saddr.sin_addr.s_addr = INADDR_ANY;
  if (bind(socket_serveur, (struct sockaddr *)&saddr, sizeof(saddr)) == -1) {
    perror("bind socket_serveur");
    return -1;
  }
  if (listen(socket_serveur, 10) == -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    $0x0,%al
call   1030 <initialiser_signaux@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0xc(%rbp),%edi
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
mov    0x2e08(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    11ea <creer_serveur+0x7a>
lea    0xe27(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1295 <creer_serveur+0x125>
cmpl   $0xffffffff,-0xc(%rbp)
jne    120c <creer_serveur+0x9c>
lea    0xe2a(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1295 <creer_serveur+0x125>
mov    0x2dcd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
jne    1261 <creer_serveur+0xf1>
lea    0xdd0(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1295 <creer_serveur+0x125>
mov    -0xc(%rbp),%edi
mov    $0xa,%esi
call   1060 <listen@plt>
cmp    $0xffffffff,%eax
jne    128f <creer_serveur+0x11f>
lea    0xdb6(%rip),%rdi
call   1080 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1295 <creer_serveur+0x125>
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
xor    %eax,%eax
call   1030 <initialiser_signaux@plt>
mov    0x2e58(%rip),%r14
mov    (%r14),%edi
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1090 <socket@plt>
mov    %eax,%ebx
movl   $0x1,0xc(%rsp)
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
mov    0x2e0b(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     1222 <creer_serveur+0xb2>
cmp    $0xffffffff,%ebx
je     122b <creer_serveur+0xbb>
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    %ebp,%edi
call   1050 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2dec(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1070 <bind@plt>
cmp    $0xffffffff,%eax
je     1234 <creer_serveur+0xc4>
mov    %ebx,%edi
mov    $0xa,%esi
call   1060 <listen@plt>
cmp    $0xffffffff,%eax
jne    1245 <creer_serveur+0xd5>
lea    0xe14(%rip),%rdi
jmp    123b <creer_serveur+0xcb>
lea    0xdd7(%rip),%rdi
jmp    123b <creer_serveur+0xcb>
lea    0xdf3(%rip),%rdi
jmp    123b <creer_serveur+0xcb>
lea    0xde5(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%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 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str = [32 x i8] c"Can not set SO_REUSEADDR option\00"
@.str.1 = [15 x i8] c"socket_serveur\00"
@INADDR_ANY = global i32 0
@.str.2 = [20 x i8] c"bind socket_serveur\00"
@.str.3 = [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 i32
%6 = alloca %struct.sockaddr_in
store i32 %0, i32* %3
%7 = call i32 (...) @initialiser_signaux()
%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
store i32 1, i32* %5
%11 = load i32, i32* %4
%12 = load i32, i32* @SOL_SOCKET
%13 = load i32, i32* @SO_REUSEADDR
%14 = call i32 @setsockopt(i32 %11, i32 %12, i32 %13, i32* %5, i32 4)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %1
%17 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %46
18: ; preds = %1
%19 = load i32, i32* %4
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %46
23: ; preds = %18
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 2
store i32 %24, i32* %25
%26 = load i32, i32* %3
%27 = call i32 @htons(i32 %26)
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %27, i32* %28
%29 = load i32, i32* @INADDR_ANY
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, 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* %4
%33 = bitcast %struct.sockaddr_in* %6 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 = %23
%37 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %2
br label %46
38: ; preds = %23
%39 = load i32, i32* %4
%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 ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %2
br label %46
44: ; preds = %38
%45 = load i32, i32* %4
store i32 %45, i32* %2
br label %46
46: ; preds = %44, %42, %36, %21, %16
%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
@SOCK_STREAM = global i32 0
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str = [32 x i8] c"Can not set SO_REUSEADDR option\00"
@.str.1 = [15 x i8] c"socket_serveur\00"
@INADDR_ANY = global i32 0
@.str.2 = [20 x i8] c"bind socket_serveur\00"
@.str.3 = [22 x i8] c"listen socket_serveur\00"
define i32 @creer_serveur(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = tail call i32 (...) @initialiser_signaux()
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
%8 = bitcast i32* %2 to i8*
store i32 1, i32* %2
%9 = load i32, i32* @SOL_SOCKET
%10 = load i32, i32* @SO_REUSEADDR
%11 = call i32 @setsockopt(i32 %7, i32 %9, i32 %10, i32* %2, 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 ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
br label %38
15: ; preds = %1
%16 = icmp eq i32 %7, -1
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %38
19: ; preds = %15
%20 = bitcast %struct.sockaddr_in* %3 to i8*
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %21, i32* %22
%23 = call i32 @htons(i32 %0)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %25, i32* %26
%27 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%28 = call i32 @bind(i32 %7, %struct.sockaddr* %27, i32 12)
%29 = icmp eq i32 %28, -1
br i1 %29, label %33, label %30
30: ; preds = %19
%31 = call i32 @listen(i32 %7, i32 10)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %30, %19
%34 = phi i8* [ getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), %19 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), %30 ]
%35 = call i32 @perror(i8* %34)
br label %36
36: ; preds = %33, %30
%37 = phi i32 [ %7, %30 ], [ -1, %33 ]
br label %38
38: ; preds = %36, %17, %13
%39 = phi i32 [ -1, %13 ], [ -1, %17 ], [ %37, %36 ]
ret i32 %39
}