#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*/ exit(int);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int main(int argc, char **argv) {
  DIR *pDir = opendir(argv[1]);
  if (pDir == NULL) {
    perror("opendir()");
    exit(-1);
  }
  struct dirent *pDirInfo = NULL;
  while ((pDirInfo = readdir(pDir)) != NULL) {
    if (strcmp(pDirInfo->d_name, ".") && strcmp(pDirInfo->d_name, "..")) {
      printf("%s\n", pDirInfo->d_name);
    }
  }
  closedir(pDir);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b8 <main+0x48>
lea    0xe57(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1229 <main+0xb9>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe26(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1224 <main+0xb4>
mov    -0x20(%rbp),%rax
mov    (%rax),%rdi
lea    0xe08(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1224 <main+0xb4>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xdee(%rip),%rdi
call   1040 <printf@plt>
jmp    11c0 <main+0x50>
mov    -0x18(%rbp),%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    0x8(%rsi),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     1211 <main+0xa1>
mov    %rax,%r13
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11fd <main+0x8d>
mov    %rax,%rbx
lea    0xe66(%rip),%r14
lea    0xe5e(%rip),%r15
lea    0xe5a(%rip),%r12
jmp    11d0 <main+0x60>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r13,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11fd <main+0x8d>
mov    (%rbx),%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11c0 <main+0x50>
mov    (%rbx),%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11c0 <main+0x50>
mov    (%rbx),%rsi
mov    %r12,%rdi
call   1040 <printf@plt>
jmp    11c0 <main+0x50>
mov    %r13,%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xde8(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [10 x i8] c"opendir()\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\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 i32*
%7 = alloca %struct.dirent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i8**, i8*** %5
%9 = getelementptr inbounds i8*, i8** %8, i64 1
%10 = load i8*, i8** %9
%11 = call i32* @opendir(i8* %10)
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 -1)
unreachable
17: ; preds = %2
store %struct.dirent* null, %struct.dirent** %7
br label %18
18: ; preds = %39, %17
%19 = load i32*, i32** %6
%20 = call %struct.dirent* @readdir(i32* %19)
store %struct.dirent* %20, %struct.dirent** %7
%21 = icmp ne %struct.dirent* %20, null
br i1 %21, label %22, label %40
22: ; preds = %18
%23 = load %struct.dirent*, %struct.dirent** %7
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = call i64 @strcmp(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %22
%29 = load %struct.dirent*, %struct.dirent** %7
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i64 @strcmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %28
%35 = load %struct.dirent*, %struct.dirent** %7
%36 = getelementptr inbounds %struct.dirent, %struct.dirent* %35, i32 0, i32 0
%37 = load i8*, i8** %36
%38 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %34, %28, %22
br label %18
40: ; preds = %18
%41 = load i32*, i32** %6
%42 = call i32 @closedir(i32* %41)
ret i32 0
}

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