#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 */
scalar_t__ mfs_change_dir(char *);
int /*<<< orphan*/ mfs_dir_close(int);
int mfs_dir_open(char *);
scalar_t__ mfs_dir_read(int, char **, int *, int *);
int /*<<< orphan*/ printf(char *, ...);
int mfs_ls_r(int recurse) {
  int fd = mfs_dir_open(".");
  int entry_type;
  int entry_size;
  char *entry_name;
  while (mfs_dir_read(fd, &entry_name, &entry_size, &entry_type) != 0) {
    if (entry_type == 2) {
      if (!(entry_name[0] == '.' && entry_name[1] == '\0') &&
          !(entry_name[0] == '.' && entry_name[1] == '.' &&
            entry_name[2] == '\0')) {
        printf("%s", ("Directory "));
        printf("%s", (entry_name));
        printf("%s", (" "));
        printf("%d ", (entry_size));
        printf("%s", ("\r\n"));
        if (recurse != 0) {
          if (!mfs_change_dir(entry_name)) {
            printf("%s", ("Failed\r\n"));
            mfs_dir_close(fd);
            return 0;
          }
          if (!mfs_ls_r(recurse - 1)) {
            mfs_dir_close(fd);
            return 0;
          }
          if (mfs_change_dir(".."))
            printf("%s", ("cd..\r\n"));
          else {
            printf("%s", ("Failed..\r\n"));
            mfs_dir_close(fd);
            return 0;
          }
        }
      }
    } else {
      printf("%s", (entry_name));
      printf("%s", (" "));
      printf("%d ", (entry_size));
      printf("%s", ("\r\n"));
    }
  }
  mfs_dir_close(fd);
  return 1;
}


