#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 TreeNode {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
struct TreeNode *generate_forest(char *);
int mode_finder(char *);
int operation_finder(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ search_forest(int, struct TreeNode *, char *, int, int, int,
                                 int);
int strtol(char *, int /*<<< orphan*/ *, int);
int type_finder(char *);
int main(int argc, char **argv) {
  if (argc < 4) {
    printf("Usage:\n\tsearch_forest DIRECTORY MODE "
           "{FILENAME/PERMS/FILETYPE/OPERATION} {SIZE_COMP}\n");
    return 0;
  }
  int perms;
  int type;
  int size_comp;
  int operation;
  int mode = mode_finder(argv[2]);
  struct TreeNode *root = generate_forest(argv[1]);
  switch (mode) {
  case 0:
    search_forest(mode, root, argv[3], 0, 1, 0, 0);
    break;
  case 1:
    perms = strtol(argv[3], NULL, 10);
    search_forest(mode, root, "null", perms, 1, 0, 0);
    break;
  case 2:
    type = type_finder(argv[3]);
    search_forest(mode, root, "null", 0, type, 0, 0);
    break;
  case 3:
    search_forest(mode, root, argv[3], 0, 1, 0, 0);
    break;
  case 4:
    if (argc != 5) {
      printf("Please enter an operation");
      exit(1);
    }
    size_comp = strtol(argv[4], NULL, 10);
    operation = operation_finder(argv[3]);
    search_forest(mode, root, "null", 0, 1, size_comp, operation);
    break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    11b8 <main+0x38>
lea    0xe6d(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1348 <main+0x1c8>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <mode_finder@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <generate_forest@plt>
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    %rax,-0x38(%rbp)
sub    $0x4,%rax
ja     1341 <main+0x1c1>
mov    -0x38(%rbp),%rax
lea    0xe0b(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
xor    %r9d,%r9d
mov    $0x1,%r8d
mov    %r9d,%ecx
movl   $0x0,(%rsp)
call   10a0 <search_forest@plt>
jmp    1341 <main+0x1c1>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x14(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x14(%rbp),%ecx
lea    0xe16(%rip),%rdx
mov    $0x1,%r8d
xor    %r9d,%r9d
movl   $0x0,(%rsp)
call   10a0 <search_forest@plt>
jmp    1341 <main+0x1c1>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1070 <type_finder@plt>
mov    %eax,-0x18(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%r8d
lea    0xdda(%rip),%rdx
xor    %r9d,%r9d
mov    %r9d,%ecx
movl   $0x0,(%rsp)
call   10a0 <search_forest@plt>
jmp    1341 <main+0x1c1>
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdx
xor    %r9d,%r9d
mov    $0x1,%r8d
mov    %r9d,%ecx
movl   $0x0,(%rsp)
call   10a0 <search_forest@plt>
jmp    1341 <main+0x1c1>
cmpl   $0x5,-0x8(%rbp)
je     12f3 <main+0x173>
lea    0xd8b(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <operation_finder@plt>
mov    %eax,-0x20(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    -0x1c(%rbp),%r9d
mov    -0x20(%rbp),%eax
lea    0xd39(%rip),%rdx
xor    %ecx,%ecx
mov    $0x1,%r8d
mov    %eax,(%rsp)
call   10a0 <search_forest@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jg     11ad <main+0x1d>
lea    0xe90(%rip),%rdi
call   1030 <puts@plt>
jmp    12a8 <main+0x118>
mov    %rsi,%r15
mov    %edi,%ebp
mov    0x10(%rsi),%rdi
call   1090 <mode_finder@plt>
mov    %eax,%ebx
mov    0x8(%r15),%rdi
call   1070 <generate_forest@plt>
cmp    $0x4,%ebx
ja     12a8 <main+0x118>
mov    %rax,%r14
mov    %ebx,%eax
lea    0xe25(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    0x18(%r15),%rdx
movl   $0x0,(%rsp)
xor    %edi,%edi
jmp    1256 <main+0xc6>
mov    0x18(%r15),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
movl   $0x0,(%rsp)
lea    0xe03(%rip),%rdx
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%ecx
jmp    125b <main+0xcb>
mov    0x18(%r15),%rdi
call   1080 <type_finder@plt>
movl   $0x0,(%rsp)
lea    0xde0(%rip),%rdx
mov    $0x2,%edi
mov    %r14,%rsi
xor    %ecx,%ecx
mov    %eax,%r8d
xor    %r9d,%r9d
jmp    12a3 <main+0x113>
mov    0x18(%r15),%rdx
movl   $0x0,(%rsp)
mov    $0x3,%edi
mov    %r14,%rsi
xor    %ecx,%ecx
mov    $0x1,%r8d
xor    %r9d,%r9d
jmp    12a3 <main+0x113>
cmp    $0x5,%ebp
jne    12b5 <main+0x125>
mov    0x20(%r15),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
mov    %eax,%ebx
mov    0x18(%r15),%rdi
call   1040 <operation_finder@plt>
mov    %eax,(%rsp)
lea    0xd84(%rip),%rdx
mov    $0x4,%edi
mov    %r14,%rsi
xor    %ecx,%ecx
mov    $0x1,%r8d
mov    %ebx,%r9d
call   10b0 <search_forest@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd5d(%rip),%rdi
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.TreeNode = type { i32 }
@.str = [86 x i8] c"Usage:\0A\09search_forest DIRECTORY MODE {FILENAME/PERMS/FILETYPE/OPERATION} {SIZE_COMP}\0A\00"
@.str.1 = [5 x i8] c"null\00"
@.str.2 = [26 x i8] c"Please enter an operation\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.TreeNode*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 4
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %79
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32 @mode_finder(i8* %19)
store i32 %20, i32* %10
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call %struct.TreeNode* @generate_forest(i8* %23)
store %struct.TreeNode* %24, %struct.TreeNode** %11
%25 = load i32, i32* %10
switch i32 %25, label %78 [
i32 0, label %26
i32 1, label %33
i32 2, label %42
i32 3, label %51
i32 4, label %58
]
26: ; preds = %16
%27 = load i32, i32* %10
%28 = load %struct.TreeNode*, %struct.TreeNode** %11
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 3
%31 = load i8*, i8** %30
%32 = call i32 @search_forest(i32 %27, %struct.TreeNode* %28, i8* %31, i32 0, i32 1, i32 0, i32 0)
br label %78
33: ; preds = %16
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 3
%36 = load i8*, i8** %35
%37 = call i32 @strtol(i8* %36, i32* null, i32 10)
store i32 %37, i32* %6
%38 = load i32, i32* %10
%39 = load %struct.TreeNode*, %struct.TreeNode** %11
%40 = load i32, i32* %6
%41 = call i32 @search_forest(i32 %38, %struct.TreeNode* %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %40, i32 1, i32 0, i32 0)
br label %78
42: ; preds = %16
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 3
%45 = load i8*, i8** %44
%46 = call i32 @type_finder(i8* %45)
store i32 %46, i32* %7
%47 = load i32, i32* %10
%48 = load %struct.TreeNode*, %struct.TreeNode** %11
%49 = load i32, i32* %7
%50 = call i32 @search_forest(i32 %47, %struct.TreeNode* %48, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %49, i32 0, i32 0)
br label %78
51: ; preds = %16
%52 = load i32, i32* %10
%53 = load %struct.TreeNode*, %struct.TreeNode** %11
%54 = load i8**, i8*** %5
%55 = getelementptr inbounds i8*, i8** %54, i64 3
%56 = load i8*, i8** %55
%57 = call i32 @search_forest(i32 %52, %struct.TreeNode* %53, i8* %56, i32 0, i32 1, i32 0, i32 0)
br label %78
58: ; preds = %16
%59 = load i32, i32* %4
%60 = icmp ne i32 %59, 5
br i1 %60, label %61, label %64
61: ; preds = %58
%62 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %58
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 4
%67 = load i8*, i8** %66
%68 = call i32 @strtol(i8* %67, i32* null, i32 10)
store i32 %68, i32* %8
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 3
%71 = load i8*, i8** %70
%72 = call i32 @operation_finder(i8* %71)
store i32 %72, i32* %9
%73 = load i32, i32* %10
%74 = load %struct.TreeNode*, %struct.TreeNode** %11
%75 = load i32, i32* %8
%76 = load i32, i32* %9
%77 = call i32 @search_forest(i32 %73, %struct.TreeNode* %74, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 1, i32 %75, i32 %76)
br label %78
78: ; preds = %16, %64, %51, %42, %33, %26
store i32 0, i32* %3
br label %79
79: ; preds = %78, %14
%80 = load i32, i32* %3
ret i32 %80
}

LLVM IR (-O2):
%struct.TreeNode = type { i32 }
@.str.1 = [5 x i8] c"null\00"
@.str.2 = [26 x i8] c"Please enter an operation\00"
@str = [85 x i8] c"Usage:\0A\09search_forest DIRECTORY MODE {FILENAME/PERMS/FILETYPE/OPERATION} {SIZE_COMP}\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 4
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @str, i64 0, i64 0))
br label %44
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = tail call i32 @mode_finder(i8* %8)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call %struct.TreeNode* @generate_forest(i8* %11)
switch i32 %9, label %44 [
i32 0, label %13
i32 1, label %17
i32 2, label %22
i32 3, label %27
i32 4, label %31
]
13: ; preds = %6
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = tail call i32 @search_forest(i32 0, %struct.TreeNode* %12, i8* %15, i32 0, i32 1, i32 0, i32 0)
br label %44
17: ; preds = %6
%18 = getelementptr inbounds i8*, i8** %1, i64 3
%19 = load i8*, i8** %18
%20 = tail call i32 @strtol(i8* nocapture %19, i32* null, i32 10)
%21 = tail call i32 @search_forest(i32 1, %struct.TreeNode* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %20, i32 1, i32 0, i32 0)
br label %44
22: ; preds = %6
%23 = getelementptr inbounds i8*, i8** %1, i64 3
%24 = load i8*, i8** %23
%25 = tail call i32 @type_finder(i8* %24)
%26 = tail call i32 @search_forest(i32 2, %struct.TreeNode* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 %25, i32 0, i32 0)
br label %44
27: ; preds = %6
%28 = getelementptr inbounds i8*, i8** %1, i64 3
%29 = load i8*, i8** %28
%30 = tail call i32 @search_forest(i32 3, %struct.TreeNode* %12, i8* %29, i32 0, i32 1, i32 0, i32 0)
br label %44
31: ; preds = %6
%32 = icmp eq i32 %0, 5
br i1 %32, label %36, label %33
33: ; preds = %31
%34 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%35 = tail call i32 @exit(i32 1)
unreachable
36: ; preds = %31
%37 = getelementptr inbounds i8*, i8** %1, i64 4
%38 = load i8*, i8** %37
%39 = tail call i32 @strtol(i8* nocapture %38, i32* null, i32 10)
%40 = getelementptr inbounds i8*, i8** %1, i64 3
%41 = load i8*, i8** %40
%42 = tail call i32 @operation_finder(i8* %41)
%43 = tail call i32 @search_forest(i32 4, %struct.TreeNode* %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 0, i32 1, i32 %39, i32 %42)
br label %44
44: ; preds = %13, %17, %22, %27, %36, %6, %4
ret i32 0
}