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

/* Variables and functions */
char *ctime(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int stat(char *, struct stat *);
int /*<<< orphan*/ strcat(char *, char const *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  char filename[500];
  struct stat fileStats;
  if (argc != 2) {
    printf("Not enough command line arguments\n");
    return 1;
  } else {
    DIR *dp = NULL;
    struct dirent *dptr = NULL;
    if (NULL == (dp = opendir(argv[1]))) {
      printf("Cannot open directory: %s\n", argv[1]);
      return 2;
    } else {
      printf("Directory: %s\n", argv[1]);
      while (NULL != (dptr = readdir(dp))) {
        const char *dirname = dptr->d_name;
        strcpy(filename, argv[1]);
        strcat(filename, "/");
        strcat(filename, dirname);
        if (stat(filename, &fileStats) == -1) {
          printf("Error");
          return 3;
        }
        if ((strcmp(".", dptr->d_name) != 0) &&
            (strcmp("..", dptr->d_name) != 0)) {
          printf("  File: %s\n", dptr->d_name);
          printf("    File size: %lld bytes\n", (long long)fileStats.st_size);
          printf("    Last modification: %s", ctime(&fileStats.st_mtime));
        }
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11bd <main+0x3d>
lea    0xe56(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    136f <main+0x1ef>
movq   $0x0,-0x228(%rbp)
movq   $0x0,-0x230(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <opendir@plt>
mov    %rax,%rcx
mov    %rcx,-0x228(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    1217 <main+0x97>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x2,-0x4(%rbp)
jmp    136f <main+0x1ef>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe18(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x228(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,%rcx
mov    %rcx,-0x230(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     135e <main+0x1de>
mov    -0x230(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x238(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x210(%rbp),%rdi
lea    0xdcc(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x210(%rbp),%rdi
mov    -0x238(%rbp),%rsi
call   10a0 <strcat@plt>
lea    -0x210(%rbp),%rdi
lea    -0x220(%rbp),%rsi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    12cf <main+0x14f>
lea    0xd93(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x3,-0x4(%rbp)
jmp    136f <main+0x1ef>
mov    -0x230(%rbp),%rax
mov    (%rax),%rsi
lea    0xd76(%rip),%rdi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1359 <main+0x1d9>
mov    -0x230(%rbp),%rax
mov    (%rax),%rsi
lea    0xd55(%rip),%rdi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     1359 <main+0x1d9>
mov    -0x230(%rbp),%rax
mov    (%rax),%rsi
lea    0xd38(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x218(%rbp),%rsi
lea    0xd2f(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x220(%rbp),%rdi
call   1050 <ctime@plt>
mov    %rax,%rsi
lea    0xd2d(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
jmp    122d <main+0xad>
jmp    1363 <main+0x1e3>
jmp    1368 <main+0x1e8>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x208,%rsp
cmp    $0x2,%edi
jne    12bf <main+0x12f>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
call   1050 <opendir@plt>
mov    0x8(%r15),%rsi
test   %rax,%rax
je     12d2 <main+0x142>
mov    %rax,%r14
lea    0xe4e(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     12fe <main+0x16e>
mov    %rax,%rbp
lea    0x10(%rsp),%rbx
mov    %rsp,%r13
jmp    1214 <main+0x84>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   10a0 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     12fc <main+0x16c>
mov    0x0(%rbp),%r12
mov    0x8(%r15),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
lea    0xdfc(%rip),%rsi
call   10b0 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   10b0 <strcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1090 <stat@plt>
cmp    $0xffffffff,%eax
je     12e7 <main+0x157>
mov    0x0(%rbp),%rsi
lea    0xdd6(%rip),%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1200 <main+0x70>
mov    0x0(%rbp),%rsi
lea    0xdc0(%rip),%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1200 <main+0x70>
mov    0x0(%rbp),%rsi
lea    0xdae(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x8(%rsp),%rsi
lea    0xda7(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rdi
call   1060 <ctime@plt>
lea    0xdac(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    1200 <main+0x70>
lea    0xdb0(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%ebx
jmp    12fe <main+0x16e>
lea    0xd27(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x2,%ebx
jmp    12fe <main+0x16e>
lea    0xd3e(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x3,%ebx
jmp    12fe <main+0x16e>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32, i64 }
%struct.dirent = type { i8* }
@.str = [35 x i8] c"Not enough command line arguments\0A\00"
@.str.1 = [27 x i8] c"Cannot open directory: %s\0A\00"
@.str.2 = [15 x i8] c"Directory: %s\0A\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [6 x i8] c"Error\00"
@.str.5 = [2 x i8] c".\00"
@.str.6 = [3 x i8] c"..\00"
@.str.7 = [12 x i8] c" File: %s\0A\00"
@.str.8 = [27 x i8] c" File size: %lld bytes\0A\00"
@.str.9 = [26 x i8] c" Last modification: %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [500 x i8]
%7 = alloca %struct.stat
%8 = alloca i32*
%9 = alloca %struct.dirent*
%10 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 2
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %3
br label %81
15: ; preds = %2
store i32* null, i32** %8
store %struct.dirent* null, %struct.dirent** %9
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32* @opendir(i8* %18)
store i32* %19, i32** %8
%20 = icmp eq i32* null, %19
br i1 %20, label %21, label %26
21: ; preds = %15
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %24)
store i32 2, i32* %3
br label %81
26: ; preds = %15
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %29)
br label %31
31: ; preds = %77, %26
%32 = load i32*, i32** %8
%33 = call %struct.dirent* @readdir(i32* %32)
store %struct.dirent* %33, %struct.dirent** %9
%34 = icmp ne %struct.dirent* null, %33
br i1 %34, label %35, label %78
35: ; preds = %31
%36 = load %struct.dirent*, %struct.dirent** %9
%37 = getelementptr inbounds %struct.dirent, %struct.dirent* %36, i32 0, i32 0
%38 = load i8*, i8** %37
store i8* %38, i8** %10
%39 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 1
%42 = load i8*, i8** %41
%43 = call i32 @strcpy(i8* %39, i8* %42)
%44 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%45 = call i32 @strcat(i8* %44, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%46 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%47 = load i8*, i8** %10
%48 = call i32 @strcat(i8* %46, i8* %47)
%49 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%50 = call i32 @stat(i8* %49, %struct.stat* %7)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %54
52: ; preds = %35
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
store i32 3, i32* %3
br label %81
54: ; preds = %35
%55 = load %struct.dirent*, %struct.dirent** %9
%56 = getelementptr inbounds %struct.dirent, %struct.dirent* %55, i32 0, i32 0
%57 = load i8*, i8** %56
%58 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* %57)
%59 = icmp ne i64 %58, 0
br i1 %59, label %60, label %77
60: ; preds = %54
%61 = load %struct.dirent*, %struct.dirent** %9
%62 = getelementptr inbounds %struct.dirent, %struct.dirent* %61, i32 0, i32 0
%63 = load i8*, i8** %62
%64 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %63)
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %77
66: ; preds = %60
%67 = load %struct.dirent*, %struct.dirent** %9
%68 = getelementptr inbounds %struct.dirent, %struct.dirent* %67, i32 0, i32 0
%69 = load i8*, i8** %68
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* %69)
%71 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 1
%72 = load i64, i64* %71
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i64 %72)
%74 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%75 = call i8* @ctime(i32* %74)
%76 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i8* %75)
br label %77
77: ; preds = %66, %60, %54
br label %31
78: ; preds = %31
br label %79
79: ; preds = %78
br label %80
80: ; preds = %79
store i32 0, i32* %3
br label %81
81: ; preds = %80, %52, %21, %13
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
%struct.stat = type { i32, i64 }
%struct.dirent = type { i8* }
@.str.1 = [27 x i8] c"Cannot open directory: %s\0A\00"
@.str.2 = [15 x i8] c"Directory: %s\0A\00"
@.str.3 = [2 x i8] c"/\00"
@.str.4 = [6 x i8] c"Error\00"
@.str.5 = [2 x i8] c".\00"
@.str.6 = [3 x i8] c"..\00"
@.str.7 = [12 x i8] c" File: %s\0A\00"
@.str.8 = [27 x i8] c" File size: %lld bytes\0A\00"
@.str.9 = [26 x i8] c" Last modification: %s\00"
@str = [34 x i8] c"Not enough command line arguments\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [500 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [500 x i8], [500 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = icmp eq i32 %0, 2
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
br label %55
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32* @opendir(i8* %12)
%14 = icmp eq i32* %13, null
%15 = load i8*, i8** %11
br i1 %14, label %16, label %18
16: ; preds = %10
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %15)
br label %55
18: ; preds = %10
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%20 = call %struct.dirent* @readdir(i32* %13)
%21 = icmp eq %struct.dirent* %20, null
br i1 %21, label %55, label %22
22: ; preds = %18
%23 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 1
%24 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
br label %25
25: ; preds = %22, %52
%26 = phi %struct.dirent* [ %20, %22 ], [ %53, %52 ]
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i64 0, i32 0
%28 = load i8*, i8** %27
%29 = load i8*, i8** %11
%30 = call i32 @strcpy(i8* %5, i8* %29)
%31 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @strcat(i8* %5, i8* %28)
%33 = call i32 @stat(i8* %5, %struct.stat* %4)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %37
35: ; preds = %25
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
br label %55
37: ; preds = %25
%38 = load i8*, i8** %27
%39 = call i64 @strcmp(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %52, label %41
41: ; preds = %37
%42 = load i8*, i8** %27
%43 = call i64 @strcmp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %42)
%44 = icmp eq i64 %43, 0
br i1 %44, label %52, label %45
45: ; preds = %41
%46 = load i8*, i8** %27
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* %46)
%48 = load i64, i64* %23
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0), i64 %48)
%50 = call i8* @ctime(i32* %24)
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %37, %41, %45
%53 = call %struct.dirent* @readdir(i32* %13)
%54 = icmp eq %struct.dirent* %53, null
br i1 %54, label %55, label %25
55: ; preds = %52, %18, %35, %16, %8
%56 = phi i32 [ 1, %8 ], [ 3, %35 ], [ 2, %16 ], [ 0, %18 ], [ 0, %52 ]
ret i32 %56
}