#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*/ err(int, char *, char *);
scalar_t__ es_dir(char *);
scalar_t__ es_fich(char *);
scalar_t__ esta_en_fich(char *, char *);
scalar_t__ file_no_acceder(char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void buscar_en_dir(char *palab, char *path) {
  DIR *dir_act;
  struct dirent *file;
  char path_aux[100];
  dir_act = opendir(path);
  if (dir_act == NULL) {
    err(1, "%s", path);
  }
  while ((file = readdir(dir_act)) != NULL) {
    if (file_no_acceder(file->d_name)) {
      continue;
    }
    strcpy(path_aux, path);
    strcat(path_aux, "/");
    strcat(path_aux, file->d_name);
    if (es_dir(path_aux)) {
      buscar_en_dir(palab, path_aux);
    } else if (es_fich(path_aux)) {
      if (esta_en_fich(palab, path_aux)) {
        printf("%s\n", path_aux);
      }
    }
  }
  closedir(dir_act);
}


x86 assembly (clang, -O0):
<buscar_en_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1200 <buscar_en_dir+0x40>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0xe05(%rip),%rsi
call   1090 <err@plt>
jmp    1205 <buscar_en_dir+0x45>
mov    -0x18(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     12ea <buscar_en_dir+0x12a>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
call   1040 <file_no_acceder@plt>
cmp    $0x0,%rax
je     1237 <buscar_en_dir+0x77>
jmp    1205 <buscar_en_dir+0x45>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x90(%rbp),%rdi
lea    0xdae(%rip),%rsi
call   10d0 <strcat@plt>
lea    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
call   10d0 <strcat@plt>
lea    -0x90(%rbp),%rdi
call   10c0 <es_dir@plt>
cmp    $0x0,%rax
je     1298 <buscar_en_dir+0xd8>
mov    -0x8(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   10e0 <buscar_en_dir@plt>
jmp    12e5 <buscar_en_dir+0x125>
lea    -0x90(%rbp),%rdi
call   10a0 <es_fich@plt>
cmp    $0x0,%rax
je     12e0 <buscar_en_dir+0x120>
mov    -0x8(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   10b0 <esta_en_fich@plt>
cmp    $0x0,%rax
je     12db <buscar_en_dir+0x11b>
lea    -0x90(%rbp),%rsi
lea    0xd2f(%rip),%rdi
call   1060 <printf@plt>
jmp    12e0 <buscar_en_dir+0x120>
jmp    12e5 <buscar_en_dir+0x125>
jmp    1205 <buscar_en_dir+0x45>
mov    -0x18(%rbp),%rdi
call   1070 <closedir@plt>
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buscar_en_dir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r15
mov    %rdi,%r14
mov    %rsi,%rdi
call   1050 <opendir@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11f8 <buscar_en_dir+0x38>
lea    0xe15(%rip),%rsi
mov    $0x1,%edi
mov    %r15,%rdx
call   1090 <err@plt>
mov    %r12,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     12a6 <buscar_en_dir+0xe6>
mov    %rax,%rbp
mov    %rsp,%rbx
lea    0xded(%rip),%r13
jmp    123b <buscar_en_dir+0x7b>
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   10e0 <buscar_en_dir@plt>
mov    %r12,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     12a6 <buscar_en_dir+0xe6>
mov    0x0(%rbp),%rdi
call   1040 <file_no_acceder@plt>
test   %rax,%rax
jne    122b <buscar_en_dir+0x6b>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   10d0 <strcat@plt>
mov    0x0(%rbp),%rsi
mov    %rbx,%rdi
call   10d0 <strcat@plt>
mov    %rbx,%rdi
call   10c0 <es_dir@plt>
test   %rax,%rax
jne    1220 <buscar_en_dir+0x60>
mov    %rbx,%rdi
call   10a0 <es_fich@plt>
test   %rax,%rax
je     122b <buscar_en_dir+0x6b>
mov    %r14,%rdi
mov    %rbx,%rsi
call   10b0 <esta_en_fich@plt>
test   %rax,%rax
je     122b <buscar_en_dir+0x6b>
lea    0xd69(%rip),%rdi
mov    %rbx,%rsi
call   1060 <printf@plt>
jmp    122b <buscar_en_dir+0x6b>
mov    %r12,%rdi
call   1070 <closedir@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @buscar_en_dir(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca %struct.dirent*
%7 = alloca [100 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %4
%9 = call i32* @opendir(i8* %8)
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %12, %2
br label %16
16: ; preds = %58, %26, %15
%17 = load i32*, i32** %5
%18 = call %struct.dirent* @readdir(i32* %17)
store %struct.dirent* %18, %struct.dirent** %6
%19 = icmp ne %struct.dirent* %18, null
br i1 %19, label %20, label %59
20: ; preds = %16
%21 = load %struct.dirent*, %struct.dirent** %6
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = call i64 @file_no_acceder(i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %20
br label %16
27: ; preds = %20
%28 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%29 = load i8*, i8** %4
%30 = call i32 @strcpy(i8* %28, i8* %29)
%31 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%32 = call i32 @strcat(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%34 = load %struct.dirent*, %struct.dirent** %6
%35 = getelementptr inbounds %struct.dirent, %struct.dirent* %34, i32 0, i32 0
%36 = load i8*, i8** %35
%37 = call i32 @strcat(i8* %33, i8* %36)
%38 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%39 = call i64 @es_dir(i8* %38)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %44
41: ; preds = %27
%42 = load i8*, i8** %3
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
br label %58
44: ; preds = %27
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%46 = call i64 @es_fich(i8* %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %57
48: ; preds = %44
%49 = load i8*, i8** %3
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%51 = call i64 @esta_en_fich(i8* %49, i8* %50)
%52 = icmp ne i64 %51, 0
br i1 %52, label %53, label %56
53: ; preds = %48
%54 = getelementptr inbounds [100 x i8], [100 x i8]* %7, i64 0, i64 0
%55 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %54)
br label %56
56: ; preds = %53, %48
br label %57
57: ; preds = %56, %44
br label %58
58: ; preds = %57, %41
br label %16
59: ; preds = %16
%60 = load i32*, i32** %5
%61 = call i32 @closedir(i32* %60)
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [3 x i8] c"%s\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @buscar_en_dir(i8* %0, i8* %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = tail call i32* @opendir(i8* %1)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %9
9: ; preds = %7, %2
%10 = call %struct.dirent* @readdir(i32* %5)
%11 = icmp eq %struct.dirent* %10, null
br i1 %11, label %37, label %12
12: ; preds = %9, %34
%13 = phi %struct.dirent* [ %35, %34 ], [ %10, %9 ]
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i64 0, i32 0
%15 = load i8*, i8** %14
%16 = call i64 @file_no_acceder(i8* %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %34
18: ; preds = %12
%19 = call i32 @strcpy(i8* %4, i8* %1)
%20 = call i32 @strcat(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = load i8*, i8** %14
%22 = call i32 @strcat(i8* %4, i8* %21)
%23 = call i64 @es_dir(i8* %4)
%24 = icmp eq i64 %23, 0
br i1 %24, label %26, label %25
25: ; preds = %18
br label %34
26: ; preds = %18
%27 = call i64 @es_fich(i8* %4)
%28 = icmp eq i64 %27, 0
br i1 %28, label %34, label %29
29: ; preds = %26
%30 = call i64 @esta_en_fich(i8* %0, i8* %4)
%31 = icmp eq i64 %30, 0
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %4)
br label %34
34: ; preds = %25, %29, %32, %26, %12
%35 = call %struct.dirent* @readdir(i32* %5)
%36 = icmp eq %struct.dirent* %35, null
br i1 %36, label %37, label %12
37: ; preds = %34, %9
%38 = call i32 @closedir(i32* %5)
ret void
}