#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*/ address;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_addr(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ scanf(char *, char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int sockfd;
  int len;
  struct sockaddr_in address;
  int result;
  char mensaje[1024];
  char respuesta[1024];
  while (respuesta != "exit") {
    printf("Escribe mensaje a enviar a servidor ");
    fflush(stdin);
    scanf("%s", mensaje);
    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    address.sin_family = AF_INET;
    address.sin_addr.s_addr = inet_addr("43.255.190.165");
    address.sin_port = htons(9734);
    len = sizeof(address);
    result = connect(sockfd, (struct sockaddr *)&address, len);
    if (result == -1) {
      perror("oops: client3");
      exit(1);
    }
    write(sockfd, mensaje, 1024);
    read(sockfd, respuesta, 1024);
    printf("Respuesta de Servidor: %s\n", respuesta);
    close(sockfd);
  }
  printf("terminado: %s !!!\n", mensaje);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x820(%rbp),%rax
lea    0xe20(%rip),%rcx
cmp    %rcx,%rax
je     12df <main+0x11f>
lea    0xe15(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
lea    -0x420(%rbp),%rsi
lea    0xe17(%rip),%rdi
call   10a0 <scanf@plt>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
lea    0xde6(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,-0x14(%rbp)
mov    $0x2606,%edi
call   1040 <htons@plt>
mov    %eax,-0x18(%rbp)
movl   $0xc,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    -0xc(%rbp),%edx
call   10d0 <connect@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1295 <main+0xd5>
lea    0xdb6(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x8(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
lea    -0x820(%rbp),%rsi
lea    0xd7f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
jmp    11d2 <main+0x12>
lea    -0x420(%rbp),%rsi
lea    0xd78(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
lea    0x410(%rsp),%rbx
mov    0x2e08(%rip),%r12
mov    %rsp,%r13
lea    0x10(%rsp),%rbp
lea    0xe56(%rip),%r14
nop
lea    0xe09(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
call   1090 <fflush@plt>
lea    0xe12(%rip),%rdi
mov    %rbx,%rsi
call   10a0 <scanf@plt>
mov    (%r12),%edi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%r15d
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
lea    0xde7(%rip),%rdi
call   1080 <inet_addr@plt>
mov    %eax,0x4(%rsp)
mov    $0x2606,%edi
call   1040 <htons@plt>
mov    %eax,(%rsp)
mov    %r15d,%edi
mov    %r13,%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
cmp    $0xffffffff,%eax
je     12a6 <main+0xe6>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1030 <write@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15d,%edi
call   1060 <close@plt>
jmp    11f0 <main+0x30>
lea    0xd8a(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [5 x i8] c"exit\00"
@.str.1 = [37 x i8] c"Escribe mensaje a enviar a servidor \00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [15 x i8] c"43.255.190.165\00"
@.str.4 = [14 x i8] c"oops: client3\00"
@.str.5 = [27 x i8] c"Respuesta de Servidor: %s\0A\00"
@.str.6 = [19 x i8] c"terminado: %s !!!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
store i32 0, i32* %1
br label %8
8: ; preds = %36, %0
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%10 = icmp ne i8* %9, getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0)
br i1 %10, label %11, label %47
11: ; preds = %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @stdin
%14 = call i32 @fflush(i32 %13)
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
store i32 %19, i32* %2
%20 = load i32, i32* @AF_INET
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 2
store i32 %20, i32* %21
%22 = call i32 @inet_addr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 1
%24 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %23, i32 0, i32 0
store i32 %22, i32* %24
%25 = call i32 @htons(i32 9734)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i32 0, i32 0
store i32 %25, i32* %26
store i32 12, i32* %3
%27 = load i32, i32* %2
%28 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%29 = load i32, i32* %3
%30 = call i32 @connect(i32 %27, %struct.sockaddr* %28, i32 %29)
store i32 %30, i32* %5
%31 = load i32, i32* %5
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %36
33: ; preds = %11
%34 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %11
%37 = load i32, i32* %2
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%39 = call i32 @write(i32 %37, i8* %38, i32 1024)
%40 = load i32, i32* %2
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%42 = call i32 @read(i32 %40, i8* %41, i32 1024)
%43 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %43)
%45 = load i32, i32* %2
%46 = call i32 @close(i32 %45)
br label %8
47: ; preds = %8
%48 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %48)
%50 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str.1 = [37 x i8] c"Escribe mensaje a enviar a servidor \00"
@stdin = global i32 0
@.str.2 = [3 x i8] c"%s\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [15 x i8] c"43.255.190.165\00"
@.str.4 = [14 x i8] c"oops: client3\00"
@.str.5 = [27 x i8] c"Respuesta de Servidor: %s\0A\00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = bitcast %struct.sockaddr_in* %1 to i8*
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
%8 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
%10 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
br label %11
11: ; preds = %27, %0
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @stdin
%14 = call i32 @fflush(i32 %13)
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%16 = load i32, i32* @AF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
%19 = load i32, i32* @AF_INET
store i32 %19, i32* %7
%20 = call i32 @inet_addr(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
store i32 %20, i32* %8
%21 = call i32 @htons(i32 9734)
store i32 %21, i32* %9
%22 = call i32 @connect(i32 %18, %struct.sockaddr* %10, i32 12)
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %11
%25 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %11
%28 = call i32 @write(i32 %18, i8* %5, i32 1024)
%29 = call i32 @read(i32 %18, i8* %6, i32 1024)
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %6)
%31 = call i32 @close(i32 %18)
br label %11
}