#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_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ sAddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  int sock, i;
  struct sockaddr_in sAddr;
  char str[128];
  if ((sock = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
    printf("error al crear el socket\n");
    exit(-1);
  }
  sAddr.sin_family = AF_INET;
  sAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
  sAddr.sin_port = htons(5000);
  if (connect(sock, (struct sockaddr *)&sAddr, sizeof(sAddr)) == -1) {
    perror("connect\n");
    exit(-1);
  }
  printf("What do you whant to send? ");
  gets(str);
  send(sock, str, strlen(str), 0);
  i = recv(sock, str, 128, 0);
  str[i] = '\0';
  printf("RESPONSE: \"%s\"\n", str);
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%edi
mov    0x2def(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    1216 <main+0x56>
lea    0xdfb(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    0xdf1(%rip),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x24(%rbp)
mov    $0x1388,%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0xffffffff,%eax
jne    126e <main+0xae>
lea    0xdc5(%rip),%rdi
call   10b0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xb0(%rbp),%rdi
call   10a0 <gets@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xbc(%rbp)
lea    -0xb0(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    -0xb0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0xbc(%rbp),%edi
mov    -0xb8(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    -0x14(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x18(%rbp)
movslq -0x18(%rbp),%rax
movb   $0x0,-0xb0(%rbp,%rax,1)
lea    -0xb0(%rbp),%rsi
lea    0xd55(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x98,%rsp
mov    0x2def(%rip),%rax
mov    (%rax),%edi
mov    0x2dee(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
je     12ae <main+0xde>
mov    %eax,%ebx
mov    0x2de3(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
lea    0xdee(%rip),%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x1388,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0xc,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
je     12c4 <main+0xf4>
lea    0xdcc(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   10b0 <gets@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x80,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movb   $0x0,0x10(%rsp,%rax,1)
lea    0xd9f(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebx,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd8a(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>
lea    0xd3f(%rip),%rdi
call   10c0 <perror@plt>
mov    $0xffffffff,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [26 x i8] c"error al crear el socket\0A\00"
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [9 x i8] c"connect\0A\00"
@.str.3 = [28 x i8] c"What do you whant to send? \00"
@.str.4 = [16 x i8] c"RESPONSE: \22%s\22\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* @PF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = call i32 @socket(i32 %10, i32 %11, i32 0)
store i32 %12, i32* %6
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%22 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %21, i32 0, i32 0
store i32 %20, i32* %22
%23 = call i32 @htons(i32 5000)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %23, i32* %24
%25 = load i32, i32* %6
%26 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%27 = call i32 @connect(i32 %25, %struct.sockaddr* %26, i32 12)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %17
%30 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 -1)
unreachable
32: ; preds = %17
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%35 = call i32 @gets(i8* %34)
%36 = load i32, i32* %6
%37 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%38 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%39 = call i32 @strlen(i8* %38)
%40 = call i32 @send(i32 %36, i8* %37, i32 %39, i32 0)
%41 = load i32, i32* %6
%42 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%43 = call i32 @recv(i32 %41, i8* %42, i32 128, i32 0)
store i32 %43, i32* %7
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 %45
store i8 0, i8* %46
%47 = getelementptr inbounds [128 x i8], [128 x i8]* %9, i64 0, i64 0
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %47)
%49 = load i32, i32* %6
%50 = call i32 @close(i32 %49)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@.str.1 = [10 x i8] c"127.0.0.1\00"
@.str.2 = [9 x i8] c"connect\0A\00"
@.str.3 = [28 x i8] c"What do you whant to send? \00"
@.str.4 = [16 x i8] c"RESPONSE: \22%s\22\0A\00"
@str = [25 x i8] c"error al crear el socket\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [128 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %2
%15 = load i32, i32* @AF_INET
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %15, i32* %16
%17 = tail call i32 @inet_addr(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
store i32 %17, i32* %18
%19 = tail call i32 @htons(i32 5000)
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %19, i32* %20
%21 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%22 = call i32 @connect(i32 %9, %struct.sockaddr* %21, i32 12)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %14
%25 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %14
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0))
%29 = call i32 @gets(i8* %6)
%30 = call i32 @strlen(i8* %6)
%31 = call i32 @send(i32 %9, i8* %6, i32 %30, i32 0)
%32 = call i32 @recv(i32 %9, i8* %6, i32 128, i32 0)
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 %33
store i8 0, i8* %34
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0), i8* %6)
%36 = call i32 @close(i32 %9)
ret i32 0
}