#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;
typedef int /*<<< orphan*/ buff_sck;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_DGRAM;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ atoi(char const *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_aton(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int read(int /*<<< orphan*/, char *, int);
int recvfrom(int, char *, int, int /*<<< orphan*/, struct sockaddr *, int *);
int /*<<< orphan*/ sendto(int, char *, int, int /*<<< orphan*/,
                          struct sockaddr *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ write(int /*<<< orphan*/, 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_DGRAM, 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 enviar datos a IP: 127.0.0.1 Puerto: %s\n", argv[1]);
  while (1) {
    if ((lee_tcl = read(STDIN_FILENO, buff_tcl, sizeof(buff_tcl))) > 0) {
      sendto(sockfd, buff_tcl, lee_tcl, 0, (struct sockaddr *)&direccion,
             sizeof(direccion));
    }
    int len = sizeof(direccion);
    lee_sck = recvfrom(sockfd, buff_sck, sizeof(buff_sck), 0,
                       (struct sockaddr *)&direccion, &len);
    write(STDOUT_FILENO, "Servidor:--> ", 13);
    write(STDOUT_FILENO, buff_sck, lee_sck);
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%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     11f5 <main+0x45>
mov    -0x10(%rbp),%rax
lea    0xe0f(%rip),%rcx
mov    %rcx,0x8(%rax)
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    0x2dd3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
mov    %eax,-0x164(%rbp)
cmpl   $0xffffffff,-0x164(%rbp)
jne    1239 <main+0x89>
lea    0xddd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x158(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   1040 <htons@plt>
mov    %eax,-0x15c(%rbp)
lea    -0x160(%rbp),%rsi
lea    0xdc2(%rip),%rdi
call   1090 <inet_aton@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xdb8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1080 <read@plt>
mov    %eax,-0x168(%rbp)
cmp    $0x0,%eax
jle    12e9 <main+0x139>
mov    -0x164(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    -0x168(%rbp),%edx
lea    -0x160(%rbp),%r8
xor    %ecx,%ecx
mov    $0xc,%r9d
call   1070 <sendto@plt>
movl   $0xc,-0x174(%rbp)
mov    -0x164(%rbp),%edi
lea    -0x150(%rbp),%rsi
lea    -0x160(%rbp),%r8
mov    $0x38,%edx
xor    %ecx,%ecx
lea    -0x174(%rbp),%r9
call   10a0 <recvfrom@plt>
mov    %eax,-0x16c(%rbp)
mov    0x2cc9(%rip),%rax
mov    (%rax),%edi
lea    0xd50(%rip),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
lea    -0x150(%rbp),%rsi
mov    -0x16c(%rbp),%edx
call   1030 <write@plt>
jmp    1299 <main+0xe9>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x168,%rsp
mov    %rsi,%r15
movl   $0x0,0x10(%rsp)
cmp    $0x2,%edi
je     11dc <main+0x2c>
lea    0xe28(%rip),%rax
mov    %rax,0x8(%r15)
mov    0x2dfd(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2deb(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10d0 <socket@plt>
cmp    $0xffffffff,%eax
je     12e9 <main+0x139>
mov    %eax,%ebx
lea    0xe4b(%rip),%rdi
call   1030 <puts@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%r15),%rdi
call   10b0 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,0x14(%rsp)
lea    0xdd6(%rip),%rdi
lea    0x10(%rsp),%r14
mov    %r14,%rsi
call   1090 <inet_aton@plt>
mov    0x8(%r15),%rsi
lea    0xdc8(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0x60(%rsp),%r15
lea    0x20(%rsp),%r12
mov    0x2d91(%rip),%rbp
jmp    12b6 <main+0x106>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movl   $0xc,0xc(%rsp)
mov    %ebx,%edi
mov    %r12,%rsi
mov    $0x38,%edx
xor    %ecx,%ecx
mov    %r14,%r8
lea    0xc(%rsp),%r9
call   10a0 <recvfrom@plt>
mov    %eax,%r13d
mov    0x0(%rbp),%edi
lea    0xda7(%rip),%rsi
mov    $0xd,%edx
call   1040 <write@plt>
mov    0x0(%rbp),%edi
mov    %r12,%rsi
mov    %r13d,%edx
call   1040 <write@plt>
mov    0x2d0b(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rsi
mov    $0x100,%edx
call   1080 <read@plt>
test   %eax,%eax
jle    1270 <main+0xc0>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
mov    %r14,%r8
mov    $0xc,%r9d
call   1070 <sendto@plt>
jmp    1270 <main+0xc0>
lea    0xd82(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10c0 <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_DGRAM = 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 = [54 x i8] c"Cliente va a enviar datos a IP: 127.0.0.1 Puerto: %s\0A\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@.str.5 = [14 x i8] c"Servidor:--> \00"
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
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = bitcast %struct.sockaddr_in* %8 to i8*
%15 = load i32, i32* %4
%16 = icmp ne i32 %15, 2
br i1 %16, label %17, label %20
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %19
br label %20
20: ; preds = %17, %2
%21 = load i32, i32* @AF_INET
%22 = load i32, i32* @SOCK_DGRAM
%23 = call i32 @socket(i32 %21, i32 %22, i32 0)
store i32 %23, i32* %9
%24 = load i32, i32* %9
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %20
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%28 = call i32 @exit(i32 -1)
unreachable
29: ; preds = %20
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %31, i32* %32
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
%37 = call i32 @htons(i32 %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %37, i32* %38
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%40 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32* %39)
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i8* %43)
br label %45
45: ; preds = %29, %56
%46 = load i32, i32* @STDIN_FILENO
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%48 = call i32 @read(i32 %46, i8* %47, i32 256)
store i32 %48, i32* %10
%49 = icmp sgt i32 %48, 0
br i1 %49, label %50, label %56
50: ; preds = %45
%51 = load i32, i32* %9
%52 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%53 = load i32, i32* %10
%54 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%55 = call i32 @sendto(i32 %51, i8* %52, i32 %53, i32 0, %struct.sockaddr* %54, i32 12)
br label %56
56: ; preds = %50, %45
store i32 12, i32* %13
%57 = load i32, i32* %9
%58 = getelementptr inbounds [56 x i8], [56 x i8]* %7, i64 0, i64 0
%59 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%60 = call i32 @recvfrom(i32 %57, i8* %58, i32 56, i32 0, %struct.sockaddr* %59, i32* %13)
store i32 %60, i32* %11
%61 = load i32, i32* @STDOUT_FILENO
%62 = call i32 @write(i32 %61, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 13)
%63 = load i32, i32* @STDOUT_FILENO
%64 = getelementptr inbounds [56 x i8], [56 x i8]* %7, i64 0, i64 0
%65 = load i32, i32* %11
%66 = call i32 @write(i32 %63, i8* %64, i32 %65)
br label %45
}

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_DGRAM = global i32 0
@.str.3 = [10 x i8] c"127.0.0.1\00"
@.str.4 = [54 x i8] c"Cliente va a enviar datos a IP: 127.0.0.1 Puerto: %s\0A\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@.str.5 = [14 x i8] c"Servidor:--> \00"
@str = [31 x i8] c"Paso 1: Se creo socket cliente\00"
@str.6 = [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 = alloca i32
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [56 x i8], [56 x i8]* %4, i64 0, i64 0
%9 = bitcast %struct.sockaddr_in* %5 to i8*
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
store i32 0, i32* %10
%11 = icmp eq i32 %0, 2
br i1 %11, label %14, label %12
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %13
br label %14
14: ; preds = %12, %2
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_DGRAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.6, i64 0, i64 0))
%21 = tail call i32 @exit(i32 -1)
unreachable
22: ; preds = %14
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %24, i32* %25
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = tail call i32 @atoi(i8* %27)
%29 = tail call i32 @htons(i32 %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1
store i32 %29, i32* %30
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 0
%32 = call i32 @inet_aton(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i32* %31)
%33 = load i8*, i8** %26
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([54 x i8], [54 x i8]* @.str.4, i64 0, i64 0), i8* %33)
%35 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%36 = bitcast i32* %6 to i8*
br label %37
37: ; preds = %43, %22
%38 = load i32, i32* @STDIN_FILENO
%39 = call i32 @read(i32 %38, i8* %7, i32 256)
%40 = icmp sgt i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %37
%42 = call i32 @sendto(i32 %17, i8* %7, i32 %39, i32 0, %struct.sockaddr* %35, i32 12)
br label %43
43: ; preds = %41, %37
store i32 12, i32* %6
%44 = call i32 @recvfrom(i32 %17, i8* %8, i32 56, i32 0, %struct.sockaddr* %35, i32* %6)
%45 = load i32, i32* @STDOUT_FILENO
%46 = call i32 @write(i32 %45, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 13)
%47 = load i32, i32* @STDOUT_FILENO
%48 = call i32 @write(i32 %47, i8* %8, i32 %44)
br label %37
}