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

/* Variables and functions */
int /*<<< orphan*/ eliminar_recursivo(char *);
int errno;
int /*<<< orphan*/ printf(char *, char *, ...);
int rmdir(char *);
char *strerror(int);
void eliminar_directorio(char *ruta, int forzar) {
  int salida;
  salida = rmdir(ruta);
  if (salida == 0) {
    printf("Borrado: %s \n", ruta);
  } else {
    if (errno == 39) {
      if (forzar) {
        eliminar_recursivo(ruta);
      } else {
        printf("No se pudo eliminar %s: Directorio no vacío\n", ruta);
      }
    } else if (errno == 2) {
      printf("Fichero desconocido: %s\n", ruta);
    } else {
      printf("Error borrando directorio %s: %d %s\n", ruta, errno,
             strerror(errno));
    }
  }
}


x86 assembly (clang, -O0):
<eliminar_directorio>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <rmdir@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jne    117c <eliminar_directorio+0x3c>
mov    -0x8(%rbp),%rsi
lea    0xe90(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1226 <eliminar_directorio+0xe6>
mov    0x2e5d(%rip),%rax
cmpl   $0x27,(%rax)
jne    11bb <eliminar_directorio+0x7b>
cmpl   $0x0,-0xc(%rbp)
je     11a4 <eliminar_directorio+0x64>
mov    -0x8(%rbp),%rdi
call   1050 <eliminar_recursivo@plt>
jmp    11b6 <eliminar_directorio+0x76>
mov    -0x8(%rbp),%rsi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1221 <eliminar_directorio+0xe1>
mov    0x2e1e(%rip),%rax
cmpl   $0x2,(%rax)
jne    11e2 <eliminar_directorio+0xa2>
mov    -0x8(%rbp),%rsi
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    121c <eliminar_directorio+0xdc>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2def(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    %rax,%rcx
lea    0xe40(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1221 <eliminar_directorio+0xe1>
jmp    1226 <eliminar_directorio+0xe6>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eliminar_directorio>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbx
call   1030 <rmdir@plt>
test   %eax,%eax
je     1177 <eliminar_directorio+0x37>
mov    0x2e86(%rip),%rax
mov    (%rax),%ebp
cmp    $0x2,%ebp
je     1180 <eliminar_directorio+0x40>
cmp    $0x27,%ebp
jne    1189 <eliminar_directorio+0x49>
test   %r14d,%r14d
je     11aa <eliminar_directorio+0x6a>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1050 <eliminar_recursivo@plt>
lea    0xe82(%rip),%rdi
jmp    11b1 <eliminar_directorio+0x71>
lea    0xeb5(%rip),%rdi
jmp    11b1 <eliminar_directorio+0x71>
mov    %ebp,%edi
call   1060 <strerror@plt>
lea    0xebe(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>
lea    0xe5d(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <printf@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"Borrado: %s \0A\00"
@errno = global i32 0
@.str.1 = [46 x i8] c"No se pudo eliminar %s: Directorio no vac\C3\ADo\0A\00"
@.str.2 = [25 x i8] c"Fichero desconocido: %s\0A\00"
@.str.3 = [37 x i8] c"Error borrando directorio %s: %d %s\0A\00"
define void @eliminar_directorio(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = call i32 @rmdir(i8* %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i8*, i8** %3
%12 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %40
13: ; preds = %2
%14 = load i32, i32* @errno
%15 = icmp eq i32 %14, 39
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i8*, i8** %3
%21 = call i32 @eliminar_recursivo(i8* %20)
br label %25
22: ; preds = %16
%23 = load i8*, i8** %3
%24 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22, %19
br label %39
26: ; preds = %13
%27 = load i32, i32* @errno
%28 = icmp eq i32 %27, 2
br i1 %28, label %29, label %32
29: ; preds = %26
%30 = load i8*, i8** %3
%31 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %30)
br label %38
32: ; preds = %26
%33 = load i8*, i8** %3
%34 = load i32, i32* @errno
%35 = load i32, i32* @errno
%36 = call i8* @strerror(i32 %35)
%37 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %33, i32 %34, i8* %36)
br label %38
38: ; preds = %32, %29
br label %39
39: ; preds = %38, %25
br label %40
40: ; preds = %39, %10
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"Borrado: %s \0A\00"
@errno = global i32 0
@.str.1 = [46 x i8] c"No se pudo eliminar %s: Directorio no vac\C3\ADo\0A\00"
@.str.2 = [25 x i8] c"Fichero desconocido: %s\0A\00"
@.str.3 = [37 x i8] c"Error borrando directorio %s: %d %s\0A\00"
define void @eliminar_directorio(i8* %0, i32 %1) {
%3 = tail call i32 @rmdir(i8* %0)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %20
7: ; preds = %2
%8 = load i32, i32* @errno
switch i32 %8, label %17 [
i32 39, label %9
i32 2, label %15
]
9: ; preds = %7
%10 = icmp eq i32 %1, 0
br i1 %10, label %13, label %11
11: ; preds = %9
%12 = tail call i32 @eliminar_recursivo(i8* %0)
br label %20
13: ; preds = %9
%14 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %20
15: ; preds = %7
%16 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %20
17: ; preds = %7
%18 = tail call i8* @strerror(i32 %8)
%19 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.3, i64 0, i64 0), i8* %0, i32 %8, i8* %18)
br label %20
20: ; preds = %13, %11, %17, %15, %5
ret void
}