#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 {
  int /*<<< orphan*/ st_size;
  int /*<<< orphan*/ st_ctime;
  int /*<<< orphan*/ st_mtime;
  int /*<<< orphan*/ st_atime;
  scalar_t__ st_gid;
  scalar_t__ st_uid;
  int /*<<< orphan*/ st_mode;
};
struct dirent {
  char *d_name;
  scalar_t__ d_type;
};
typedef int /*<<< orphan*/ filepath;
typedef int /*<<< orphan*/ dirpath;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ DT_BLK;
scalar_t__ DT_CHR;
scalar_t__ DT_DIR;
scalar_t__ DT_FIFO;
scalar_t__ DT_LNK;
scalar_t__ DT_REG;
scalar_t__ DT_SOCK;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int lstat(char *, struct stat *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pretty_print_mode(int /*<<< orphan*/);
char *pretty_print_size(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void list_dir(const char *path, int depth) {
  char dirpath[100] = {0};
  strncpy(dirpath, path, sizeof(dirpath));
  if (dirpath[strlen(dirpath) - 1] != '/')
    strncat(dirpath, "/", sizeof(dirpath));
  DIR *d = opendir(dirpath);
  if (d == NULL) {
    fprintf(stderr, "Error: unable to open dir %s\n", dirpath);
    perror("opendir()");
    exit(1);
  }
  struct dirent *item;
  char filepath[100] = {0};
  strncpy(filepath, dirpath, sizeof(filepath));
  char *name = filepath + strlen(filepath);
  int buflen = sizeof(filepath) - strlen(filepath);
  while ((item = readdir(d)) != NULL) {
    char *type = "?";
    if (strncmp(item->d_name, "..", 2) == 0 ||
        strncmp(item->d_name, ".", 1) == 0)
      continue;
    strncpy(name, item->d_name, buflen);
    if (item->d_type == DT_REG)
      type = "-";
    else if (item->d_type == DT_FIFO)
      type = "F";
    else if (item->d_type == DT_SOCK)
      type = "S";
    else if (item->d_type == DT_CHR)
      type = "c";
    else if (item->d_type == DT_BLK)
      type = "b";
    else if (item->d_type == DT_DIR)
      type = "d";
    else if (item->d_type == DT_LNK)
      type = "l";
    struct stat stat;
    int res = lstat(filepath, &stat);
    if (res == 0) {
      printf("%s%s %ld:%ld  %.19s  %.19s  %.19s  %s\t%s\n", type,
             pretty_print_mode(stat.st_mode), (long)stat.st_uid,
             (long)stat.st_gid, ctime(&stat.st_atime), ctime(&stat.st_mtime),
             ctime(&stat.st_ctime), pretty_print_size(stat.st_size), filepath);
      if (item->d_type == DT_DIR && strncmp("/sys", filepath, 4) != 0)
        list_dir(filepath, depth + 1);
    } else {
      printf("%s????????? ?:?  %.19s  %.19s  %.19s  %s\t%s\n", type, "?", "?",
             "?", pretty_print_size(stat.st_size), filepath);
    }
  }
  closedir(d);
}


x86 assembly (clang, -O0):
<list_dir>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0x198,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1090 <memset@plt>
lea    -0x80(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x64,%edx
call   1030 <strncpy@plt>
lea    -0x80(%rbp),%rdi
call   1070 <strlen@plt>
sub    $0x1,%eax
cltq
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0x2f,%eax
je     1276 <list_dir+0x66>
lea    -0x80(%rbp),%rdi
lea    0xd94(%rip),%rsi
mov    $0x64,%edx
call   10a0 <strncat@plt>
lea    -0x80(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x88(%rbp)
cmpq   $0x0,-0x88(%rbp)
jne    12c3 <list_dir+0xb3>
mov    0x2d3d(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rdx
lea    0xd5a(%rip),%rsi
call   10d0 <fprintf@plt>
lea    0xd6c(%rip),%rdi
call   1110 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    -0x100(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1090 <memset@plt>
lea    -0x100(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1030 <strncpy@plt>
lea    -0x100(%rbp),%rax
mov    %rax,-0x150(%rbp)
lea    -0x100(%rbp),%rdi
call   1070 <strlen@plt>
mov    %eax,%ecx
mov    -0x150(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x108(%rbp)
lea    -0x100(%rbp),%rdi
call   1070 <strlen@plt>
movslq %eax,%rcx
mov    $0x64,%eax
sub    %rcx,%rax
mov    %eax,-0x10c(%rbp)
mov    -0x88(%rbp),%rdi
call   10f0 <readdir@plt>
mov    %rax,-0x90(%rbp)
cmp    $0x0,%rax
je     16cc <list_dir+0x4bc>
lea    0xcce(%rip),%rax
mov    %rax,-0x118(%rbp)
mov    -0x90(%rbp),%rax
mov    (%rax),%rdi
lea    0xcb8(%rip),%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     13ad <list_dir+0x19d>
mov    -0x90(%rbp),%rax
mov    (%rax),%rdi
lea    0xc94(%rip),%rsi
mov    $0x1,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
jne    13b2 <list_dir+0x1a2>
jmp    1338 <list_dir+0x128>
mov    -0x108(%rbp),%rdi
mov    -0x90(%rbp),%rax
mov    (%rax),%rsi
mov    -0x10c(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x90(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2c00(%rip),%rcx
cmp    (%rcx),%rax
jne    13fc <list_dir+0x1ec>
lea    0xc3f(%rip),%rax
mov    %rax,-0x118(%rbp)
jmp    1529 <list_dir+0x319>
mov    -0x90(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2b9a(%rip),%rcx
cmp    (%rcx),%rax
jne    142a <list_dir+0x21a>
lea    0xc13(%rip),%rax
mov    %rax,-0x118(%rbp)
jmp    1524 <list_dir+0x314>
mov    -0x90(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2b64(%rip),%rcx
cmp    (%rcx),%rax
jne    1458 <list_dir+0x248>
lea    0xbe7(%rip),%rax
mov    %rax,-0x118(%rbp)
jmp    151f <list_dir+0x30f>
mov    -0x90(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2b56(%rip),%rcx
cmp    (%rcx),%rax
jne    1486 <list_dir+0x276>
lea    0xbbb(%rip),%rax
mov    %rax,-0x118(%rbp)
jmp    151a <list_dir+0x30a>
mov    -0x90(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2b30(%rip),%rcx
cmp    (%rcx),%rax
jne    14b4 <list_dir+0x2a4>
lea    0xb8f(%rip),%rax
mov    %rax,-0x118(%rbp)
jmp    1515 <list_dir+0x305>
mov    -0x90(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2b0a(%rip),%rcx
cmp    (%rcx),%rax
jne    14e2 <list_dir+0x2d2>
lea    0xb63(%rip),%rax
mov    %rax,-0x118(%rbp)
jmp    1510 <list_dir+0x300>
mov    -0x90(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2ac4(%rip),%rcx
cmp    (%rcx),%rax
jne    150b <list_dir+0x2fb>
lea    0xb37(%rip),%rax
mov    %rax,-0x118(%rbp)
jmp    1510 <list_dir+0x300>
jmp    1515 <list_dir+0x305>
jmp    151a <list_dir+0x30a>
jmp    151f <list_dir+0x30f>
jmp    1524 <list_dir+0x314>
jmp    1529 <list_dir+0x319>
lea    -0x100(%rbp),%rdi
lea    -0x140(%rbp),%rsi
call   10c0 <lstat@plt>
mov    %eax,-0x144(%rbp)
cmpl   $0x0,-0x144(%rbp)
jne    167e <list_dir+0x46e>
mov    -0x118(%rbp),%rax
mov    %rax,-0x178(%rbp)
mov    -0x120(%rbp),%edi
call   1130 <pretty_print_mode@plt>
cltq
mov    %rax,-0x170(%rbp)
mov    -0x128(%rbp),%rax
mov    %rax,-0x168(%rbp)
mov    -0x130(%rbp),%rax
mov    %rax,-0x160(%rbp)
lea    -0x140(%rbp),%rdi
add    $0xc,%rdi
call   1060 <ctime@plt>
mov    %eax,-0x158(%rbp)
lea    -0x140(%rbp),%rdi
add    $0x8,%rdi
call   1060 <ctime@plt>
mov    %eax,%ebx
lea    -0x140(%rbp),%rdi
add    $0x4,%rdi
call   1060 <ctime@plt>
mov    %eax,-0x154(%rbp)
mov    -0x140(%rbp),%edi
call   10e0 <pretty_print_size@plt>
mov    -0x178(%rbp),%rsi
mov    -0x170(%rbp),%rdx
mov    -0x168(%rbp),%rcx
mov    -0x160(%rbp),%r8
mov    -0x158(%rbp),%r9d
mov    -0x154(%rbp),%r11d
mov    %rax,%r10
lea    -0x100(%rbp),%rax
lea    0xa2c(%rip),%rdi
mov    %ebx,(%rsp)
mov    %r11d,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x90(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2994(%rip),%rcx
cmp    (%rcx),%rax
jne    1679 <list_dir+0x469>
lea    -0x100(%rbp),%rsi
lea    0xa14(%rip),%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1679 <list_dir+0x469>
lea    -0x100(%rbp),%rdi
mov    -0x14(%rbp),%esi
add    $0x1,%esi
call   1100 <list_dir@plt>
jmp    16c7 <list_dir+0x4b7>
mov    -0x118(%rbp),%rax
mov    %rax,-0x180(%rbp)
mov    -0x140(%rbp),%edi
call   10e0 <pretty_print_size@plt>
mov    -0x180(%rbp),%rsi
mov    %rax,%r9
lea    -0x100(%rbp),%rax
lea    0x9bd(%rip),%rdi
lea    0x974(%rip),%r8
mov    %r8,%rdx
mov    %r8,%rcx
mov    %rax,(%rsp)
mov    $0x0,%al
call   1080 <printf@plt>
jmp    1338 <list_dir+0x128>
mov    -0x88(%rbp),%rdi
call   10b0 <closedir@plt>
add    $0x198,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_dir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x148,%rsp
mov    %esi,0xc(%rsp)
mov    %rdi,%rsi
xorps  %xmm0,%xmm0
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movl   $0x0,0xd0(%rsp)
lea    0x70(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%edx
call   1030 <strncpy@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
je     128c <list_dir+0x8c>
lea    0xd83(%rip),%rsi
lea    0x70(%rsp),%rdi
mov    $0x64,%edx
call   1090 <strncat@plt>
lea    0x70(%rsp),%rdi
call   1050 <opendir@plt>
mov    %rax,0x10(%rsp)
test   %rax,%rax
je     15ae <list_dir+0x3ae>
xorps  %xmm0,%xmm0
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movl   $0x0,0x140(%rsp)
lea    0xe0(%rsp),%r13
lea    0x70(%rsp),%rsi
mov    $0x64,%r15d
mov    %r13,%rdi
mov    $0x64,%edx
call   1030 <strncpy@plt>
mov    %r13,%rdi
call   1070 <strlen@plt>
mov    %eax,%r14d
mov    %r13,%rdi
call   1070 <strlen@plt>
mov    %eax,%ebp
mov    0x10(%rsp),%rdi
call   10e0 <readdir@plt>
test   %rax,%rax
je     1592 <list_dir+0x392>
mov    %rax,%r12
movslq %r14d,%rax
lea    (%rsp,%rax,1),%rbx
add    $0xe0,%rbx
sub    %ebp,%r15d
addl   $0x1,0xc(%rsp)
lea    0xce2(%rip),%rbp
mov    %rbx,0x20(%rsp)
mov    %r15d,0x1c(%rsp)
jmp    13bf <list_dir+0x1bf>
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
lea    0x48(%rsp),%rsi
call   10b0 <lstat@plt>
test   %eax,%eax
je     14ae <list_dir+0x2ae>
mov    0x48(%rsp),%edi
call   10d0 <pretty_print_size@plt>
sub    $0x8,%rsp
lea    0xce3(%rip),%rdi
mov    %r14,%rsi
lea    0xc97(%rip),%rcx
mov    %rcx,%rdx
mov    %rcx,%r8
mov    %rax,%r9
xor    %eax,%eax
push   %r13
call   1080 <printf@plt>
add    $0x10,%rsp
mov    0x10(%rsp),%rdi
call   10e0 <readdir@plt>
mov    %rax,%r12
test   %rax,%rax
je     1592 <list_dir+0x392>
mov    (%r12),%rdi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     13a9 <list_dir+0x1a9>
mov    (%r12),%rdi
lea    0xc4d(%rip),%rsi
mov    $0x1,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     13a9 <list_dir+0x1a9>
mov    (%r12),%rsi
mov    %rbx,%rdi
mov    %r15d,%edx
call   1030 <strncpy@plt>
mov    0x8(%r12),%rax
lea    0xc25(%rip),%r14
mov    0x2bcf(%rip),%rcx
cmp    (%rcx),%rax
je     1360 <list_dir+0x160>
lea    0xc10(%rip),%r14
mov    0x2b80(%rip),%rcx
cmp    (%rcx),%rax
je     1360 <list_dir+0x160>
lea    0xbfb(%rip),%r14
mov    0x2b61(%rip),%rcx
cmp    (%rcx),%rax
je     1360 <list_dir+0x160>
lea    0xbe6(%rip),%r14
mov    0x2b6a(%rip),%rcx
cmp    (%rcx),%rax
je     1360 <list_dir+0x160>
lea    0xbd1(%rip),%r14
mov    0x2b5b(%rip),%rcx
cmp    (%rcx),%rax
je     1360 <list_dir+0x160>
lea    0xbbc(%rip),%r14
mov    0x2b4c(%rip),%rcx
cmp    (%rcx),%rax
je     1360 <list_dir+0x160>
mov    0x2b24(%rip),%rcx
cmp    (%rcx),%rax
lea    0xb8c(%rip),%r14
lea    0xb96(%rip),%rax
cmove  %rax,%r14
jmp    1360 <list_dir+0x160>
mov    0x68(%rsp),%edi
call   1120 <pretty_print_mode@plt>
cltq
mov    %rax,0x30(%rsp)
mov    0x58(%rsp),%rax
mov    %rax,0x40(%rsp)
mov    0x60(%rsp),%rax
mov    %rax,0x28(%rsp)
lea    0x54(%rsp),%rdi
call   1060 <ctime@plt>
mov    %eax,%r13d
lea    0x50(%rsp),%rdi
call   1060 <ctime@plt>
mov    %rax,0x38(%rsp)
lea    0x4c(%rsp),%rdi
call   1060 <ctime@plt>
mov    %rbp,%rbx
mov    %eax,%r15d
mov    0x48(%rsp),%edi
call   10d0 <pretty_print_size@plt>
mov    %rax,%rbp
lea    0xb2c(%rip),%rdi
mov    %r14,%rsi
mov    0x30(%rsp),%rdx
mov    0x28(%rsp),%rcx
mov    0x40(%rsp),%r8
mov    %r13d,%r9d
lea    0xe0(%rsp),%r13
xor    %eax,%eax
push   %r13
push   %rbp
push   %r15
mov    %rbx,%rbp
mov    0x34(%rsp),%r15d
mov    0x38(%rsp),%rbx
push   0x50(%rsp)
call   1080 <printf@plt>
add    $0x20,%rsp
mov    0x8(%r12),%rax
mov    0x2a75(%rip),%rcx
cmp    (%rcx),%rax
jne    13a9 <list_dir+0x1a9>
lea    0xafc(%rip),%rdi
mov    %r13,%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     13a9 <list_dir+0x1a9>
mov    %r13,%rdi
mov    0xc(%rsp),%esi
call   10f0 <list_dir@plt>
jmp    13a9 <list_dir+0x1a9>
mov    0x10(%rsp),%rdi
call   10a0 <closedir@plt>
add    $0x148,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2a23(%rip),%rax
mov    (%rax),%edi
lea    0xa44(%rip),%rsi
lea    0x70(%rsp),%rdx
call   10c0 <fprintf@plt>
lea    0xa51(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8*, i64 }
%struct.stat = type { i32, i32, i32, i32, i64, i64, i32 }
@.str = [2 x i8] c"/\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Error: unable to open dir %s\0A\00"
@.str.2 = [10 x i8] c"opendir()\00"
@.str.3 = [2 x i8] c"?\00"
@.str.4 = [3 x i8] c"..\00"
@.str.5 = [2 x i8] c".\00"
@DT_REG = global i64 0
@.str.6 = [2 x i8] c"-\00"
@DT_FIFO = global i64 0
@.str.7 = [2 x i8] c"F\00"
@DT_SOCK = global i64 0
@.str.8 = [2 x i8] c"S\00"
@DT_CHR = global i64 0
@.str.9 = [2 x i8] c"c\00"
@DT_BLK = global i64 0
@.str.10 = [2 x i8] c"b\00"
@DT_DIR = global i64 0
@.str.11 = [2 x i8] c"d\00"
@DT_LNK = global i64 0
@.str.12 = [2 x i8] c"l\00"
@.str.13 = [42 x i8] c"%s%s %ld:%ld %.19s %.19s %.19s %s\09%s\0A\00"
@.str.14 = [5 x i8] c"/sys\00"
@.str.15 = [45 x i8] c"%s????????? ?:? %.19s %.19s %.19s %s\09%s\0A\00"
define void @list_dir(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca [100 x i8]
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca [100 x i8]
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca %struct.stat
%13 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%14 = bitcast [100 x i8]* %5 to i8*
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%16 = load i8*, i8** %3
%17 = call i32 @strncpy(i8* %15, i8* %16, i32 100)
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = sub nsw i32 %19, 1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 %21
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 47
br i1 %25, label %26, label %29
26: ; preds = %2
%27 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%28 = call i32 @strncat(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 100)
br label %29
29: ; preds = %26, %2
%30 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%31 = call i32* @opendir(i8* %30)
store i32* %31, i32** %6
%32 = load i32*, i32** %6
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %40
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %36)
%38 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %29
%41 = bitcast [100 x i8]* %8 to i8*
%42 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%43 = getelementptr inbounds [100 x i8], [100 x i8]* %5, i64 0, i64 0
%44 = call i32 @strncpy(i8* %42, i8* %43, i32 100)
%45 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%46 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%47 = call i32 @strlen(i8* %46)
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %45, i64 %48
store i8* %49, i8** %9
%50 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%51 = call i32 @strlen(i8* %50)
%52 = sext i32 %51 to i64
%53 = sub i64 100, %52
%54 = trunc i64 %53 to i32
store i32 %54, i32* %10
br label %55
55: ; preds = %181, %71, %40
%56 = load i32*, i32** %6
%57 = call %struct.dirent* @readdir(i32* %56)
store %struct.dirent* %57, %struct.dirent** %7
%58 = icmp ne %struct.dirent* %57, null
br i1 %58, label %59, label %182
59: ; preds = %55
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8** %11
%60 = load %struct.dirent*, %struct.dirent** %7
%61 = getelementptr inbounds %struct.dirent, %struct.dirent* %60, i32 0, i32 0
%62 = load i8*, i8** %61
%63 = call i64 @strncmp(i8* %62, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%64 = icmp eq i64 %63, 0
br i1 %64, label %71, label %65
65: ; preds = %59
%66 = load %struct.dirent*, %struct.dirent** %7
%67 = getelementptr inbounds %struct.dirent, %struct.dirent* %66, i32 0, i32 0
%68 = load i8*, i8** %67
%69 = call i64 @strncmp(i8* %68, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %65, %59
br label %55
72: ; preds = %65
%73 = load i8*, i8** %9
%74 = load %struct.dirent*, %struct.dirent** %7
%75 = getelementptr inbounds %struct.dirent, %struct.dirent* %74, i32 0, i32 0
%76 = load i8*, i8** %75
%77 = load i32, i32* %10
%78 = call i32 @strncpy(i8* %73, i8* %76, i32 %77)
%79 = load %struct.dirent*, %struct.dirent** %7
%80 = getelementptr inbounds %struct.dirent, %struct.dirent* %79, i32 0, i32 1
%81 = load i64, i64* %80
%82 = load i64, i64* @DT_REG
%83 = icmp eq i64 %81, %82
br i1 %83, label %84, label %85
84: ; preds = %72
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i8** %11
br label %133
85: ; preds = %72
%86 = load %struct.dirent*, %struct.dirent** %7
%87 = getelementptr inbounds %struct.dirent, %struct.dirent* %86, i32 0, i32 1
%88 = load i64, i64* %87
%89 = load i64, i64* @DT_FIFO
%90 = icmp eq i64 %88, %89
br i1 %90, label %91, label %92
91: ; preds = %85
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), i8** %11
br label %132
92: ; preds = %85
%93 = load %struct.dirent*, %struct.dirent** %7
%94 = getelementptr inbounds %struct.dirent, %struct.dirent* %93, i32 0, i32 1
%95 = load i64, i64* %94
%96 = load i64, i64* @DT_SOCK
%97 = icmp eq i64 %95, %96
br i1 %97, label %98, label %99
98: ; preds = %92
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i8** %11
br label %131
99: ; preds = %92
%100 = load %struct.dirent*, %struct.dirent** %7
%101 = getelementptr inbounds %struct.dirent, %struct.dirent* %100, i32 0, i32 1
%102 = load i64, i64* %101
%103 = load i64, i64* @DT_CHR
%104 = icmp eq i64 %102, %103
br i1 %104, label %105, label %106
105: ; preds = %99
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), i8** %11
br label %130
106: ; preds = %99
%107 = load %struct.dirent*, %struct.dirent** %7
%108 = getelementptr inbounds %struct.dirent, %struct.dirent* %107, i32 0, i32 1
%109 = load i64, i64* %108
%110 = load i64, i64* @DT_BLK
%111 = icmp eq i64 %109, %110
br i1 %111, label %112, label %113
112: ; preds = %106
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), i8** %11
br label %129
113: ; preds = %106
%114 = load %struct.dirent*, %struct.dirent** %7
%115 = getelementptr inbounds %struct.dirent, %struct.dirent* %114, i32 0, i32 1
%116 = load i64, i64* %115
%117 = load i64, i64* @DT_DIR
%118 = icmp eq i64 %116, %117
br i1 %118, label %119, label %120
119: ; preds = %113
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), i8** %11
br label %128
120: ; preds = %113
%121 = load %struct.dirent*, %struct.dirent** %7
%122 = getelementptr inbounds %struct.dirent, %struct.dirent* %121, i32 0, i32 1
%123 = load i64, i64* %122
%124 = load i64, i64* @DT_LNK
%125 = icmp eq i64 %123, %124
br i1 %125, label %126, label %127
126: ; preds = %120
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0), i8** %11
br label %127
127: ; preds = %126, %120
br label %128
128: ; preds = %127, %119
br label %129
129: ; preds = %128, %112
br label %130
130: ; preds = %129, %105
br label %131
131: ; preds = %130, %98
br label %132
132: ; preds = %131, %91
br label %133
133: ; preds = %132, %84
%134 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%135 = call i32 @lstat(i8* %134, %struct.stat* %12)
store i32 %135, i32* %13
%136 = load i32, i32* %13
%137 = icmp eq i32 %136, 0
br i1 %137, label %138, label %174
138: ; preds = %133
%139 = load i8*, i8** %11
%140 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 6
%141 = load i32, i32* %140
%142 = call i32 @pretty_print_mode(i32 %141)
%143 = sext i32 %142 to i64
%144 = inttoptr i64 %143 to i8*
%145 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 5
%146 = load i64, i64* %145
%147 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 4
%148 = load i64, i64* %147
%149 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 3
%150 = call i32 @ctime(i32* %149)
%151 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 2
%152 = call i32 @ctime(i32* %151)
%153 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 1
%154 = call i32 @ctime(i32* %153)
%155 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%156 = load i32, i32* %155
%157 = call i8* @pretty_print_size(i32 %156)
%158 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%159 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.13, i64 0, i64 0), i8* %139, i8* %144, i64 %146, i64 %148, i32 %150, i32 %152, i32 %154, i8* %157, i8* %158)
%160 = load %struct.dirent*, %struct.dirent** %7
%161 = getelementptr inbounds %struct.dirent, %struct.dirent* %160, i32 0, i32 1
%162 = load i64, i64* %161
%163 = load i64, i64* @DT_DIR
%164 = icmp eq i64 %162, %163
br i1 %164, label %165, label %173
165: ; preds = %138
%166 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%167 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0), i8* %166, i32 4)
%168 = icmp ne i64 %167, 0
br i1 %168, label %169, label %173
169: ; preds = %165
%170 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%171 = load i32, i32* %4
%172 = add nsw i32 %171, 1
br label %173
173: ; preds = %169, %165, %138
br label %181
174: ; preds = %133
%175 = load i8*, i8** %11
%176 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%177 = load i32, i32* %176
%178 = call i8* @pretty_print_size(i32 %177)
%179 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%180 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.15, i64 0, i64 0), i8* %175, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %178, i8* %179)
br label %181
181: ; preds = %174, %173
br label %55
182: ; preds = %55
%183 = load i32*, i32** %6
%184 = call i32 @closedir(i32* %183)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32, i32, i64, i64, i32 }
%struct.dirent = type { i8*, i64 }
@.str = [2 x i8] c"/\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"Error: unable to open dir %s\0A\00"
@.str.2 = [10 x i8] c"opendir()\00"
@.str.3 = [2 x i8] c"?\00"
@.str.4 = [3 x i8] c"..\00"
@.str.5 = [2 x i8] c".\00"
@DT_REG = global i64 0
@.str.6 = [2 x i8] c"-\00"
@DT_FIFO = global i64 0
@.str.7 = [2 x i8] c"F\00"
@DT_SOCK = global i64 0
@.str.8 = [2 x i8] c"S\00"
@DT_CHR = global i64 0
@.str.9 = [2 x i8] c"c\00"
@DT_BLK = global i64 0
@.str.10 = [2 x i8] c"b\00"
@DT_DIR = global i64 0
@.str.11 = [2 x i8] c"d\00"
@DT_LNK = global i64 0
@.str.12 = [2 x i8] c"l\00"
@.str.13 = [42 x i8] c"%s%s %ld:%ld %.19s %.19s %.19s %s\09%s\0A\00"
@.str.14 = [5 x i8] c"/sys\00"
@.str.15 = [45 x i8] c"%s????????? ?:? %.19s %.19s %.19s %s\09%s\0A\00"
define void @list_dir(i8* %0, i32 %1) {
%3 = alloca [100 x i8]
%4 = alloca [100 x i8]
%5 = alloca %struct.stat
%6 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%7 = call i32 @strncpy(i8* %6, i8* %0, i32 100)
%8 = call i32 @strlen(i8* %6)
%9 = add nsw i32 %8, -1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 47
br i1 %13, label %16, label %14
14: ; preds = %2
%15 = call i32 @strncat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 100)
br label %16
16: ; preds = %14, %2
%17 = call i32* @opendir(i8* %6)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %24
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%22 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %16
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%26 = call i32 @strncpy(i8* %25, i8* %6, i32 100)
%27 = call i32 @strlen(i8* %25)
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 %28
%30 = call i32 @strlen(i8* %25)
%31 = sub i32 100, %30
%32 = call %struct.dirent* @readdir(i32* %17)
%33 = icmp eq %struct.dirent* %32, null
br i1 %33, label %112, label %34
34: ; preds = %24
%35 = bitcast %struct.stat* %5 to i8*
%36 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%37 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 6
%38 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 5
%39 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 4
%40 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 3
%41 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 2
%42 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 1
%43 = add nsw i32 %1, 1
br label %44
44: ; preds = %34, %109
%45 = phi %struct.dirent* [ %32, %34 ], [ %110, %109 ]
%46 = getelementptr inbounds %struct.dirent, %struct.dirent* %45, i64 0, i32 0
%47 = load i8*, i8** %46
%48 = call i64 @strncmp(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i32 2)
%49 = icmp eq i64 %48, 0
br i1 %49, label %109, label %50
50: ; preds = %44
%51 = load i8*, i8** %46
%52 = call i64 @strncmp(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i32 1)
%53 = icmp eq i64 %52, 0
br i1 %53, label %109, label %54
54: ; preds = %50
%55 = load i8*, i8** %46
%56 = call i32 @strncpy(i8* %29, i8* %55, i32 %31)
%57 = getelementptr inbounds %struct.dirent, %struct.dirent* %45, i64 0, i32 1
%58 = load i64, i64* %57
%59 = load i64, i64* @DT_REG
%60 = icmp eq i64 %58, %59
br i1 %60, label %80, label %61
61: ; preds = %54
%62 = load i64, i64* @DT_FIFO
%63 = icmp eq i64 %58, %62
br i1 %63, label %80, label %64
64: ; preds = %61
%65 = load i64, i64* @DT_SOCK
%66 = icmp eq i64 %58, %65
br i1 %66, label %80, label %67
67: ; preds = %64
%68 = load i64, i64* @DT_CHR
%69 = icmp eq i64 %58, %68
br i1 %69, label %80, label %70
70: ; preds = %67
%71 = load i64, i64* @DT_BLK
%72 = icmp eq i64 %58, %71
br i1 %72, label %80, label %73
73: ; preds = %70
%74 = load i64, i64* @DT_DIR
%75 = icmp eq i64 %58, %74
br i1 %75, label %80, label %76
76: ; preds = %73
%77 = load i64, i64* @DT_LNK
%78 = icmp eq i64 %58, %77
%79 = select i1 %78, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0)
br label %80
80: ; preds = %76, %73, %70, %67, %64, %61, %54
%81 = phi i8* [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), %54 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0), %61 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), %64 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0), %67 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0), %70 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0), %73 ], [ %79, %76 ]
%82 = call i32 @lstat(i8* %25, %struct.stat* %5)
%83 = icmp eq i32 %82, 0
br i1 %83, label %84, label %104
84: ; preds = %80
%85 = load i32, i32* %37
%86 = call i32 @pretty_print_mode(i32 %85)
%87 = sext i32 %86 to i64
%88 = inttoptr i64 %87 to i8*
%89 = load i64, i64* %38
%90 = load i64, i64* %39
%91 = call i32 @ctime(i32* %40)
%92 = call i32 @ctime(i32* %41)
%93 = call i32 @ctime(i32* %42)
%94 = load i32, i32* %36
%95 = call i8* @pretty_print_size(i32 %94)
%96 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.13, i64 0, i64 0), i8* %81, i8* %88, i64 %89, i64 %90, i32 %91, i32 %92, i32 %93, i8* %95, i8* %25)
%97 = load i64, i64* %57
%98 = load i64, i64* @DT_DIR
%99 = icmp eq i64 %97, %98
br i1 %99, label %100, label %108
100: ; preds = %84
%101 = call i64 @strncmp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.14, i64 0, i64 0), i8* %25, i32 4)
%102 = icmp eq i64 %101, 0
br i1 %102, label %108, label %103
103: ; preds = %100
br label %108
104: ; preds = %80
%105 = load i32, i32* %36
%106 = call i8* @pretty_print_size(i32 %105)
%107 = call i32 (i8*, i8*, i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.15, i64 0, i64 0), i8* %81, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0), i8* %106, i8* %25)
br label %108
108: ; preds = %84, %100, %103, %104
br label %109
109: ; preds = %44, %50, %108
%110 = call %struct.dirent* @readdir(i32* %17)
%111 = icmp eq %struct.dirent* %110, null
br i1 %111, label %112, label %44
112: ; preds = %109, %24
%113 = call i32 @closedir(i32* %17)
ret void
}