#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 /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
scalar_t__ connect(int, struct sockaddr *, int);
scalar_t__ inet_ntoa(int /*<<< orphan*/);
int ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, int);
int conectarCliente(int sockfd, struct sockaddr_in *server_addr) {
  if (connect(sockfd, (struct sockaddr *)server_addr, sizeof(struct sockaddr)) <
      0) {
    return (-1);
  }
  printf("[Cliente: Conexión establecida con el servidor IP %s, port %d] \n",
         (char *)inet_ntoa(server_addr->sin_addr),
         ntohs(server_addr->sin_port));
  return (0);
}


x86 assembly (clang, -O0):
<conectarCliente>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   1060 <connect@plt>
cmp    $0x0,%rax
jge    1176 <conectarCliente+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11aa <conectarCliente+0x6a>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1050 <ntohs@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
lea    0xe62(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<conectarCliente>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    $0x4,%edx
call   1060 <connect@plt>
test   %rax,%rax
js     117d <conectarCliente+0x3d>
mov    0x4(%rbx),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%r14
mov    (%rbx),%edi
call   1050 <ntohs@plt>
lea    0xe91(%rip),%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <printf@plt>
xor    %eax,%eax
jmp    1182 <conectarCliente+0x42>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [66 x i8] c"[Cliente: Conexi\C3\B3n establecida con el servidor IP %s, port %d] \0A\00"
define i32 @conectarCliente(i32 %0, %struct.sockaddr_in* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.sockaddr_in*
store i32 %0, i32* %4
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %5
%6 = load i32, i32* %4
%7 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%8 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%9 = call i64 @connect(i32 %6, %struct.sockaddr* %8, i32 4)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %23
12: ; preds = %2
%13 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = call i64 @inet_ntoa(i32 %15)
%17 = inttoptr i64 %16 to i8*
%18 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @ntohs(i32 %20)
%22 = call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i8* %17, i32 %21)
store i32 0, i32* %3
br label %23
23: ; preds = %12, %11
%24 = load i32, i32* %3
ret i32 %24
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [66 x i8] c"[Cliente: Conexi\C3\B3n establecida con el servidor IP %s, port %d] \0A\00"
define i32 @conectarCliente(i32 %0, %struct.sockaddr_in* %1) {
%3 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%4 = tail call i64 @connect(i32 %0, %struct.sockaddr* %3, i32 4)
%5 = icmp slt i64 %4, 0
br i1 %5, label %15, label %6
6: ; preds = %2
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1
%8 = load i32, i32* %7
%9 = tail call i64 @inet_ntoa(i32 %8)
%10 = inttoptr i64 %9 to i8*
%11 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i32 @ntohs(i32 %12)
%14 = tail call i32 @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %13)
br label %15
15: ; preds = %2, %6
%16 = phi i32 [ 0, %6 ], [ -1, %2 ]
ret i32 %16
}