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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  char *path;
  DIR *dirp;
  struct dirent *dp;
  if (argc > 2) {
    fputs("Usage: ls [<path>]\n", stderr);
    return 1;
  } else if (argc == 2) {
    path = *++argv;
  } else {
    path = ".";
  }
  if ((dirp = opendir(path)) == NULL) {
    perror("ls");
    return 1;
  }
  while ((dp = readdir(dirp)) != NULL) {
    if ((dp->d_name[0] == '.' && dp->d_name[1] == '\0') ||
        (dp->d_name[0] == '.' && dp->d_name[1] == '.' && dp->d_name[2] == '\0'))
      continue;
    printf("%s\n", dp->d_name);
  }
  closedir(dirp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11a1 <main+0x41>
mov    0x2e59(%rip),%rax
mov    (%rax),%esi
lea    0xe70(%rip),%rdi
call   1050 <fputs@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b1 <main+0x151>
cmpl   $0x2,-0x8(%rbp)
jne    11c7 <main+0x67>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    11d2 <main+0x72>
lea    0xe46(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    11d7 <main+0x77>
mov    -0x18(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1206 <main+0xa6>
lea    0xe21(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b1 <main+0x151>
jmp    120b <main+0xab>
mov    -0x20(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     12a1 <main+0x141>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1249 <main+0xe9>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x0,%eax
je     1284 <main+0x124>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1289 <main+0x129>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    1289 <main+0x129>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
movsbl 0x2(%rax),%eax
cmp    $0x0,%eax
jne    1289 <main+0x129>
jmp    120b <main+0xab>
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
lea    0xd82(%rip),%rdi
call   1040 <printf@plt>
jmp    120b <main+0xab>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jl     1185 <main+0x25>
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
lea    0xe87(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x1,%eax
jmp    11fb <main+0x9b>
cmp    $0x2,%edi
jne    1190 <main+0x30>
mov    0x8(%rsi),%rdi
jmp    1197 <main+0x37>
lea    0xe7d(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     1203 <main+0xa3>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11f1 <main+0x91>
lea    0xe61(%rip),%r14
jmp    11d5 <main+0x75>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11f1 <main+0x91>
mov    (%rax),%rsi
cmpb   $0x2e,(%rsi)
jne    11c0 <main+0x60>
movzbl 0x1(%rsi),%eax
test   %al,%al
je     11c8 <main+0x68>
cmp    $0x2e,%al
jne    11c0 <main+0x60>
cmpb   $0x0,0x2(%rsi)
jne    11c0 <main+0x60>
jmp    11c8 <main+0x68>
mov    %rbx,%rdi
call   1060 <closedir@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe0c(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%eax
jmp    11fb <main+0x9b>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [20 x i8] c"Usage: ls [<path>]\0A\00"
@stderr = global i32 0
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"ls\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca %struct.dirent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp sgt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fputs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 1, i32* %3
br label %83
14: ; preds = %2
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i32 1
store i8** %19, i8*** %5
%20 = load i8*, i8** %19
store i8* %20, i8** %6
br label %22
21: ; preds = %14
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %22
22: ; preds = %21, %17
br label %23
23: ; preds = %22
%24 = load i8*, i8** %6
%25 = call i32* @opendir(i8* %24)
store i32* %25, i32** %7
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %29
27: ; preds = %23
%28 = call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %83
29: ; preds = %23
br label %30
30: ; preds = %75, %74, %29
%31 = load i32*, i32** %7
%32 = call %struct.dirent* @readdir(i32* %31)
store %struct.dirent* %32, %struct.dirent** %8
%33 = icmp ne %struct.dirent* %32, null
br i1 %33, label %34, label %80
34: ; preds = %30
%35 = load %struct.dirent*, %struct.dirent** %8
%36 = getelementptr inbounds %struct.dirent, %struct.dirent* %35, i32 0, i32 0
%37 = load i8*, i8** %36
%38 = getelementptr inbounds i8, i8* %37, i64 0
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 46
br i1 %41, label %42, label %50
42: ; preds = %34
%43 = load %struct.dirent*, %struct.dirent** %8
%44 = getelementptr inbounds %struct.dirent, %struct.dirent* %43, i32 0, i32 0
%45 = load i8*, i8** %44
%46 = getelementptr inbounds i8, i8* %45, i64 1
%47 = load i8, i8* %46
%48 = sext i8 %47 to i32
%49 = icmp eq i32 %48, 0
br i1 %49, label %74, label %50
50: ; preds = %42, %34
%51 = load %struct.dirent*, %struct.dirent** %8
%52 = getelementptr inbounds %struct.dirent, %struct.dirent* %51, i32 0, i32 0
%53 = load i8*, i8** %52
%54 = getelementptr inbounds i8, i8* %53, i64 0
%55 = load i8, i8* %54
%56 = sext i8 %55 to i32
%57 = icmp eq i32 %56, 46
br i1 %57, label %58, label %75
58: ; preds = %50
%59 = load %struct.dirent*, %struct.dirent** %8
%60 = getelementptr inbounds %struct.dirent, %struct.dirent* %59, i32 0, i32 0
%61 = load i8*, i8** %60
%62 = getelementptr inbounds i8, i8* %61, i64 1
%63 = load i8, i8* %62
%64 = sext i8 %63 to i32
%65 = icmp eq i32 %64, 46
br i1 %65, label %66, label %75
66: ; preds = %58
%67 = load %struct.dirent*, %struct.dirent** %8
%68 = getelementptr inbounds %struct.dirent, %struct.dirent* %67, i32 0, i32 0
%69 = load i8*, i8** %68
%70 = getelementptr inbounds i8, i8* %69, i64 2
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 0
br i1 %73, label %74, label %75
74: ; preds = %66, %42
br label %30
75: ; preds = %66, %58, %50
%76 = load %struct.dirent*, %struct.dirent** %8
%77 = getelementptr inbounds %struct.dirent, %struct.dirent* %76, i32 0, i32 0
%78 = load i8*, i8** %77
%79 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %78)
br label %30
80: ; preds = %30
%81 = load i32*, i32** %7
%82 = call i32 @closedir(i32* %81)
store i32 0, i32* %3
br label %83
83: ; preds = %80, %27, %11
%84 = load i32, i32* %3
ret i32 %84
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [20 x i8] c"Usage: ls [<path>]\0A\00"
@stderr = global i32 0
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"ls\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fputs(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %41
7: ; preds = %2
%8 = icmp eq i32 %0, 2
br i1 %8, label %9, label %12
9: ; preds = %7
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
br label %12
12: ; preds = %7, %9
%13 = phi i8* [ %11, %9 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %7 ]
%14 = tail call i32* @opendir(i8* %13)
%15 = icmp eq i32* %14, null
br i1 %15, label %19, label %16
16: ; preds = %12
%17 = tail call %struct.dirent* @readdir(i32* %14)
%18 = icmp eq %struct.dirent* %17, null
br i1 %18, label %39, label %21
19: ; preds = %12
%20 = tail call i32 @perror(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %41
21: ; preds = %16, %34
%22 = phi %struct.dirent* [ %35, %34 ], [ %17, %16 ]
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i64 0, i32 0
%24 = load i8*, i8** %23
%25 = load i8, i8* %24
%26 = icmp eq i8 %25, 46
br i1 %26, label %27, label %37
27: ; preds = %21
%28 = getelementptr inbounds i8, i8* %24, i64 1
%29 = load i8, i8* %28
switch i8 %29, label %37 [
i8 0, label %34
i8 46, label %30
]
30: ; preds = %27
%31 = getelementptr inbounds i8, i8* %24, i64 2
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 0
br i1 %33, label %34, label %37
34: ; preds = %27, %30, %37
%35 = tail call %struct.dirent* @readdir(i32* %14)
%36 = icmp eq %struct.dirent* %35, null
br i1 %36, label %39, label %21
37: ; preds = %27, %21, %30
%38 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %24)
br label %34
39: ; preds = %34, %16
%40 = tail call i32 @closedir(i32* %14)
br label %41
41: ; preds = %39, %19, %4
%42 = phi i32 [ 1, %4 ], [ 1, %19 ], [ 0, %39 ]
ret i32 %42
}