#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 st_mode;
  int st_ino;
  int st_size;
  int /*<<< orphan*/ st_rdev;
};
struct dirent {
  scalar_t__ d_ino;
  char *d_name;
};
typedef int /*<<< orphan*/ buf;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int S_IFMT;
scalar_t__ S_ISBLK(int);
scalar_t__ S_ISCHR(int);
scalar_t__ S_ISDIR(int);
scalar_t__ S_ISFIFO(int);
scalar_t__ S_ISLNK(int);
scalar_t__ S_ISREG(int);
scalar_t__ S_ISSOCK(int);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int major(int /*<<< orphan*/);
int minor(int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ strcat(char *, char *);
char *strdup(char *);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int main(int argc, char *argv[]) {
  DIR *d;
  struct dirent *dir;
  char *path, buf[512];
  struct stat st;
  if (argc < 2) {
    path = strdup(".");
  } else {
    path = strdup(argv[1]);
  }
  if (stat(path, &st) < 0) {
    printf("ls: cannot stat %s\n", path);
    return 1;
  }
  if (S_ISFIFO(st.st_mode)) {
    printf("%s, pipe, mode: %o, inode: %d, size: %d\n", path,
           st.st_mode & ~S_IFMT, st.st_ino, st.st_size);
  } else if (S_ISCHR(st.st_mode)) {
    printf("%s, char device, mode:%o, inode:%d, major:%d, minor:%d\n", path,
           st.st_mode & ~S_IFMT, st.st_ino, major(st.st_rdev),
           minor(st.st_rdev));
  } else if (S_ISBLK(st.st_mode)) {
    printf("%s, block device, mode:%o, inode:%d, major:%d, minor:%d\n", path,
           st.st_mode & ~S_IFMT, st.st_ino, major(st.st_rdev),
           minor(st.st_rdev));
  } else if (S_ISREG(st.st_mode)) {
    printf("%s, regular, mode:%o, inode:%d size:%d\n", path,
           st.st_mode & ~S_IFMT, st.st_ino, st.st_size);
  } else if (S_ISDIR(st.st_mode)) {
    printf("type ino  size   name\n");
    if (!(d = opendir(path))) {
      printf("cannot open %s\n", path);
    }
    while ((dir = readdir(d))) {
      if (dir->d_ino == 0)
        continue;
      strncpy(buf, path, sizeof(buf) - 1);
      strcat(buf, "/");
      strncat(buf, dir->d_name, sizeof(buf) - 1 - strlen(buf) - 1);
      if (stat(buf, &st) < 0) {
        printf("ls: cannot stat %s\n", buf);
        continue;
      }
      if (S_ISFIFO(st.st_mode))
        printf("f");
      else if (S_ISCHR(st.st_mode))
        printf("c");
      else if (S_ISDIR(st.st_mode))
        printf("d");
      else if (S_ISBLK(st.st_mode))
        printf("b");
      else if (S_ISREG(st.st_mode))
        printf("-");
      else if (S_ISLNK(st.st_mode))
        printf("l");
      else if (S_ISSOCK(st.st_mode))
        printf("s");
      printf("    %-4d %-6d %s\n", st.st_ino, st.st_size, dir->d_name);
    }
    closedir(d);
    return 0;
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x280,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1268 <main+0x38>
lea    0xda6(%rip),%rdi
call   1150 <strdup@plt>
mov    %rax,-0x28(%rbp)
jmp    1279 <main+0x49>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1150 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
lea    -0x240(%rbp),%rsi
call   10f0 <stat@plt>
cmp    $0x0,%rax
jge    12b1 <main+0x81>
mov    -0x28(%rbp),%rsi
lea    0xd64(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1717 <main+0x4e7>
mov    -0x240(%rbp),%edi
call   1080 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     12fe <main+0xce>
mov    -0x28(%rbp),%rsi
mov    -0x240(%rbp),%edx
mov    0x2d09(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
mov    -0x23c(%rbp),%ecx
mov    -0x238(%rbp),%r8d
lea    0xd24(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    1717 <main+0x4e7>
mov    -0x240(%rbp),%edi
call   1120 <S_ISCHR@plt>
cmp    $0x0,%rax
je     1390 <main+0x160>
mov    -0x28(%rbp),%rax
mov    %rax,-0x258(%rbp)
mov    -0x240(%rbp),%eax
mov    0x2cb5(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x24c(%rbp)
mov    -0x23c(%rbp),%eax
mov    %eax,-0x248(%rbp)
mov    -0x234(%rbp),%edi
call   10c0 <major@plt>
mov    %eax,-0x244(%rbp)
mov    -0x234(%rbp),%edi
call   1060 <minor@plt>
mov    -0x258(%rbp),%rsi
mov    -0x24c(%rbp),%edx
mov    -0x248(%rbp),%ecx
mov    -0x244(%rbp),%r8d
mov    %eax,%r9d
lea    0xcbb(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    1712 <main+0x4e2>
mov    -0x240(%rbp),%edi
call   1130 <S_ISBLK@plt>
cmp    $0x0,%rax
je     1422 <main+0x1f2>
mov    -0x28(%rbp),%rax
mov    %rax,-0x270(%rbp)
mov    -0x240(%rbp),%eax
mov    0x2c23(%rip),%rcx
mov    (%rcx),%ecx
xor    $0xffffffff,%ecx
and    %ecx,%eax
mov    %eax,-0x264(%rbp)
mov    -0x23c(%rbp),%eax
mov    %eax,-0x260(%rbp)
mov    -0x234(%rbp),%edi
call   10c0 <major@plt>
mov    %eax,-0x25c(%rbp)
mov    -0x234(%rbp),%edi
call   1060 <minor@plt>
mov    -0x270(%rbp),%rsi
mov    -0x264(%rbp),%edx
mov    -0x260(%rbp),%ecx
mov    -0x25c(%rbp),%r8d
mov    %eax,%r9d
lea    0xc61(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    170d <main+0x4dd>
mov    -0x240(%rbp),%edi
call   1100 <S_ISREG@plt>
cmp    $0x0,%rax
je     146f <main+0x23f>
mov    -0x28(%rbp),%rsi
mov    -0x240(%rbp),%edx
mov    0x2b98(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%edx
mov    -0x23c(%rbp),%ecx
mov    -0x238(%rbp),%r8d
lea    0xc4d(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    1708 <main+0x4d8>
mov    -0x240(%rbp),%edi
call   10b0 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1703 <main+0x4d3>
lea    0xc4d(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    14bb <main+0x28b>
mov    -0x28(%rbp),%rsi
lea    0xc3b(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    14c0 <main+0x290>
mov    -0x18(%rbp),%rdi
call   1110 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     16ee <main+0x4be>
mov    -0x20(%rbp),%rax
cmpq   $0x0,(%rax)
jne    14ea <main+0x2ba>
jmp    14c0 <main+0x290>
lea    -0x230(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    $0x1ff,%edx
call   1030 <strncpy@plt>
lea    -0x230(%rbp),%rdi
lea    0xbf2(%rip),%rsi
call   1140 <strcat@plt>
lea    -0x230(%rbp),%rax
mov    %rax,-0x280(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x278(%rbp)
lea    -0x230(%rbp),%rdi
call   1070 <strlen@plt>
mov    -0x280(%rbp),%rdi
mov    -0x278(%rbp),%rsi
movslq %eax,%rcx
mov    $0x1ff,%eax
sub    %rcx,%rax
sub    $0x1,%rax
mov    %eax,%edx
call   10d0 <strncat@plt>
lea    -0x230(%rbp),%rdi
lea    -0x240(%rbp),%rsi
call   10f0 <stat@plt>
cmp    $0x0,%rax
jge    1596 <main+0x366>
lea    -0x230(%rbp),%rsi
lea    0xa78(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    14c0 <main+0x290>
mov    -0x240(%rbp),%edi
call   1080 <S_ISFIFO@plt>
cmp    $0x0,%rax
je     15be <main+0x38e>
lea    0xb4f(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    16c7 <main+0x497>
mov    -0x240(%rbp),%edi
call   1120 <S_ISCHR@plt>
cmp    $0x0,%rax
je     15e6 <main+0x3b6>
lea    0xb29(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    16c2 <main+0x492>
mov    -0x240(%rbp),%edi
call   10b0 <S_ISDIR@plt>
cmp    $0x0,%rax
je     160e <main+0x3de>
lea    0xb03(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    16bd <main+0x48d>
mov    -0x240(%rbp),%edi
call   1130 <S_ISBLK@plt>
cmp    $0x0,%rax
je     1636 <main+0x406>
lea    0xadd(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    16b8 <main+0x488>
mov    -0x240(%rbp),%edi
call   1100 <S_ISREG@plt>
cmp    $0x0,%rax
je     165e <main+0x42e>
lea    0xab7(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    16b3 <main+0x483>
mov    -0x240(%rbp),%edi
call   1040 <S_ISLNK@plt>
cmp    $0x0,%rax
je     1686 <main+0x456>
lea    0xa91(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    16ae <main+0x47e>
mov    -0x240(%rbp),%edi
call   1090 <S_ISSOCK@plt>
cmp    $0x0,%rax
je     16a9 <main+0x479>
lea    0xa6b(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    16ae <main+0x47e>
jmp    16b3 <main+0x483>
jmp    16b8 <main+0x488>
jmp    16bd <main+0x48d>
jmp    16c2 <main+0x492>
jmp    16c7 <main+0x497>
mov    -0x23c(%rbp),%esi
mov    -0x238(%rbp),%edx
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xa2d(%rip),%rdi
mov    $0x0,%al
call   10a0 <printf@plt>
jmp    14c0 <main+0x290>
mov    -0x18(%rbp),%rdi
call   10e0 <closedir@plt>
movl   $0x0,-0x4(%rbp)
jmp    1717 <main+0x4e7>
jmp    1708 <main+0x4d8>
jmp    170d <main+0x4dd>
jmp    1712 <main+0x4e2>
jmp    1717 <main+0x4e7>
mov    -0x4(%rbp),%eax
add    $0x280,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
cmp    $0x1,%edi
jg     126f <main+0x1f>
lea    0xd93(%rip),%rdi
jmp    1273 <main+0x23>
mov    0x8(%rsi),%rdi
call   1170 <strdup@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1110 <stat@plt>
test   %rax,%rax
js     12ca <main+0x7a>
mov    (%rsp),%edi
call   10a0 <S_ISFIFO@plt>
mov    (%rsp),%edx
test   %rax,%rax
je     12e6 <main+0x96>
mov    0x2d3e(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,%edx
mov    0x4(%rsp),%ecx
mov    0x8(%rsp),%r8d
lea    0xd5e(%rip),%rdi
xor    %r13d,%r13d
mov    %rbx,%rsi
xor    %eax,%eax
call   10c0 <printf@plt>
jmp    137a <main+0x12a>
lea    0xd31(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10c0 <printf@plt>
mov    $0x1,%r13d
jmp    137a <main+0x12a>
mov    %edx,%edi
call   1140 <S_ISCHR@plt>
mov    (%rsp),%ebp
test   %rax,%rax
je     1325 <main+0xd5>
mov    0x2ce4(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,%ebp
mov    0x4(%rsp),%r14d
mov    0xc(%rsp),%edi
call   10e0 <major@plt>
mov    %eax,%r15d
mov    0xc(%rsp),%edi
call   1080 <minor@plt>
lea    0xd1c(%rip),%rdi
jmp    1362 <main+0x112>
mov    %ebp,%edi
call   1150 <S_ISBLK@plt>
mov    (%rsp),%ebp
test   %rax,%rax
je     138f <main+0x13f>
mov    0x2ca5(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,%ebp
mov    0x4(%rsp),%r14d
mov    0xc(%rsp),%edi
call   10e0 <major@plt>
mov    %eax,%r15d
mov    0xc(%rsp),%edi
call   1080 <minor@plt>
lea    0xd15(%rip),%rdi
xor    %r13d,%r13d
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %r14d,%ecx
mov    %r15d,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   10c0 <printf@plt>
mov    %r13d,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebp,%edi
call   1120 <S_ISREG@plt>
mov    (%rsp),%edx
test   %rax,%rax
je     13c0 <main+0x170>
mov    0x2c3b(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,%edx
mov    0x4(%rsp),%ecx
mov    0x8(%rsp),%r8d
lea    0xcf5(%rip),%rdi
jmp    12b8 <main+0x68>
mov    %edx,%edi
call   10d0 <S_ISDIR@plt>
xor    %r13d,%r13d
test   %rax,%rax
je     137a <main+0x12a>
lea    0xd26(%rip),%rdi
call   1060 <puts@plt>
mov    %rbx,%rdi
call   1070 <opendir@plt>
mov    %rax,%r14
test   %rax,%rax
jne    13fc <main+0x1ac>
lea    0xce6(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10c0 <printf@plt>
mov    %r14,%rdi
call   1130 <readdir@plt>
test   %rax,%rax
je     1534 <main+0x2e4>
mov    %rax,%r12
lea    0x10(%rsp),%r15
jmp    143c <main+0x1ec>
lea    0xbe4(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   10c0 <printf@plt>
mov    %r14,%rdi
call   1130 <readdir@plt>
mov    %rax,%r12
test   %rax,%rax
je     1534 <main+0x2e4>
cmpq   $0x0,(%r12)
je     1428 <main+0x1d8>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x1ff,%edx
call   1040 <strncpy@plt>
mov    %r15,%rdi
lea    0xc8b(%rip),%rsi
call   1160 <strcat@plt>
mov    0x8(%r12),%rbp
mov    %r15,%rdi
call   1090 <strlen@plt>
mov    $0x1fe,%edx
sub    %eax,%edx
mov    %r15,%rdi
mov    %rbp,%rsi
call   10f0 <strncat@plt>
mov    %r15,%rdi
mov    %rsp,%rsi
call   1110 <stat@plt>
test   %rax,%rax
js     1417 <main+0x1c7>
mov    (%rsp),%edi
call   10a0 <S_ISFIFO@plt>
mov    $0x66,%edi
test   %rax,%rax
jne    150f <main+0x2bf>
mov    (%rsp),%edi
call   1140 <S_ISCHR@plt>
mov    $0x63,%edi
test   %rax,%rax
jne    150f <main+0x2bf>
mov    (%rsp),%edi
call   10d0 <S_ISDIR@plt>
mov    $0x64,%edi
test   %rax,%rax
jne    150f <main+0x2bf>
mov    (%rsp),%edi
call   1150 <S_ISBLK@plt>
mov    $0x62,%edi
test   %rax,%rax
jne    150f <main+0x2bf>
mov    (%rsp),%edi
call   1120 <S_ISREG@plt>
mov    $0x2d,%edi
test   %rax,%rax
jne    150f <main+0x2bf>
mov    (%rsp),%edi
call   1050 <S_ISLNK@plt>
mov    $0x6c,%edi
test   %rax,%rax
jne    150f <main+0x2bf>
mov    (%rsp),%edi
call   10b0 <S_ISSOCK@plt>
mov    $0x73,%edi
test   %rax,%rax
je     1514 <main+0x2c4>
call   1030 <putchar@plt>
mov    0x4(%rsp),%esi
mov    0x8(%rsp),%edx
mov    0x8(%r12),%rcx
lea    0xbc2(%rip),%rdi
xor    %eax,%eax
call   10c0 <printf@plt>
jmp    1428 <main+0x1d8>
mov    %r14,%rdi
call   1100 <closedir@plt>
jmp    137a <main+0x12a>

LLVM IR (-O0):
%struct.dirent = type { i64, i8* }
%struct.stat = type { i32, i32, i32, i32 }
@.str = [2 x i8] c".\00"
@.str.1 = [20 x i8] c"ls: cannot stat %s\0A\00"
@.str.2 = [41 x i8] c"%s, pipe, mode: %o, inode: %d, size: %d\0A\00"
@S_IFMT = global i32 0
@.str.3 = [56 x i8] c"%s, char device, mode:%o, inode:%d, major:%d, minor:%d\0A\00"
@.str.4 = [57 x i8] c"%s, block device, mode:%o, inode:%d, major:%d, minor:%d\0A\00"
@.str.5 = [40 x i8] c"%s, regular, mode:%o, inode:%d size:%d\0A\00"
@.str.6 = [23 x i8] c"type ino size name\0A\00"
@.str.7 = [16 x i8] c"cannot open %s\0A\00"
@.str.8 = [2 x i8] c"/\00"
@.str.9 = [2 x i8] c"f\00"
@.str.10 = [2 x i8] c"c\00"
@.str.11 = [2 x i8] c"d\00"
@.str.12 = [2 x i8] c"b\00"
@.str.13 = [2 x i8] c"-\00"
@.str.14 = [2 x i8] c"l\00"
@.str.15 = [2 x i8] c"s\00"
@.str.16 = [18 x i8] c" %-4d %-6d %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca i8*
%9 = alloca [512 x i8]
%10 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %14, i8** %8
br label %20
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i8* @strdup(i8* %18)
store i8* %19, i8** %8
br label %20
20: ; preds = %15, %13
%21 = load i8*, i8** %8
%22 = call i64 @stat(i8* %21, %struct.stat* %10)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %20
%25 = load i8*, i8** %8
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %25)
store i32 1, i32* %3
br label %221
27: ; preds = %20
%28 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i64 @S_ISFIFO(i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %44
32: ; preds = %27
%33 = load i8*, i8** %8
%34 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%35 = load i32, i32* %34
%36 = load i32, i32* @S_IFMT
%37 = xor i32 %36, -1
%38 = and i32 %35, %37
%39 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 1
%40 = load i32, i32* %39
%41 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 2
%42 = load i32, i32* %41
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %33, i32 %38, i32 %40, i32 %42)
br label %221
44: ; preds = %27
%45 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%46 = load i32, i32* %45
%47 = call i64 @S_ISCHR(i32 %46)
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %65
49: ; preds = %44
%50 = load i8*, i8** %8
%51 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%52 = load i32, i32* %51
%53 = load i32, i32* @S_IFMT
%54 = xor i32 %53, -1
%55 = and i32 %52, %54
%56 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 1
%57 = load i32, i32* %56
%58 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 3
%59 = load i32, i32* %58
%60 = call i32 @major(i32 %59)
%61 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 3
%62 = load i32, i32* %61
%63 = call i32 @minor(i32 %62)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), i8* %50, i32 %55, i32 %57, i32 %60, i32 %63)
br label %220
65: ; preds = %44
%66 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%67 = load i32, i32* %66
%68 = call i64 @S_ISBLK(i32 %67)
%69 = icmp ne i64 %68, 0
br i1 %69, label %70, label %86
70: ; preds = %65
%71 = load i8*, i8** %8
%72 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%73 = load i32, i32* %72
%74 = load i32, i32* @S_IFMT
%75 = xor i32 %74, -1
%76 = and i32 %73, %75
%77 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 1
%78 = load i32, i32* %77
%79 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 3
%80 = load i32, i32* %79
%81 = call i32 @major(i32 %80)
%82 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 3
%83 = load i32, i32* %82
%84 = call i32 @minor(i32 %83)
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0), i8* %71, i32 %76, i32 %78, i32 %81, i32 %84)
br label %219
86: ; preds = %65
%87 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%88 = load i32, i32* %87
%89 = call i64 @S_ISREG(i32 %88)
%90 = icmp ne i64 %89, 0
br i1 %90, label %91, label %103
91: ; preds = %86
%92 = load i8*, i8** %8
%93 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%94 = load i32, i32* %93
%95 = load i32, i32* @S_IFMT
%96 = xor i32 %95, -1
%97 = and i32 %94, %96
%98 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 1
%99 = load i32, i32* %98
%100 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 2
%101 = load i32, i32* %100
%102 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* %92, i32 %97, i32 %99, i32 %101)
br label %218
103: ; preds = %86
%104 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%105 = load i32, i32* %104
%106 = call i64 @S_ISDIR(i32 %105)
%107 = icmp ne i64 %106, 0
br i1 %107, label %108, label %217
108: ; preds = %103
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.6, i64 0, i64 0))
%110 = load i8*, i8** %8
%111 = call i32* @opendir(i8* %110)
store i32* %111, i32** %6
%112 = icmp ne i32* %111, null
br i1 %112, label %116, label %113
113: ; preds = %108
%114 = load i8*, i8** %8
%115 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %114)
br label %116
116: ; preds = %113, %108
br label %117
117: ; preds = %205, %147, %126, %116
%118 = load i32*, i32** %6
%119 = call %struct.dirent* @readdir(i32* %118)
store %struct.dirent* %119, %struct.dirent** %7
%120 = icmp ne %struct.dirent* %119, null
br i1 %120, label %121, label %214
121: ; preds = %117
%122 = load %struct.dirent*, %struct.dirent** %7
%123 = getelementptr inbounds %struct.dirent, %struct.dirent* %122, i32 0, i32 0
%124 = load i64, i64* %123
%125 = icmp eq i64 %124, 0
br i1 %125, label %126, label %127
126: ; preds = %121
br label %117
127: ; preds = %121
%128 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%129 = load i8*, i8** %8
%130 = call i32 @strncpy(i8* %128, i8* %129, i32 511)
%131 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%132 = call i32 @strcat(i8* %131, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%133 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%134 = load %struct.dirent*, %struct.dirent** %7
%135 = getelementptr inbounds %struct.dirent, %struct.dirent* %134, i32 0, i32 1
%136 = load i8*, i8** %135
%137 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%138 = call i32 @strlen(i8* %137)
%139 = sext i32 %138 to i64
%140 = sub i64 511, %139
%141 = sub i64 %140, 1
%142 = trunc i64 %141 to i32
%143 = call i32 @strncat(i8* %133, i8* %136, i32 %142)
%144 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%145 = call i64 @stat(i8* %144, %struct.stat* %10)
%146 = icmp slt i64 %145, 0
br i1 %146, label %147, label %150
147: ; preds = %127
%148 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %148)
br label %117
150: ; preds = %127
%151 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%152 = load i32, i32* %151
%153 = call i64 @S_ISFIFO(i32 %152)
%154 = icmp ne i64 %153, 0
br i1 %154, label %155, label %157
155: ; preds = %150
%156 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
br label %205
157: ; preds = %150
%158 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%159 = load i32, i32* %158
%160 = call i64 @S_ISCHR(i32 %159)
%161 = icmp ne i64 %160, 0
br i1 %161, label %162, label %164
162: ; preds = %157
%163 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
br label %204
164: ; preds = %157
%165 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%166 = load i32, i32* %165
%167 = call i64 @S_ISDIR(i32 %166)
%168 = icmp ne i64 %167, 0
br i1 %168, label %169, label %171
169: ; preds = %164
%170 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
br label %203
171: ; preds = %164
%172 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%173 = load i32, i32* %172
%174 = call i64 @S_ISBLK(i32 %173)
%175 = icmp ne i64 %174, 0
br i1 %175, label %176, label %178
176: ; preds = %171
%177 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.12, i64 0, i64 0))
br label %202
178: ; preds = %171
%179 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%180 = load i32, i32* %179
%181 = call i64 @S_ISREG(i32 %180)
%182 = icmp ne i64 %181, 0
br i1 %182, label %183, label %185
183: ; preds = %178
%184 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
br label %201
185: ; preds = %178
%186 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%187 = load i32, i32* %186
%188 = call i64 @S_ISLNK(i32 %187)
%189 = icmp ne i64 %188, 0
br i1 %189, label %190, label %192
190: ; preds = %185
%191 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0))
br label %200
192: ; preds = %185
%193 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 0
%194 = load i32, i32* %193
%195 = call i64 @S_ISSOCK(i32 %194)
%196 = icmp ne i64 %195, 0
br i1 %196, label %197, label %199
197: ; preds = %192
%198 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.15, i64 0, i64 0))
br label %199
199: ; preds = %197, %192
br label %200
200: ; preds = %199, %190
br label %201
201: ; preds = %200, %183
br label %202
202: ; preds = %201, %176
br label %203
203: ; preds = %202, %169
br label %204
204: ; preds = %203, %162
br label %205
205: ; preds = %204, %155
%206 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 1
%207 = load i32, i32* %206
%208 = getelementptr inbounds %struct.stat, %struct.stat* %10, i32 0, i32 2
%209 = load i32, i32* %208
%210 = load %struct.dirent*, %struct.dirent** %7
%211 = getelementptr inbounds %struct.dirent, %struct.dirent* %210, i32 0, i32 1
%212 = load i8*, i8** %211
%213 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.16, i64 0, i64 0), i32 %207, i32 %209, i8* %212)
br label %117
214: ; preds = %117
%215 = load i32*, i32** %6
%216 = call i32 @closedir(i32* %215)
store i32 0, i32* %3
br label %221
217: ; preds = %103
br label %218
218: ; preds = %217, %91
br label %219
219: ; preds = %218, %70
br label %220
220: ; preds = %219, %49
br label %221
221: ; preds = %24, %214, %220, %32
%222 = load i32, i32* %3
ret i32 %222
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32, i32 }
%struct.dirent = type { i64, i8* }
@.str = [2 x i8] c".\00"
@.str.1 = [20 x i8] c"ls: cannot stat %s\0A\00"
@.str.2 = [41 x i8] c"%s, pipe, mode: %o, inode: %d, size: %d\0A\00"
@S_IFMT = global i32 0
@.str.3 = [56 x i8] c"%s, char device, mode:%o, inode:%d, major:%d, minor:%d\0A\00"
@.str.4 = [57 x i8] c"%s, block device, mode:%o, inode:%d, major:%d, minor:%d\0A\00"
@.str.5 = [40 x i8] c"%s, regular, mode:%o, inode:%d size:%d\0A\00"
@.str.7 = [16 x i8] c"cannot open %s\0A\00"
@.str.8 = [2 x i8] c"/\00"
@.str.16 = [18 x i8] c" %-4d %-6d %s\0A\00"
@str = [22 x i8] c"type ino size name\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call dereferenceable_or_null(2) i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %14
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i8* @strdup(i8* %12)
br label %14
14: ; preds = %10, %8
%15 = phi i8* [ %9, %8 ], [ %13, %10 ]
%16 = call i64 @stat(i8* %15, %struct.stat* %4)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %153
20: ; preds = %14
%21 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%22 = load i32, i32* %21
%23 = call i64 @S_ISFIFO(i32 %22)
%24 = icmp eq i64 %23, 0
%25 = load i32, i32* %21
br i1 %24, label %35, label %26
26: ; preds = %20
%27 = load i32, i32* @S_IFMT
%28 = xor i32 %27, -1
%29 = and i32 %25, %28
%30 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 2
%33 = load i32, i32* %32
%34 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i8* %15, i32 %29, i32 %31, i32 %33)
br label %153
35: ; preds = %20
%36 = call i64 @S_ISCHR(i32 %25)
%37 = icmp eq i64 %36, 0
%38 = load i32, i32* %21
br i1 %37, label %51, label %39
39: ; preds = %35
%40 = load i32, i32* @S_IFMT
%41 = xor i32 %40, -1
%42 = and i32 %38, %41
%43 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%44 = load i32, i32* %43
%45 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 3
%46 = load i32, i32* %45
%47 = call i32 @major(i32 %46)
%48 = load i32, i32* %45
%49 = call i32 @minor(i32 %48)
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0), i8* %15, i32 %42, i32 %44, i32 %47, i32 %49)
br label %153
51: ; preds = %35
%52 = call i64 @S_ISBLK(i32 %38)
%53 = icmp eq i64 %52, 0
%54 = load i32, i32* %21
br i1 %53, label %67, label %55
55: ; preds = %51
%56 = load i32, i32* @S_IFMT
%57 = xor i32 %56, -1
%58 = and i32 %54, %57
%59 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%60 = load i32, i32* %59
%61 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 3
%62 = load i32, i32* %61
%63 = call i32 @major(i32 %62)
%64 = load i32, i32* %61
%65 = call i32 @minor(i32 %64)
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @.str.4, i64 0, i64 0), i8* %15, i32 %58, i32 %60, i32 %63, i32 %65)
br label %153
67: ; preds = %51
%68 = call i64 @S_ISREG(i32 %54)
%69 = icmp eq i64 %68, 0
%70 = load i32, i32* %21
br i1 %69, label %80, label %71
71: ; preds = %67
%72 = load i32, i32* @S_IFMT
%73 = xor i32 %72, -1
%74 = and i32 %70, %73
%75 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%76 = load i32, i32* %75
%77 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 2
%78 = load i32, i32* %77
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i8* %15, i32 %74, i32 %76, i32 %78)
br label %153
80: ; preds = %67
%81 = call i64 @S_ISDIR(i32 %70)
%82 = icmp eq i64 %81, 0
br i1 %82, label %153, label %83
83: ; preds = %80
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%85 = call i32* @opendir(i8* %15)
%86 = icmp eq i32* %85, null
br i1 %86, label %87, label %89
87: ; preds = %83
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0), i8* %15)
br label %89
89: ; preds = %87, %83
%90 = call %struct.dirent* @readdir(i32* %85)
%91 = icmp eq %struct.dirent* %90, null
br i1 %91, label %151, label %92
92: ; preds = %89
%93 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%94 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 2
br label %95
95: ; preds = %92, %112
%96 = phi %struct.dirent* [ %90, %92 ], [ %113, %112 ]
%97 = getelementptr inbounds %struct.dirent, %struct.dirent* %96, i64 0, i32 0
%98 = load i64, i64* %97
%99 = icmp eq i64 %98, 0
br i1 %99, label %112, label %100
100: ; preds = %95
%101 = call i32 @strncpy(i8* %5, i8* %15, i32 511)
%102 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0))
%103 = getelementptr inbounds %struct.dirent, %struct.dirent* %96, i64 0, i32 1
%104 = load i8*, i8** %103
%105 = call i32 @strlen(i8* %5)
%106 = sub i32 510, %105
%107 = call i32 @strncat(i8* %5, i8* %104, i32 %106)
%108 = call i64 @stat(i8* %5, %struct.stat* %4)
%109 = icmp slt i64 %108, 0
br i1 %109, label %110, label %115
110: ; preds = %100
%111 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %112
112: ; preds = %110, %146, %95
%113 = call %struct.dirent* @readdir(i32* %85)
%114 = icmp eq %struct.dirent* %113, null
br i1 %114, label %151, label %95
115: ; preds = %100
%116 = load i32, i32* %21
%117 = call i64 @S_ISFIFO(i32 %116)
%118 = icmp eq i64 %117, 0
br i1 %118, label %119, label %143
119: ; preds = %115
%120 = load i32, i32* %21
%121 = call i64 @S_ISCHR(i32 %120)
%122 = icmp eq i64 %121, 0
br i1 %122, label %123, label %143
123: ; preds = %119
%124 = load i32, i32* %21
%125 = call i64 @S_ISDIR(i32 %124)
%126 = icmp eq i64 %125, 0
br i1 %126, label %127, label %143
127: ; preds = %123
%128 = load i32, i32* %21
%129 = call i64 @S_ISBLK(i32 %128)
%130 = icmp eq i64 %129, 0
br i1 %130, label %131, label %143
131: ; preds = %127
%132 = load i32, i32* %21
%133 = call i64 @S_ISREG(i32 %132)
%134 = icmp eq i64 %133, 0
br i1 %134, label %135, label %143
135: ; preds = %131
%136 = load i32, i32* %21
%137 = call i64 @S_ISLNK(i32 %136)
%138 = icmp eq i64 %137, 0
br i1 %138, label %139, label %143
139: ; preds = %135
%140 = load i32, i32* %21
%141 = call i64 @S_ISSOCK(i32 %140)
%142 = icmp eq i64 %141, 0
br i1 %142, label %146, label %143
143: ; preds = %139, %135, %131, %127, %123, %119, %115
%144 = phi i32 [ 102, %115 ], [ 99, %119 ], [ 100, %123 ], [ 98, %127 ], [ 45, %131 ], [ 108, %135 ], [ 115, %139 ]
%145 = call i32 @putchar(i32 %144)
br label %146
146: ; preds = %143, %139
%147 = load i32, i32* %93
%148 = load i32, i32* %94
%149 = load i8*, i8** %103
%150 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.16, i64 0, i64 0), i32 %147, i32 %148, i8* %149)
br label %112
151: ; preds = %112, %89
%152 = call i32 @closedir(i32* %85)
br label %153
153: ; preds = %26, %55, %80, %71, %39, %151, %18
%154 = phi i32 [ 1, %18 ], [ 0, %151 ], [ 0, %39 ], [ 0, %71 ], [ 0, %80 ], [ 0, %55 ], [ 0, %26 ]
ret i32 %154
}