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


x86 assembly (clang, -O0):
<creer_serveur>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
movl   $0x1,-0x10(%rbp)
mov    0x2e67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e48(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    11c7 <creer_serveur+0x67>
lea    0xe57(%rip),%rdi
call   1070 <perror@plt>
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0xc,%edx
call   1060 <bind@plt>
cmp    $0xffffffff,%eax
jne    11ed <creer_serveur+0x8d>
lea    0xe18(%rip),%rdi
call   1070 <perror@plt>
mov    -0xc(%rbp),%edi
mov    $0xa,%esi
call   1050 <listen@plt>
cmp    $0xffffffff,%eax
jne    120f <creer_serveur+0xaf>
lea    0xe08(%rip),%rdi
call   1070 <perror@plt>
mov    -0xc(%rbp),%edi
mov    0x2dcf(%rip),%rax
mov    (%rax),%esi
mov    0x2d9e(%rip),%rax
mov    (%rax),%edx
lea    -0x10(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
jne    1254 <creer_serveur+0xf4>
lea    0xde5(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <creer_serveur+0xfa>
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   %rbx
sub    $0x20,%rsp
movl   $0x1,0xc(%rsp)
mov    0x2e6c(%rip),%rbx
mov    (%rbx),%eax
mov    %eax,0x18(%rsp)
call   1040 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
mov    (%rbx),%edi
mov    0x2e2f(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1080 <socket@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1201 <creer_serveur+0xa1>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   1060 <bind@plt>
cmp    $0xffffffff,%eax
je     120f <creer_serveur+0xaf>
mov    %ebx,%edi
mov    $0xa,%esi
call   1050 <listen@plt>
cmp    $0xffffffff,%eax
je     121d <creer_serveur+0xbd>
mov    0x2e11(%rip),%rax
mov    (%rax),%esi
mov    0x2de0(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebx,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
cmp    $0xffffffff,%eax
je     122b <creer_serveur+0xcb>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
ret
lea    0xe11(%rip),%rdi
call   1070 <perror@plt>
jmp    11a9 <creer_serveur+0x49>
lea    0xdea(%rip),%rdi
call   1070 <perror@plt>
jmp    11bf <creer_serveur+0x5f>
lea    0xdee(%rip),%rdi
call   1070 <perror@plt>
jmp    11d0 <creer_serveur+0x70>
lea    0xdf6(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%ebx
jmp    11f9 <creer_serveur+0x99>

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

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