#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*/ tmp;
struct stat {
  int /*<<< orphan*/ st_mode;
};
struct dirent {
  char const *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ listfile(char const *, char *, int);
int lstat(char *, struct stat *);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ rewinddir(int /*<<< orphan*/ *);
int /*<<< orphan*/ show_total_size(char const *, int /*<<< orphan*/ *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, ...);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char const *, char *);
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int listdir(const char *name, int flags) {
  char tmp[4096];
  DIR *d;
  struct dirent *de;
  d = opendir(name);
  if (d == 0) {
    fprintf(stderr, "opendir failed, %s\n", strerror(errno));
    return -1;
  }
  if ((flags & (1 << 4)) != 0) {
    show_total_size(name, d, flags);
  }
  while ((de = readdir(d)) != 0) {
    if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
      continue;
    if (de->d_name[0] == '.' && (flags & (1 << 1)) == 0)
      continue;
    listfile(name, de->d_name, flags);
  }
  if (flags & (1 << 2)) {
    rewinddir(d);
    while ((de = readdir(d)) != 0) {
      struct stat s;
      int err;
      if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
        continue;
      if (de->d_name[0] == '.' && (flags & (1 << 1)) == 0)
        continue;
      if (!strcmp(name, "/"))
        snprintf(tmp, sizeof(tmp), "/%s", de->d_name);
      else
        snprintf(tmp, sizeof(tmp), "%s/%s", name, de->d_name);
      if (tmp[strlen(tmp) - 1] == '/')
        err = stat(tmp, &s);
      else
        err = lstat(tmp, &s);
      if (err < 0) {
        perror(tmp);
        closedir(d);
        return -1;
      }
      if (S_ISDIR(s.st_mode)) {
        printf("\n%s:\n", tmp);
        listdir(tmp, flags);
      }
    }
  }
  closedir(d);
  return 0;
}


