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

/* Variables and functions */
int errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *, char *);
int /*<<< orphan*/ *getcwd(char *, int);
int /*<<< orphan*/ ls_dirtime(int /*<<< orphan*/ *, struct dirent *,
                              struct stat, char *);
int /*<<< orphan*/ ls_filetype(int /*<<< orphan*/ *, struct dirent *,
                               struct stat, char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *strerror(int);
int main(int argc, char *argv[]) {
  DIR *dir;
  struct dirent *dirent;
  char cwd[1024];
  struct stat fileStat;
  if (getcwd(cwd, sizeof(cwd)) == NULL)
    perror("getcwd() error");
  if (NULL == (dir = opendir(cwd))) {
    fprintf(stderr, "%d (%s) opendir %s failed\n", errno, strerror(errno), cwd);
    return 2;
  }
  if (argv[1] == NULL) {
    while (NULL != (dirent = readdir(dir))) {
      if (strcmp(dirent->d_name, ".") != 0 &&
          strcmp(dirent->d_name, "..") != 0) {
        printf("%s\n", dirent->d_name);
      }
    }
  } else if (strcmp(argv[1], "-t") == 0) {
    ls_dirtime(dir, dirent, fileStat, cwd);
  } else if (strcmp(argv[1], "-f") == 0) {
    ls_filetype(dir, dirent, fileStat, cwd);
  } else {
    printf("That file extension is not recognized.\n");
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x420(%rbp),%rdi
mov    $0x400,%esi
call   1050 <getcwd@plt>
cmp    $0x0,%rax
jne    11e0 <main+0x40>
lea    0xe25(%rip),%rdi
call   10b0 <perror@plt>
lea    -0x420(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    1258 <main+0xb8>
mov    0x2ddb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x430(%rbp)
mov    0x2dc4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x42c(%rbp)
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   10c0 <strerror@plt>
mov    -0x430(%rbp),%edi
mov    -0x42c(%rbp),%edx
mov    %rax,%rcx
lea    -0x420(%rbp),%r8
lea    0xdc8(%rip),%rsi
call   1080 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1372 <main+0x1d2>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
jne    12e0 <main+0x140>
jmp    126c <main+0xcc>
mov    -0x18(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     12db <main+0x13b>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xd96(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     12d6 <main+0x136>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xd78(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     12d6 <main+0x136>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    126c <main+0xcc>
jmp    1372 <main+0x1d2>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd42(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    131d <main+0x17d>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x420(%rbp),%rcx
mov    -0x428(%rbp),%edx
call   1060 <ls_dirtime@plt>
jmp    136d <main+0x1cd>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xd08(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    135a <main+0x1ba>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x420(%rbp),%rcx
mov    -0x428(%rbp),%edx
call   10a0 <ls_filetype@plt>
jmp    1368 <main+0x1c8>
lea    0xcd6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    136d <main+0x1cd>
jmp    1372 <main+0x1d2>
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%rbp
mov    %rsp,%rdi
mov    $0x400,%esi
call   1050 <getcwd@plt>
test   %rax,%rax
je     12eb <main+0x14b>
mov    %rsp,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1220 <main+0x80>
mov    %rax,%rbx
mov    0x8(%rbp),%rdi
test   %rdi,%rdi
je     125a <main+0xba>
lea    0xe45(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12bd <main+0x11d>
mov    0x8(%rbp),%rdi
lea    0xe2f(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     12ca <main+0x12a>
lea    0xe1d(%rip),%rdi
call   1030 <puts@plt>
jmp    12d5 <main+0x135>
mov    0x2db9(%rip),%rax
mov    (%rax),%ebx
mov    0x2da8(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   10c0 <strerror@plt>
lea    0xdcf(%rip),%rsi
mov    %rsp,%r8
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1080 <fprintf@plt>
mov    $0x2,%r14d
jmp    12d8 <main+0x138>
mov    %rbx,%rdi
call   1090 <readdir@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     12d8 <main+0x138>
mov    %rax,%rbp
lea    0xdb7(%rip),%r12
lea    0xdaf(%rip),%r15
jmp    1290 <main+0xf0>
nopl   (%rax)
mov    %rbx,%rdi
call   1090 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     12d8 <main+0x138>
mov    0x0(%rbp),%rdi
mov    %r12,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1280 <main+0xe0>
mov    0x0(%rbp),%rdi
mov    %r15,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1280 <main+0xe0>
mov    0x0(%rbp),%rdi
call   1030 <puts@plt>
jmp    1280 <main+0xe0>
mov    %rsp,%rcx
mov    %rbx,%rdi
call   1060 <ls_dirtime@plt>
jmp    12d5 <main+0x135>
mov    %rsp,%rcx
mov    %rbx,%rdi
call   10a0 <ls_filetype@plt>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd0e(%rip),%rdi
call   10b0 <perror@plt>
jmp    11c8 <main+0x28>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32 }
@.str = [15 x i8] c"getcwd() error\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"%d (%s) opendir %s failed\0A\00"
@errno = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.4 = [4 x i8] c"%s\0A\00"
@.str.5 = [3 x i8] c"-t\00"
@.str.6 = [3 x i8] c"-f\00"
@.str.7 = [40 x i8] c"That file extension is not recognized.\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 [1024 x i8]
%9 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%11 = call i32* @getcwd(i8* %10, i32 1024)
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %13, %2
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%17 = call i32* @opendir(i8* %16)
store i32* %17, i32** %6
%18 = icmp eq i32* null, %17
br i1 %18, label %19, label %26
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = load i32, i32* @errno
%22 = load i32, i32* @errno
%23 = call i8* @strerror(i32 %22)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%25 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %21, i8* %23, i8* %24)
store i32 2, i32* %3
br label %85
26: ; preds = %15
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %55
31: ; preds = %26
br label %32
32: ; preds = %53, %31
%33 = load i32*, i32** %6
%34 = call %struct.dirent* @readdir(i32* %33)
store %struct.dirent* %34, %struct.dirent** %7
%35 = icmp ne %struct.dirent* null, %34
br i1 %35, label %36, label %54
36: ; preds = %32
%37 = load %struct.dirent*, %struct.dirent** %7
%38 = getelementptr inbounds %struct.dirent, %struct.dirent* %37, i32 0, i32 0
%39 = load i8*, i8** %38
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%41 = icmp ne i64 %40, 0
br i1 %41, label %42, label %53
42: ; preds = %36
%43 = load %struct.dirent*, %struct.dirent** %7
%44 = getelementptr inbounds %struct.dirent, %struct.dirent* %43, i32 0, i32 0
%45 = load i8*, i8** %44
%46 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %42
%49 = load %struct.dirent*, %struct.dirent** %7
%50 = getelementptr inbounds %struct.dirent, %struct.dirent* %49, i32 0, i32 0
%51 = load i8*, i8** %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %51)
br label %53
53: ; preds = %48, %42, %36
br label %32
54: ; preds = %32
br label %85
55: ; preds = %26
%56 = load i8**, i8*** %5
%57 = getelementptr inbounds i8*, i8** %56, i64 1
%58 = load i8*, i8** %57
%59 = call i64 @strcmp(i8* %58, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%60 = icmp eq i64 %59, 0
br i1 %60, label %61, label %68
61: ; preds = %55
%62 = load i32*, i32** %6
%63 = load %struct.dirent*, %struct.dirent** %7
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%65 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%66 = load i32, i32* %65
%67 = call i32 @ls_dirtime(i32* %62, %struct.dirent* %63, i32 %66, i8* %64)
br label %84
68: ; preds = %55
%69 = load i8**, i8*** %5
%70 = getelementptr inbounds i8*, i8** %69, i64 1
%71 = load i8*, i8** %70
%72 = call i64 @strcmp(i8* %71, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%73 = icmp eq i64 %72, 0
br i1 %73, label %74, label %81
74: ; preds = %68
%75 = load i32*, i32** %6
%76 = load %struct.dirent*, %struct.dirent** %7
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%78 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%79 = load i32, i32* %78
%80 = call i32 @ls_filetype(i32* %75, %struct.dirent* %76, i32 %79, i8* %77)
br label %83
81: ; preds = %68
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.7, i64 0, i64 0))
br label %83
83: ; preds = %81, %74
br label %84
84: ; preds = %83, %61
br label %85
85: ; preds = %19, %84, %54
%86 = load i32, i32* %3
ret i32 %86
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [15 x i8] c"getcwd() error\00"
@stderr = global i32 0
@.str.1 = [27 x i8] c"%d (%s) opendir %s failed\0A\00"
@errno = global i32 0
@.str.2 = [2 x i8] c".\00"
@.str.3 = [3 x i8] c"..\00"
@.str.5 = [3 x i8] c"-t\00"
@.str.6 = [3 x i8] c"-f\00"
@str = [39 x i8] c"That file extension is not recognized.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32* @getcwd(i8* %4, i32 1024)
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %2
%8 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = call i32* @opendir(i8* %4)
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = load i32, i32* @errno
%15 = call i8* @strerror(i32 %14)
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i32 %14, i8* %15, i8* %4)
br label %53
17: ; preds = %9
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %40
21: ; preds = %17
%22 = call %struct.dirent* @readdir(i32* %10)
%23 = icmp eq %struct.dirent* %22, null
br i1 %23, label %53, label %24
24: ; preds = %21, %37
%25 = phi %struct.dirent* [ %38, %37 ], [ %22, %21 ]
%26 = getelementptr inbounds %struct.dirent, %struct.dirent* %25, i64 0, i32 0
%27 = load i8*, i8** %26
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %37, label %30
30: ; preds = %24
%31 = load i8*, i8** %26
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%33 = icmp eq i64 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %30
%35 = load i8*, i8** %26
%36 = call i32 @puts(i8* dereferenceable(1) %35)
br label %37
37: ; preds = %34, %30, %24
%38 = call %struct.dirent* @readdir(i32* %10)
%39 = icmp eq %struct.dirent* %38, null
br i1 %39, label %53, label %24
40: ; preds = %17
%41 = call i64 @strcmp(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%42 = icmp eq i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 @ls_dirtime(i32* %10, %struct.dirent* undef, i32 undef, i8* %4)
br label %53
45: ; preds = %40
%46 = load i8*, i8** %18
%47 = call i64 @strcmp(i8* %46, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %45
%50 = call i32 @ls_filetype(i32* %10, %struct.dirent* undef, i32 undef, i8* %4)
br label %53
51: ; preds = %45
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
br label %53
53: ; preds = %37, %21, %49, %51, %43, %12
%54 = phi i32 [ 2, %12 ], [ 0, %43 ], [ 0, %51 ], [ 0, %49 ], [ 0, %21 ], [ 0, %37 ]
ret i32 %54
}