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

/* 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 sscanf(char *, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int d_ls(char *ip_y_puerto, char *directorio) {
  int rc, r_errno, socket;
  char cadena[300] = "";
  char ipRem[32] = "";
  int puertoRem;
  if (ip_y_puerto == NULL ||
      sscanf(ip_y_puerto, "%[^:]:%d", ipRem, &puertoRem) != 2 ||
      directorio == NULL || sizeof(directorio) > 255) {
    errno = EINVAL;
    return -1;
  }
  if ((socket = conecta(ipRem, puertoRem)) == -1) {
    perror("d_ls(): conecta()");
    return -1;
  }
  sprintf(cadena, "d_ls %s\n", directorio);
  if (envia(socket, cadena, strlen(cadena)) == -1) {
    perror("d_ls(): envia()");
    close(socket);
    return -1;
  }
  rc = pollIn(socket, 3000);
  if (rc == 1) {
    fprintf(stderr, "d_ls(): pollIn(): timeout\n");
    close(socket);
    return -1;
  }
  rc = 0;
  while (rc == 0) {
    rc = recibe(socket, cadena, 300);
    if (rc == -1) {
      perror("d_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):
<d_ls>:
push   %rbp
mov    %rsp,%rbp
sub    $0x190,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x150(%rbp),%rdi
xor    %esi,%esi
mov    $0x12c,%edx
call   1060 <memset@plt>
lea    -0x170(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1060 <memset@plt>
cmpq   $0x0,-0x10(%rbp)
je     1228 <d_ls+0x78>
mov    -0x10(%rbp),%rdi
lea    -0x170(%rbp),%rdx
lea    0xdfa(%rip),%rsi
lea    -0x174(%rbp),%rcx
mov    $0x0,%al
call   10a0 <sscanf@plt>
cmp    $0x2,%eax
jne    1228 <d_ls+0x78>
cmpq   $0x0,-0x18(%rbp)
jne    1246 <d_ls+0x96>
mov    0x2da1(%rip),%rax
mov    (%rax),%ecx
mov    0x2da0(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    13d6 <d_ls+0x226>
lea    -0x170(%rbp),%rdi
mov    -0x174(%rbp),%esi
call   10d0 <conecta@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    127c <d_ls+0xcc>
lea    0xd9e(%rip),%rdi
call   10b0 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d6 <d_ls+0x226>
lea    -0x150(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xd8d(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x184(%rbp)
lea    -0x150(%rbp),%rax
mov    %rax,-0x180(%rbp)
lea    -0x150(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x184(%rbp),%edi
mov    -0x180(%rbp),%rsi
mov    %eax,%edx
call   1040 <envia@plt>
cmp    $0xffffffff,%eax
jne    12f3 <d_ls+0x143>
lea    0xd4a(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d6 <d_ls+0x226>
mov    -0x24(%rbp),%edi
mov    $0xbb8,%esi
call   1070 <pollIn@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x1,-0x1c(%rbp)
jne    1336 <d_ls+0x186>
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
lea    0xd17(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d6 <d_ls+0x226>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    138d <d_ls+0x1dd>
mov    -0x24(%rbp),%edi
lea    -0x150(%rbp),%rsi
mov    $0x12c,%edx
call   1030 <recibe@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1388 <d_ls+0x1d8>
lea    0xce0(%rip),%rdi
call   10b0 <perror@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d6 <d_ls+0x226>
jmp    133d <d_ls+0x18d>
lea    -0x150(%rbp),%rdi
lea    0xc6b(%rip),%rsi
lea    -0x20(%rbp),%rdx
mov    $0x0,%al
call   10a0 <sscanf@plt>
cmpl   $0x0,-0x20(%rbp)
je     13d0 <d_ls+0x220>
mov    -0x20(%rbp),%ecx
mov    0x2c1e(%rip),%rax
mov    %ecx,(%rax)
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13d6 <d_ls+0x226>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x190,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<d_ls>:
push   %r15
push   %r14
push   %rbx
sub    $0x160,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x30(%rsp),%rdi
mov    $0x12c,%edx
xor    %esi,%esi
call   1060 <memset@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
test   %rbx,%rbx
je     1283 <d_ls+0xd3>
lea    0xe10(%rip),%rsi
lea    0x10(%rsp),%rdx
lea    0x8(%rsp),%rcx
mov    %rbx,%rdi
xor    %eax,%eax
call   10a0 <sscanf@plt>
test   %r14,%r14
je     1283 <d_ls+0xd3>
cmp    $0x2,%eax
jne    1283 <d_ls+0xd3>
mov    0x8(%rsp),%esi
lea    0x10(%rsp),%rdi
call   10d0 <conecta@plt>
cmp    $0xffffffff,%eax
je     130a <d_ls+0x15a>
mov    %eax,%ebx
lea    0xded(%rip),%rsi
lea    0x30(%rsp),%r15
mov    %r15,%rdi
mov    %r14,%rdx
call   10c0 <sprintf@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1040 <envia@plt>
cmp    $0xffffffff,%eax
je     1318 <d_ls+0x168>
mov    %ebx,%edi
mov    $0xbb8,%esi
call   1070 <pollIn@plt>
cmp    $0x1,%eax
jne    1297 <d_ls+0xe7>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
call   1090 <fprintf@plt>
jmp    12ef <d_ls+0x13f>
mov    0x2d46(%rip),%rax
mov    (%rax),%eax
mov    0x2d45(%rip),%rcx
mov    %eax,(%rcx)
jmp    12f6 <d_ls+0x146>
xor    %eax,%eax
lea    0x30(%rsp),%r14
xchg   %ax,%ax
test   %eax,%eax
jne    12c6 <d_ls+0x116>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x12c,%edx
call   1030 <recibe@plt>
cmp    $0xffffffff,%eax
jne    12a0 <d_ls+0xf0>
lea    0xd90(%rip),%rdi
call   10b0 <perror@plt>
jmp    12ef <d_ls+0x13f>
lea    0xd39(%rip),%rsi
lea    0x30(%rsp),%rdi
lea    0xc(%rsp),%rdx
xor    %eax,%eax
call   10a0 <sscanf@plt>
mov    0xc(%rsp),%eax
test   %eax,%eax
je     12fb <d_ls+0x14b>
mov    0x2ceb(%rip),%rcx
mov    %eax,(%rcx)
mov    %ebx,%edi
call   1080 <close@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x160,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xcf8(%rip),%rdi
call   10b0 <perror@plt>
jmp    12f6 <d_ls+0x146>
lea    0xd05(%rip),%rdi
call   10b0 <perror@plt>
jmp    12ef <d_ls+0x13f>

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

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