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

/* Variables and functions */
int /*<<< orphan*/ PATH_MAX;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ eliminar_fichero(char *);
int errno;
scalar_t__ es_directorio(char *);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char *, char const *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int rmdir(char const *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char *);
scalar_t__ strcmp(char *, char *);
char *strerror(int);
void eliminar_recursivo(const char *nombre) {
  DIR *dir;
  struct dirent *entrada;
  if (!(dir = opendir(nombre))) {
    if (errno == 2) {
      printf("Directorio inexistente insuficientes privilegios: %s\n", nombre);
    } else {
      printf("Error obteniendo info de directorio %s: %d %s\n", nombre, errno,
             strerror(errno));
    }
    return;
  }
  dir = opendir(nombre);
  while ((entrada = readdir(dir)) != NULL) {
    if (strcmp(".", entrada->d_name) == 0 ||
        strcmp("..", entrada->d_name) == 0) {
      continue;
    }
    char ruta[PATH_MAX + 1];
    snprintf(ruta, sizeof(ruta), "%s/%s", nombre, entrada->d_name);
    if (es_directorio(ruta)) {
      eliminar_recursivo(ruta);
    } else {
      eliminar_fichero(ruta);
    }
  }
  int salida;
  salida = rmdir(nombre);
  if (salida == 0) {
    printf("Borrado: %s \n", nombre);
  } else {
    printf("Error borrando directorio %s: %d %s\n", nombre, errno,
           strerror(errno));
  }
  closedir(dir);
}


