#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  scalar_t__ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  int /*<<< orphan*/ ai_flags;
};

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ AI_PASSIVE;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ _exit(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
int /*<<< orphan*/ getaddrinfo(char *, char *, struct addrinfo *,
                               struct addrinfo **);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ scanf(char *, char *);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, scalar_t__);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  int sd;
  struct addrinfo hints;
  struct addrinfo *res;
  char buffer[80];
  int sdC = 0;
  int r = 0;
  hints.ai_flags = AI_PASSIVE;
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_protocol = 0;
  if (argc < 3) {
    perror("Error de argumentos.\n");
  }
  getaddrinfo(argv[1], argv[2], &hints, &res);
  printf("Creando socket.\n");
  sd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
  printf("Connect.\n");
  connect(sd, res->ai_addr, res->ai_addrlen);
  while (strcmp("Q\n", buffer) != 0) {
    scanf("%s", buffer);
    if (strcmp("Q\n", buffer) == 0) {
      close(sd);
      _exit(1);
    }
    send(sd, buffer, strlen(buffer), 0);
    printf("Recibiendo.\n");
    r = recv(sd, buffer, 80, 0);
    buffer[r] = '\0';
    printf("Mensaje: %s\n", buffer);
  }
  freeaddrinfo(res);
  close(sd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x94(%rbp)
movl   $0x0,-0x98(%rbp)
mov    0x2de4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    123f <main+0x6f>
lea    0xdc6(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x40(%rbp),%rcx
call   10d0 <getaddrinfo@plt>
lea    0xdb3(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x40(%rbp),%rax
mov    0x14(%rax),%edi
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%esi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%rdx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   10c0 <connect@plt>
lea    -0x90(%rbp),%rsi
lea    0xd78(%rip),%rdi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     1396 <main+0x1c6>
lea    -0x90(%rbp),%rsi
lea    0xd5e(%rip),%rdi
call   10a0 <scanf@plt>
lea    -0x90(%rbp),%rsi
lea    0xd48(%rip),%rdi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    130a <main+0x13a>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0xa4(%rbp)
lea    -0x90(%rbp),%rax
mov    %rax,-0xa0(%rbp)
lea    -0x90(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xa4(%rbp),%edi
mov    -0xa0(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
lea    0xced(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x90(%rbp),%rsi
mov    $0x50,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x98(%rbp)
movslq -0x98(%rbp),%rax
movb   $0x0,-0x90(%rbp,%rax,1)
lea    -0x90(%rbp),%rsi
lea    0xcba(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    12ab <main+0xdb>
mov    -0x40(%rbp),%rdi
call   10e0 <freeaddrinfo@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%rbx
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
mov    0x2dd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x20(%rsp)
movq   $0x0,0x18(%rsp)
cmp    $0x2,%edi
jle    1357 <main+0x177>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
call   10e0 <getaddrinfo@plt>
lea    0xdde(%rip),%rdi
call   1050 <puts@plt>
mov    0x8(%rsp),%rax
mov    0x14(%rax),%edi
mov    0x10(%rax),%esi
mov    0x8(%rax),%rdx
call   1100 <socket@plt>
mov    %eax,%ebp
lea    0xdcc(%rip),%rdi
call   1050 <puts@plt>
mov    0x8(%rsp),%rax
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %ebp,%edi
call   10d0 <connect@plt>
lea    0xd8c(%rip),%rdi
lea    0x30(%rsp),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1332 <main+0x152>
lea    0xd75(%rip),%r14
lea    0x30(%rsp),%rbx
lea    0xd66(%rip),%r15
lea    0xd8b(%rip),%r12
lea    0xd5e(%rip),%r13
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
call   10b0 <scanf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1368 <main+0x188>
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    %r12,%rdi
call   1050 <puts@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x50,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
cltq
movb   $0x0,0x30(%rsp,%rax,1)
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    12c0 <main+0xe0>
mov    0x8(%rsp),%rdi
call   10f0 <freeaddrinfo@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xca2(%rip),%rdi
call   10c0 <perror@plt>
jmp    122d <main+0x4d>
mov    %ebp,%edi
call   1090 <close@plt>
mov    $0x1,%edi
call   1040 <_exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i64, i32, i32, i32 }
@AI_PASSIVE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [22 x i8] c"Error de argumentos.\0A\00"
@.str.1 = [17 x i8] c"Creando socket.\0A\00"
@.str.2 = [10 x i8] c"Connect.\0A\00"
@.str.3 = [3 x i8] c"Q\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [13 x i8] c"Recibiendo.\0A\00"
@.str.6 = [13 x i8] c"Mensaje: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.addrinfo
%8 = alloca %struct.addrinfo*
%9 = alloca [80 x i8]
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %10
store i32 0, i32* %11
%12 = load i32, i32* @AI_PASSIVE
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 5
store i32 %12, i32* %13
%14 = load i32, i32* @AF_UNSPEC
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 4
store i32 %14, i32* %15
%16 = load i32, i32* @SOCK_STREAM
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 3
store i32 %16, i32* %17
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %7, i32 0, i32 2
store i64 0, i64* %18
%19 = load i32, i32* %4
%20 = icmp slt i32 %19, 3
br i1 %20, label %21, label %23
21: ; preds = %2
%22 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 2
%29 = load i8*, i8** %28
%30 = call i32 @getaddrinfo(i8* %26, i8* %29, %struct.addrinfo* %7, %struct.addrinfo** %8)
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%32 = load %struct.addrinfo*, %struct.addrinfo** %8
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i32 0, i32 4
%34 = load i32, i32* %33
%35 = load %struct.addrinfo*, %struct.addrinfo** %8
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i32 0, i32 3
%37 = load i32, i32* %36
%38 = load %struct.addrinfo*, %struct.addrinfo** %8
%39 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %38, i32 0, i32 2
%40 = load i64, i64* %39
%41 = call i32 @socket(i32 %34, i32 %37, i64 %40)
store i32 %41, i32* %6
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%43 = load i32, i32* %6
%44 = load %struct.addrinfo*, %struct.addrinfo** %8
%45 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %44, i32 0, i32 1
%46 = load i32, i32* %45
%47 = load %struct.addrinfo*, %struct.addrinfo** %8
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i32 @connect(i32 %43, i32 %46, i32 %49)
br label %51
51: ; preds = %65, %23
%52 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%53 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %80
55: ; preds = %51
%56 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%57 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %56)
%58 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%59 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %58)
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %65
61: ; preds = %55
%62 = load i32, i32* %6
%63 = call i32 @close(i32 %62)
%64 = call i32 @_exit(i32 1)
unreachable
65: ; preds = %55
%66 = load i32, i32* %6
%67 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%68 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%69 = call i32 @strlen(i8* %68)
%70 = call i32 @send(i32 %66, i8* %67, i32 %69, i32 0)
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%72 = load i32, i32* %6
%73 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%74 = call i32 @recv(i32 %72, i8* %73, i32 80, i32 0)
store i32 %74, i32* %11
%75 = load i32, i32* %11
%76 = sext i32 %75 to i64
%77 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 %76
store i8 0, i8* %77
%78 = getelementptr inbounds [80 x i8], [80 x i8]* %9, i64 0, i64 0
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %78)
br label %51
80: ; preds = %51
%81 = load %struct.addrinfo*, %struct.addrinfo** %8
%82 = call i32 @freeaddrinfo(%struct.addrinfo* %81)
%83 = load i32, i32* %6
%84 = call i32 @close(i32 %83)
ret i32 0
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i64, i32, i32, i32 }
@AI_PASSIVE = global i32 0
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@.str = [22 x i8] c"Error de argumentos.\0A\00"
@.str.3 = [3 x i8] c"Q\0A\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.6 = [13 x i8] c"Mensaje: %s\0A\00"
@str = [16 x i8] c"Creando socket.\00"
@str.7 = [9 x i8] c"Connect.\00"
@str.8 = [12 x i8] c"Recibiendo.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = alloca [80 x i8]
%6 = bitcast %struct.addrinfo* %3 to i8*
%7 = bitcast %struct.addrinfo** %4 to i8*
%8 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* @AI_PASSIVE
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 5
store i32 %9, i32* %10
%11 = load i32, i32* @AF_UNSPEC
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %11, i32* %12
%13 = load i32, i32* @SOCK_STREAM
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %13, i32* %14
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 2
store i64 0, i64* %15
%16 = icmp slt i32 %0, 3
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = call i32 @getaddrinfo(i8* %21, i8* %23, %struct.addrinfo* %3, %struct.addrinfo** %4)
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%26 = load %struct.addrinfo*, %struct.addrinfo** %4
%27 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 4
%28 = load i32, i32* %27
%29 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 3
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %26, i64 0, i32 2
%32 = load i64, i64* %31
%33 = call i32 @socket(i32 %28, i32 %30, i64 %32)
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str.7, i64 0, i64 0))
%35 = load %struct.addrinfo*, %struct.addrinfo** %4
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 1
%37 = load i32, i32* %36
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i64 0, i32 0
%39 = load i32, i32* %38
%40 = call i32 @connect(i32 %33, i32 %37, i32 %39)
%41 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%42 = icmp eq i64 %41, 0
br i1 %42, label %60, label %43
43: ; preds = %19, %50
%44 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %8)
%45 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%46 = icmp eq i64 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %43
%48 = call i32 @close(i32 %33)
%49 = call i32 @_exit(i32 1)
unreachable
50: ; preds = %43
%51 = call i32 @strlen(i8* %8)
%52 = call i32 @send(i32 %33, i8* %8, i32 %51, i32 0)
%53 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.8, i64 0, i64 0))
%54 = call i32 @recv(i32 %33, i8* %8, i32 80, i32 0)
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 %55
store i8 0, i8* %56
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i8* %8)
%58 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %8)
%59 = icmp eq i64 %58, 0
br i1 %59, label %60, label %43
60: ; preds = %50, %19
%61 = load %struct.addrinfo*, %struct.addrinfo** %4
%62 = call i32 @freeaddrinfo(%struct.addrinfo* %61)
%63 = call i32 @close(i32 %33)
ret i32 0
}