#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 dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *show_dir(char *path) {
  DIR *my_path;
  struct dirent *dir;
  if ((my_path = opendir(path)) == NULL) {
    fprintf(stderr, "Error al leer el directorio\n");
    exit(1);
  }
  char *buf = (char *)malloc(sizeof(char) * 1000);
  strcpy(buf, "DIRECTORIO COMPARTIDO: ");
  strcat(buf, path);
  strcat(buf, "\n\n");
  while ((dir = readdir(my_path)) != NULL) {
    strcat(buf, "\t");
    strcat(buf, dir->d_name);
    strcat(buf, "\n");
  }
  closedir(my_path);
  return buf;
}


x86 assembly (clang, -O0):
<show_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    11c2 <show_dir+0x42>
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x3e8,%edi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xe3d(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x10(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1249 <show_dir+0xc9>
mov    -0x20(%rbp),%rdi
lea    0xe19(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
call   1090 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xdf7(%rip),%rsi
call   1090 <strcat@plt>
jmp    11fd <show_dir+0x7d>
mov    -0x10(%rbp),%rdi
call   1050 <closedir@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<show_dir>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r15
call   1040 <opendir@plt>
test   %rax,%rax
je     1246 <show_dir+0xc6>
mov    %rax,%r14
mov    $0x3e8,%edi
call   1080 <malloc@plt>
mov    %rax,%r13
lea    0xe6c(%rip),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
mov    %r13,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
lea    0xe6a(%rip),%rsi
mov    %r13,%rdi
call   1090 <strcat@plt>
mov    %r14,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     1231 <show_dir+0xb1>
mov    %rax,%rbx
lea    0xe4e(%rip),%r15
lea    0xe45(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r15,%rsi
call   1090 <strcat@plt>
mov    (%rbx),%rsi
mov    %r13,%rdi
call   1090 <strcat@plt>
mov    %r13,%rdi
mov    %r12,%rsi
call   1090 <strcat@plt>
mov    %r14,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1200 <show_dir+0x80>
mov    %r14,%rdi
call   1050 <closedir@plt>
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
mov    0x2d93(%rip),%rax
mov    (%rax),%edi
lea    0xdaa(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [29 x i8] c"Error al leer el directorio\0A\00"
@.str.1 = [24 x i8] c"DIRECTORIO COMPARTIDO: \00"
@.str.2 = [3 x i8] c"\0A\0A\00"
@.str.3 = [2 x i8] c"\09\00"
@.str.4 = [2 x i8] c"\0A\00"
define i8* @show_dir(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @opendir(i8* %6)
store i32* %7, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %13
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
%14 = call i64 @malloc(i32 1000)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = call i32 @strcpy(i8* %16, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%18 = load i8*, i8** %5
%19 = load i8*, i8** %2
%20 = call i32 @strcat(i8* %18, i8* %19)
%21 = load i8*, i8** %5
%22 = call i32 @strcat(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %23
23: ; preds = %27, %13
%24 = load i32*, i32** %3
%25 = call %struct.dirent* @readdir(i32* %24)
store %struct.dirent* %25, %struct.dirent** %4
%26 = icmp ne %struct.dirent* %25, null
br i1 %26, label %27, label %37
27: ; preds = %23
%28 = load i8*, i8** %5
%29 = call i32 @strcat(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%30 = load i8*, i8** %5
%31 = load %struct.dirent*, %struct.dirent** %4
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i32 0, i32 0
%33 = load i8*, i8** %32
%34 = call i32 @strcat(i8* %30, i8* %33)
%35 = load i8*, i8** %5
%36 = call i32 @strcat(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %23
37: ; preds = %23
%38 = load i32*, i32** %3
%39 = call i32 @closedir(i32* %38)
%40 = load i8*, i8** %5
ret i8* %40
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [29 x i8] c"Error al leer el directorio\0A\00"
@.str.1 = [24 x i8] c"DIRECTORIO COMPARTIDO: \00"
@.str.2 = [3 x i8] c"\0A\0A\00"
@.str.3 = [2 x i8] c"\09\00"
@.str.4 = [2 x i8] c"\0A\00"
define i8* @show_dir(i8* %0) {
%2 = tail call i32* @opendir(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %1
%9 = tail call i64 @malloc(i32 1000)
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @strcat(i8* %10, i8* %0)
%13 = tail call i32 @strcat(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%14 = tail call %struct.dirent* @readdir(i32* %2)
%15 = icmp eq %struct.dirent* %14, null
br i1 %15, label %25, label %16
16: ; preds = %8, %16
%17 = phi %struct.dirent* [ %23, %16 ], [ %14, %8 ]
%18 = tail call i32 @strcat(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i64 0, i32 0
%20 = load i8*, i8** %19
%21 = tail call i32 @strcat(i8* %10, i8* %20)
%22 = tail call i32 @strcat(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%23 = tail call %struct.dirent* @readdir(i32* %2)
%24 = icmp eq %struct.dirent* %23, null
br i1 %24, label %25, label %16
25: ; preds = %16, %8
%26 = tail call i32 @closedir(i32* %2)
ret i8* %10
}