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

/* Variables and functions */
int /*<<< orphan*/ cd();
int /*<<< orphan*/ fileInstructions();
int /*<<< orphan*/ getInt(int *);
char *getcwd(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ ls();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *selectFile();
FILE *getFile() {
  printf("#########################################################\n"
         "# Welcome to a low-level file navigation and input system\n"
         "# Basic UNIX-esque functions are provided\n"
         "#   ls: lists the files in the current working directory\n"
         "#   cd: change the current working directory\n"
         "#   select: choose a *.txt file (from the current working directory) "
         "to import into the AVL tree\n"
         "#   exit: exits this file browser\n"
         "#########################################################\n");
  printf("-----------------------\n");
  ;
  fileInstructions();
  int cmd = 0;
  FILE *res = NULL;
  while (4 != cmd) {
    printf("-----------------------\n");
    ;
    char *pwd = getcwd(NULL, 0);
    printf("# PWD: %s\n", pwd);
    printf("# Enter a command: ");
    getInt(&cmd);
    switch (cmd) {
    case 1:
      ls();
      break;
    case 2:
      cd();
      break;
    case 3:
      res = selectFile();
      if (res) {
        return res;
      }
      break;
    case 4:
      printf("# Exiting file browser...\n");
      break;
    default:
      printf("# Invalid command!\n");
      fileInstructions();
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<getFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xe91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0x1045(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <fileInstructions@plt>
movl   $0x0,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
mov    $0x4,%eax
cmp    -0xc(%rbp),%eax
je     129e <getFile+0x12e>
lea    0x1013(%rip),%rdi
xor    %eax,%eax
mov    %eax,-0x30(%rbp)
mov    %al,-0x29(%rbp)
call   1040 <printf@plt>
mov    -0x30(%rbp),%esi
mov    %esi,%edi
call   1060 <getcwd@plt>
mov    %rax,%rcx
mov    -0x29(%rbp),%al
mov    %rcx,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0x1000(%rip),%rdi
call   1040 <printf@plt>
mov    -0x29(%rbp),%al
lea    0xffc(%rip),%rdi
call   1040 <printf@plt>
lea    -0xc(%rbp),%rdi
call   1090 <getInt@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x3,%eax
ja     1284 <getFile+0x114>
mov    -0x28(%rbp),%rax
lea    0xdd8(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    $0x0,%al
call   1070 <ls@plt>
jmp    1299 <getFile+0x129>
mov    $0x0,%al
call   1030 <cd@plt>
jmp    1299 <getFile+0x129>
mov    $0x0,%al
call   1050 <selectFile@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     126c <getFile+0xfc>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    12a6 <getFile+0x136>
jmp    1299 <getFile+0x129>
lea    0xf92(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1299 <getFile+0x129>
lea    0xf9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1080 <fileInstructions@plt>
jmp    11aa <getFile+0x3a>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xe9d(%rip),%rdi
call   1030 <puts@plt>
lea    0x1052(%rip),%r15
mov    %r15,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1090 <fileInstructions@plt>
movl   $0x0,0x4(%rsp)
lea    0xe54(%rip),%r12
lea    0xe58(%rip),%r13
lea    0x4(%rsp),%rbx
lea    0xe31(%rip),%rbp
lea    0x1032(%rip),%r14
jmp    11fb <getFile+0x7b>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1080 <ls@plt>
nopw   0x0(%rax,%rax,1)
cmpl   $0x4,0x4(%rsp)
je     129d <getFile+0x11d>
mov    %r15,%rdi
call   1030 <puts@plt>
xor    %edi,%edi
xor    %esi,%esi
call   1070 <getcwd@plt>
mov    %r12,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r13,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rbx,%rdi
call   10a0 <getInt@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x3,%eax
ja     1250 <getFile+0xd0>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
xor    %eax,%eax
call   1040 <cd@plt>
jmp    11f0 <getFile+0x70>
nopw   0x0(%rax,%rax,1)
lea    0xfcb(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1090 <fileInstructions@plt>
jmp    11f0 <getFile+0x70>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1060 <selectFile@plt>
test   %rax,%rax
je     11f0 <getFile+0x70>
jmp    129f <getFile+0x11f>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <puts@plt>
jmp    11f0 <getFile+0x70>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [450 x i8] c"#########################################################\0A# Welcome to a low-level file navigation and input system\0A# Basic UNIX-esque functions are provided\0A# ls: lists the files in the current working directory\0A# cd: change the current working directory\0A# select: choose a *.txt file (from the current working directory) to import into the AVL tree\0A# exit: exits this file browser\0A#########################################################\0A\00"
@.str.1 = [25 x i8] c"-----------------------\0A\00"
@.str.2 = [11 x i8] c"# PWD: %s\0A\00"
@.str.3 = [20 x i8] c"# Enter a command: \00"
@.str.4 = [27 x i8] c"# Exiting file browser...\0A\00"
@.str.5 = [20 x i8] c"# Invalid command!\0A\00"
define i32* @getFile() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32*
%4 = alloca i8*
%5 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([450 x i8], [450 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 (...) @fileInstructions()
store i32 0, i32* %2
store i32* null, i32** %3
br label %8
8: ; preds = %35, %0
%9 = load i32, i32* %2
%10 = icmp ne i32 4, %9
br i1 %10, label %11, label %36
11: ; preds = %8
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%13 = call i8* @getcwd(i32* null, i32 0)
store i8* %13, i8** %4
%14 = load i8*, i8** %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %14)
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 @getInt(i32* %2)
%18 = load i32, i32* %2
switch i32 %18, label %32 [
i32 1, label %19
i32 2, label %21
i32 3, label %23
i32 4, label %30
]
19: ; preds = %11
%20 = call i32 (...) @ls()
br label %35
21: ; preds = %11
%22 = call i32 (...) @cd()
br label %35
23: ; preds = %11
%24 = call i32* (...) @selectFile()
store i32* %24, i32** %3
%25 = load i32*, i32** %3
%26 = icmp ne i32* %25, null
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = load i32*, i32** %3
store i32* %28, i32** %1
br label %37
29: ; preds = %23
br label %35
30: ; preds = %11
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %35
32: ; preds = %11
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.5, i64 0, i64 0))
%34 = call i32 (...) @fileInstructions()
br label %35
35: ; preds = %32, %30, %29, %21, %19
br label %8
36: ; preds = %8
store i32* null, i32** %1
br label %37
37: ; preds = %36, %27
%38 = load i32*, i32** %1
ret i32* %38
}

LLVM IR (-O2):
@.str.2 = [11 x i8] c"# PWD: %s\0A\00"
@.str.3 = [20 x i8] c"# Enter a command: \00"
@str = [449 x i8] c"#########################################################\0A# Welcome to a low-level file navigation and input system\0A# Basic UNIX-esque functions are provided\0A# ls: lists the files in the current working directory\0A# cd: change the current working directory\0A# select: choose a *.txt file (from the current working directory) to import into the AVL tree\0A# exit: exits this file browser\0A#########################################################\00"
@str.7 = [24 x i8] c"-----------------------\00"
@str.8 = [26 x i8] c"# Exiting file browser...\00"
@str.9 = [19 x i8] c"# Invalid command!\00"
define i32* @getFile() {
%1 = alloca i32
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([449 x i8], [449 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.7, i64 0, i64 0))
%4 = tail call i32 (...) @fileInstructions()
%5 = bitcast i32* %1 to i8*
store i32 0, i32* %1
br label %9
6: ; preds = %16, %18, %23, %25, %20
%7 = load i32, i32* %1
%8 = icmp eq i32 %7, 4
br i1 %8, label %28, label %9
9: ; preds = %0, %6
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.7, i64 0, i64 0))
%11 = call i8* @getcwd(i32* null, i32 0)
%12 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 @getInt(i32* %1)
%15 = load i32, i32* %1
switch i32 %15, label %25 [
i32 1, label %16
i32 2, label %18
i32 3, label %20
i32 4, label %23
]
16: ; preds = %9
%17 = call i32 (...) @ls()
br label %6
18: ; preds = %9
%19 = call i32 (...) @cd()
br label %6
20: ; preds = %9
%21 = call i32* (...) @selectFile()
%22 = icmp eq i32* %21, null
br i1 %22, label %6, label %28
23: ; preds = %9
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.8, i64 0, i64 0))
br label %6
25: ; preds = %9
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.9, i64 0, i64 0))
%27 = call i32 (...) @fileInstructions()
br label %6
28: ; preds = %20, %6
%29 = phi i32* [ null, %6 ], [ %21, %20 ]
ret i32* %29
}