x86 assembly (clang, -O0):
<mfs_ls_r>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
lea    0xeaa(%rip),%rdi
call   1070 <mfs_dir_open@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x10(%rbp),%rcx
call   1030 <mfs_dir_read@plt>
cmp    $0x0,%rax
je     137f <mfs_ls_r+0x21f>
cmpl   $0x2,-0x10(%rbp)
jne    132d <mfs_ls_r+0x1cd>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11c3 <mfs_ls_r+0x63>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1328 <mfs_ls_r+0x1c8>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11f5 <mfs_ls_r+0x95>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    11f5 <mfs_ls_r+0x95>
mov    -0x20(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x0,%eax
je     1328 <mfs_ls_r+0x1c8>
lea    0xe04(%rip),%rdi
lea    0xe00(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rsi
lea    0xdeb(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xddd(%rip),%rdi
lea    0xde6(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xdb7(%rip),%rdi
lea    0xdd2(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
cmpl   $0x0,-0x8(%rbp)
je     1323 <mfs_ls_r+0x1c3>
mov    -0x20(%rbp),%rdi
call   1050 <mfs_change_dir@plt>
cmp    $0x0,%rax
jne    129d <mfs_ls_r+0x13d>
lea    0xd85(%rip),%rdi
lea    0xd90(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1060 <mfs_dir_close@plt>
movl   $0x0,-0x4(%rbp)
jmp    138e <mfs_ls_r+0x22e>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1080 <mfs_ls_r@plt>
cmp    $0x0,%eax
jne    12c5 <mfs_ls_r+0x165>
mov    -0xc(%rbp),%edi
call   1060 <mfs_dir_close@plt>
movl   $0x0,-0x4(%rbp)
jmp    138e <mfs_ls_r+0x22e>
lea    0xd4f(%rip),%rdi
call   1050 <mfs_change_dir@plt>
cmp    $0x0,%rax
je     12f5 <mfs_ls_r+0x195>
lea    0xd1e(%rip),%rdi
lea    0xd35(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    131e <mfs_ls_r+0x1be>
lea    0xd04(%rip),%rdi
lea    0xd22(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0xc(%rbp),%edi
call   1060 <mfs_dir_close@plt>
movl   $0x0,-0x4(%rbp)
jmp    138e <mfs_ls_r+0x22e>
jmp    1323 <mfs_ls_r+0x1c3>
jmp    1328 <mfs_ls_r+0x1c8>
jmp    137a <mfs_ls_r+0x21a>
mov    -0x20(%rbp),%rsi
lea    0xcc8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xcba(%rip),%rdi
lea    0xcc3(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%esi
lea    0xcb0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xc94(%rip),%rdi
lea    0xcaf(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    117a <mfs_ls_r+0x1a>
mov    -0xc(%rbp),%edi
call   1060 <mfs_dir_close@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mfs_ls_r>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %edi,%r14d
lea    0xe7b(%rip),%rdi
call   1090 <mfs_dir_open@plt>
mov    %eax,%ebx
lea    0x10(%rsp),%rsi
lea    0x8(%rsp),%rdx
lea    0xc(%rsp),%rcx
mov    %eax,%edi
call   1030 <mfs_dir_read@plt>
mov    $0x1,%ebp
test   %rax,%rax
je     1315 <mfs_ls_r+0x195>
mov    %r14,%rax
mov    %r14,0x20(%rsp)
lea    -0x1(%r14),%eax
mov    %eax,0x1c(%rsp)
lea    0xe26(%rip),%rbp
lea    0xe4a(%rip),%r15
lea    0x10(%rsp),%r13
lea    0x8(%rsp),%r14
lea    0xc(%rsp),%r12
jmp    1247 <mfs_ls_r+0xc7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbp,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x20,%edi
call   1040 <putchar@plt>
mov    0x8(%rsp),%esi
lea    0xdef(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1050 <puts@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    %r14,%rdx
mov    %r12,%rcx
call   1030 <mfs_dir_read@plt>
test   %rax,%rax
je     1300 <mfs_ls_r+0x180>
cmpl   $0x2,0xc(%rsp)
mov    0x10(%rsp),%rsi
jne    1200 <mfs_ls_r+0x80>
cmpb   $0x2e,(%rsi)
jne    1270 <mfs_ls_r+0xf0>
movzbl 0x1(%rsi),%eax
test   %al,%al
je     122e <mfs_ls_r+0xae>
cmp    $0x2e,%al
jne    1270 <mfs_ls_r+0xf0>
cmpb   $0x0,0x2(%rsi)
je     122e <mfs_ls_r+0xae>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
lea    0xd89(%rip),%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rsp),%rsi
mov    %rbp,%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x20,%edi
call   1040 <putchar@plt>
mov    0x8(%rsp),%esi
lea    0xd69(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r15,%rdi
call   1050 <puts@plt>
cmpl   $0x0,0x20(%rsp)
je     122e <mfs_ls_r+0xae>
mov    0x10(%rsp),%rdi
call   1070 <mfs_change_dir@plt>
test   %rax,%rax
je     1307 <mfs_ls_r+0x187>
mov    0x1c(%rsp),%edi
call   10a0 <mfs_ls_r@plt>
test   %eax,%eax
je     1313 <mfs_ls_r+0x193>
lea    0xd30(%rip),%rdi
call   1070 <mfs_change_dir@plt>
lea    0xd39(%rip),%rdi
test   %rax,%rax
jne    1229 <mfs_ls_r+0xa9>
lea    0xd1f(%rip),%rdi
jmp    130e <mfs_ls_r+0x18e>
mov    $0x1,%ebp
jmp    1315 <mfs_ls_r+0x195>
lea    0xd07(%rip),%rdi
call   1050 <puts@plt>
xor    %ebp,%ebp
mov    %ebx,%edi
call   1080 <mfs_dir_close@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [11 x i8] c"Directory \00"
@.str.3 = [2 x i8] c" \00"
@.str.4 = [4 x i8] c"%d \00"
@.str.5 = [3 x i8] c"\0D\0A\00"
@.str.6 = [9 x i8] c"Failed\0D\0A\00"
@.str.7 = [3 x i8] c"..\00"
@.str.8 = [7 x i8] c"cd..\0D\0A\00"
@.str.9 = [11 x i8] c"Failed..\0D\0A\00"
define i32 @mfs_ls_r(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %3
%8 = call i32 @mfs_dir_open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 %8, i32* %4
br label %9
9: ; preds = %91, %1
%10 = load i32, i32* %4
%11 = call i64 @mfs_dir_read(i32 %10, i8** %7, i32* %6, i32* %5)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %92
13: ; preds = %9
%14 = load i32, i32* %5
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %84
16: ; preds = %13
%17 = load i8*, i8** %7
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 46
br i1 %21, label %22, label %28
22: ; preds = %16
%23 = load i8*, i8** %7
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 0
br i1 %27, label %83, label %28
28: ; preds = %22, %16
%29 = load i8*, i8** %7
%30 = getelementptr inbounds i8, i8* %29, i64 0
%31 = load i8, i8* %30
%32 = sext i8 %31 to i32
%33 = icmp eq i32 %32, 46
br i1 %33, label %34, label %46
34: ; preds = %28
%35 = load i8*, i8** %7
%36 = getelementptr inbounds i8, i8* %35, i64 1
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 46
br i1 %39, label %40, label %46
40: ; preds = %34
%41 = load i8*, i8** %7
%42 = getelementptr inbounds i8, i8* %41, i64 2
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp eq i32 %44, 0
br i1 %45, label %83, label %46
46: ; preds = %40, %34, %28
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%48 = load i8*, i8** %7
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %48)
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%51 = load i32, i32* %6
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %51)
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%54 = load i32, i32* %3
%55 = icmp ne i32 %54, 0
br i1 %55, label %56, label %82
56: ; preds = %46
%57 = load i8*, i8** %7
%58 = call i64 @mfs_change_dir(i8* %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %64, label %60
60: ; preds = %56
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0))
%62 = load i32, i32* %4
%63 = call i32 @mfs_dir_close(i32 %62)
store i32 0, i32* %2
br label %95
64: ; preds = %56
%65 = load i32, i32* %3
%66 = sub nsw i32 %65, 1
%67 = call i32 @mfs_ls_r(i32 %66)
%68 = icmp ne i32 %67, 0
br i1 %68, label %72, label %69
69: ; preds = %64
%70 = load i32, i32* %4
%71 = call i32 @mfs_dir_close(i32 %70)
store i32 0, i32* %2
br label %95
72: ; preds = %64
%73 = call i64 @mfs_change_dir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %72
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i64 0, i64 0))
br label %81
77: ; preds = %72
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.9, i64 0, i64 0))
%79 = load i32, i32* %4
%80 = call i32 @mfs_dir_close(i32 %79)
store i32 0, i32* %2
br label %95
81: ; preds = %75
br label %82
82: ; preds = %81, %46
br label %83
83: ; preds = %82, %40, %22
br label %91
84: ; preds = %13
%85 = load i8*, i8** %7
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %85)
%87 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%88 = load i32, i32* %6
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %88)
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
br label %91
91: ; preds = %84, %83
br label %9
92: ; preds = %9
%93 = load i32, i32* %4
%94 = call i32 @mfs_dir_close(i32 %93)
store i32 1, i32* %2
br label %95
95: ; preds = %92, %77, %69, %60
%96 = load i32, i32* %2
ret i32 %96
}

LLVM IR (-O2):
@.str = [2 x i8] c".\00"
@.str.1 = [3 x i8] c"%s\00"
@.str.2 = [11 x i8] c"Directory \00"
@.str.4 = [4 x i8] c"%d \00"
@.str.7 = [3 x i8] c"..\00"
@str.10 = [2 x i8] c"\0D\00"
@str.11 = [8 x i8] c"Failed\0D\00"
@str.12 = [10 x i8] c"Failed..\0D\00"
@str.13 = [6 x i8] c"cd..\0D\00"
define i32 @mfs_ls_r(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = tail call i32 @mfs_dir_open(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = bitcast i32* %2 to i8*
%7 = bitcast i32* %3 to i8*
%8 = bitcast i8** %4 to i8*
%9 = call i64 @mfs_dir_read(i32 %5, i8** %4, i32* %3, i32* %2)
%10 = icmp eq i64 %9, 0
br i1 %10, label %60, label %11
11: ; preds = %1
%12 = icmp eq i32 %0, 0
%13 = add nsw i32 %0, -1
br label %14
14: ; preds = %11, %54
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 2
%17 = load i8*, i8** %4
br i1 %16, label %18, label %46
18: ; preds = %14
%19 = load i8, i8* %17
%20 = icmp eq i8 %19, 46
br i1 %20, label %21, label %28
21: ; preds = %18
%22 = getelementptr inbounds i8, i8* %17, i64 1
%23 = load i8, i8* %22
switch i8 %23, label %28 [
i8 0, label %54
i8 46, label %24
]
24: ; preds = %21
%25 = getelementptr inbounds i8, i8* %17, i64 2
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 0
br i1 %27, label %54, label %28
28: ; preds = %21, %18, %24
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
%30 = load i8*, i8** %4
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %30)
%32 = call i32 @putchar(i32 32)
%33 = load i32, i32* %3
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %33)
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.10, i64 0, i64 0))
br i1 %12, label %54, label %36
36: ; preds = %28
%37 = load i8*, i8** %4
%38 = call i64 @mfs_change_dir(i8* %37)
%39 = icmp eq i64 %38, 0
br i1 %39, label %57, label %40
40: ; preds = %36
%41 = call i32 @mfs_ls_r(i32 %13)
%42 = icmp eq i32 %41, 0
br i1 %42, label %60, label %43
43: ; preds = %40
%44 = call i64 @mfs_change_dir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %57, label %51
46: ; preds = %14
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %17)
%48 = call i32 @putchar(i32 32)
%49 = load i32, i32* %3
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %49)
br label %51
51: ; preds = %43, %46
%52 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @str.10, i64 0, i64 0), %46 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @str.13, i64 0, i64 0), %43 ]
%53 = call i32 @puts(i8* dereferenceable(1) %52)
br label %54
54: ; preds = %51, %21, %24, %28
%55 = call i64 @mfs_dir_read(i32 %5, i8** %4, i32* %3, i32* %2)
%56 = icmp eq i64 %55, 0
br i1 %56, label %60, label %14
57: ; preds = %43, %36
%58 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @str.11, i64 0, i64 0), %36 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @str.12, i64 0, i64 0), %43 ]
%59 = call i32 @puts(i8* dereferenceable(1) %58)
br label %60
60: ; preds = %54, %40, %57, %1
%61 = phi i32 [ 1, %1 ], [ 0, %57 ], [ 0, %40 ], [ 1, %54 ]
%62 = call i32 @mfs_dir_close(i32 %5)
ret i32 %61
}