#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 stat {
  scalar_t__ st_size;
};
typedef scalar_t__ ssize_t;

/* Variables and functions */
int EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ catfile(char *, scalar_t__, char *, char *, int, size_t *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ fstat(int, struct stat *);
int getopt(int, char **, char *);
int /*<<< orphan*/ lsdir(char *, scalar_t__, char *, int);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
char *optarg;
size_t optind;
scalar_t__ read(int, char *, scalar_t__);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  int fd, opt, recurse = 0;
  struct stat st;
  char *scratch, *dir = NULL, *file = NULL;
  size_t ssize = 0;
  char *buf;
  while ((opt = getopt(argc, argv, "rd:f:")) > 0) {
    switch (opt) {
    case 'd':
      dir = optarg;
      break;
    case 'f':
      file = optarg;
      break;
    case 'r':
      recurse++;
      break;
    default:
      fprintf(stderr, "Usage: jffs2reader <image> [-d|-f] < path > \n");
      exit(EXIT_FAILURE);
    }
  }
  fd = open(argv[optind], O_RDONLY);
  if (fd == -1) {
    fprintf(stderr, "%s: %s\n", argv[optind], strerror(errno));
    exit(2);
  }
  if (fstat(fd, &st)) {
    fprintf(stderr, "%s: %s\n", argv[optind], strerror(errno));
    exit(3);
  }
  buf = malloc((size_t)st.st_size);
  if (buf == NULL) {
    fprintf(stderr, "%s: memory exhausted\n", argv[optind]);
    exit(4);
  }
  if (read(fd, buf, st.st_size) != (ssize_t)st.st_size) {
    fprintf(stderr, "%s: %s\n", argv[optind], strerror(errno));
    exit(5);
  }
  if (dir)
    lsdir(buf, st.st_size, dir, recurse);
  if (file) {
    scratch = malloc((5 * 1024 * 1024));
    if (scratch == NULL) {
      fprintf(stderr, "%s: memory exhausted\n", argv[optind]);
      exit(6);
    }
    catfile(buf, st.st_size, file, scratch, (5 * 1024 * 1024), &ssize);
    free(scratch);
  }
  if (!dir && !file)
    lsdir(buf, st.st_size, "/", 1);
  free(buf);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
movq   $0x0,-0x38(%rbp)
movq   $0x0,-0x40(%rbp)
movq   $0x0,-0x48(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe0a(%rip),%rdx
call   10a0 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jle    129b <main+0xeb>
mov    -0x18(%rbp),%eax
mov    %eax,-0x54(%rbp)
sub    $0x64,%eax
je     123d <main+0x8d>
jmp    121b <main+0x6b>
mov    -0x54(%rbp),%eax
sub    $0x66,%eax
je     1250 <main+0xa0>
jmp    122c <main+0x7c>
mov    -0x54(%rbp),%eax
sub    $0x72,%eax
je     1263 <main+0xb3>
jmp    1271 <main+0xc1>
mov    0x2db4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    1296 <main+0xe6>
mov    0x2da1(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    1296 <main+0xe6>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1296 <main+0xe6>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
jmp    11e8 <main+0x38>
mov    -0x10(%rbp),%rax
mov    0x2d32(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2d2c(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    131a <main+0x16a>
mov    0x2cf9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2cf9(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x60(%rbp)
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xd2b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
call   10d0 <fstat@plt>
cmp    $0x0,%rax
je     1382 <main+0x1d2>
mov    0x2c91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2c91(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x70(%rbp)
mov    0x2c67(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    -0x70(%rbp),%rdx
mov    %rax,%rcx
lea    0xcc3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x3,%edi
call   10b0 <exit@plt>
mov    -0x28(%rbp),%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    13cf <main+0x21f>
mov    0x2c25(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x2c28(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xc7e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x4,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    -0x50(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1050 <read@plt>
cmp    -0x28(%rbp),%rax
je     1441 <main+0x291>
mov    0x2bd8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
mov    -0x10(%rbp),%rax
mov    0x2bd5(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x80(%rbp)
mov    0x2bab(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x84(%rbp),%edi
mov    -0x80(%rbp),%rdx
mov    %rax,%rcx
lea    0xc04(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x5,%edi
call   10b0 <exit@plt>
cmpq   $0x0,-0x38(%rbp)
je     1460 <main+0x2b0>
mov    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1040 <lsdir@plt>
cmpq   $0x0,-0x40(%rbp)
je     14df <main+0x32f>
mov    $0x500000,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    14b7 <main+0x307>
mov    0x2b3d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x2b40(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xb96(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0x6,%edi
call   10b0 <exit@plt>
mov    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x500000,%r8d
lea    -0x48(%rbp),%r9
call   1080 <catfile@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
cmpq   $0x0,-0x38(%rbp)
jne    150e <main+0x35e>
cmpq   $0x0,-0x40(%rbp)
jne    150e <main+0x35e>
mov    -0x50(%rbp),%rdi
mov    -0x28(%rbp),%rsi
lea    0xb4e(%rip),%rdx
mov    $0x1,%ecx
call   1040 <lsdir@plt>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    0x2a92(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r13
mov    %edi,%ebp
movq   $0x0,0x18(%rsp)
lea    0xe2d(%rip),%rdx
call   10a0 <getopt@plt>
test   %eax,%eax
jle    1246 <main+0x96>
xor    %r15d,%r15d
lea    0xe1a(%rip),%rbx
mov    0x2e0b(%rip),%r14
xor    %ecx,%ecx
mov    %rcx,0x8(%rsp)
xor    %r12d,%r12d
jmp    1219 <main+0x69>
nopl   0x0(%rax)
mov    (%r14),%rax
mov    %rax,0x8(%rsp)
mov    %ebp,%edi
mov    %r13,%rsi
mov    %rbx,%rdx
call   10a0 <getopt@plt>
test   %eax,%eax
jle    1253 <main+0xa3>
cmp    $0x72,%eax
je     1240 <main+0x90>
cmp    $0x66,%eax
je     1200 <main+0x50>
cmp    $0x64,%eax
jne    1344 <main+0x194>
mov    (%r14),%r12
jmp    1208 <main+0x58>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
add    $0x1,%r15d
jmp    1208 <main+0x58>
xor    %r12d,%r12d
xor    %eax,%eax
mov    %rax,0x8(%rsp)
xor    %r15d,%r15d
mov    0x2d7e(%rip),%r14
mov    (%r14),%rax
mov    0x0(%r13,%rax,8),%rdi
mov    0x2d77(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
cmp    $0xffffffff,%eax
jne    12b4 <main+0x104>
mov    0x2d4c(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rax
mov    0x0(%r13,%rax,8),%rbp
mov    0x2d33(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd99(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x2,%edi
call   10b0 <exit@plt>
mov    %eax,%ebp
lea    0x20(%rsp),%rsi
mov    %eax,%edi
call   10d0 <fstat@plt>
test   %rax,%rax
jne    1305 <main+0x155>
mov    0x20(%rsp),%rbx
mov    %ebx,%edi
call   1070 <malloc@plt>
test   %rax,%rax
jne    1369 <main+0x1b9>
mov    0x2ce5(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rax
mov    0x0(%r13,%rax,8),%rdx
lea    0xd48(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x4,%edi
call   10b0 <exit@plt>
mov    0x2cbc(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rax
mov    0x0(%r13,%rax,8),%rbp
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xd09(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x3,%edi
call   10b0 <exit@plt>
mov    0x2c7d(%rip),%rax
mov    (%rax),%edi
lea    0xcb2(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    0x2c56(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    %ebp,%edi
mov    %rax,%rsi
mov    %rbx,%rdx
mov    %rax,%rbp
call   1050 <read@plt>
cmp    %rbx,%rax
jne    13b3 <main+0x203>
mov    %rbp,0x10(%rsp)
test   %r12,%r12
jne    13f2 <main+0x242>
mov    0x8(%rsp),%rbp
test   %rbp,%rbp
mov    0x10(%rsp),%r15
jne    1412 <main+0x262>
lea    0xcb4(%rip),%rdx
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1,%ecx
call   1040 <lsdir@plt>
jmp    1479 <main+0x2c9>
mov    0x2c0e(%rip),%rax
mov    (%rax),%ebx
mov    (%r14),%rax
mov    0x0(%r13,%rax,8),%rbp
mov    0x2bf5(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
lea    0xc5b(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x5,%edi
call   10b0 <exit@plt>
mov    0x10(%rsp),%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r15d,%ecx
mov    %rdi,%r15
call   1040 <lsdir@plt>
mov    0x8(%rsp),%rbp
test   %rbp,%rbp
je     1479 <main+0x2c9>
mov    %r14,%r15
mov    $0x500000,%edi
call   1070 <malloc@plt>
test   %rax,%rax
jne    144d <main+0x29d>
mov    0x2b9d(%rip),%rax
mov    (%rax),%edi
mov    (%r15),%rax
mov    0x0(%r13,%rax,8),%rdx
lea    0xc00(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x6,%edi
call   10b0 <exit@plt>
mov    %rax,%r14
lea    0x18(%rsp),%r9
mov    0x10(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %rbp,%rdx
mov    %rax,%rcx
mov    $0x500000,%r8d
call   1080 <catfile@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x2b28(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [6 x i8] c"rd:f:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.1 = [46 x i8] c"Usage: jffs2reader <image> [-d|-f] < path > \0A\00"
@EXIT_FAILURE = global i32 0
@optind = global i64 0
@O_RDONLY = global i32 0
@.str.2 = [8 x i8] c"%s: %s\0A\00"
@errno = global i32 0
@.str.3 = [22 x i8] c"%s: memory exhausted\0A\00"
@.str.4 = [2 x i8] c"/\00"
@EXIT_SUCCESS = global i32 0
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 %struct.stat
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
store i8* null, i8** %11
store i8* null, i8** %12
store i64 0, i64* %13
br label %15
15: ; preds = %34, %2
%16 = load i32, i32* %4
%17 = load i8**, i8*** %5
%18 = call i32 @getopt(i32 %16, i8** %17, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
store i32 %18, i32* %7
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %35
20: ; preds = %15
%21 = load i32, i32* %7
switch i32 %21, label %29 [
i32 100, label %22
i32 102, label %24
i32 114, label %26
]
22: ; preds = %20
%23 = load i8*, i8** @optarg
store i8* %23, i8** %11
br label %34
24: ; preds = %20
%25 = load i8*, i8** @optarg
store i8* %25, i8** %12
br label %34
26: ; preds = %20
%27 = load i32, i32* %8
%28 = add nsw i32 %27, 1
store i32 %28, i32* %8
br label %34
29: ; preds = %20
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %26, %24, %22
br label %15
35: ; preds = %15
%36 = load i8**, i8*** %5
%37 = load i64, i64* @optind
%38 = getelementptr inbounds i8*, i8** %36, i64 %37
%39 = load i8*, i8** %38
%40 = load i32, i32* @O_RDONLY
%41 = call i32 @open(i8* %39, i32 %40)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %54
44: ; preds = %35
%45 = load i32, i32* @stderr
%46 = load i8**, i8*** %5
%47 = load i64, i64* @optind
%48 = getelementptr inbounds i8*, i8** %46, i64 %47
%49 = load i8*, i8** %48
%50 = load i32, i32* @errno
%51 = call i8* @strerror(i32 %50)
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %49, i8* %51)
%53 = call i32 @exit(i32 2)
unreachable
54: ; preds = %35
%55 = load i32, i32* %6
%56 = call i64 @fstat(i32 %55, %struct.stat* %9)
%57 = icmp ne i64 %56, 0
br i1 %57, label %58, label %68
58: ; preds = %54
%59 = load i32, i32* @stderr
%60 = load i8**, i8*** %5
%61 = load i64, i64* @optind
%62 = getelementptr inbounds i8*, i8** %60, i64 %61
%63 = load i8*, i8** %62
%64 = load i32, i32* @errno
%65 = call i8* @strerror(i32 %64)
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %63, i8* %65)
%67 = call i32 @exit(i32 3)
unreachable
68: ; preds = %54
%69 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%70 = load i64, i64* %69
%71 = trunc i64 %70 to i32
%72 = call i8* @malloc(i32 %71)
store i8* %72, i8** %14
%73 = load i8*, i8** %14
%74 = icmp eq i8* %73, null
br i1 %74, label %75, label %83
75: ; preds = %68
%76 = load i32, i32* @stderr
%77 = load i8**, i8*** %5
%78 = load i64, i64* @optind
%79 = getelementptr inbounds i8*, i8** %77, i64 %78
%80 = load i8*, i8** %79
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %80)
%82 = call i32 @exit(i32 4)
unreachable
83: ; preds = %68
%84 = load i32, i32* %6
%85 = load i8*, i8** %14
%86 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%87 = load i64, i64* %86
%88 = call i64 @read(i32 %84, i8* %85, i64 %87)
%89 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%90 = load i64, i64* %89
%91 = icmp ne i64 %88, %90
br i1 %91, label %92, label %102
92: ; preds = %83
%93 = load i32, i32* @stderr
%94 = load i8**, i8*** %5
%95 = load i64, i64* @optind
%96 = getelementptr inbounds i8*, i8** %94, i64 %95
%97 = load i8*, i8** %96
%98 = load i32, i32* @errno
%99 = call i8* @strerror(i32 %98)
%100 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %97, i8* %99)
%101 = call i32 @exit(i32 5)
unreachable
102: ; preds = %83
%103 = load i8*, i8** %11
%104 = icmp ne i8* %103, null
br i1 %104, label %105, label %112
105: ; preds = %102
%106 = load i8*, i8** %14
%107 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%108 = load i64, i64* %107
%109 = load i8*, i8** %11
%110 = load i32, i32* %8
%111 = call i32 @lsdir(i8* %106, i64 %108, i8* %109, i32 %110)
br label %112
112: ; preds = %105, %102
%113 = load i8*, i8** %12
%114 = icmp ne i8* %113, null
br i1 %114, label %115, label %136
115: ; preds = %112
%116 = call i8* @malloc(i32 5242880)
store i8* %116, i8** %10
%117 = load i8*, i8** %10
%118 = icmp eq i8* %117, null
br i1 %118, label %119, label %127
119: ; preds = %115
%120 = load i32, i32* @stderr
%121 = load i8**, i8*** %5
%122 = load i64, i64* @optind
%123 = getelementptr inbounds i8*, i8** %121, i64 %122
%124 = load i8*, i8** %123
%125 = call i32 (i32, i8*, ...) @fprintf(i32 %120, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %124)
%126 = call i32 @exit(i32 6)
unreachable
127: ; preds = %115
%128 = load i8*, i8** %14
%129 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%130 = load i64, i64* %129
%131 = load i8*, i8** %12
%132 = load i8*, i8** %10
%133 = call i32 @catfile(i8* %128, i64 %130, i8* %131, i8* %132, i32 5242880, i64* %13)
%134 = load i8*, i8** %10
%135 = call i32 @free(i8* %134)
br label %136
136: ; preds = %127, %112
%137 = load i8*, i8** %11
%138 = icmp ne i8* %137, null
br i1 %138, label %147, label %139
139: ; preds = %136
%140 = load i8*, i8** %12
%141 = icmp ne i8* %140, null
br i1 %141, label %147, label %142
142: ; preds = %139
%143 = load i8*, i8** %14
%144 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%145 = load i64, i64* %144
%146 = call i32 @lsdir(i8* %143, i64 %145, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
br label %147
147: ; preds = %142, %139, %136
%148 = load i8*, i8** %14
%149 = call i32 @free(i8* %148)
%150 = load i32, i32* @EXIT_SUCCESS
%151 = call i32 @exit(i32 %150)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [6 x i8] c"rd:f:\00"
@optarg = global i8* null
@stderr = global i32 0
@.str.1 = [46 x i8] c"Usage: jffs2reader <image> [-d|-f] < path > \0A\00"
@EXIT_FAILURE = global i32 0
@optind = global i64 0
@O_RDONLY = global i32 0
@.str.2 = [8 x i8] c"%s: %s\0A\00"
@errno = global i32 0
@.str.3 = [22 x i8] c"%s: memory exhausted\0A\00"
@.str.4 = [2 x i8] c"/\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = alloca i64
%5 = bitcast %struct.stat* %3 to i8*
%6 = bitcast i64* %4 to i8*
store i64 0, i64* %4
%7 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%8 = icmp sgt i32 %7, 0
br i1 %8, label %9, label %31
9: ; preds = %2, %25
%10 = phi i32 [ %29, %25 ], [ %7, %2 ]
%11 = phi i32 [ %28, %25 ], [ 0, %2 ]
%12 = phi i8* [ %27, %25 ], [ null, %2 ]
%13 = phi i8* [ %26, %25 ], [ null, %2 ]
switch i32 %10, label %20 [
i32 100, label %14
i32 102, label %16
i32 114, label %18
]
14: ; preds = %9
%15 = load i8*, i8** @optarg
br label %25
16: ; preds = %9
%17 = load i8*, i8** @optarg
br label %25
18: ; preds = %9
%19 = add nsw i32 %11, 1
br label %25
20: ; preds = %9
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %18, %16, %14
%26 = phi i8* [ %13, %18 ], [ %13, %16 ], [ %15, %14 ]
%27 = phi i8* [ %12, %18 ], [ %17, %16 ], [ %12, %14 ]
%28 = phi i32 [ %19, %18 ], [ %11, %16 ], [ %11, %14 ]
%29 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0))
%30 = icmp sgt i32 %29, 0
br i1 %30, label %9, label %31
31: ; preds = %25, %2
%32 = phi i8* [ null, %2 ], [ %26, %25 ]
%33 = phi i8* [ null, %2 ], [ %27, %25 ]
%34 = phi i32 [ 0, %2 ], [ %28, %25 ]
%35 = load i64, i64* @optind
%36 = getelementptr inbounds i8*, i8** %1, i64 %35
%37 = load i8*, i8** %36
%38 = load i32, i32* @O_RDONLY
%39 = tail call i32 @open(i8* %37, i32 %38)
%40 = icmp eq i32 %39, -1
br i1 %40, label %41, label %50
41: ; preds = %31
%42 = load i32, i32* @stderr
%43 = load i64, i64* @optind
%44 = getelementptr inbounds i8*, i8** %1, i64 %43
%45 = load i8*, i8** %44
%46 = load i32, i32* @errno
%47 = tail call i8* @strerror(i32 %46)
%48 = tail call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %45, i8* %47)
%49 = tail call i32 @exit(i32 2)
unreachable
50: ; preds = %31
%51 = call i64 @fstat(i32 %39, %struct.stat* %3)
%52 = icmp eq i64 %51, 0
br i1 %52, label %62, label %53
53: ; preds = %50
%54 = load i32, i32* @stderr
%55 = load i64, i64* @optind
%56 = getelementptr inbounds i8*, i8** %1, i64 %55
%57 = load i8*, i8** %56
%58 = load i32, i32* @errno
%59 = tail call i8* @strerror(i32 %58)
%60 = tail call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %57, i8* %59)
%61 = tail call i32 @exit(i32 3)
unreachable
62: ; preds = %50
%63 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%64 = load i64, i64* %63
%65 = trunc i64 %64 to i32
%66 = tail call i8* @malloc(i32 %65)
%67 = icmp eq i8* %66, null
br i1 %67, label %68, label %75
68: ; preds = %62
%69 = load i32, i32* @stderr
%70 = load i64, i64* @optind
%71 = getelementptr inbounds i8*, i8** %1, i64 %70
%72 = load i8*, i8** %71
%73 = tail call i32 (i32, i8*, ...) @fprintf(i32 %69, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %72)
%74 = tail call i32 @exit(i32 4)
unreachable
75: ; preds = %62
%76 = tail call i64 @read(i32 %39, i8* %66, i64 %64)
%77 = icmp eq i64 %76, %64
br i1 %77, label %87, label %78
78: ; preds = %75
%79 = load i32, i32* @stderr
%80 = load i64, i64* @optind
%81 = getelementptr inbounds i8*, i8** %1, i64 %80
%82 = load i8*, i8** %81
%83 = load i32, i32* @errno
%84 = tail call i8* @strerror(i32 %83)
%85 = tail call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %82, i8* %84)
%86 = tail call i32 @exit(i32 5)
unreachable
87: ; preds = %75
%88 = icmp eq i8* %32, null
br i1 %88, label %89, label %91
89: ; preds = %87
%90 = icmp eq i8* %33, null
br i1 %90, label %107, label %94
91: ; preds = %87
%92 = tail call i32 @lsdir(i8* %66, i64 %64, i8* %32, i32 %34)
%93 = icmp eq i8* %33, null
br i1 %93, label %109, label %94
94: ; preds = %91, %89
%95 = tail call dereferenceable_or_null(5242880) i8* @malloc(i32 5242880)
%96 = icmp eq i8* %95, null
br i1 %96, label %97, label %104
97: ; preds = %94
%98 = load i32, i32* @stderr
%99 = load i64, i64* @optind
%100 = getelementptr inbounds i8*, i8** %1, i64 %99
%101 = load i8*, i8** %100
%102 = tail call i32 (i32, i8*, ...) @fprintf(i32 %98, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0), i8* %101)
%103 = tail call i32 @exit(i32 6)
unreachable
104: ; preds = %94
%105 = call i32 @catfile(i8* %66, i64 %64, i8* %33, i8* %95, i32 5242880, i64* %4)
%106 = call i32 @free(i8* %95)
br label %109
107: ; preds = %89
%108 = tail call i32 @lsdir(i8* %66, i64 %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i32 1)
br label %109
109: ; preds = %91, %104, %107
%110 = call i32 @free(i8* %66)
%111 = load i32, i32* @EXIT_SUCCESS
%112 = call i32 @exit(i32 %111)
unreachable
}