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

/* Type definitions */
struct addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
scalar_t__ bind(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
struct addrinfo *getAddrInfo(char *, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              int *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int bindedSocket(char *nom, char *service, int type) {
  int sock = -1;
  int yes = 1;
  struct addrinfo *rp;
  rp = getAddrInfo(nom, service, type);
  if ((sock = socket(rp->ai_family, rp->ai_socktype, rp->ai_protocol)) <= 0) {
    perror("\n pb creation socket \n");
  }
  setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof yes);
  if (bind(sock, rp->ai_addr, rp->ai_addrlen) < 0) {
    perror("\n pb de bind");
    sock = -2;
  }
  freeaddrinfo(rp);
  return (sock);
}


x86 assembly (clang, -O0):
<bindedSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <getAddrInfo@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x28(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%edx
call   1080 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jg     11c7 <bindedSocket+0x67>
lea    0xe3e(%rip),%rdi
call   1060 <perror@plt>
mov    -0x18(%rbp),%edi
mov    0x2e17(%rip),%rax
mov    (%rax),%esi
mov    0x2dfe(%rip),%rax
mov    (%rax),%edx
lea    -0x1c(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x18(%rbp),%edi
mov    -0x28(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
call   1050 <bind@plt>
cmp    $0x0,%rax
jge    121d <bindedSocket+0xbd>
lea    0xe06(%rip),%rdi
call   1060 <perror@plt>
movl   $0xfffffffe,-0x18(%rbp)
mov    -0x28(%rbp),%rdi
call   1070 <freeaddrinfo@plt>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bindedSocket>:
push   %rbp
push   %rbx
push   %rax
movl   $0x1,0x4(%rsp)
call   1040 <getAddrInfo@plt>
mov    %rax,%rbx
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   1080 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11cd <bindedSocket+0x6d>
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    0x2e41(%rip),%rax
mov    (%rax),%edx
lea    0x4(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %ebp,%edi
call   1050 <bind@plt>
test   %rax,%rax
js     11db <bindedSocket+0x7b>
mov    %rbx,%rdi
call   1070 <freeaddrinfo@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe2c(%rip),%rdi
call   1060 <perror@plt>
jmp    1187 <bindedSocket+0x27>
lea    0xe35(%rip),%rdi
call   1060 <perror@plt>
mov    $0xfffffffe,%ebp
jmp    11bc <bindedSocket+0x5c>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@.str = [23 x i8] c"\0A pb creation socket \0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [13 x i8] c"\0A pb de bind\00"
define i32 @bindedSocket(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.addrinfo*
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i32 -1, i32* %7
store i32 1, i32* %8
%10 = load i8*, i8** %4
%11 = load i8*, i8** %5
%12 = load i32, i32* %6
%13 = call %struct.addrinfo* @getAddrInfo(i8* %10, i8* %11, i32 %12)
store %struct.addrinfo* %13, %struct.addrinfo** %9
%14 = load %struct.addrinfo*, %struct.addrinfo** %9
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %14, i32 0, i32 4
%16 = load i32, i32* %15
%17 = load %struct.addrinfo*, %struct.addrinfo** %9
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i32 0, i32 3
%19 = load i32, i32* %18
%20 = load %struct.addrinfo*, %struct.addrinfo** %9
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %20, i32 0, i32 2
%22 = load i32, i32* %21
%23 = call i32 @socket(i32 %16, i32 %19, i32 %22)
store i32 %23, i32* %7
%24 = icmp sle i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %3
%26 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %3
%28 = load i32, i32* %7
%29 = load i32, i32* @SOL_SOCKET
%30 = load i32, i32* @SO_REUSEADDR
%31 = call i32 @setsockopt(i32 %28, i32 %29, i32 %30, i32* %8, i32 4)
%32 = load i32, i32* %7
%33 = load %struct.addrinfo*, %struct.addrinfo** %9
%34 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %33, i32 0, i32 1
%35 = load i32, i32* %34
%36 = load %struct.addrinfo*, %struct.addrinfo** %9
%37 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %36, i32 0, i32 0
%38 = load i32, i32* %37
%39 = call i64 @bind(i32 %32, i32 %35, i32 %38)
%40 = icmp slt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %27
%42 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %7
br label %43
43: ; preds = %41, %27
%44 = load %struct.addrinfo*, %struct.addrinfo** %9
%45 = call i32 @freeaddrinfo(%struct.addrinfo* %44)
%46 = load i32, i32* %7
ret i32 %46
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32 }
@.str = [23 x i8] c"\0A pb creation socket \0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.1 = [13 x i8] c"\0A pb de bind\00"
define i32 @bindedSocket(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
store i32 1, i32* %4
%6 = tail call %struct.addrinfo* @getAddrInfo(i8* %0, i8* %1, i32 %2)
%7 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 4
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 3
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 2
%12 = load i32, i32* %11
%13 = tail call i32 @socket(i32 %8, i32 %10, i32 %12)
%14 = icmp slt i32 %13, 1
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %3
%18 = load i32, i32* @SOL_SOCKET
%19 = load i32, i32* @SO_REUSEADDR
%20 = call i32 @setsockopt(i32 %13, i32 %18, i32 %19, i32* %4, i32 4)
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %6, i64 0, i32 0
%24 = load i32, i32* %23
%25 = call i64 @bind(i32 %13, i32 %22, i32 %24)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %17
%28 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %17
%30 = phi i32 [ -2, %27 ], [ %13, %17 ]
%31 = call i32 @freeaddrinfo(%struct.addrinfo* %6)
ret i32 %30
}