#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 in_addr {
  int dummy;
};
struct sockaddr_in {
  struct in_addr sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct hostent {
  scalar_t__ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int crearSocketCliente(struct sockaddr_in *serv_addr, int port,
                       struct hostent *he) {
  int sockdesc;
  if ((sockdesc = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("ERROR socket");
    return (-1);
  }
  serv_addr->sin_family = AF_INET;
  serv_addr->sin_port = htons(port);
  serv_addr->sin_addr = *((struct in_addr *)he->h_addr);
  printf("[Cliente: Socket TCP creado]\n");
  return sockdesc;
}


x86 assembly (clang, -O0):
<crearSocketCliente>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%edi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    1190 <crearSocketCliente+0x50>
lea    0xe81(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d2 <crearSocketCliente+0x92>
mov    0x2e51(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x14(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    (%rcx),%rcx
mov    (%rcx),%ecx
mov    %ecx,(%rax)
lea    0xe46(%rip),%rdi
call   1040 <printf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<crearSocketCliente>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%rbx
mov    0x2e90(%rip),%r12
mov    (%r12),%edi
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <socket@plt>
test   %eax,%eax
js     11a2 <crearSocketCliente+0x62>
mov    %eax,%ebp
mov    (%r12),%eax
mov    %eax,0x8(%rbx)
mov    %r15d,%edi
call   1040 <htons@plt>
mov    %eax,0x4(%rbx)
mov    (%r14),%rax
mov    (%rax),%eax
mov    %eax,(%rbx)
lea    0xe7b(%rip),%rdi
call   1030 <puts@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe57(%rip),%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%ebp
jmp    1197 <crearSocketCliente+0x57>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [13 x i8] c"ERROR socket\00"
@.str.1 = [30 x i8] c"[Cliente: Socket TCP creado]\0A\00"
define i32 @crearSocketCliente(%struct.sockaddr_in* %0, i32 %1, %struct.hostent* %2) {
%4 = alloca i32
%5 = alloca %struct.sockaddr_in*
%6 = alloca i32
%7 = alloca %struct.hostent*
%8 = alloca i32
store %struct.sockaddr_in* %0, %struct.sockaddr_in** %5
store i32 %1, i32* %6
store %struct.hostent* %2, %struct.hostent** %7
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
store i32 %11, i32* %8
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %33
15: ; preds = %3
%16 = load i32, i32* @AF_INET
%17 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 2
store i32 %16, i32* %18
%19 = load i32, i32* %6
%20 = call i32 @htons(i32 %19)
%21 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %21, i32 0, i32 1
store i32 %20, i32* %22
%23 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %23, i32 0, i32 0
%25 = load %struct.hostent*, %struct.hostent** %7
%26 = getelementptr inbounds %struct.hostent, %struct.hostent* %25, i32 0, i32 0
%27 = load i64, i64* %26
%28 = inttoptr i64 %27 to %struct.in_addr*
%29 = bitcast %struct.in_addr* %24 to i8*
%30 = bitcast %struct.in_addr* %28 to i8*
%31 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* %8
store i32 %32, i32* %4
br label %33
33: ; preds = %15, %13
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [13 x i8] c"ERROR socket\00"
@str = [29 x i8] c"[Cliente: Socket TCP creado]\00"
define i32 @crearSocketCliente(%struct.sockaddr_in* nocapture writeonly %0, i32 %1, %struct.hostent* nocapture %2) {
%4 = load i32, i32* @AF_INET
%5 = load i32, i32* @SOCK_STREAM
%6 = tail call i32 @socket(i32 %4, i32 %5, i32 0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
br label %21
10: ; preds = %3
%11 = load i32, i32* @AF_INET
%12 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 2
store i32 %11, i32* %12
%13 = tail call i32 @htons(i32 %1)
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 1
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %2, i64 0, i32 0
%16 = load i64, i64* %15
%17 = inttoptr i64 %16 to i32*
%18 = getelementptr %struct.sockaddr_in, %struct.sockaddr_in* %0, i64 0, i32 0, i32 0
%19 = load i32, i32* %17
store i32 %19, i32* %18
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
br label %21
21: ; preds = %10, %8
%22 = phi i32 [ -1, %8 ], [ %6, %10 ]
ret i32 %22
}