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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char const *, char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcmp(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int DFS(const char *s, int deep, const char *file) {
  DIR *hw;
  struct dirent *entry;
  printf("Searching %s in directory %s\n", file, s);
  if (0 <= deep) {
    if ((hw = opendir(s)) == NULL) {
      fprintf(stderr, "Error\n");
      perror("Your error");
      exit(EXIT_FAILURE);
    }
    while ((entry = readdir(hw)) != NULL) {
      if (!strcmp(entry->d_name, file)) {
        printf("Found %s in dirctory %s\n", file, s);
        return 1;
      }
      if (entry->d_type == 4) {
        char new_dir[1000];
        strcpy(new_dir, s);
        strcat(new_dir, "/");
        strcat(new_dir, entry->d_name);
        DFS(new_dir, deep - 1, file);
      }
    }
    closedir(hw);
  }
}


x86 assembly (clang, -O0):
<DFS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xe2b(%rip),%rdi
call   1050 <printf@plt>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jg     12e8 <DFS+0x138>
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    122b <DFS+0x7b>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe12(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xe0d(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    1230 <DFS+0x80>
mov    -0x28(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     12df <DFS+0x12f>
mov    -0x30(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1280 <DFS+0xd0>
mov    -0x20(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xdc1(%rip),%rdi
call   1050 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e8 <DFS+0x138>
mov    -0x30(%rbp),%rax
cmpl   $0x4,0x8(%rax)
jne    12da <DFS+0x12a>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x420(%rbp),%rdi
lea    0xd9d(%rip),%rsi
call   10c0 <strcat@plt>
lea    -0x420(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    (%rax),%rsi
call   10c0 <strcat@plt>
lea    -0x420(%rbp),%rdi
mov    -0x14(%rbp),%esi
sub    $0x1,%esi
mov    -0x20(%rbp),%rdx
call   10a0 <DFS@plt>
jmp    1230 <DFS+0x80>
mov    -0x28(%rbp),%rdi
call   1060 <closedir@plt>
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<DFS>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3e8,%rsp
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %rdi,%r14
lea    0xe2f(%rip),%rdi
mov    %rdx,%rsi
mov    %r14,%rdx
call   1050 <printf@plt>
test   %r15d,%r15d
js     1299 <DFS+0xe9>
mov    %r14,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     12b0 <DFS+0x100>
mov    %rax,%rbp
mov    %rax,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     127d <DFS+0xcd>
mov    %rax,%r13
add    $0xffffffff,%r15d
mov    %rsp,%r12
jmp    1230 <DFS+0x80>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
call   1090 <readdir@plt>
mov    %rax,%r13
test   %rax,%rax
je     127d <DFS+0xcd>
mov    0x0(%r13),%rdi
mov    %rbx,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1287 <DFS+0xd7>
cmpl   $0x4,0x8(%r13)
jne    1220 <DFS+0x70>
mov    %r12,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r12,%rdi
lea    0xded(%rip),%rsi
call   10c0 <strcat@plt>
mov    0x0(%r13),%rsi
mov    %r12,%rdi
call   10c0 <strcat@plt>
mov    %r12,%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
call   10a0 <DFS@plt>
jmp    1220 <DFS+0x70>
mov    %rbp,%rdi
call   1060 <closedir@plt>
jmp    1299 <DFS+0xe9>
lea    0xda2(%rip),%rdi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1050 <printf@plt>
mov    $0x1,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
lea    0xd5e(%rip),%rsi
call   1080 <fprintf@plt>
lea    0xd59(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d00(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8*, i32 }
@.str = [30 x i8] c"Searching %s in directory %s\0A\00"
@stderr = global i32 0
@.str.1 = [7 x i8] c"Error\0A\00"
@.str.2 = [11 x i8] c"Your error\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [25 x i8] c"Found %s in dirctory %s\0A\00"
@.str.4 = [2 x i8] c"/\00"
define i32 @DFS(i8* %0, i32 %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca %struct.dirent*
%10 = alloca [1000 x i8]
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
%11 = load i8*, i8** %7
%12 = load i8*, i8** %5
%13 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %11, i8* %12)
%14 = load i32, i32* %6
%15 = icmp sle i32 0, %14
br i1 %15, label %16, label %67
16: ; preds = %3
%17 = load i8*, i8** %5
%18 = call i32* @opendir(i8* %17)
store i32* %18, i32** %8
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = call i32 @fprintf(i32 %21, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %16
br label %27
27: ; preds = %63, %26
%28 = load i32*, i32** %8
%29 = call %struct.dirent* @readdir(i32* %28)
store %struct.dirent* %29, %struct.dirent** %9
%30 = icmp ne %struct.dirent* %29, null
br i1 %30, label %31, label %64
31: ; preds = %27
%32 = load %struct.dirent*, %struct.dirent** %9
%33 = getelementptr inbounds %struct.dirent, %struct.dirent* %32, i32 0, i32 0
%34 = load i8*, i8** %33
%35 = load i8*, i8** %7
%36 = call i32 @strcmp(i8* %34, i8* %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %31
%39 = load i8*, i8** %7
%40 = load i8*, i8** %5
%41 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %39, i8* %40)
store i32 1, i32* %4
br label %67
42: ; preds = %31
%43 = load %struct.dirent*, %struct.dirent** %9
%44 = getelementptr inbounds %struct.dirent, %struct.dirent* %43, i32 0, i32 1
%45 = load i32, i32* %44
%46 = icmp eq i32 %45, 4
br i1 %46, label %47, label %63
47: ; preds = %42
%48 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%49 = load i8*, i8** %5
%50 = call i32 @strcpy(i8* %48, i8* %49)
%51 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%52 = call i32 @strcat(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%53 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%54 = load %struct.dirent*, %struct.dirent** %9
%55 = getelementptr inbounds %struct.dirent, %struct.dirent* %54, i32 0, i32 0
%56 = load i8*, i8** %55
%57 = call i32 @strcat(i8* %53, i8* %56)
%58 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%59 = load i32, i32* %6
%60 = sub nsw i32 %59, 1
%61 = load i8*, i8** %7
%62 = call i32 @DFS(i8* %58, i32 %60, i8* %61)
br label %63
63: ; preds = %47, %42
br label %27
64: ; preds = %27
%65 = load i32*, i32** %8
%66 = call i32 @closedir(i32* %65)
br label %67
67: ; preds = %38, %64, %3
%68 = load i32, i32* %4
ret i32 %68
}

LLVM IR (-O2):
%struct.dirent = type { i8*, i32 }
@.str = [30 x i8] c"Searching %s in directory %s\0A\00"
@stderr = global i32 0
@.str.1 = [7 x i8] c"Error\0A\00"
@.str.2 = [11 x i8] c"Your error\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [25 x i8] c"Found %s in dirctory %s\0A\00"
@.str.4 = [2 x i8] c"/\00"
define i32 @DFS(i8* %0, i32 %1, i8* %2) {
%4 = alloca [1000 x i8]
%5 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %2, i8* %0)
%6 = icmp sgt i32 %1, -1
br i1 %6, label %7, label %45
7: ; preds = %3
%8 = tail call i32* @opendir(i8* %0)
%9 = icmp eq i32* %8, null
br i1 %9, label %16, label %10
10: ; preds = %7
%11 = call %struct.dirent* @readdir(i32* %8)
%12 = icmp eq %struct.dirent* %11, null
br i1 %12, label %43, label %13
13: ; preds = %10
%14 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%15 = add nsw i32 %1, -1
br label %22
16: ; preds = %7
%17 = load i32, i32* @stderr
%18 = tail call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = tail call i32 @exit(i32 %20)
unreachable
22: ; preds = %13, %40
%23 = phi %struct.dirent* [ %11, %13 ], [ %41, %40 ]
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i64 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 @strcmp(i8* dereferenceable(1) %25, i8* dereferenceable(1) %2)
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %22
%29 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.3, i64 0, i64 0), i8* %2, i8* %0)
br label %45
30: ; preds = %22
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i64 0, i32 1
%32 = load i32, i32* %31
%33 = icmp eq i32 %32, 4
br i1 %33, label %34, label %40
34: ; preds = %30
%35 = call i32 @strcpy(i8* %14, i8* %0)
%36 = call i32 @strcat(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%37 = load i8*, i8** %24
%38 = call i32 @strcat(i8* %14, i8* %37)
%39 = call i32 @DFS(i8* %14, i32 %15, i8* %2)
br label %40
40: ; preds = %34, %30
%41 = call %struct.dirent* @readdir(i32* %8)
%42 = icmp eq %struct.dirent* %41, null
br i1 %42, label %43, label %22
43: ; preds = %40, %10
%44 = call i32 @closedir(i32* %8)
br label %45
45: ; preds = %3, %43, %28
ret i32 1
}