#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*/ EXIT_FAILURE;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
void ls(char *directoryPath) {
  DIR *directory;
  struct dirent *dirstruct;
  directory = opendir(directoryPath);
  if (directory) {
    while ((dirstruct = readdir(directory)) != NULL) {
      if (dirstruct->d_name[0] != '.') {
        fprintf(stdout, "%s  ", dirstruct->d_name);
      }
    }
    fprintf(stdout, "\n");
    closedir(directory);
  } else {
    fprintf(stderr, "Couldn't read directory with opendir.");
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<ls>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11eb <ls+0x9b>
jmp    1179 <ls+0x29>
mov    -0x10(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11c6 <ls+0x76>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11c1 <ls+0x71>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rdx
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1179 <ls+0x29>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <closedir@plt>
jmp    1210 <ls+0xc0>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ls>:
push   %r15
push   %r14
push   %rbx
call   1030 <opendir@plt>
test   %rax,%rax
je     11c8 <ls+0x78>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11a4 <ls+0x54>
mov    0x2e5a(%rip),%r15
lea    0xe83(%rip),%r14
jmp    118d <ls+0x3d>
nop
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11a4 <ls+0x54>
mov    (%rax),%rdx
cmpb   $0x2e,(%rdx)
je     1180 <ls+0x30>
mov    (%r15),%edi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1180 <ls+0x30>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <closedir@plt>
mov    0x2e11(%rip),%rax
mov    (%rax),%edi
lea    0xe2f(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@stdout = global i32 0
@.str = [5 x i8] c"%s \00"
@.str.1 = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.2 = [38 x i8] c"Couldn't read directory with opendir.\00"
@EXIT_FAILURE = global i32 0
define void @ls(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @opendir(i8* %5)
store i32* %6, i32** %3
%7 = load i32*, i32** %3
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %34
9: ; preds = %1
br label %10
10: ; preds = %28, %9
%11 = load i32*, i32** %3
%12 = call %struct.dirent* @readdir(i32* %11)
store %struct.dirent* %12, %struct.dirent** %4
%13 = icmp ne %struct.dirent* %12, null
br i1 %13, label %14, label %29
14: ; preds = %10
%15 = load %struct.dirent*, %struct.dirent** %4
%16 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i32 0, i32 0
%17 = load i8*, i8** %16
%18 = getelementptr inbounds i8, i8* %17, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp ne i32 %20, 46
br i1 %21, label %22, label %28
22: ; preds = %14
%23 = load i32, i32* @stdout
%24 = load %struct.dirent*, %struct.dirent** %4
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i32 0, i32 0
%26 = load i8*, i8** %25
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %22, %14
br label %10
29: ; preds = %10
%30 = load i32, i32* @stdout
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32*, i32** %3
%33 = call i32 @closedir(i32* %32)
br label %39
34: ; preds = %1
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %29
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@stdout = global i32 0
@.str = [5 x i8] c"%s \00"
@.str.1 = [2 x i8] c"\0A\00"
@stderr = global i32 0
@.str.2 = [38 x i8] c"Couldn't read directory with opendir.\00"
@EXIT_FAILURE = global i32 0
define void @ls(i8* nocapture %0) {
%2 = tail call i32* @opendir(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %23, label %4
4: ; preds = %1
%5 = tail call %struct.dirent* @readdir(i32* %2)
%6 = icmp eq %struct.dirent* %5, null
br i1 %6, label %19, label %7
7: ; preds = %4, %16
%8 = phi %struct.dirent* [ %17, %16 ], [ %5, %4 ]
%9 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i64 0, i32 0
%10 = load i8*, i8** %9
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 46
br i1 %12, label %16, label %13
13: ; preds = %7
%14 = load i32, i32* @stdout
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %10)
br label %16
16: ; preds = %13, %7
%17 = tail call %struct.dirent* @readdir(i32* %2)
%18 = icmp eq %struct.dirent* %17, null
br i1 %18, label %19, label %7
19: ; preds = %16, %4
%20 = load i32, i32* @stdout
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 @closedir(i32* %2)
ret void
23: ; preds = %1
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = tail call i32 @exit(i32 %26)
unreachable
}