#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int errno;
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
char *strerror(int);
int main(int argc, char *argv[]) {
  DIR *dp;
  struct dirent *pDirEntry;
  if (argc == 1) {
    printf("Usage: myls <dir1>\n");
  }
  dp = opendir(argv[1]);
  if (dp == NULL) {
    printf("Cannot open directory[%s].[%d][%s]\n", argv[1], errno,
           strerror(errno));
    return EXIT_FAILURE;
  }
  while (NULL != (pDirEntry = readdir(dp))) {
    printf("%s\n", pDirEntry->d_name);
  }
  closedir(dp);
  return EXIT_SUCCESS;
}


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   $0x1,-0x8(%rbp)
jne    117e <main+0x2e>
lea    0xe89(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11e9 <main+0x99>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    0x2e27(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x30(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    %rax,%rcx
lea    0xe43(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2df9(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1238 <main+0xe8>
jmp    11ee <main+0x9e>
mov    -0x18(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     1223 <main+0xd3>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ee <main+0x9e>
mov    -0x18(%rbp),%rdi
call   1050 <closedir@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
cmp    $0x1,%edi
jne    1178 <main+0x18>
lea    0xeb1(%rip),%rdi
call   1030 <puts@plt>
mov    0x8(%r14),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     11b8 <main+0x58>
mov    %rax,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11a7 <main+0x47>
mov    (%rax),%rdi
call   1030 <puts@plt>
jmp    1190 <main+0x30>
mov    %rbx,%rdi
call   1060 <closedir@plt>
mov    0x2e1a(%rip),%rax
jmp    11e9 <main+0x89>
mov    0x8(%r14),%rbx
mov    0x2e1d(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
lea    0xe2d(%rip),%rdi
mov    %rbx,%rsi
mov    %ebp,%edx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [20 x i8] c"Usage: myls <dir1>\0A\00"
@.str.1 = [36 x i8] c"Cannot open directory[%s].[%d][%s]\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.dirent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @opendir(i8* %15)
store i32* %16, i32** %6
%17 = load i32*, i32** %6
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %28
19: ; preds = %12
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @errno
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %22, i32 %23, i8* %25)
%27 = load i32, i32* @EXIT_FAILURE
store i32 %27, i32* %3
br label %42
28: ; preds = %12
br label %29
29: ; preds = %33, %28
%30 = load i32*, i32** %6
%31 = call %struct.dirent* @readdir(i32* %30)
store %struct.dirent* %31, %struct.dirent** %7
%32 = icmp ne %struct.dirent* null, %31
br i1 %32, label %33, label %38
33: ; preds = %29
%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 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %36)
br label %29
38: ; preds = %29
%39 = load i32*, i32** %6
%40 = call i32 @closedir(i32* %39)
%41 = load i32, i32* @EXIT_SUCCESS
store i32 %41, i32* %3
br label %42
42: ; preds = %38, %19
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str.1 = [36 x i8] c"Cannot open directory[%s].[%d][%s]\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
@str = [19 x i8] c"Usage: myls <dir1>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 1
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
br label %6
6: ; preds = %4, %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @opendir(i8* %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %6
%12 = tail call %struct.dirent* @readdir(i32* %9)
%13 = icmp eq %struct.dirent* %12, null
br i1 %13, label %26, label %19
14: ; preds = %6
%15 = load i8*, i8** %7
%16 = load i32, i32* @errno
%17 = tail call i8* @strerror(i32 %16)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32 %16, i8* %17)
br label %28
19: ; preds = %11, %19
%20 = phi %struct.dirent* [ %24, %19 ], [ %12, %11 ]
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i64 0, i32 0
%22 = load i8*, i8** %21
%23 = tail call i32 @puts(i8* dereferenceable(1) %22)
%24 = tail call %struct.dirent* @readdir(i32* %9)
%25 = icmp eq %struct.dirent* %24, null
br i1 %25, label %26, label %19
26: ; preds = %19, %11
%27 = tail call i32 @closedir(i32* %9)
br label %28
28: ; preds = %26, %14
%29 = phi i32* [ @EXIT_FAILURE, %14 ], [ @EXIT_SUCCESS, %26 ]
%30 = load i32, i32* %29
ret i32 %30
}