#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 sockaddr_in {
  int dummy;
};
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*/ memcpy(struct sockaddr_in *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
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,
                 struct sockaddr_in *addrin) {
  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;
  }
  if (addrin != NULL) {
    memcpy(addrin, rp->ai_addr, rp->ai_addrlen);
  }
  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)
mov    %rcx,-0x20(%rbp)
movl   $0xffffffff,-0x24(%rbp)
movl   $0x1,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1040 <getAddrInfo@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x30(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%edx
call   1090 <socket@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jg     11db <bindedSocket+0x6b>
lea    0xe2a(%rip),%rdi
call   1070 <perror@plt>
mov    -0x24(%rbp),%edi
mov    0x2e03(%rip),%rax
mov    (%rax),%esi
mov    0x2dea(%rip),%rax
mov    (%rax),%edx
lea    -0x28(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
call   1060 <bind@plt>
cmp    $0x0,%rax
jge    1231 <bindedSocket+0xc1>
lea    0xdf2(%rip),%rdi
call   1070 <perror@plt>
movl   $0xfffffffe,-0x24(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1252 <bindedSocket+0xe2>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
call   1050 <memcpy@plt>
mov    -0x30(%rbp),%rdi
call   1080 <freeaddrinfo@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bindedSocket>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
movl   $0x1,0xc(%rsp)
call   1040 <getAddrInfo@plt>
mov    %rax,%rbx
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   1090 <socket@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11f9 <bindedSocket+0x89>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %ebp,%edi
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %ebp,%edi
call   1060 <bind@plt>
test   %rax,%rax
js     1207 <bindedSocket+0x97>
test   %r14,%r14
je     11e6 <bindedSocket+0x76>
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %r14,%rdi
call   1050 <memcpy@plt>
mov    %rbx,%rdi
call   1080 <freeaddrinfo@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe00(%rip),%rdi
call   1070 <perror@plt>
jmp    119f <bindedSocket+0x2f>
lea    0xe09(%rip),%rdi
call   1070 <perror@plt>
mov    $0xfffffffe,%ebp
test   %r14,%r14
jne    11d9 <bindedSocket+0x69>
jmp    11e6 <bindedSocket+0x76>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%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, %struct.sockaddr_in* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.sockaddr_in*
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.addrinfo*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store %struct.sockaddr_in* %3, %struct.sockaddr_in** %8
store i32 -1, i32* %9
store i32 1, i32* %10
%12 = load i8*, i8** %5
%13 = load i8*, i8** %6
%14 = load i32, i32* %7
%15 = call %struct.addrinfo* @getAddrInfo(i8* %12, i8* %13, i32 %14)
store %struct.addrinfo* %15, %struct.addrinfo** %11
%16 = load %struct.addrinfo*, %struct.addrinfo** %11
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %16, i32 0, i32 4
%18 = load i32, i32* %17
%19 = load %struct.addrinfo*, %struct.addrinfo** %11
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i32 0, i32 3
%21 = load i32, i32* %20
%22 = load %struct.addrinfo*, %struct.addrinfo** %11
%23 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %22, i32 0, i32 2
%24 = load i32, i32* %23
%25 = call i32 @socket(i32 %18, i32 %21, i32 %24)
store i32 %25, i32* %9
%26 = icmp sle i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %4
%28 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %29
29: ; preds = %27, %4
%30 = load i32, i32* %9
%31 = load i32, i32* @SOL_SOCKET
%32 = load i32, i32* @SO_REUSEADDR
%33 = call i32 @setsockopt(i32 %30, i32 %31, i32 %32, i32* %10, i32 4)
%34 = load i32, i32* %9
%35 = load %struct.addrinfo*, %struct.addrinfo** %11
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i32 0, i32 1
%37 = load i32, i32* %36
%38 = load %struct.addrinfo*, %struct.addrinfo** %11
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i32 0, i32 0
%40 = load i32, i32* %39
%41 = call i64 @bind(i32 %34, i32 %37, i32 %40)
%42 = icmp slt i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %29
%44 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 -2, i32* %9
br label %45
45: ; preds = %43, %29
%46 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%47 = icmp ne %struct.sockaddr_in* %46, null
br i1 %47, label %48, label %57
48: ; preds = %45
%49 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%50 = load %struct.addrinfo*, %struct.addrinfo** %11
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 1
%52 = load i32, i32* %51
%53 = load %struct.addrinfo*, %struct.addrinfo** %11
%54 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %53, i32 0, i32 0
%55 = load i32, i32* %54
%56 = call i32 @memcpy(%struct.sockaddr_in* %49, i32 %52, i32 %55)
br label %57
57: ; preds = %48, %45
%58 = load %struct.addrinfo*, %struct.addrinfo** %11
%59 = call i32 @freeaddrinfo(%struct.addrinfo* %58)
%60 = load i32, i32* %9
ret i32 %60
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%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, %struct.sockaddr_in* %3) {
%5 = alloca i32
%6 = bitcast i32* %5 to i8*
store i32 1, i32* %5
%7 = tail call %struct.addrinfo* @getAddrInfo(i8* %0, i8* %1, i32 %2)
%8 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 4
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 3
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 2
%13 = load i32, i32* %12
%14 = tail call i32 @socket(i32 %9, i32 %11, i32 %13)
%15 = icmp slt i32 %14, 1
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %18
18: ; preds = %16, %4
%19 = load i32, i32* @SOL_SOCKET
%20 = load i32, i32* @SO_REUSEADDR
%21 = call i32 @setsockopt(i32 %14, i32 %19, i32 %20, i32* %5, i32 4)
%22 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 1
%23 = load i32, i32* %22
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i64 0, i32 0
%25 = load i32, i32* %24
%26 = call i64 @bind(i32 %14, i32 %23, i32 %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %18
%29 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %18
%31 = phi i32 [ -2, %28 ], [ %14, %18 ]
%32 = icmp eq %struct.sockaddr_in* %3, null
br i1 %32, label %37, label %33
33: ; preds = %30
%34 = load i32, i32* %22
%35 = load i32, i32* %24
%36 = call i32 @memcpy(%struct.sockaddr_in* %3, i32 %34, i32 %35)
br label %37
37: ; preds = %33, %30
%38 = call i32 @freeaddrinfo(%struct.addrinfo* %7)
ret i32 %31
}