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

/* Variables and functions */
int /*<<< orphan*/ chdir(char *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ compute_access(int /*<<< orphan*/, char *);
int /*<<< orphan*/ compute_ftype(struct stat *, char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int lstat(char *, struct stat *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sec2datetimestr(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void printDir(char *dir_path) {
  struct stat buf;
  char ftype[5];
  char faccess[10];
  char ctime[20];
  char mtime[20];
  printf("%-5s %-10s %-50s %-22s %-22s\n", "type", "access", "file_name",
         "ctime", "mtime");
  printf("---------------------------------------------------------------------"
         "-------------------------------\n");
  chdir(dir_path);
  DIR *ds = opendir(dir_path);
  struct dirent *dp = readdir(ds);
  while (NULL != dp) {
    if (lstat(dp->d_name, &buf) == -1) {
      fprintf(stderr, "get [%s] inode information fail\n", dp->d_name);
      strerror(errno);
      dp = readdir(ds);
      continue;
    }
    compute_ftype(&buf, ftype);
    compute_access(buf.st_mode, faccess);
    sec2datetimestr(buf.st_ctime, ctime);
    sec2datetimestr(buf.st_mtime, mtime);
    printf("%-5s %-10s %-50s %-22s %-22s\n", ftype, faccess, dp->d_name, ctime,
           mtime);
    dp = readdir(ds);
  }
  closedir(ds);
}


x86 assembly (clang, -O0):
<printDir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe3d(%rip),%rdi
lea    0xe54(%rip),%rsi
lea    0xe52(%rip),%rdx
lea    0xe52(%rip),%rcx
lea    0xe55(%rip),%r8
lea    0xe54(%rip),%r9
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <chdir@plt>
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rdi
call   10c0 <readdir@plt>
mov    %rax,-0x70(%rbp)
xor    %eax,%eax
cmp    -0x70(%rbp),%rax
je     12e7 <printDir+0x137>
mov    -0x70(%rbp),%rax
mov    (%rax),%rdi
lea    -0x18(%rbp),%rsi
call   1090 <lstat@plt>
cmp    $0xffffffff,%eax
jne    127f <printDir+0xcf>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
mov    -0x70(%rbp),%rax
mov    (%rax),%rdx
lea    0xe4c(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
call   10d0 <strerror@plt>
mov    -0x68(%rbp),%rdi
call   10c0 <readdir@plt>
mov    %rax,-0x70(%rbp)
jmp    121e <printDir+0x6e>
lea    -0x1d(%rbp),%rsi
lea    -0x18(%rbp),%rdi
call   10b0 <compute_ftype@plt>
mov    -0x10(%rbp),%edi
lea    -0x27(%rbp),%rsi
call   1060 <compute_access@plt>
mov    -0x14(%rbp),%edi
lea    -0x40(%rbp),%rsi
call   1070 <sec2datetimestr@plt>
mov    -0x18(%rbp),%edi
lea    -0x60(%rbp),%rsi
call   1070 <sec2datetimestr@plt>
lea    -0x1d(%rbp),%rsi
lea    -0x27(%rbp),%rdx
mov    -0x70(%rbp),%rax
mov    (%rax),%rcx
lea    -0x40(%rbp),%r8
lea    -0x60(%rbp),%r9
lea    0xd32(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x68(%rbp),%rdi
call   10c0 <readdir@plt>
mov    %rax,-0x70(%rbp)
jmp    121e <printDir+0x6e>
mov    -0x68(%rbp),%rdi
call   1080 <closedir@plt>
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<printDir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x68,%rsp
mov    %rdi,%rbx
lea    0xe28(%rip),%rdi
lea    0xe3f(%rip),%rsi
lea    0xe3d(%rip),%rdx
lea    0xe3d(%rip),%rcx
lea    0xe40(%rip),%r8
lea    0xe3f(%rip),%r9
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe58(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <chdir@plt>
mov    %rbx,%rdi
call   1040 <opendir@plt>
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
call   10d0 <readdir@plt>
test   %rax,%rax
je     12f0 <printDir+0x130>
mov    %rax,%r12
lea    0x10(%rsp),%rbx
jmp    1279 <printDir+0xb9>
xchg   %ax,%ax
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xdec(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
call   10e0 <strerror@plt>
mov    0x8(%rsp),%rdi
call   10d0 <readdir@plt>
mov    %rax,%r12
test   %rax,%rax
je     12f0 <printDir+0x130>
mov    (%r12),%rdi
mov    %rbx,%rsi
call   10a0 <lstat@plt>
cmp    $0xffffffff,%eax
je     1240 <printDir+0x80>
mov    %rbx,%rdi
lea    0x21(%rsp),%r13
mov    %r13,%rsi
call   10c0 <compute_ftype@plt>
mov    0x18(%rsp),%edi
lea    0x26(%rsp),%rbp
mov    %rbp,%rsi
call   1070 <compute_access@plt>
mov    0x14(%rsp),%edi
lea    0x50(%rsp),%r15
mov    %r15,%rsi
call   1080 <sec2datetimestr@plt>
mov    0x10(%rsp),%edi
lea    0x30(%rsp),%r14
mov    %r14,%rsi
call   1080 <sec2datetimestr@plt>
mov    (%r12),%rcx
lea    0xd28(%rip),%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
mov    %r15,%r8
mov    %r14,%r9
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1267 <printDir+0xa7>
mov    0x8(%rsp),%rdi
call   1090 <closedir@plt>
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i32, i32 }
%struct.dirent = type { i8* }
@.str = [30 x i8] c"%-5s %-10s %-50s %-22s %-22s\0A\00"
@.str.1 = [5 x i8] c"type\00"
@.str.2 = [7 x i8] c"access\00"
@.str.3 = [10 x i8] c"file_name\00"
@.str.4 = [6 x i8] c"ctime\00"
@.str.5 = [6 x i8] c"mtime\00"
@.str.6 = [102 x i8] c"----------------------------------------------------------------------------------------------------\0A\00"
@stderr = global i32 0
@.str.7 = [33 x i8] c"get [%s] inode information fail\0A\00"
@errno = global i32 0
define void @printDir(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.stat
%4 = alloca [5 x i8]
%5 = alloca [10 x i8]
%6 = alloca [20 x i8]
%7 = alloca [20 x i8]
%8 = alloca i32*
%9 = alloca %struct.dirent*
store i8* %0, i8** %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str.6, i64 0, i64 0))
%12 = load i8*, i8** %2
%13 = call i32 @chdir(i8* %12)
%14 = load i8*, i8** %2
%15 = call i32* @opendir(i8* %14)
store i32* %15, i32** %8
%16 = load i32*, i32** %8
%17 = call %struct.dirent* @readdir(i32* %16)
store %struct.dirent* %17, %struct.dirent** %9
br label %18
18: ; preds = %37, %27, %1
%19 = load %struct.dirent*, %struct.dirent** %9
%20 = icmp ne %struct.dirent* null, %19
br i1 %20, label %21, label %62
21: ; preds = %18
%22 = load %struct.dirent*, %struct.dirent** %9
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = call i32 @lstat(i8* %24, %struct.stat* %3)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %37
27: ; preds = %21
%28 = load i32, i32* @stderr
%29 = load %struct.dirent*, %struct.dirent** %9
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32 @fprintf(i32 %28, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i8* %31)
%33 = load i32, i32* @errno
%34 = call i32 @strerror(i32 %33)
%35 = load i32*, i32** %8
%36 = call %struct.dirent* @readdir(i32* %35)
store %struct.dirent* %36, %struct.dirent** %9
br label %18
37: ; preds = %21
%38 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%39 = call i32 @compute_ftype(%struct.stat* %3, i8* %38)
%40 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 2
%41 = load i32, i32* %40
%42 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%43 = call i32 @compute_access(i32 %41, i8* %42)
%44 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 1
%45 = load i32, i32* %44
%46 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%47 = call i32 @sec2datetimestr(i32 %45, i8* %46)
%48 = getelementptr inbounds %struct.stat, %struct.stat* %3, i32 0, i32 0
%49 = load i32, i32* %48
%50 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%51 = call i32 @sec2datetimestr(i32 %49, i8* %50)
%52 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%53 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%54 = load %struct.dirent*, %struct.dirent** %9
%55 = getelementptr inbounds %struct.dirent, %struct.dirent* %54, i32 0, i32 0
%56 = load i8*, i8** %55
%57 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%58 = getelementptr inbounds [20 x i8], [20 x i8]* %7, i64 0, i64 0
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %52, i8* %53, i8* %56, i8* %57, i8* %58)
%60 = load i32*, i32** %8
%61 = call %struct.dirent* @readdir(i32* %60)
store %struct.dirent* %61, %struct.dirent** %9
br label %18
62: ; preds = %18
%63 = load i32*, i32** %8
%64 = call i32 @closedir(i32* %63)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32, i32, i32 }
%struct.dirent = type { i8* }
@.str = [30 x i8] c"%-5s %-10s %-50s %-22s %-22s\0A\00"
@.str.1 = [5 x i8] c"type\00"
@.str.2 = [7 x i8] c"access\00"
@.str.3 = [10 x i8] c"file_name\00"
@.str.4 = [6 x i8] c"ctime\00"
@.str.5 = [6 x i8] c"mtime\00"
@stderr = global i32 0
@.str.7 = [33 x i8] c"get [%s] inode information fail\0A\00"
@errno = global i32 0
@str = [101 x i8] c"----------------------------------------------------------------------------------------------------\00"
define void @printDir(i8* %0) {
%2 = alloca %struct.stat
%3 = alloca [5 x i8]
%4 = alloca [10 x i8]
%5 = alloca [20 x i8]
%6 = alloca [20 x i8]
%7 = bitcast %struct.stat* %2 to i8*
%8 = getelementptr inbounds [5 x i8], [5 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%13 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([101 x i8], [101 x i8]* @str, i64 0, i64 0))
%14 = tail call i32 @chdir(i8* %0)
%15 = tail call i32* @opendir(i8* %0)
%16 = tail call %struct.dirent* @readdir(i32* %15)
%17 = icmp eq %struct.dirent* %16, null
br i1 %17, label %47, label %18
18: ; preds = %1
%19 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 2
%20 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 1
%21 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
br label %22
22: ; preds = %18, %34
%23 = phi %struct.dirent* [ %16, %18 ], [ %35, %34 ]
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i64 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 @lstat(i8* %25, %struct.stat* %2)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %37
28: ; preds = %22
%29 = load i32, i32* @stderr
%30 = load i8*, i8** %24
%31 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i8* %30)
%32 = load i32, i32* @errno
%33 = call i32 @strerror(i32 %32)
br label %34
34: ; preds = %28, %37
%35 = call %struct.dirent* @readdir(i32* %15)
%36 = icmp eq %struct.dirent* %35, null
br i1 %36, label %47, label %22
37: ; preds = %22
%38 = call i32 @compute_ftype(%struct.stat* %2, i8* %8)
%39 = load i32, i32* %19
%40 = call i32 @compute_access(i32 %39, i8* %9)
%41 = load i32, i32* %20
%42 = call i32 @sec2datetimestr(i32 %41, i8* %10)
%43 = load i32, i32* %21
%44 = call i32 @sec2datetimestr(i32 %43, i8* %11)
%45 = load i8*, i8** %24
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %8, i8* %9, i8* %45, i8* %10, i8* %11)
br label %34
47: ; preds = %34, %1
%48 = call i32 @closedir(i32* %15)
ret void
}