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

/* Variables and functions */
int EINVAL;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ envia(int, char *, int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int lsopen(char *);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ *tmpfile();
FILE *petic_rls(int sockCliente, char *path) {
  int rc, error, fd;
  char cadena[300] = "";
  char datos[5120] = "";
  FILE *pFich;
  if (path == NULL) {
    error = EINVAL;
    fprintf(stderr,
            "petic_rls(): esperaba 1 argumento: directorio que listar\n");
    sprintf(cadena, "%d\n", error);
    envia(sockCliente, cadena, strlen(cadena));
    return NULL;
  }
  pFich = tmpfile();
  if (pFich == NULL) {
    error = errno;
    perror("petic_rls(): tmpfile()");
    sprintf(cadena, "%d\n", error);
    envia(sockCliente, cadena, strlen(cadena));
    return NULL;
  }
  fd = lsopen(path);
  if (fd == -1) {
    fclose(pFich);
    error = errno;
    perror("petic_rls(): lsopen()");
    sprintf(cadena, "%d\n", error);
    envia(sockCliente, cadena, strlen(cadena));
    return NULL;
  }
  while ((rc = read(fd, datos, 5120 - 1)) > 0) {
    datos[rc] = '\0';
    fprintf(pFich, "%s", datos);
  }
  close(fd);
  if (rc == -1) {
    fclose(pFich);
    error = errno;
    perror("petic_rls(): read()");
    sprintf(cadena, "%d\n", error);
    envia(sockCliente, cadena, strlen(cadena));
    return NULL;
  }
  rewind(pFich);
  error = 0;
  sprintf(cadena, "%d\n", error);
  envia(sockCliente, cadena, strlen(cadena));
  return pFich;
}


x86 assembly (clang, -O0):
<petic_rls>:
push   %rbp
mov    %rsp,%rbp
sub    $0x15b0,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x150(%rbp),%rdi
xor    %esi,%esi
mov    $0x12c,%edx
call   1070 <memset@plt>
lea    -0x1550(%rbp),%rdi
xor    %esi,%esi
mov    $0x1400,%edx
call   1070 <memset@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1281 <petic_rls+0xc1>
mov    0x2dc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2dca(%rip),%rax
movslq (%rax),%rdi
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
lea    -0x150(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xe02(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1564(%rbp)
lea    -0x150(%rbp),%rax
mov    %rax,-0x1560(%rbp)
lea    -0x150(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1564(%rbp),%edi
mov    -0x1560(%rbp),%rsi
mov    %eax,%edx
call   1040 <envia@plt>
movq   $0x0,-0x8(%rbp)
jmp    14f0 <petic_rls+0x330>
mov    $0x0,%al
call   10a0 <tmpfile@plt>
mov    %rax,-0x1558(%rbp)
cmpq   $0x0,-0x1558(%rbp)
jne    130f <petic_rls+0x14f>
mov    0x2d34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    0xd8e(%rip),%rdi
call   10c0 <perror@plt>
lea    -0x150(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xd74(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1574(%rbp)
lea    -0x150(%rbp),%rax
mov    %rax,-0x1570(%rbp)
lea    -0x150(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1574(%rbp),%edi
mov    -0x1570(%rbp),%rsi
mov    %eax,%edx
call   1040 <envia@plt>
movq   $0x0,-0x8(%rbp)
jmp    14f0 <petic_rls+0x330>
mov    -0x18(%rbp),%rdi
call   10e0 <lsopen@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    13a3 <petic_rls+0x1e3>
mov    -0x1558(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2ca0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    0xd11(%rip),%rdi
call   10c0 <perror@plt>
lea    -0x150(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xce0(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1584(%rbp)
lea    -0x150(%rbp),%rax
mov    %rax,-0x1580(%rbp)
lea    -0x150(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1584(%rbp),%edi
mov    -0x1580(%rbp),%rsi
mov    %eax,%edx
call   1040 <envia@plt>
movq   $0x0,-0x8(%rbp)
jmp    14f0 <petic_rls+0x330>
jmp    13a8 <petic_rls+0x1e8>
mov    -0x24(%rbp),%edi
lea    -0x1550(%rbp),%rsi
mov    $0x13ff,%edx
call   1090 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jle    13f5 <petic_rls+0x235>
movslq -0x1c(%rbp),%rax
movb   $0x0,-0x1550(%rbp,%rax,1)
mov    -0x1558(%rbp),%rdi
lea    -0x1550(%rbp),%rdx
lea    0xc82(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    13a8 <petic_rls+0x1e8>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1485 <petic_rls+0x2c5>
mov    -0x1558(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2bbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
lea    0xc48(%rip),%rdi
call   10c0 <perror@plt>
lea    -0x150(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xbfe(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x1594(%rbp)
lea    -0x150(%rbp),%rax
mov    %rax,-0x1590(%rbp)
lea    -0x150(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x1594(%rbp),%edi
mov    -0x1590(%rbp),%rsi
mov    %eax,%edx
call   1040 <envia@plt>
movq   $0x0,-0x8(%rbp)
jmp    14f0 <petic_rls+0x330>
mov    -0x1558(%rbp),%rdi
call   1060 <rewind@plt>
movl   $0x0,-0x20(%rbp)
lea    -0x150(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xb91(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x15a4(%rbp)
lea    -0x150(%rbp),%rax
mov    %rax,-0x15a0(%rbp)
lea    -0x150(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x15a4(%rbp),%edi
mov    -0x15a0(%rbp),%rsi
mov    %eax,%edx
call   1040 <envia@plt>
mov    -0x1558(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x15b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<petic_rls>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1530,%rsp
mov    %rsi,%rbp
mov    %edi,%r14d
mov    %rsp,%rdi
mov    $0x12c,%edx
xor    %esi,%esi
call   1080 <memset@plt>
lea    0x130(%rsp),%rdi
mov    $0x1400,%edx
xor    %esi,%esi
call   1080 <memset@plt>
test   %rbp,%rbp
je     12a4 <petic_rls+0xd4>
xor    %eax,%eax
call   10b0 <tmpfile@plt>
test   %rax,%rax
je     12cf <petic_rls+0xff>
mov    %rax,%r15
mov    %rbp,%rdi
call   10f0 <lsopen@plt>
cmp    $0xffffffff,%eax
je     12e1 <petic_rls+0x111>
mov    %eax,%r12d
lea    0x130(%rsp),%rsi
mov    %eax,%edi
mov    $0x13ff,%edx
call   10a0 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    128b <petic_rls+0xbb>
lea    0x130(%rsp),%rbp
nopw   0x0(%rax,%rax,1)
mov    %ebx,%eax
movb   $0x0,0x130(%rsp,%rax,1)
mov    %rbp,%rdi
mov    %r15,%rsi
call   1070 <fputs@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x13ff,%edx
call   10a0 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jg     1260 <petic_rls+0x90>
mov    %r12d,%edi
call   1090 <close@plt>
cmp    $0xffffffff,%ebx
je     12fb <petic_rls+0x12b>
mov    %r15,%rdi
call   1060 <rewind@plt>
xor    %ebp,%ebp
jmp    131b <petic_rls+0x14b>
mov    0x2d25(%rip),%rax
mov    (%rax),%ebp
mov    0x2d2c(%rip),%rax
movslq (%rax),%rcx
lea    0xd42(%rip),%rdi
mov    $0x39,%esi
mov    $0x1,%edx
call   10e0 <fwrite@plt>
jmp    1318 <petic_rls+0x148>
mov    0x2d02(%rip),%rax
mov    (%rax),%ebp
lea    0xd5f(%rip),%rdi
jmp    1313 <petic_rls+0x143>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    0x2ce8(%rip),%rax
mov    (%rax),%ebp
lea    0xd5c(%rip),%rdi
jmp    1313 <petic_rls+0x143>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    0x2cce(%rip),%rax
mov    (%rax),%ebp
lea    0xd58(%rip),%rdi
call   10c0 <perror@plt>
xor    %r15d,%r15d
lea    0xd18(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %ebp,%edx
call   10d0 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <envia@plt>
mov    %r15,%rax
add    $0x1530,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@stderr = global i32 0
@.str = [58 x i8] c"petic_rls(): esperaba 1 argumento: directorio que listar\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@errno = global i32 0
@.str.2 = [23 x i8] c"petic_rls(): tmpfile()\00"
@.str.3 = [22 x i8] c"petic_rls(): lsopen()\00"
@.str.4 = [3 x i8] c"%s\00"
@.str.5 = [20 x i8] c"petic_rls(): read()\00"
define i32* @petic_rls(i32 %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [300 x i8]
%10 = alloca [5120 x i8]
%11 = alloca i32*
store i32 %0, i32* %4
store i8* %1, i8** %5
%12 = bitcast [300 x i8]* %9 to i8*
%13 = bitcast [5120 x i8]* %10 to i8*
%14 = load i8*, i8** %5
%15 = icmp eq i8* %14, null
br i1 %15, label %16, label %30
16: ; preds = %2
%17 = load i32, i32* @EINVAL
store i32 %17, i32* %7
%18 = load i32, i32* @stderr
%19 = sext i32 %18 to i64
%20 = inttoptr i64 %19 to i32*
%21 = call i32 (i32*, i8*, ...) @fprintf(i32* %20, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0))
%22 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%23 = load i32, i32* %7
%24 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load i32, i32* %4
%26 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%27 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%28 = call i32 @strlen(i8* %27)
%29 = call i32 @envia(i32 %25, i8* %26, i32 %28)
store i32* null, i32** %3
br label %106
30: ; preds = %2
%31 = call i32* (...) @tmpfile()
store i32* %31, i32** %11
%32 = load i32*, i32** %11
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %45
34: ; preds = %30
%35 = load i32, i32* @errno
store i32 %35, i32* %7
%36 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%37 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%38 = load i32, i32* %7
%39 = call i32 @sprintf(i8* %37, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = load i32, i32* %4
%41 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%42 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%43 = call i32 @strlen(i8* %42)
%44 = call i32 @envia(i32 %40, i8* %41, i32 %43)
store i32* null, i32** %3
br label %106
45: ; preds = %30
%46 = load i8*, i8** %5
%47 = call i32 @lsopen(i8* %46)
store i32 %47, i32* %8
%48 = load i32, i32* %8
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %63
50: ; preds = %45
%51 = load i32*, i32** %11
%52 = call i32 @fclose(i32* %51)
%53 = load i32, i32* @errno
store i32 %53, i32* %7
%54 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%55 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%56 = load i32, i32* %7
%57 = call i32 @sprintf(i8* %55, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %56)
%58 = load i32, i32* %4
%59 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%60 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%61 = call i32 @strlen(i8* %60)
%62 = call i32 @envia(i32 %58, i8* %59, i32 %61)
store i32* null, i32** %3
br label %106
63: ; preds = %45
br label %64
64: ; preds = %69, %63
%65 = load i32, i32* %8
%66 = getelementptr inbounds [5120 x i8], [5120 x i8]* %10, i64 0, i64 0
%67 = call i32 @read(i32 %65, i8* %66, i32 5119)
store i32 %67, i32* %6
%68 = icmp sgt i32 %67, 0
br i1 %68, label %69, label %76
69: ; preds = %64
%70 = load i32, i32* %6
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [5120 x i8], [5120 x i8]* %10, i64 0, i64 %71
store i8 0, i8* %72
%73 = load i32*, i32** %11
%74 = getelementptr inbounds [5120 x i8], [5120 x i8]* %10, i64 0, i64 0
%75 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %74)
br label %64
76: ; preds = %64
%77 = load i32, i32* %8
%78 = call i32 @close(i32 %77)
%79 = load i32, i32* %6
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %94
81: ; preds = %76
%82 = load i32*, i32** %11
%83 = call i32 @fclose(i32* %82)
%84 = load i32, i32* @errno
store i32 %84, i32* %7
%85 = call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%86 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%87 = load i32, i32* %7
%88 = call i32 @sprintf(i8* %86, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %87)
%89 = load i32, i32* %4
%90 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%91 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%92 = call i32 @strlen(i8* %91)
%93 = call i32 @envia(i32 %89, i8* %90, i32 %92)
store i32* null, i32** %3
br label %106
94: ; preds = %76
%95 = load i32*, i32** %11
%96 = call i32 @rewind(i32* %95)
store i32 0, i32* %7
%97 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%98 = load i32, i32* %7
%99 = call i32 @sprintf(i8* %97, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %98)
%100 = load i32, i32* %4
%101 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%102 = getelementptr inbounds [300 x i8], [300 x i8]* %9, i64 0, i64 0
%103 = call i32 @strlen(i8* %102)
%104 = call i32 @envia(i32 %100, i8* %101, i32 %103)
%105 = load i32*, i32** %11
store i32* %105, i32** %3
br label %106
106: ; preds = %94, %81, %50, %34, %16
%107 = load i32*, i32** %3
ret i32* %107
}

LLVM IR (-O2):
@EINVAL = global i32 0
@stderr = global i32 0
@.str = [58 x i8] c"petic_rls(): esperaba 1 argumento: directorio que listar\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@errno = global i32 0
@.str.2 = [23 x i8] c"petic_rls(): tmpfile()\00"
@.str.3 = [22 x i8] c"petic_rls(): lsopen()\00"
@.str.5 = [20 x i8] c"petic_rls(): read()\00"
define noalias i32* @petic_rls(i32 %0, i8* %1) {
%3 = alloca [300 x i8]
%4 = alloca [5120 x i8]
%5 = getelementptr inbounds [300 x i8], [300 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [5120 x i8], [5120 x i8]* %4, i64 0, i64 0
%7 = icmp eq i8* %1, null
br i1 %7, label %8, label %14
8: ; preds = %2
%9 = load i32, i32* @EINVAL
%10 = load i32, i32* @stderr
%11 = sext i32 %10 to i64
%12 = inttoptr i64 %11 to i32*
%13 = tail call i64 @fwrite(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str, i64 0, i64 0), i64 57, i64 1, i32* %12)
br label %47
14: ; preds = %2
%15 = tail call i32* (...) @tmpfile()
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* @errno
%19 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %47
20: ; preds = %14
%21 = tail call i32 @lsopen(i8* %1)
%22 = icmp eq i32 %21, -1
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = call i32 @read(i32 %21, i8* %6, i32 5119)
%25 = icmp sgt i32 %24, 0
br i1 %25, label %30, label %37
26: ; preds = %20
%27 = tail call i32 @fclose(i32* %15)
%28 = load i32, i32* @errno
%29 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %47
30: ; preds = %23, %30
%31 = phi i32 [ %35, %30 ], [ %24, %23 ]
%32 = zext i32 %31 to i64
%33 = getelementptr inbounds [5120 x i8], [5120 x i8]* %4, i64 0, i64 %32
store i8 0, i8* %33
%34 = call i32 @fputs(i8* %6, i32* %15)
%35 = call i32 @read(i32 %21, i8* %6, i32 5119)
%36 = icmp sgt i32 %35, 0
br i1 %36, label %30, label %37
37: ; preds = %30, %23
%38 = phi i32 [ %24, %23 ], [ %35, %30 ]
%39 = tail call i32 @close(i32 %21)
%40 = icmp eq i32 %38, -1
br i1 %40, label %41, label %45
41: ; preds = %37
%42 = tail call i32 @fclose(i32* %15)
%43 = load i32, i32* @errno
%44 = tail call i32 @perror(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
br label %47
45: ; preds = %37
%46 = tail call i32 @rewind(i32* %15)
br label %47
47: ; preds = %45, %41, %26, %17, %8
%48 = phi i32 [ 0, %45 ], [ %43, %41 ], [ %28, %26 ], [ %18, %17 ], [ %9, %8 ]
%49 = phi i32* [ %15, %45 ], [ null, %41 ], [ null, %26 ], [ null, %17 ], [ null, %8 ]
%50 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %48)
%51 = call i32 @strlen(i8* %5)
%52 = call i32 @envia(i32 %0, i8* %5, i32 %51)
ret i32* %49
}