#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 scalar_t__ uint32_t;
struct jffs2_raw_dirent {
  scalar_t__ type;
};
struct dir {
  int dummy;
};

/* Variables and functions */
scalar_t__ DT_DIR;
int /*<<< orphan*/ EXIT_FAILURE;
struct dir *collectdir(char *, size_t, scalar_t__, struct dir *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ freedir(struct dir *);
int /*<<< orphan*/ printdir(char *, size_t, struct dir *, char *, int);
struct jffs2_raw_dirent *resolvepath(char *, size_t, int, char *, scalar_t__ *);
int /*<<< orphan*/ stderr;
void lsdir(char *o, size_t size, char *path, int recurse) {
  struct jffs2_raw_dirent *dd;
  struct dir *d = NULL;
  uint32_t ino;
  dd = resolvepath(o, size, 1, path, &ino);
  if (ino == 0 || (dd == NULL && ino == 0) ||
      (dd != NULL && dd->type != DT_DIR)) {
    fprintf(stderr, "jffs2reader: %s: No such file or directory\n", path);
    exit(EXIT_FAILURE);
  }
  d = collectdir(o, size, ino, d);
  printdir(o, size, d, path, recurse);
  freedir(d);
}


x86 assembly (clang, -O0):
<lsdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
lea    -0x38(%rbp),%r8
call   1030 <resolvepath@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     11e0 <lsdir+0x80>
cmpq   $0x0,-0x28(%rbp)
jne    11be <lsdir+0x5e>
cmpq   $0x0,-0x38(%rbp)
je     11e0 <lsdir+0x80>
cmpq   $0x0,-0x28(%rbp)
je     1207 <lsdir+0xa7>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    0x2e01(%rip),%rcx
cmp    (%rcx),%rax
je     1207 <lsdir+0xa7>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe0c(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x30(%rbp),%rcx
call   1040 <collectdir@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
call   1060 <printdir@plt>
mov    -0x30(%rbp),%rdi
call   1080 <freedir@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lsdir>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rdi,%rbx
lea    0x8(%rsp),%r8
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <resolvepath@plt>
mov    0x8(%rsp),%rdx
test   %rdx,%rdx
je     11e1 <lsdir+0x81>
test   %rax,%rax
je     11a8 <lsdir+0x48>
mov    (%rax),%rax
mov    0x2e35(%rip),%rcx
cmp    (%rcx),%rax
jne    11e1 <lsdir+0x81>
mov    %rbx,%rdi
mov    %r12,%rsi
xor    %ecx,%ecx
call   1040 <collectdir@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %rax,%rdx
mov    %r15,%rcx
mov    %r14d,%r8d
call   1060 <printdir@plt>
mov    %rbp,%rdi
call   1080 <freedir@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2df8(%rip),%rax
mov    (%rax),%edi
lea    0xe0f(%rip),%rsi
mov    %r15,%rdx
call   1050 <fprintf@plt>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.jffs2_raw_dirent = type { i64 }
%struct.dir = type { i32 }
@DT_DIR = global i64 0
@stderr = global i32 0
@.str = [44 x i8] c"jffs2reader: %s: No such file or directory\0A\00"
@EXIT_FAILURE = global i32 0
define void @lsdir(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.jffs2_raw_dirent*
%10 = alloca %struct.dir*
%11 = alloca i64
store i8* %0, i8** %5
store i64 %1, i64* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
store %struct.dir* null, %struct.dir** %10
%12 = load i8*, i8** %5
%13 = load i64, i64* %6
%14 = load i8*, i8** %7
%15 = call %struct.jffs2_raw_dirent* @resolvepath(i8* %12, i64 %13, i32 1, i8* %14, i64* %11)
store %struct.jffs2_raw_dirent* %15, %struct.jffs2_raw_dirent** %9
%16 = load i64, i64* %11
%17 = icmp eq i64 %16, 0
br i1 %17, label %33, label %18
18: ; preds = %4
%19 = load %struct.jffs2_raw_dirent*, %struct.jffs2_raw_dirent** %9
%20 = icmp eq %struct.jffs2_raw_dirent* %19, null
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i64, i64* %11
%23 = icmp eq i64 %22, 0
br i1 %23, label %33, label %24
24: ; preds = %21, %18
%25 = load %struct.jffs2_raw_dirent*, %struct.jffs2_raw_dirent** %9
%26 = icmp ne %struct.jffs2_raw_dirent* %25, null
br i1 %26, label %27, label %39
27: ; preds = %24
%28 = load %struct.jffs2_raw_dirent*, %struct.jffs2_raw_dirent** %9
%29 = getelementptr inbounds %struct.jffs2_raw_dirent, %struct.jffs2_raw_dirent* %28, i32 0, i32 0
%30 = load i64, i64* %29
%31 = load i64, i64* @DT_DIR
%32 = icmp ne i64 %30, %31
br i1 %32, label %33, label %39
33: ; preds = %27, %21, %4
%34 = load i32, i32* @stderr
%35 = load i8*, i8** %7
%36 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %35)
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %27, %24
%40 = load i8*, i8** %5
%41 = load i64, i64* %6
%42 = load i64, i64* %11
%43 = load %struct.dir*, %struct.dir** %10
%44 = call %struct.dir* @collectdir(i8* %40, i64 %41, i64 %42, %struct.dir* %43)
store %struct.dir* %44, %struct.dir** %10
%45 = load i8*, i8** %5
%46 = load i64, i64* %6
%47 = load %struct.dir*, %struct.dir** %10
%48 = load i8*, i8** %7
%49 = load i32, i32* %8
%50 = call i32 @printdir(i8* %45, i64 %46, %struct.dir* %47, i8* %48, i32 %49)
%51 = load %struct.dir*, %struct.dir** %10
%52 = call i32 @freedir(%struct.dir* %51)
ret void
}

LLVM IR (-O2):
%struct.dir = type { i32 }
%struct.jffs2_raw_dirent = type { i64 }
@DT_DIR = global i64 0
@stderr = global i32 0
@.str = [44 x i8] c"jffs2reader: %s: No such file or directory\0A\00"
@EXIT_FAILURE = global i32 0
define void @lsdir(i8* %0, i64 %1, i8* %2, i32 %3) {
%5 = alloca i64
%6 = bitcast i64* %5 to i8*
%7 = call %struct.jffs2_raw_dirent* @resolvepath(i8* %0, i64 %1, i32 1, i8* %2, i64* %5)
%8 = load i64, i64* %5
%9 = icmp eq i64 %8, 0
br i1 %9, label %17, label %10
10: ; preds = %4
%11 = icmp eq %struct.jffs2_raw_dirent* %7, null
br i1 %11, label %22, label %12
12: ; preds = %10
%13 = getelementptr inbounds %struct.jffs2_raw_dirent, %struct.jffs2_raw_dirent* %7, i64 0, i32 0
%14 = load i64, i64* %13
%15 = load i64, i64* @DT_DIR
%16 = icmp eq i64 %14, %15
br i1 %16, label %22, label %17
17: ; preds = %12, %4
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str, i64 0, i64 0), i8* %2)
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %12, %10
%23 = call %struct.dir* @collectdir(i8* %0, i64 %1, i64 %8, %struct.dir* null)
%24 = call i32 @printdir(i8* %0, i64 %1, %struct.dir* %23, i8* %2, i32 %3)
%25 = call i32 @freedir(%struct.dir* %23)
ret void
}