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

/* Variables and functions */
int EINVAL;
int /*<<< orphan*/ close(int);
int conecta(char *, int);
int envia(int, char *, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int pollIn(int, int);
int recibe(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ sscanf(char *, char *, int *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int r_ls(char *ip, int port, char *ruta) {
  int rc, r_errno, socket;
  char cadena[300] = "";
  if ((ruta == NULL) || (sizeof(ruta) > 255)) {
    errno = EINVAL;
    fprintf(stderr, "r_ls(): ruta incorrecta\n");
    return -1;
  }
  if ((socket = conecta(ip, port)) == -1) {
    perror("r_ls(): conecta()");
    return -1;
  }
  sprintf(cadena, "r_ls %s\n", ruta);
  if (envia(socket, cadena, strlen(cadena)) == -1) {
    perror("r_ls(): envia()");
    close(socket);
    return -1;
  }
  rc = pollIn(socket, 3000);
  if (rc == 1) {
    fprintf(stderr, "r_ls(): pollIn(): timeout\n");
    close(socket);
    return -1;
  }
  rc = 0;
  while (rc == 0) {
    rc = recibe(socket, cadena, 300);
    if (rc == -1) {
      perror("r_ls(): recibe()");
      close(socket);
      return -1;
    }
  }
  sscanf(cadena, "%d", &r_errno);
  if (r_errno != 0) {
    errno = r_errno;
    close(socket);
    return -1;
  }
  return socket;
}


x86 assembly (clang, -O0):
<r_ls>:
push   %rbp
mov    %rsp,%rbp
sub    $0x170,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x160(%rbp),%rdi
xor    %esi,%esi
mov    $0x12c,%edx
call   1060 <memset@plt>
cmpq   $0x0,-0x20(%rbp)
jne    1217 <r_ls+0x67>
mov    0x2de5(%rip),%rax
mov    (%rax),%ecx
mov    0x2de4(%rip),%rax
mov    %ecx,(%rax)
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    0xdfa(%rip),%rsi
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    139f <r_ls+0x1ef>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   10d0 <conecta@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    1247 <r_ls+0x97>
lea    0xde3(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    139f <r_ls+0x1ef>
lea    -0x160(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xdd2(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x16c(%rbp)
lea    -0x160(%rbp),%rax
mov    %rax,-0x168(%rbp)
lea    -0x160(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x16c(%rbp),%edi
mov    -0x168(%rbp),%rsi
mov    %eax,%edx
call   1040 <envia@plt>
cmp    $0xffffffff,%eax
jne    12be <r_ls+0x10e>
lea    0xd8f(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    139f <r_ls+0x1ef>
mov    -0x2c(%rbp),%edi
mov    $0xbb8,%esi
call   1070 <pollIn@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jne    1301 <r_ls+0x151>
mov    0x2d01(%rip),%rax
mov    (%rax),%edi
lea    0xd5c(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    139f <r_ls+0x1ef>
movl   $0x0,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    1358 <r_ls+0x1a8>
mov    -0x2c(%rbp),%edi
lea    -0x160(%rbp),%rsi
mov    $0x12c,%edx
call   1030 <recibe@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1353 <r_ls+0x1a3>
lea    0xd25(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    139f <r_ls+0x1ef>
jmp    1308 <r_ls+0x158>
lea    -0x160(%rbp),%rdi
lea    0xd0a(%rip),%rsi
lea    -0x28(%rbp),%rdx
call   10a0 <sscanf@plt>
cmpl   $0x0,-0x28(%rbp)
je     1399 <r_ls+0x1e9>
mov    -0x28(%rbp),%ecx
mov    0x2c55(%rip),%rax
mov    %ecx,(%rax)
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    139f <r_ls+0x1ef>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x170,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<r_ls>:
push   %rbp
push   %r14
push   %rbx
sub    $0x140,%rsp
mov    %rdx,%r14
mov    %esi,%ebx
mov    %rdi,%rbp
lea    0x10(%rsp),%rdi
mov    $0x12c,%edx
xor    %esi,%esi
call   1060 <memset@plt>
test   %r14,%r14
je     124d <r_ls+0x9d>
mov    %rbp,%rdi
mov    %ebx,%esi
call   10d0 <conecta@plt>
cmp    $0xffffffff,%eax
je     12e7 <r_ls+0x137>
mov    %eax,%ebp
lea    0xe36(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r14,%rdx
call   10c0 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <envia@plt>
cmp    $0xffffffff,%eax
je     12f5 <r_ls+0x145>
mov    %ebp,%edi
mov    $0xbb8,%esi
call   1070 <pollIn@plt>
cmp    $0x1,%eax
jne    1276 <r_ls+0xc6>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
call   1090 <fprintf@plt>
jmp    12cd <r_ls+0x11d>
mov    0x2d7c(%rip),%rax
mov    (%rax),%eax
mov    0x2d7b(%rip),%rcx
mov    %eax,(%rcx)
mov    0x2d7a(%rip),%rax
mov    (%rax),%edi
lea    0xd91(%rip),%rsi
call   1090 <fprintf@plt>
jmp    12d4 <r_ls+0x124>
xor    %eax,%eax
lea    0x10(%rsp),%rbx
nopl   (%rax)
test   %eax,%eax
jne    12a6 <r_ls+0xf6>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x12c,%edx
call   1030 <recibe@plt>
cmp    $0xffffffff,%eax
jne    1280 <r_ls+0xd0>
lea    0xdc0(%rip),%rdi
call   10b0 <perror@plt>
jmp    12cd <r_ls+0x11d>
lea    0xdc3(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rdx
call   10a0 <sscanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     12d9 <r_ls+0x129>
mov    0x2d0d(%rip),%rcx
mov    %eax,(%rcx)
mov    %ebp,%edi
call   1080 <close@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x140,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd2b(%rip),%rdi
call   10b0 <perror@plt>
jmp    12d4 <r_ls+0x124>
lea    0xd38(%rip),%rdi
call   10b0 <perror@plt>
jmp    12cd <r_ls+0x11d>

LLVM IR (-O0):
@EINVAL = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"r_ls(): ruta incorrecta\0A\00"
@.str.1 = [18 x i8] c"r_ls(): conecta()\00"
@.str.2 = [9 x i8] c"r_ls %s\0A\00"
@.str.3 = [16 x i8] c"r_ls(): envia()\00"
@.str.4 = [27 x i8] c"r_ls(): pollIn(): timeout\0A\00"
@.str.5 = [17 x i8] c"r_ls(): recibe()\00"
@.str.6 = [3 x i8] c"%d\00"
define i32 @r_ls(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca [300 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%12 = bitcast [300 x i8]* %11 to i8*
%13 = load i8*, i8** %7
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = load i32, i32* @EINVAL
store i32 %16, i32* @errno
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %76
19: ; preds = %3
%20 = load i8*, i8** %5
%21 = load i32, i32* %6
%22 = call i32 @conecta(i8* %20, i32 %21)
store i32 %22, i32* %10
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %26
24: ; preds = %19
%25 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %4
br label %76
26: ; preds = %19
%27 = getelementptr inbounds [300 x i8], [300 x i8]* %11, i64 0, i64 0
%28 = load i8*, i8** %7
%29 = call i32 @sprintf(i8* %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %28)
%30 = load i32, i32* %10
%31 = getelementptr inbounds [300 x i8], [300 x i8]* %11, i64 0, i64 0
%32 = getelementptr inbounds [300 x i8], [300 x i8]* %11, i64 0, i64 0
%33 = call i32 @strlen(i8* %32)
%34 = call i32 @envia(i32 %30, i8* %31, i32 %33)
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %40
36: ; preds = %26
%37 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* %10
%39 = call i32 @close(i32 %38)
store i32 -1, i32* %4
br label %76
40: ; preds = %26
%41 = load i32, i32* %10
%42 = call i32 @pollIn(i32 %41, i32 3000)
store i32 %42, i32* %8
%43 = load i32, i32* %8
%44 = icmp eq i32 %43, 1
br i1 %44, label %45, label %50
45: ; preds = %40
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%48 = load i32, i32* %10
%49 = call i32 @close(i32 %48)
store i32 -1, i32* %4
br label %76
50: ; preds = %40
store i32 0, i32* %8
br label %51
51: ; preds = %64, %50
%52 = load i32, i32* %8
%53 = icmp eq i32 %52, 0
br i1 %53, label %54, label %65
54: ; preds = %51
%55 = load i32, i32* %10
%56 = getelementptr inbounds [300 x i8], [300 x i8]* %11, i64 0, i64 0
%57 = call i32 @recibe(i32 %55, i8* %56, i32 300)
store i32 %57, i32* %8
%58 = load i32, i32* %8
%59 = icmp eq i32 %58, -1
br i1 %59, label %60, label %64
60: ; preds = %54
%61 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%62 = load i32, i32* %10
%63 = call i32 @close(i32 %62)
store i32 -1, i32* %4
br label %76
64: ; preds = %54
br label %51
65: ; preds = %51
%66 = getelementptr inbounds [300 x i8], [300 x i8]* %11, i64 0, i64 0
%67 = call i32 @sscanf(i8* %66, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %9)
%68 = load i32, i32* %9
%69 = icmp ne i32 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %65
%71 = load i32, i32* %9
store i32 %71, i32* @errno
%72 = load i32, i32* %10
%73 = call i32 @close(i32 %72)
store i32 -1, i32* %4
br label %76
74: ; preds = %65
%75 = load i32, i32* %10
store i32 %75, i32* %4
br label %76
76: ; preds = %74, %70, %60, %45, %36, %24, %15
%77 = load i32, i32* %4
ret i32 %77
}

LLVM IR (-O2):
@EINVAL = global i32 0
@errno = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"r_ls(): ruta incorrecta\0A\00"
@.str.1 = [18 x i8] c"r_ls(): conecta()\00"
@.str.2 = [9 x i8] c"r_ls %s\0A\00"
@.str.3 = [16 x i8] c"r_ls(): envia()\00"
@.str.4 = [27 x i8] c"r_ls(): pollIn(): timeout\0A\00"
@.str.5 = [17 x i8] c"r_ls(): recibe()\00"
@.str.6 = [3 x i8] c"%d\00"
define i32 @r_ls(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca [300 x i8]
%6 = bitcast i32* %4 to i8*
%7 = getelementptr inbounds [300 x i8], [300 x i8]* %5, i64 0, i64 0
%8 = icmp eq i8* %2, null
br i1 %8, label %9, label %13
9: ; preds = %3
%10 = load i32, i32* @EINVAL
store i32 %10, i32* @errno
%11 = load i32, i32* @stderr
%12 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %48
13: ; preds = %3
%14 = tail call i32 @conecta(i8* %0, i32 %1)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = tail call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %48
18: ; preds = %13
%19 = call i32 @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%20 = call i32 @strlen(i8* %7)
%21 = call i32 @envia(i32 %14, i8* %7, i32 %20)
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %26
23: ; preds = %18
%24 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @close(i32 %14)
br label %48
26: ; preds = %18
%27 = call i32 @pollIn(i32 %14, i32 3000)
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 @close(i32 %14)
br label %48
33: ; preds = %26, %36
%34 = phi i32 [ %37, %36 ], [ 0, %26 ]
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %42
36: ; preds = %33
%37 = call i32 @recibe(i32 %14, i8* %7, i32 300)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %33
39: ; preds = %36
%40 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%41 = call i32 @close(i32 %14)
br label %48
42: ; preds = %33
%43 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32* %4)
%44 = load i32, i32* %4
%45 = icmp eq i32 %44, 0
br i1 %45, label %48, label %46
46: ; preds = %42
store i32 %44, i32* @errno
%47 = call i32 @close(i32 %14)
br label %48
48: ; preds = %42, %46, %39, %29, %23, %16, %9
%49 = phi i32 [ -1, %9 ], [ -1, %16 ], [ -1, %23 ], [ -1, %29 ], [ -1, %39 ], [ -1, %46 ], [ %14, %42 ]
ret i32 %49
}