#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 sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ bind(int, struct sockaddr *, int);
scalar_t__ creerSockAddr(char *, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int, int /*<<< orphan*/);
int bindedSocket(char *nom, int type, int numport) {
  int sock = -1;
  struct sockaddr_in *adsock =
      (struct sockaddr_in *)creerSockAddr(nom, numport);
  if ((sock = socket(AF_INET, type, 0)) <= 0) {
    perror("\n pb creation socket \n");
  }
  if (bind(sock, (struct sockaddr *)adsock, sizeof(*adsock)) < 0) {
    perror("\n pb de bind");
    sock = -2;
  }
  return (sock);
}


x86 assembly (clang, -O0):
<bindedSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1040 <creerSockAddr@plt>
mov    %rax,-0x20(%rbp)
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jg     1194 <bindedSocket+0x54>
lea    0xe71(%rip),%rdi
call   1050 <perror@plt>
mov    -0x14(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    $0x4,%edx
call   1030 <bind@plt>
cmp    $0x0,%rax
jge    11c2 <bindedSocket+0x82>
lea    0xe61(%rip),%rdi
call   1050 <perror@plt>
movl   $0xfffffffe,-0x14(%rbp)
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<bindedSocket>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edx,%esi
call   1040 <creerSockAddr@plt>
mov    %rax,%r14
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
mov    %ebx,%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1186 <bindedSocket+0x46>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <bind@plt>
test   %rax,%rax
js     1194 <bindedSocket+0x54>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe73(%rip),%rdi
call   1050 <perror@plt>
jmp    1168 <bindedSocket+0x28>
lea    0xe7c(%rip),%rdi
call   1050 <perror@plt>
mov    $0xfffffffe,%ebx
jmp    117c <bindedSocket+0x3c>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [23 x i8] c"\0A pb creation socket \0A\00"
@.str.1 = [13 x i8] c"\0A pb de bind\00"
define i32 @bindedSocket(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 -1, i32* %7
%9 = load i8*, i8** %4
%10 = load i32, i32* %6
%11 = call i64 @creerSockAddr(i8* %9, i32 %10)
%12 = inttoptr i64 %11 to %struct.sockaddr_in*
store %struct.sockaddr_in* %12, %struct.sockaddr_in** %8
%13 = load i32, i32* @AF_INET
%14 = load i32, i32* %5
%15 = call i32 @socket(i32 %13, i32 %14, i32 0)
store i32 %15, i32* %7
%16 = icmp sle i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %3
%18 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %3
%20 = load i32, i32* %7
%21 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%22 = bitcast %struct.sockaddr_in* %21 to %struct.sockaddr*
%23 = call i64 @bind(i32 %20, %struct.sockaddr* %22, i32 4)
%24 = icmp slt i64 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = 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 %27
27: ; preds = %25, %19
%28 = load i32, i32* %7
ret i32 %28
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@.str = [23 x i8] c"\0A pb creation socket \0A\00"
@.str.1 = [13 x i8] c"\0A pb de bind\00"
define i32 @bindedSocket(i8* %0, i32 %1, i32 %2) {
%4 = tail call i64 @creerSockAddr(i8* %0, i32 %2)
%5 = load i32, i32* @AF_INET
%6 = tail call i32 @socket(i32 %5, i32 %1, i32 0)
%7 = icmp slt i32 %6, 1
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %3
%11 = inttoptr i64 %4 to %struct.sockaddr*
%12 = tail call i64 @bind(i32 %6, %struct.sockaddr* %11, i32 4)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %10
%17 = phi i32 [ -2, %14 ], [ %6, %10 ]
ret i32 %17
}