#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 /*<<< orphan*/ st_mtime;
  int /*<<< orphan*/ st_gid;
  int /*<<< orphan*/ st_uid;
  scalar_t__ st_ino;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int S_IFDIR;
int S_IFMT;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
scalar_t__ file_pathcat(char *, char *, char *, int);
char *filetype(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *get_gnamebyid(int /*<<< orphan*/);
int /*<<< orphan*/ get_privileges(int, char *);
char *get_unamebyid(int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
int strlen(char *);
int listdir(int options, char *pathname) {
  DIR *dp;
  struct dirent *dirp;
  struct stat statbuf;
  char apathbuf[1024];
  if ((dp = opendir(pathname)) == NULL) {
    fprintf(stderr, "cann't open %s\n", pathname);
    return 1;
  }
  while ((dirp = readdir(dp)) != NULL) {
    if (!strcmp(dirp->d_name, "..") || !strcmp(dirp->d_name, "."))
      continue;
    if (!(options & (1 << (2)))) {
      if (dirp->d_name[0] == '.')
        continue;
    }
    if (file_pathcat(apathbuf, pathname, dirp->d_name, 1024)) {
      if (stat(apathbuf, &statbuf) != 0) {
        fprintf(stderr, "get failure:%s\n", strerror(errno));
        return 1;
      }
    } else {
    }
    if (options & (1 << (0)) || options & (1 << (1))) {
      if (options & (1 << (1)))
        printf("%d\t", (int)statbuf.st_ino);
      if (options & (1 << (0))) {
        char *uname, *gname, *mtime;
        int timelength;
        char privileges[10];
        get_privileges(statbuf.st_mode, privileges);
        printf("%s\t", filetype(statbuf.st_mode));
        printf("%s\t", privileges);
        if ((uname = get_unamebyid(statbuf.st_uid)) != NULL) {
          printf("%s\t", uname);
        }
        if ((gname = get_gnamebyid(statbuf.st_gid)) != NULL) {
          printf("%s\t", gname);
        }
        mtime = ctime(&statbuf.st_mtime);
        timelength = strlen(mtime);
        mtime[timelength - 1] = '\0';
        printf("%s\t", mtime);
      }
    }
    printf("%s", dirp->d_name);
    if ((statbuf.st_mode & S_IFMT) == S_IFDIR) {
      printf("/");
    }
    printf("\n");
  }
  closedir(dp);
  return 0;
}


x86 assembly (clang, -O0):
<listdir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    123e <listdir+0x4e>
mov    0x2db8(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdd3(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14ec <listdir+0x2fc>
jmp    1243 <listdir+0x53>
mov    -0x18(%rbp),%rdi
call   10d0 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     14dc <listdir+0x2ec>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xda8(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
je     1292 <listdir+0xa2>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xd8d(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%eax
jne    1297 <listdir+0xa7>
jmp    1243 <listdir+0x53>
mov    -0x8(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
jne    12c3 <listdir+0xd3>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    12be <listdir+0xce>
jmp    1243 <listdir+0x53>
jmp    12c3 <listdir+0xd3>
lea    -0x440(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%rdx
mov    $0x400,%ecx
call   10f0 <file_pathcat@plt>
cmp    $0x0,%rax
je     1346 <listdir+0x156>
lea    -0x440(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0x0,%rax
je     1341 <listdir+0x151>
mov    0x2cce(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x46c(%rbp)
mov    0x2cb7(%rip),%rax
mov    (%rax),%edi
call   1110 <strerror@plt>
mov    -0x46c(%rbp),%edi
mov    %rax,%rdx
lea    0xce3(%rip),%rsi
call   10a0 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14ec <listdir+0x2fc>
jmp    134b <listdir+0x15b>
jmp    134b <listdir+0x15b>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
jne    1369 <listdir+0x179>
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     148b <listdir+0x29b>
mov    -0x8(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     138c <listdir+0x19c>
mov    -0x28(%rbp),%rax
mov    %eax,%esi
lea    0xc9e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x8(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1486 <listdir+0x296>
mov    -0x38(%rbp),%edi
lea    -0x466(%rbp),%rsi
call   10c0 <get_privileges@plt>
mov    -0x38(%rbp),%edi
call   1030 <filetype@plt>
mov    %rax,%rsi
lea    0xc6b(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x466(%rbp),%rsi
lea    0xc56(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1100 <get_unamebyid@plt>
mov    %rax,-0x448(%rbp)
cmp    $0x0,%rax
je     1406 <listdir+0x216>
mov    -0x448(%rbp),%rsi
lea    0xc28(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x30(%rbp),%edi
call   10e0 <get_gnamebyid@plt>
mov    %rax,-0x450(%rbp)
cmp    $0x0,%rax
je     1434 <listdir+0x244>
mov    -0x450(%rbp),%rsi
lea    0xbfa(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x38(%rbp),%rdi
add    $0x4,%rdi
call   1050 <ctime@plt>
mov    %rax,-0x458(%rbp)
mov    -0x458(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x45c(%rbp)
mov    -0x458(%rbp),%rax
mov    -0x45c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x458(%rbp),%rsi
lea    0xba8(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    148b <listdir+0x29b>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xb92(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x38(%rbp),%eax
mov    0x2b36(%rip),%rcx
and    (%rcx),%eax
mov    0x2b0d(%rip),%rcx
cmp    (%rcx),%eax
jne    14c9 <listdir+0x2d9>
lea    0xb6c(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xb3e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    1243 <listdir+0x53>
mov    -0x18(%rbp),%rdi
call   1080 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listdir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    %rsi,%rbp
mov    %edi,%r14d
mov    %rsi,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     13ea <listdir+0x1ea>
mov    %rax,%rbx
mov    %rbp,0x18(%rsp)
mov    %rax,%rdi
call   10e0 <readdir@plt>
test   %rax,%rax
je     13de <listdir+0x1de>
mov    %rax,%r15
lea    0xdc5(%rip),%rbp
jmp    126e <listdir+0x6e>
nopl   (%rax)
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %rbx,%rdi
call   10e0 <readdir@plt>
mov    %rax,%r15
test   %rax,%rax
je     13de <listdir+0x1de>
mov    (%r15),%r13
mov    %r13,%rdi
mov    %rbp,%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     125a <listdir+0x5a>
mov    %r13,%rdi
lea    0xd87(%rip),%rsi
call   10a0 <strcmp@plt>
test   %eax,%eax
je     125a <listdir+0x5a>
test   $0x4,%r14b
jne    12a0 <listdir+0xa0>
cmpb   $0x2e,0x0(%r13)
je     125a <listdir+0x5a>
mov    %rbp,%r12
lea    0x30(%rsp),%rdi
mov    0x18(%rsp),%rsi
mov    %r13,%rdx
mov    %rdi,%rbp
mov    $0x400,%ecx
call   1100 <file_pathcat@plt>
test   %rax,%rax
je     12d6 <listdir+0xd6>
mov    %rbp,%rdi
mov    %rsp,%rsi
call   10c0 <stat@plt>
test   %rax,%rax
jne    1419 <listdir+0x219>
test   $0x3,%r14b
mov    %r12,%rbp
je     13a3 <listdir+0x1a3>
test   $0x2,%r14b
je     12fb <listdir+0xfb>
mov    0x10(%rsp),%esi
lea    0xd2f(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
test   $0x1,%r14b
je     13a3 <listdir+0x1a3>
mov    (%rsp),%edi
lea    0x26(%rsp),%r13
mov    %r13,%rsi
call   10d0 <get_privileges@plt>
mov    (%rsp),%edi
call   1040 <filetype@plt>
lea    0xd03(%rip),%rbp
mov    %rbp,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
mov    %rbp,%r13
xor    %eax,%eax
call   1080 <printf@plt>
mov    0xc(%rsp),%edi
call   1110 <get_unamebyid@plt>
test   %rax,%rax
je     135c <listdir+0x15c>
mov    %r13,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x8(%rsp),%edi
call   10f0 <get_gnamebyid@plt>
test   %rax,%rax
je     1377 <listdir+0x177>
mov    %r13,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
lea    0x4(%rsp),%rdi
call   1060 <ctime@plt>
mov    %rax,%rbp
mov    %rax,%rdi
call   1070 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbp,1)
mov    %r13,%rdi
mov    %rbp,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r12,%rbp
mov    (%r15),%rsi
lea    0xc7e(%rip),%rdi
xor    %eax,%eax
call   1080 <printf@plt>
mov    0x2c25(%rip),%rax
mov    (%rax),%eax
and    (%rsp),%eax
mov    0x2bf9(%rip),%rcx
cmp    (%rcx),%eax
jne    1250 <listdir+0x50>
mov    $0x2f,%edi
call   1030 <putchar@plt>
jmp    1250 <listdir+0x50>
mov    %rbx,%rdi
call   1090 <closedir@plt>
xor    %eax,%eax
jmp    1407 <listdir+0x207>
mov    0x2be7(%rip),%rax
mov    (%rax),%edi
lea    0xc06(%rip),%rsi
mov    %rbp,%rdx
call   10b0 <fprintf@plt>
mov    $0x1,%eax
add    $0x438,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bb8(%rip),%rax
mov    (%rax),%ebx
mov    0x2ba7(%rip),%rax
mov    (%rax),%edi
call   1120 <strerror@plt>
lea    0xbdc(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
jmp    13fd <listdir+0x1fd>

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

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