x86 assembly (clang, -O0):
<listdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x1028(%rbp)
cmpq   $0x0,-0x1028(%rbp)
jne    127e <listdir+0x6e>
mov    0x2d99(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1040(%rbp)
mov    0x2d82(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
mov    -0x1040(%rbp),%edi
mov    %rax,%rdx
lea    0xd93(%rip),%rsi
call   10e0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1537 <listdir+0x327>
mov    -0x14(%rbp),%eax
and    $0x10,%eax
cmp    $0x0,%eax
je     12a0 <listdir+0x90>
mov    -0x10(%rbp),%rdi
mov    -0x1028(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <show_total_size@plt>
jmp    12a5 <listdir+0x95>
mov    -0x1028(%rbp),%rdi
call   1100 <readdir@plt>
mov    %rax,-0x1030(%rbp)
cmp    $0x0,%rax
je     134a <listdir+0x13a>
mov    -0x1030(%rbp),%rax
mov    (%rax),%rdi
lea    0xd42(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%eax
je     1300 <listdir+0xf0>
mov    -0x1030(%rbp),%rax
mov    (%rax),%rdi
lea    0xd22(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%eax
jne    1305 <listdir+0xf5>
jmp    12a5 <listdir+0x95>
mov    -0x1030(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    132f <listdir+0x11f>
mov    -0x14(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
jne    132f <listdir+0x11f>
jmp    12a5 <listdir+0x95>
mov    -0x10(%rbp),%rdi
mov    -0x1030(%rbp),%rax
mov    (%rax),%rsi
mov    -0x14(%rbp),%edx
call   1110 <listfile@plt>
jmp    12a5 <listdir+0x95>
mov    -0x14(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     1524 <listdir+0x314>
mov    -0x1028(%rbp),%rdi
call   10a0 <rewinddir@plt>
mov    -0x1028(%rbp),%rdi
call   1100 <readdir@plt>
mov    %rax,-0x1030(%rbp)
cmp    $0x0,%rax
je     151f <listdir+0x30f>
mov    -0x1030(%rbp),%rax
mov    (%rax),%rdi
lea    0xc82(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%eax
je     13c0 <listdir+0x1b0>
mov    -0x1030(%rbp),%rax
mov    (%rax),%rdi
lea    0xc62(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%eax
jne    13c5 <listdir+0x1b5>
jmp    1365 <listdir+0x155>
mov    -0x1030(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    13ef <listdir+0x1df>
mov    -0x14(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
jne    13ef <listdir+0x1df>
jmp    1365 <listdir+0x155>
mov    -0x10(%rbp),%rdi
lea    0xc1d(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%eax
jne    1431 <listdir+0x221>
lea    -0x1020(%rbp),%rdi
mov    -0x1030(%rbp),%rax
mov    (%rax),%rcx
mov    $0x1000,%esi
lea    0xbf6(%rip),%rdx
mov    $0x0,%al
call   1090 <snprintf@plt>
jmp    1459 <listdir+0x249>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    -0x1030(%rbp),%rax
mov    (%rax),%r8
mov    $0x1000,%esi
lea    0xbc7(%rip),%rdx
mov    $0x0,%al
call   1090 <snprintf@plt>
lea    -0x1020(%rbp),%rdi
call   1050 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x1020(%rbp,%rax,1),%eax
ff
cmp    $0x2f,%eax
jne    1499 <listdir+0x289>
lea    -0x1020(%rbp),%rdi
lea    -0x1038(%rbp),%rsi
call   10f0 <stat@plt>
mov    %eax,-0x103c(%rbp)
jmp    14b2 <listdir+0x2a2>
lea    -0x1020(%rbp),%rdi
lea    -0x1038(%rbp),%rsi
call   10c0 <lstat@plt>
mov    %eax,-0x103c(%rbp)
cmpl   $0x0,-0x103c(%rbp)
jge    14e3 <listdir+0x2d3>
lea    -0x1020(%rbp),%rdi
call   1120 <perror@plt>
mov    -0x1028(%rbp),%rdi
call   10b0 <closedir@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1537 <listdir+0x327>
mov    -0x1038(%rbp),%edi
call   1080 <S_ISDIR@plt>
cmp    $0x0,%rax
je     151a <listdir+0x30a>
lea    -0x1020(%rbp),%rsi
lea    0xb19(%rip),%rdi
call   1070 <printf@plt>
lea    -0x1020(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <listdir@plt>
jmp    1365 <listdir+0x155>
jmp    1524 <listdir+0x314>
mov    -0x1028(%rbp),%rdi
call   10b0 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listdir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %esi,%r12d
mov    %rdi,%r14
call   1040 <opendir@plt>
test   %rax,%rax
je     13e3 <listdir+0x1d3>
mov    %rax,%rbx
test   $0x10,%r12b
je     124c <listdir+0x3c>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1030 <show_total_size@plt>
mov    %rbx,%rdi
call   1100 <readdir@plt>
test   %rax,%rax
je     12bc <listdir+0xac>
lea    0xdb5(%rip),%r13
lea    0xdad(%rip),%r15
jmp    128d <listdir+0x7d>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r12d,%edx
call   1110 <listfile@plt>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1100 <readdir@plt>
test   %rax,%rax
je     12bc <listdir+0xac>
mov    (%rax),%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
call   10d0 <strcmp@plt>
test   %eax,%eax
je     1280 <listdir+0x70>
mov    %rbp,%rdi
mov    %r15,%rsi
call   10d0 <strcmp@plt>
test   %eax,%eax
je     1280 <listdir+0x70>
test   $0x2,%r12b
jne    1269 <listdir+0x59>
cmpb   $0x2e,0x0(%rbp)
je     1280 <listdir+0x70>
jmp    1269 <listdir+0x59>
test   $0x4,%r12b
je     13d7 <listdir+0x1c7>
mov    %rbx,%rdi
call   10a0 <rewinddir@plt>
mov    %rbx,%rdi
call   1100 <readdir@plt>
test   %rax,%rax
je     13d7 <listdir+0x1c7>
lea    0xd2f(%rip),%r15
lea    0x10(%rsp),%r13
jmp    1301 <listdir+0xf1>
nopl   (%rax)
mov    %rbx,%rdi
call   1100 <readdir@plt>
test   %rax,%rax
je     13d7 <listdir+0x1c7>
mov    (%rax),%rbp
mov    %rbp,%rdi
mov    %r15,%rsi
call   10d0 <strcmp@plt>
test   %eax,%eax
je     12f0 <listdir+0xe0>
mov    %rbp,%rdi
lea    0xcf7(%rip),%rsi
call   10d0 <strcmp@plt>
test   %eax,%eax
je     12f0 <listdir+0xe0>
test   $0x2,%r12b
jne    1332 <listdir+0x122>
cmpb   $0x2e,0x0(%rbp)
je     12f0 <listdir+0xe0>
mov    %r14,%rdi
lea    0xcdb(%rip),%rsi
call   10d0 <strcmp@plt>
mov    %r13,%rdi
mov    $0x1000,%esi
test   %eax,%eax
je     1363 <listdir+0x153>
lea    0xcc5(%rip),%rdx
mov    %r14,%rcx
mov    %rbp,%r8
xor    %eax,%eax
call   1090 <snprintf@plt>
jmp    1374 <listdir+0x164>
lea    0xcb1(%rip),%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1090 <snprintf@plt>
mov    %r13,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%r13,1)
jne    1395 <listdir+0x185>
mov    %r13,%rdi
lea    0x8(%rsp),%rsi
call   10f0 <stat@plt>
jmp    13a2 <listdir+0x192>
mov    %r13,%rdi
lea    0x8(%rsp),%rsi
call   10c0 <lstat@plt>
test   %eax,%eax
js     1422 <listdir+0x212>
mov    0x8(%rsp),%edi
call   1080 <S_ISDIR@plt>
test   %rax,%rax
je     12f0 <listdir+0xe0>
lea    0xc60(%rip),%rdi
mov    %r13,%rsi
call   1070 <printf@plt>
mov    %r13,%rdi
mov    %r12d,%esi
call   1060 <listdir@plt>
jmp    12f0 <listdir+0xe0>
mov    %rbx,%rdi
call   10b0 <closedir@plt>
xor    %eax,%eax
jmp    1410 <listdir+0x200>
mov    0x2bf6(%rip),%rax
mov    (%rax),%ebx
mov    0x2be5(%rip),%rax
mov    (%rax),%edi
call   1130 <strerror@plt>
lea    0xbff(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10e0 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0x10(%rsp),%rdi
call   1120 <perror@plt>
mov    %rbx,%rdi
call   10b0 <closedir@plt>
jmp    140b <listdir+0x1fb>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [20 x i8] c"opendir failed, %s\0A\00"
@errno = global i32 0
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [4 x i8] c"/%s\00"
@.str.5 = [6 x i8] c"%s/%s\00"
@.str.6 = [6 x i8] c"\0A%s:\0A\00"
define i32 @listdir(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [4096 x i8]
%7 = alloca i32*
%8 = alloca %struct.dirent*
%9 = alloca %struct.stat
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%11 = load i8*, i8** %4
%12 = call i32* @opendir(i8* %11)
store i32* %12, i32** %7
%13 = load i32*, i32** %7
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 -1, i32* %3
br label %160
20: ; preds = %2
%21 = load i32, i32* %5
%22 = and i32 %21, 16
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = load i8*, i8** %4
%26 = load i32*, i32** %7
%27 = load i32, i32* %5
%28 = call i32 @show_total_size(i8* %25, i32* %26, i32 %27)
br label %29
29: ; preds = %24, %20
br label %30
30: ; preds = %60, %59, %46, %29
%31 = load i32*, i32** %7
%32 = call %struct.dirent* @readdir(i32* %31)
store %struct.dirent* %32, %struct.dirent** %8
%33 = icmp ne %struct.dirent* %32, null
br i1 %33, label %34, label %67
34: ; preds = %30
%35 = load %struct.dirent*, %struct.dirent** %8
%36 = getelementptr inbounds %struct.dirent, %struct.dirent* %35, i32 0, i32 0
%37 = load i8*, i8** %36
%38 = call i32 @strcmp(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %46
40: ; preds = %34
%41 = load %struct.dirent*, %struct.dirent** %8
%42 = getelementptr inbounds %struct.dirent, %struct.dirent* %41, i32 0, i32 0
%43 = load i8*, i8** %42
%44 = call i32 @strcmp(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%45 = icmp ne i32 %44, 0
br i1 %45, label %47, label %46
46: ; preds = %40, %34
br label %30
47: ; preds = %40
%48 = load %struct.dirent*, %struct.dirent** %8
%49 = getelementptr inbounds %struct.dirent, %struct.dirent* %48, i32 0, i32 0
%50 = load i8*, i8** %49
%51 = getelementptr inbounds i8, i8* %50, i64 0
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp eq i32 %53, 46
br i1 %54, label %55, label %60
55: ; preds = %47
%56 = load i32, i32* %5
%57 = and i32 %56, 2
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %60
59: ; preds = %55
br label %30
60: ; preds = %55, %47
%61 = load i8*, i8** %4
%62 = load %struct.dirent*, %struct.dirent** %8
%63 = getelementptr inbounds %struct.dirent, %struct.dirent* %62, i32 0, i32 0
%64 = load i8*, i8** %63
%65 = load i32, i32* %5
%66 = call i32 @listfile(i8* %61, i8* %64, i32 %65)
br label %30
67: ; preds = %30
%68 = load i32, i32* %5
%69 = and i32 %68, 4
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %157
71: ; preds = %67
%72 = load i32*, i32** %7
%73 = call i32 @rewinddir(i32* %72)
br label %74
74: ; preds = %155, %103, %90, %71
%75 = load i32*, i32** %7
%76 = call %struct.dirent* @readdir(i32* %75)
store %struct.dirent* %76, %struct.dirent** %8
%77 = icmp ne %struct.dirent* %76, null
br i1 %77, label %78, label %156
78: ; preds = %74
%79 = load %struct.dirent*, %struct.dirent** %8
%80 = getelementptr inbounds %struct.dirent, %struct.dirent* %79, i32 0, i32 0
%81 = load i8*, i8** %80
%82 = call i32 @strcmp(i8* %81, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%83 = icmp ne i32 %82, 0
br i1 %83, label %84, label %90
84: ; preds = %78
%85 = load %struct.dirent*, %struct.dirent** %8
%86 = getelementptr inbounds %struct.dirent, %struct.dirent* %85, i32 0, i32 0
%87 = load i8*, i8** %86
%88 = call i32 @strcmp(i8* %87, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%89 = icmp ne i32 %88, 0
br i1 %89, label %91, label %90
90: ; preds = %84, %78
br label %74
91: ; preds = %84
%92 = load %struct.dirent*, %struct.dirent** %8
%93 = getelementptr inbounds %struct.dirent, %struct.dirent* %92, i32 0, i32 0
%94 = load i8*, i8** %93
%95 = getelementptr inbounds i8, i8* %94, i64 0
%96 = load i8, i8* %95
%97 = sext i8 %96 to i32
%98 = icmp eq i32 %97, 46
br i1 %98, label %99, label %104
99: ; preds = %91
%100 = load i32, i32* %5
%101 = and i32 %100, 2
%102 = icmp eq i32 %101, 0
br i1 %102, label %103, label %104
103: ; preds = %99
br label %74
104: ; preds = %99, %91
%105 = load i8*, i8** %4
%106 = call i32 @strcmp(i8* %105, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%107 = icmp ne i32 %106, 0
br i1 %107, label %114, label %108
108: ; preds = %104
%109 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%110 = load %struct.dirent*, %struct.dirent** %8
%111 = getelementptr inbounds %struct.dirent, %struct.dirent* %110, i32 0, i32 0
%112 = load i8*, i8** %111
%113 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %109, i32 4096, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %112)
br label %121
114: ; preds = %104
%115 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%116 = load i8*, i8** %4
%117 = load %struct.dirent*, %struct.dirent** %8
%118 = getelementptr inbounds %struct.dirent, %struct.dirent* %117, i32 0, i32 0
%119 = load i8*, i8** %118
%120 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %115, i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %116, i8* %119)
br label %121
121: ; preds = %114, %108
%122 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%123 = call i32 @strlen(i8* %122)
%124 = sub nsw i32 %123, 1
%125 = sext i32 %124 to i64
%126 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 %125
%127 = load i8, i8* %126
%128 = sext i8 %127 to i32
%129 = icmp eq i32 %128, 47
br i1 %129, label %130, label %133
130: ; preds = %121
%131 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%132 = call i32 @stat(i8* %131, %struct.stat* %9)
store i32 %132, i32* %10
br label %136
133: ; preds = %121
%134 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%135 = call i32 @lstat(i8* %134, %struct.stat* %9)
store i32 %135, i32* %10
br label %136
136: ; preds = %133, %130
%137 = load i32, i32* %10
%138 = icmp slt i32 %137, 0
br i1 %138, label %139, label %144
139: ; preds = %136
%140 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%141 = call i32 @perror(i8* %140)
%142 = load i32*, i32** %7
%143 = call i32 @closedir(i32* %142)
store i32 -1, i32* %3
br label %160
144: ; preds = %136
%145 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%146 = load i32, i32* %145
%147 = call i64 @S_ISDIR(i32 %146)
%148 = icmp ne i64 %147, 0
br i1 %148, label %149, label %155
149: ; preds = %144
%150 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%151 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %150)
%152 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%153 = load i32, i32* %5
%154 = call i32 @listdir(i8* %152, i32 %153)
br label %155
155: ; preds = %149, %144
br label %74
156: ; preds = %74
br label %157
157: ; preds = %156, %67
%158 = load i32*, i32** %7
%159 = call i32 @closedir(i32* %158)
store i32 0, i32* %3
br label %160
160: ; preds = %157, %139, %15
%161 = load i32, i32* %3
ret i32 %161
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [20 x i8] c"opendir failed, %s\0A\00"
@errno = global i32 0
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [4 x i8] c"/%s\00"
@.str.5 = [6 x i8] c"%s/%s\00"
@.str.6 = [6 x i8] c"\0A%s:\0A\00"
define i32 @listdir(i8* %0, i32 %1) {
%3 = alloca [4096 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%6 = tail call i32* @opendir(i8* %0)
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = tail call i8* @strerror(i32 %10)
%12 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %103
13: ; preds = %2
%14 = and i32 %1, 16
%15 = icmp eq i32 %14, 0
br i1 %15, label %18, label %16
16: ; preds = %13
%17 = tail call i32 @show_total_size(i8* %0, i32* %6, i32 %1)
br label %18
18: ; preds = %16, %13
%19 = tail call %struct.dirent* @readdir(i32* %6)
%20 = icmp eq %struct.dirent* %19, null
br i1 %20, label %42, label %21
21: ; preds = %18
%22 = and i32 %1, 2
%23 = icmp eq i32 %22, 0
br label %24
24: ; preds = %21, %33
%25 = phi %struct.dirent* [ %19, %21 ], [ %34, %33 ]
%26 = getelementptr inbounds %struct.dirent, %struct.dirent* %25, i64 0, i32 0
%27 = load i8*, i8** %26
%28 = tail call i32 @strcmp(i8* dereferenceable(1) %27, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %24
%31 = tail call i32 @strcmp(i8* dereferenceable(1) %27, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %24, %30, %40, %36
%34 = tail call %struct.dirent* @readdir(i32* %6)
%35 = icmp eq %struct.dirent* %34, null
br i1 %35, label %42, label %24
36: ; preds = %30
%37 = load i8, i8* %27
%38 = icmp eq i8 %37, 46
%39 = and i1 %23, %38
br i1 %39, label %33, label %40
40: ; preds = %36
%41 = tail call i32 @listfile(i8* %0, i8* %27, i32 %1)
br label %33
42: ; preds = %33, %18
%43 = and i32 %1, 4
%44 = icmp eq i32 %43, 0
br i1 %44, label %101, label %45
45: ; preds = %42
%46 = tail call i32 @rewinddir(i32* %6)
%47 = call %struct.dirent* @readdir(i32* %6)
%48 = icmp eq %struct.dirent* %47, null
br i1 %48, label %101, label %49
49: ; preds = %45
%50 = bitcast %struct.stat* %4 to i8*
%51 = and i32 %1, 2
%52 = icmp eq i32 %51, 0
%53 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
br label %54
54: ; preds = %49, %98
%55 = phi %struct.dirent* [ %47, %49 ], [ %99, %98 ]
%56 = getelementptr inbounds %struct.dirent, %struct.dirent* %55, i64 0, i32 0
%57 = load i8*, i8** %56
%58 = call i32 @strcmp(i8* dereferenceable(1) %57, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%59 = icmp eq i32 %58, 0
br i1 %59, label %98, label %60
60: ; preds = %54
%61 = call i32 @strcmp(i8* dereferenceable(1) %57, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%62 = icmp eq i32 %61, 0
br i1 %62, label %98, label %63
63: ; preds = %60
%64 = load i8, i8* %57
%65 = icmp eq i8 %64, 46
%66 = and i1 %52, %65
br i1 %66, label %98, label %67
67: ; preds = %63
%68 = call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%69 = icmp eq i32 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %67
%71 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %5, i32 4096, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %57)
br label %74
72: ; preds = %67
%73 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %5, i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %57)
br label %74
74: ; preds = %72, %70
%75 = call i32 @strlen(i8* %5)
%76 = add nsw i32 %75, -1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 %77
%79 = load i8, i8* %78
%80 = icmp eq i8 %79, 47
br i1 %80, label %81, label %83
81: ; preds = %74
%82 = call i32 @stat(i8* %5, %struct.stat* %4)
br label %85
83: ; preds = %74
%84 = call i32 @lstat(i8* %5, %struct.stat* %4)
br label %85
85: ; preds = %83, %81
%86 = phi i32 [ %82, %81 ], [ %84, %83 ]
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %85
%89 = call i32 @perror(i8* %5)
%90 = call i32 @closedir(i32* %6)
br label %103
91: ; preds = %85
%92 = load i32, i32* %53
%93 = call i64 @S_ISDIR(i32 %92)
%94 = icmp eq i64 %93, 0
br i1 %94, label %98, label %95
95: ; preds = %91
%96 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* %5)
%97 = call i32 @listdir(i8* %5, i32 %1)
br label %98
98: ; preds = %91, %95, %63, %54, %60
%99 = call %struct.dirent* @readdir(i32* %6)
%100 = icmp eq %struct.dirent* %99, null
br i1 %100, label %101, label %54
101: ; preds = %98, %45, %42
%102 = call i32 @closedir(i32* %6)
br label %103
103: ; preds = %88, %101, %8
%104 = phi i32 [ -1, %8 ], [ 0, %101 ], [ -1, %88 ]
ret i32 %104
}