#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_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ direccion;
typedef int /*<<< orphan*/ buff_tcl;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int STDIN_FILENO;
int STDOUT_FILENO;
int /*<<< orphan*/ atoi(char const *);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char const *argv[]) {
  char buff_tcl[256], buff_sck[56];
  struct sockaddr_in direccion = {};
  int sockfd, lee_tcl, lee_sck, conn;
  if (argc != 2) {
    argv[1] = "2000";
  }
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd == -1) {
    printf("ERROR en funcion socket()\n");
    exit(-1);
  }
  printf("Paso 1: Se creo socket cliente\n");
  direccion.sin_family = AF_INET;
  direccion.sin_port = htons(atoi(argv[1]));
  inet_aton("127.0.0.1", &direccion.sin_addr);
  printf("Cliente va a conectarse con IP:127.0.0.1 Puerto: %s\n", argv[1]);
  conn = connect(sockfd, (struct sockaddr *)&direccion, sizeof(direccion));
  if (conn == -1) {
    printf("ERROR en funcion connect()\n");
    exit(-1);
  }
  printf("Paso 2: Connect(), cliente conectado\n");
  while (1) {
    lee_sck = read(sockfd, buff_sck, sizeof(buff_tcl));
    write(STDOUT_FILENO, "Servidor:--> ", 13);
    write(STDOUT_FILENO, buff_sck, lee_sck);
    if ((lee_tcl = read(STDIN_FILENO, buff_tcl, sizeof(buff_tcl))) > 0) {
      write(sockfd, buff_tcl, lee_tcl);
    }
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x160(%rbp),%rdi
xor    %esi,%esi
mov    $0xc,%edx
call   1060 <memset@plt>
cmpl   $0x2,-0x8(%rbp)
je     11e5 <main+0x45>
mov    -0x10(%rbp),%rax
lea    0xe1f(%rip),%rcx
mov    %rcx,0x8(%rax)
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
mov    0x2ddb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
mov    %eax,-0x164(%rbp)
cmpl   $0xffffffff,-0x164(%rbp)
jne    1229 <main+0x89>
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2da2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x158(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x15c(%rbp)
lea    -0x160(%rbp),%rsi
lea    0xdd2(%rip),%rdi
call   1080 <inet_aton@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x164(%rbp),%edi
lea    -0x160(%rbp),%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
mov    %eax,-0x170(%rbp)
cmpl   $0xffffffff,-0x170(%rbp)
jne    12cb <main+0x12b>
lea    0xdc5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>
lea    0xdc9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x164(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0x100,%edx
call   1070 <read@plt>
mov    %eax,-0x16c(%rbp)
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
lea    0xdbb(%rip),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
mov    0x2cd9(%rip),%rax
mov    (%rax),%edi
lea    -0x150(%rbp),%rsi
mov    -0x16c(%rbp),%edx
call   1030 <write@plt>
mov    0x2c96(%rip),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1070 <read@plt>
mov    %eax,-0x168(%rbp)
cmp    $0x0,%eax
jle    136c <main+0x1cc>
mov    -0x164(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    -0x168(%rbp),%edx
call   1030 <write@plt>
jmp    12d9 <main+0x139>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x158,%rsp
mov    %rsi,%r14
movl   $0x0,(%rsp)
cmp    $0x2,%edi
je     11cb <main+0x2b>
lea    0xe39(%rip),%rax
mov    %rax,0x8(%r14)
mov    0x2e0e(%rip),%rbx
mov    (%rbx),%edi
mov    0x2df5(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10c0 <socket@plt>
cmp    $0xffffffff,%eax
je     12d4 <main+0x134>
mov    %eax,%r12d
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
mov    (%rbx),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%r14),%rdi
call   1090 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
lea    0xde8(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1080 <inet_aton@plt>
mov    0x8(%r14),%rsi
lea    0xddc(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10b0 <connect@plt>
cmp    $0xffffffff,%eax
je     12dd <main+0x13d>
lea    0xe17(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%r13
mov    0x2d85(%rip),%rbx
mov    0x2d56(%rip),%r14
lea    0x50(%rsp),%r15
nopw   0x0(%rax,%rax,1)
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0x100,%edx
call   1070 <read@plt>
mov    %eax,%ebp
mov    (%rbx),%edi
lea    0xda9(%rip),%rsi
mov    $0xd,%edx
call   1040 <write@plt>
mov    (%rbx),%edi
mov    %r13,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
mov    (%r14),%edi
mov    %r15,%rsi
mov    $0x100,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    1280 <main+0xe0>
mov    %r12d,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <write@plt>
jmp    1280 <main+0xe0>
lea    0xdd6(%rip),%rdi
jmp    12e4 <main+0x144>
lea    0xdb2(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"2000\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [27 x i8] c"ERROR en funcion socket()\0A\00"
@.str.2 = [32 x i8] c"Paso 1: Se creo socket cliente\0A\00"
@.str.3 = [10 x i8] c"127.0.0.1\00"
@.str.4 = [53 x i8] c"Cliente va a conectarse con IP:127.0.0.1 Puerto: %s\0A\00"
@.str.5 = [28 x i8] c"ERROR en funcion connect()\0A\00"
@.str.6 = [38 x i8] c"Paso 2: Connect(), cliente conectado\0A\00"
@STDOUT_FILENO = global i32 0
@.str.7 = [14 x i8] c"Servidor:--> \00"
@STDIN_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [256 x i8]
%7 = alloca [56 x i8]
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = bitcast %struct.sockaddr_in* %8 to i8*
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 2
br i1 %15, label %16, label %19
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %18
br label %19
19: ; preds = %16, %2
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %9
%23 = load i32, i32* %9
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %28
25: ; preds = %19
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 -1)
unreachable
28: ; preds = %19
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* @AF_INET
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %30, i32* %31
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @atoi(i8* %34)
%36 = call i32 @htons(i32 %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %36, i32* %37
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%39 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32* %38)
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i8* %42)
%44 = load i32, i32* %9
%45 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%46 = call i32 @connect(i32 %44, %struct.sockaddr* %45, i32 12)
store i32 %46, i32* %12
%47 = load i32, i32* %12
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %52
49: ; preds = %28
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%51 = call i32 @exit(i32 -1)
unreachable
52: ; preds = %28
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.6, i64 0, i64 0))
br label %54
54: ; preds = %52, %73
%55 = load i32, i32* %9
%56 = getelementptr inbounds [56 x i8], [56 x i8]* %7, i64 0, i64 0
%57 = call i32 @read(i32 %55, i8* %56, i32 256)
store i32 %57, i32* %11
%58 = load i32, i32* @STDOUT_FILENO
%59 = call i32 @write(i32 %58, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 13)
%60 = load i32, i32* @STDOUT_FILENO
%61 = getelementptr inbounds [56 x i8], [56 x i8]* %7, i64 0, i64 0
%62 = load i32, i32* %11
%63 = call i32 @write(i32 %60, i8* %61, i32 %62)
%64 = load i32, i32* @STDIN_FILENO
%65 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%66 = call i32 @read(i32 %64, i8* %65, i32 256)
store i32 %66, i32* %10
%67 = icmp sgt i32 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %54
%69 = load i32, i32* %9
%70 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%71 = load i32, i32* %10
%72 = call i32 @write(i32 %69, i8* %70, i32 %71)
br label %73
73: ; preds = %68, %54
br label %54
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"2000\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [10 x i8] c"127.0.0.1\00"
@.str.4 = [53 x i8] c"Cliente va a conectarse con IP:127.0.0.1 Puerto: %s\0A\00"
@STDOUT_FILENO = global i32 0
@.str.7 = [14 x i8] c"Servidor:--> \00"
@STDIN_FILENO = global i32 0
@str = [31 x i8] c"Paso 1: Se creo socket cliente\00"
@str.8 = [37 x i8] c"Paso 2: Connect(), cliente conectado\00"
@str.9 = [27 x i8] c"ERROR en funcion connect()\00"
@str.10 = [26 x i8] c"ERROR en funcion socket()\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [256 x i8]
%4 = alloca [56 x i8]
%5 = alloca %struct.sockaddr_in
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [56 x i8], [56 x i8]* %4, i64 0, i64 0
%8 = bitcast %struct.sockaddr_in* %5 to i8*
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 0, i32* %9
%10 = icmp eq i32 %0, 2
br i1 %10, label %13, label %11
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %12
br label %13
13: ; preds = %11, %2
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.10, i64 0, i64 0))
%20 = tail call i32 @exit(i32 -1)
unreachable
21: ; preds = %13
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %23, i32* %24
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = tail call i32 @atoi(i8* %26)
%28 = tail call i32 @htons(i32 %27)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %28, i32* %29
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%31 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32* %30)
%32 = load i8*, i8** %25
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i8* %32)
%34 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%35 = call i32 @connect(i32 %16, %struct.sockaddr* %34, i32 12)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %21
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.9, i64 0, i64 0))
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %21
%41 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.8, i64 0, i64 0))
br label %42
42: ; preds = %53, %40
%43 = call i32 @read(i32 %16, i8* %7, i32 256)
%44 = load i32, i32* @STDOUT_FILENO
%45 = call i32 @write(i32 %44, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.7, i64 0, i64 0), i32 13)
%46 = load i32, i32* @STDOUT_FILENO
%47 = call i32 @write(i32 %46, i8* %7, i32 %43)
%48 = load i32, i32* @STDIN_FILENO
%49 = call i32 @read(i32 %48, i8* %6, i32 256)
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %42
%52 = call i32 @write(i32 %16, i8* %6, i32 %49)
br label %53
53: ; preds = %51, %42
br label %42
}