#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_zero;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ atoi(char *);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ gettext(char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ memset(int /*<<< orphan*/, char, int);
int /*<<< orphan*/ perror(int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
void connect_request(int *sockfd, struct sockaddr_in *server_addr, char *puerto,
                     char *direccion) {
  if ((*sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror(gettext("Socket"));
    exit(1);
  }
  server_addr->sin_family = AF_INET;
  server_addr->sin_port = htons(atoi(puerto));
  server_addr->sin_addr.s_addr = inet_addr(direccion);
  memset(server_addr->sin_zero, '\0', sizeof server_addr->sin_zero);
  if (connect(*sockfd, (struct sockaddr *)server_addr,
              sizeof(struct sockaddr)) == -1) {
    perror(gettext("Conectar"));
    exit(1);
  }
}


x86 assembly (clang, -O0):
<connect_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    0x2e20(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    -0x8(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0xffffffff,%eax
jne    11ed <connect_request+0x5d>
lea    0xe29(%rip),%rdi
call   1030 <gettext@plt>
mov    %eax,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0xc(%rax)
mov    -0x18(%rbp),%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    -0x20(%rbp),%rdi
call   1060 <inet_addr@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
mov    $0x4,%edx
call   10a0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1274 <connect_request+0xe4>
lea    0xda9(%rip),%rdi
call   1030 <gettext@plt>
mov    %eax,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<connect_request>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %rdx,%r12
mov    %rsi,%rbx
mov    %rdi,%r14
mov    0x2e3c(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10b0 <socket@plt>
mov    %eax,(%r14)
cmp    $0xffffffff,%eax
je     1219 <connect_request+0x89>
mov    0x0(%r13),%eax
mov    %eax,0xc(%rbx)
mov    %r12,%rdi
call   1080 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,0x8(%rbx)
mov    %r15,%rdi
call   1060 <inet_addr@plt>
mov    %eax,0x4(%rbx)
mov    (%rbx),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1050 <memset@plt>
mov    (%r14),%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   10a0 <connect@plt>
cmp    $0xffffffff,%eax
je     1222 <connect_request+0x92>
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xde0(%rip),%rdi
jmp    1229 <connect_request+0x99>
lea    0xdde(%rip),%rdi
call   1030 <gettext@plt>
mov    %eax,%edi
call   1070 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"Socket\00"
@.str.1 = [9 x i8] c"Conectar\00"
define void @connect_request(i32* %0, %struct.sockaddr_in* %1, i8* %2, i8* %3) {
%5 = alloca i32*
%6 = alloca %struct.sockaddr_in*
%7 = alloca i8*
%8 = alloca i8*
store i32* %0, i32** %5
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%9 = load i32, i32* @AF_INET
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 %9, i32 %10, i32 0)
%12 = load i32*, i32** %5
store i32 %11, i32* %12
%13 = icmp eq i32 %11, -1
br i1 %13, label %14, label %18
14: ; preds = %4
%15 = call i32 @gettext(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @perror(i32 %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %4
%19 = load i32, i32* @AF_INET
%20 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %20, i32 0, i32 3
store i32 %19, i32* %21
%22 = load i8*, i8** %7
%23 = call i32 @atoi(i8* %22)
%24 = call i32 @htons(i32 %23)
%25 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %25, i32 0, i32 2
store i32 %24, i32* %26
%27 = load i8*, i8** %8
%28 = call i32 @inet_addr(i8* %27)
%29 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %29, i32 0, i32 1
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 0
store i32 %28, i32* %31
%32 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @memset(i32 %34, i8 signext 0, i32 4)
%36 = load i32*, i32** %5
%37 = load i32, i32* %36
%38 = load %struct.sockaddr_in*, %struct.sockaddr_in** %6
%39 = bitcast %struct.sockaddr_in* %38 to %struct.sockaddr*
%40 = call i32 @connect(i32 %37, %struct.sockaddr* %39, i32 4)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %18
%43 = call i32 @gettext(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%44 = call i32 @perror(i32 %43)
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %18
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [7 x i8] c"Socket\00"
@.str.1 = [9 x i8] c"Conectar\00"
define void @connect_request(i32* nocapture %0, %struct.sockaddr_in* %1, i8* nocapture %2, i8* %3) {
%5 = load i32, i32* @AF_INET
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 %5, i32 %6, i32 0)
store i32 %7, i32* %0
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = tail call i32 @gettext(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @perror(i32 %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %4
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 3
store i32 %14, i32* %15
%16 = tail call i32 @atoi(i8* %2)
%17 = tail call i32 @htons(i32 %16)
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %17, i32* %18
%19 = tail call i32 @inet_addr(i8* %3)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
store i32 %19, i32* %20
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%22 = load i32, i32* %21
%23 = tail call i32 @memset(i32 %22, i8 signext 0, i32 4)
%24 = load i32, i32* %0
%25 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%26 = tail call i32 @connect(i32 %24, %struct.sockaddr* %25, i32 4)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %32
28: ; preds = %13
%29 = tail call i32 @gettext(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%30 = tail call i32 @perror(i32 %29)
%31 = tail call i32 @exit(i32 1)
unreachable
32: ; preds = %13
ret void
}