#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*/ print(char *);
int /*<<< orphan*/ putnum(int);
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')) {
        print("Directory ");
        print(entry_name);
        print(" ");
        putnum(entry_size);
        print("\r\n");
        if (recurse != 0) {
          if (!mfs_change_dir(entry_name)) {
            print("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(".."))
            print("cd..\r\n");
          else {
            print("Failed..\r\n");
            mfs_dir_close(fd);
            return 0;
          }
        }
      }
    } else {
      print(entry_name);
      print(" ");
      putnum(entry_size);
      print("\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    0xe93(%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     1323 <mfs_ls_r+0x1b3>
cmpl   $0x2,-0x10(%rbp)
jne    12f5 <mfs_ls_r+0x185>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    11d3 <mfs_ls_r+0x63>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     12f0 <mfs_ls_r+0x180>
mov    -0x20(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1205 <mfs_ls_r+0x95>
mov    -0x20(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    1205 <mfs_ls_r+0x95>
mov    -0x20(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x0,%eax
je     12f0 <mfs_ls_r+0x180>
lea    0xdf4(%rip),%rdi
call   1040 <print@plt>
mov    -0x20(%rbp),%rdi
call   1040 <print@plt>
lea    0xde8(%rip),%rdi
call   1040 <print@plt>
mov    -0x14(%rbp),%edi
call   1080 <putnum@plt>
lea    0xde6(%rip),%rdi
call   1040 <print@plt>
cmpl   $0x0,-0x8(%rbp)
je     12eb <mfs_ls_r+0x17b>
mov    -0x20(%rbp),%rdi
call   1050 <mfs_change_dir@plt>
cmp    $0x0,%rax
jne    1277 <mfs_ls_r+0x107>
lea    0xdad(%rip),%rdi
call   1040 <print@plt>
mov    -0xc(%rbp),%edi
call   1060 <mfs_dir_close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1332 <mfs_ls_r+0x1c2>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
call   1090 <mfs_ls_r@plt>
cmp    $0x0,%eax
jne    129f <mfs_ls_r+0x12f>
mov    -0xc(%rbp),%edi
call   1060 <mfs_dir_close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1332 <mfs_ls_r+0x1c2>
lea    0xd6e(%rip),%rdi
call   1050 <mfs_change_dir@plt>
cmp    $0x0,%rax
je     12c6 <mfs_ls_r+0x156>
lea    0xd5b(%rip),%rdi
call   1040 <print@plt>
jmp    12e6 <mfs_ls_r+0x176>
lea    0xd51(%rip),%rdi
call   1040 <print@plt>
mov    -0xc(%rbp),%edi
call   1060 <mfs_dir_close@plt>
movl   $0x0,-0x4(%rbp)
jmp    1332 <mfs_ls_r+0x1c2>
jmp    12eb <mfs_ls_r+0x17b>
jmp    12f0 <mfs_ls_r+0x180>
jmp    131e <mfs_ls_r+0x1ae>
mov    -0x20(%rbp),%rdi
call   1040 <print@plt>
lea    0xd04(%rip),%rdi
call   1040 <print@plt>
mov    -0x14(%rbp),%edi
call   1080 <putnum@plt>
lea    0xd02(%rip),%rdi
call   1040 <print@plt>
jmp    118a <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    0xe8d(%rip),%rdi
call   1070 <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     12dc <mfs_ls_r+0x16c>
mov    %r14,%rax
mov    %r14,0x20(%rsp)
lea    -0x1(%r14),%eax
mov    %eax,0x1c(%rsp)
lea    0xe3f(%rip),%r15
lea    0xe4a(%rip),%r12
lea    0x10(%rsp),%r13
lea    0x8(%rsp),%rbp
lea    0xc(%rsp),%r14
jmp    1227 <mfs_ls_r+0xb7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
call   1040 <print@plt>
mov    %r15,%rdi
call   1040 <print@plt>
mov    0x8(%rsp),%edi
call   1080 <putnum@plt>
mov    %r12,%rdi
call   1040 <print@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    %r14,%rcx
call   1030 <mfs_dir_read@plt>
test   %rax,%rax
je     12c7 <mfs_ls_r+0x157>
cmpl   $0x2,0xc(%rsp)
mov    0x10(%rsp),%rdi
jne    11f0 <mfs_ls_r+0x80>
cmpb   $0x2e,(%rdi)
jne    1250 <mfs_ls_r+0xe0>
movzbl 0x1(%rdi),%eax
test   %al,%al
je     120e <mfs_ls_r+0x9e>
cmp    $0x2e,%al
jne    1250 <mfs_ls_r+0xe0>
cmpb   $0x0,0x2(%rdi)
je     120e <mfs_ls_r+0x9e>
nopw   0x0(%rax,%rax,1)
lea    0xda9(%rip),%rdi
call   1040 <print@plt>
mov    0x10(%rsp),%rdi
call   1040 <print@plt>
mov    %r15,%rdi
call   1040 <print@plt>
mov    0x8(%rsp),%edi
call   1080 <putnum@plt>
mov    %r12,%rdi
call   1040 <print@plt>
cmpl   $0x0,0x20(%rsp)
je     120e <mfs_ls_r+0x9e>
mov    0x10(%rsp),%rdi
call   1050 <mfs_change_dir@plt>
test   %rax,%rax
je     12ce <mfs_ls_r+0x15e>
mov    0x1c(%rsp),%edi
call   1090 <mfs_ls_r@plt>
test   %eax,%eax
je     12da <mfs_ls_r+0x16a>
lea    0xd6b(%rip),%rdi
call   1050 <mfs_change_dir@plt>
lea    0xd62(%rip),%rdi
test   %rax,%rax
jne    1209 <mfs_ls_r+0x99>
lea    0xd59(%rip),%rdi
jmp    12d5 <mfs_ls_r+0x165>
mov    $0x1,%ebp
jmp    12dc <mfs_ls_r+0x16c>
lea    0xd36(%rip),%rdi
call   1040 <print@plt>
xor    %ebp,%ebp
mov    %ebx,%edi
call   1060 <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 = [11 x i8] c"Directory \00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [3 x i8] c"\0D\0A\00"
@.str.4 = [9 x i8] c"Failed\0D\0A\00"
@.str.5 = [3 x i8] c"..\00"
@.str.6 = [7 x i8] c"cd..\0D\0A\00"
@.str.7 = [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 @print(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%48 = load i8*, i8** %7
%49 = call i32 @print(i8* %48)
%50 = call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%51 = load i32, i32* %6
%52 = call i32 @putnum(i32 %51)
%53 = call i32 @print(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, 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 @print(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, 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.5, i64 0, i64 0))
%74 = icmp ne i64 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %72
%76 = call i32 @print(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %81
77: ; preds = %72
%78 = call i32 @print(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, 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 @print(i8* %85)
%87 = call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%88 = load i32, i32* %6
%89 = call i32 @putnum(i32 %88)
%90 = call i32 @print(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, 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 = [11 x i8] c"Directory \00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [3 x i8] c"\0D\0A\00"
@.str.4 = [9 x i8] c"Failed\0D\0A\00"
@.str.5 = [3 x i8] c"..\00"
@.str.6 = [7 x i8] c"cd..\0D\0A\00"
@.str.7 = [11 x i8] c"Failed..\0D\0A\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 @print(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
%30 = load i8*, i8** %4
%31 = call i32 @print(i8* %30)
%32 = call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32, i32* %3
%34 = call i32 @putnum(i32 %33)
%35 = call i32 @print(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, 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.5, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %57, label %51
46: ; preds = %14
%47 = call i32 @print(i8* %17)
%48 = call i32 @print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%49 = load i32, i32* %3
%50 = call i32 @putnum(i32 %49)
br label %51
51: ; preds = %43, %46
%52 = phi i8* [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), %46 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), %43 ]
%53 = call i32 @print(i8* %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 ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), %36 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), %43 ]
%59 = call i32 @print(i8* %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
}