x86 assembly (clang, -O0):
<eliminar_recursivo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    1239 <eliminar_recursivo+0x89>
mov    0x2dfe(%rip),%rax
cmpl   $0x2,(%rax)
jne    11fa <eliminar_recursivo+0x4a>
mov    -0x8(%rbp),%rsi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1234 <eliminar_recursivo+0x84>
mov    -0x8(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    0x2dcf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    0x2dc3(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%edx
mov    %rax,%rcx
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    138a <eliminar_recursivo+0x1da>
mov    -0x8(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10b0 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     131a <eliminar_recursivo+0x16a>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xdfb(%rip),%rdi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1297 <eliminar_recursivo+0xe7>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xddd(%rip),%rdi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    129c <eliminar_recursivo+0xec>
jmp    1246 <eliminar_recursivo+0x96>
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x40(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x28(%rbp)
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    (%rax),%r8
lea    0xd89(%rip),%rdx
call   1080 <snprintf@plt>
mov    -0x40(%rbp),%rdi
call   1030 <es_directorio@plt>
cmp    $0x0,%rax
je     1305 <eliminar_recursivo+0x155>
mov    -0x40(%rbp),%rdi
call   10c0 <eliminar_recursivo@plt>
jmp    130e <eliminar_recursivo+0x15e>
mov    -0x40(%rbp),%rdi
call   1040 <eliminar_fichero@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
jmp    1246 <eliminar_recursivo+0x96>
mov    -0x8(%rbp),%rdi
call   1060 <rmdir@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jne    1347 <eliminar_recursivo+0x197>
mov    -0x8(%rbp),%rsi
lea    0xd33(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1381 <eliminar_recursivo+0x1d1>
mov    -0x8(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    0x2c82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2c76(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x50(%rbp),%rsi
mov    -0x44(%rbp),%edx
mov    %rax,%rcx
lea    0xd02(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1090 <closedir@plt>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eliminar_recursivo>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <opendir@plt>
test   %rax,%rax
je     12ce <eliminar_recursivo+0x11e>
mov    %rbx,-0x30(%rbp)
mov    %rbx,%rdi
call   1050 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10b0 <readdir@plt>
test   %rax,%rax
je     1293 <eliminar_recursivo+0xe3>
mov    %rax,%r13
lea    0xe6d(%rip),%r15
jmp    1218 <eliminar_recursivo+0x68>
nopl   0x0(%rax,%rax,1)
call   10c0 <eliminar_recursivo@plt>
mov    %r14,%rsp
mov    %rbx,%rdi
call   10b0 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     1293 <eliminar_recursivo+0xe3>
mov    0x0(%r13),%rsi
mov    %r15,%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1208 <eliminar_recursivo+0x58>
mov    0x0(%r13),%rsi
lea    0xe31(%rip),%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1208 <eliminar_recursivo+0x58>
mov    %rsp,%r14
mov    0x2da8(%rip),%rax
mov    (%rax),%esi
add    $0x1,%esi
mov    %rsp,%r12
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    0x0(%r13),%r8
mov    %r12,%rdi
lea    0xdfc(%rip),%rdx
mov    -0x30(%rbp),%rcx
call   1080 <snprintf@plt>
mov    %r12,%rdi
call   1030 <es_directorio@plt>
mov    %r12,%rdi
test   %rax,%rax
jne    1200 <eliminar_recursivo+0x50>
call   1040 <eliminar_fichero@plt>
jmp    1205 <eliminar_recursivo+0x55>
mov    -0x30(%rbp),%r14
mov    %r14,%rdi
call   1060 <rmdir@plt>
test   %eax,%eax
je     12fd <eliminar_recursivo+0x14d>
mov    0x2d2e(%rip),%rax
mov    (%rax),%r15d
mov    %r15d,%edi
call   10d0 <strerror@plt>
lea    0xdc0(%rip),%rdi
mov    %r14,%rsi
mov    %r15d,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    130e <eliminar_recursivo+0x15e>
mov    0x2d03(%rip),%rax
mov    (%rax),%r14d
cmp    $0x2,%r14d
jne    1325 <eliminar_recursivo+0x175>
lea    0xd1b(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <printf@plt>
lea    0xd6a(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1090 <closedir@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r14d,%edi
call   10d0 <strerror@plt>
lea    0xd02(%rip),%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
mov    %rax,%rcx
xor    %eax,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1070 <printf@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@errno = global i32 0
@.str = [54 x i8] c"Directorio inexistente insuficientes privilegios: %s\0A\00"
@.str.1 = [47 x i8] c"Error obteniendo info de directorio %s: %d %s\0A\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@PATH_MAX = global i32 0
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [14 x i8] c"Borrado: %s \0A\00"
@.str.6 = [37 x i8] c"Error borrando directorio %s: %d %s\0A\00"
define void @eliminar_recursivo(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = call i32* @opendir(i8* %8)
store i32* %9, i32** %3
%10 = icmp ne i32* %9, null
br i1 %10, label %24, label %11
11: ; preds = %1
%12 = load i32, i32* @errno
%13 = icmp eq i32 %12, 2
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i8*, i8** %2
%16 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %15)
br label %23
17: ; preds = %11
%18 = load i8*, i8** %2
%19 = load i32, i32* @errno
%20 = load i32, i32* @errno
%21 = call i8* @strerror(i32 %20)
%22 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i8* %18, i32 %19, i8* %21)
br label %23
23: ; preds = %17, %14
br label %80
24: ; preds = %1
%25 = load i8*, i8** %2
%26 = call i32* @opendir(i8* %25)
store i32* %26, i32** %3
br label %27
27: ; preds = %61, %43, %24
%28 = load i32*, i32** %3
%29 = call %struct.dirent* @readdir(i32* %28)
store %struct.dirent* %29, %struct.dirent** %4
%30 = icmp ne %struct.dirent* %29, null
br i1 %30, label %31, label %63
31: ; preds = %27
%32 = load %struct.dirent*, %struct.dirent** %4
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %32, i32 0, i32 0
%34 = load i8*, i8** %33
%35 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %43, label %37
37: ; preds = %31
%38 = load %struct.dirent*, %struct.dirent** %4
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i32 0, i32 0
%40 = load i8*, i8** %39
%41 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %40)
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %44
43: ; preds = %37, %31
br label %27
44: ; preds = %37
%45 = load i32, i32* @PATH_MAX
%46 = add nsw i32 %45, 1
%47 = zext i32 %46 to i64
%48 = call i8* @llvm.stacksave()
store i8* %48, i8** %5
%49 = alloca i8, i64 %47
store i64 %47, i64* %6
%50 = trunc i64 %47 to i32
%51 = load i8*, i8** %2
%52 = load %struct.dirent*, %struct.dirent** %4
%53 = getelementptr inbounds %struct.dirent, %struct.dirent* %52, i32 0, i32 0
%54 = load i8*, i8** %53
%55 = call i32 @snprintf(i8* %49, i32 %50, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %51, i8* %54)
%56 = call i64 @es_directorio(i8* %49)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %59
58: ; preds = %44
br label %61
59: ; preds = %44
%60 = call i32 @eliminar_fichero(i8* %49)
br label %61
61: ; preds = %59, %58
%62 = load i8*, i8** %5
br label %27
63: ; preds = %27
%64 = load i8*, i8** %2
%65 = call i32 @rmdir(i8* %64)
store i32 %65, i32* %7
%66 = load i32, i32* %7
%67 = icmp eq i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %63
%69 = load i8*, i8** %2
%70 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %69)
br label %77
71: ; preds = %63
%72 = load i8*, i8** %2
%73 = load i32, i32* @errno
%74 = load i32, i32* @errno
%75 = call i8* @strerror(i32 %74)
%76 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), i8* %72, i32 %73, i8* %75)
br label %77
77: ; preds = %71, %68
%78 = load i32*, i32** %3
%79 = call i32 @closedir(i32* %78)
br label %80
80: ; preds = %77, %23
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@errno = global i32 0
@.str = [54 x i8] c"Directorio inexistente insuficientes privilegios: %s\0A\00"
@.str.1 = [47 x i8] c"Error obteniendo info de directorio %s: %d %s\0A\00"
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@PATH_MAX = global i32 0
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [14 x i8] c"Borrado: %s \0A\00"
@.str.6 = [37 x i8] c"Error borrando directorio %s: %d %s\0A\00"
define void @eliminar_recursivo(i8* %0) {
%2 = tail call i32* @opendir(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %12
4: ; preds = %1
%5 = load i32, i32* @errno
%6 = icmp eq i32 %5, 2
br i1 %6, label %7, label %9
7: ; preds = %4
%8 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %54
9: ; preds = %4
%10 = tail call i8* @strerror(i32 %5)
%11 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i8* %0, i32 %5, i8* %10)
br label %54
12: ; preds = %1
%13 = tail call i32* @opendir(i8* %0)
%14 = call %struct.dirent* @readdir(i32* %13)
%15 = icmp eq %struct.dirent* %14, null
br i1 %15, label %43, label %16
16: ; preds = %12, %26
%17 = phi %struct.dirent* [ %27, %26 ], [ %14, %12 ]
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i64 0, i32 0
%19 = load i8*, i8** %18
%20 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %16
%23 = load i8*, i8** %18
%24 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %16, %22, %42
%27 = call %struct.dirent* @readdir(i32* %13)
%28 = icmp eq %struct.dirent* %27, null
br i1 %28, label %43, label %16
29: ; preds = %22
%30 = load i32, i32* @PATH_MAX
%31 = add nsw i32 %30, 1
%32 = zext i32 %31 to i64
%33 = call i8* @llvm.stacksave()
%34 = alloca i8, i64 %32
%35 = load i8*, i8** %18
%36 = call i32 @snprintf(i8* %34, i32 %31, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %35)
%37 = call i64 @es_directorio(i8* %34)
%38 = icmp eq i64 %37, 0
br i1 %38, label %40, label %39
39: ; preds = %29
br label %42
40: ; preds = %29
%41 = call i32 @eliminar_fichero(i8* %34)
br label %42
42: ; preds = %40, %39
br label %26
43: ; preds = %26, %12
%44 = call i32 @rmdir(i8* %0)
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %48
46: ; preds = %43
%47 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i8* %0)
br label %52
48: ; preds = %43
%49 = load i32, i32* @errno
%50 = call i8* @strerror(i32 %49)
%51 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.6, i64 0, i64 0), i8* %0, i32 %49, i8* %50)
br label %52
52: ; preds = %48, %46
%53 = call i32 @closedir(i32* %13)
br label %54
54: ; preds = %7, %9, %52
ret void
}