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

/* Variables and functions */
int /*<<< orphan*/ _PC_PATH_MAX;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
char *getcwd(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ pathconf(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/, int /*<<< orphan*/);
struct dirent *readdir(int /*<<< orphan*/ *);
int openDirectory() {
  char *cwd;
  struct dirent *dp;
  cwd = getcwd(NULL, pathconf(".", _PC_PATH_MAX));
  DIR *dir;
  dir = opendir(cwd);
  do {
    if ((dp = readdir(dir)) != NULL) {
      printf("%lu \t %s\n", dp->d_ino, dp->d_name);
    }
  } while (dp != NULL);
  closedir(dir);
}


x86 assembly (clang, -O0):
<openDirectory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
call   1030 <pathconf@plt>
mov    %eax,%esi
xor    %eax,%eax
mov    %eax,%edi
call   1060 <getcwd@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11c9 <openDirectory+0x69>
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xe3e(%rip),%rdi
call   1050 <printf@plt>
jmp    11ce <openDirectory+0x6e>
cmpq   $0x0,-0x18(%rbp)
jne    1199 <openDirectory+0x39>
mov    -0x20(%rbp),%rdi
call   1070 <closedir@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openDirectory>:
push   %r14
push   %rbx
push   %rax
mov    0x2e75(%rip),%rax
mov    (%rax),%esi
lea    0xe8c(%rip),%rdi
call   1030 <pathconf@plt>
xor    %edi,%edi
mov    %eax,%esi
call   1060 <getcwd@plt>
mov    %rax,%rdi
call   1040 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     11ca <openDirectory+0x6a>
lea    0xe61(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    (%rax),%edx
mov    0x4(%rax),%esi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
jne    11b0 <openDirectory+0x50>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <closedir@plt>

LLVM IR (-O0):
%struct.dirent = type { i32, i32 }
@.str = [2 x i8] c".\00"
@_PC_PATH_MAX = global i32 0
@.str.1 = [10 x i8] c"%lu \09 %s\0A\00"
define i32 @openDirectory() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca %struct.dirent*
%4 = alloca i32*
%5 = load i32, i32* @_PC_PATH_MAX
%6 = call i32 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = call i8* @getcwd(i32* null, i32 %6)
store i8* %7, i8** %2
%8 = load i8*, i8** %2
%9 = call i32* @opendir(i8* %8)
store i32* %9, i32** %4
br label %10
10: ; preds = %23, %0
%11 = load i32*, i32** %4
%12 = call %struct.dirent* @readdir(i32* %11)
store %struct.dirent* %12, %struct.dirent** %3
%13 = icmp ne %struct.dirent* %12, null
br i1 %13, label %14, label %22
14: ; preds = %10
%15 = load %struct.dirent*, %struct.dirent** %3
%16 = getelementptr inbounds %struct.dirent, %struct.dirent* %15, i32 0, i32 1
%17 = load i32, i32* %16
%18 = load %struct.dirent*, %struct.dirent** %3
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %20)
br label %22
22: ; preds = %14, %10
br label %23
23: ; preds = %22
%24 = load %struct.dirent*, %struct.dirent** %3
%25 = icmp ne %struct.dirent* %24, null
br i1 %25, label %10, label %26
26: ; preds = %23
%27 = load i32*, i32** %4
%28 = call i32 @closedir(i32* %27)
%29 = load i32, i32* %1
ret i32 %29
}

LLVM IR (-O2):
%struct.dirent = type { i32, i32 }
@.str = [2 x i8] c".\00"
@_PC_PATH_MAX = global i32 0
@.str.1 = [10 x i8] c"%lu \09 %s\0A\00"
define i32 @openDirectory() {
%1 = load i32, i32* @_PC_PATH_MAX
%2 = tail call i32 @pathconf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = tail call i8* @getcwd(i32* null, i32 %2)
%4 = tail call i32* @opendir(i8* %3)
%5 = tail call %struct.dirent* @readdir(i32* %4)
%6 = icmp eq %struct.dirent* %5, null
br i1 %6, label %16, label %7
7: ; preds = %0, %7
%8 = phi %struct.dirent* [ %14, %7 ], [ %5, %0 ]
%9 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i64 0, i32 1
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %12)
%14 = tail call %struct.dirent* @readdir(i32* %4)
%15 = icmp eq %struct.dirent* %14, null
br i1 %15, label %16, label %7
16: ; preds = %7, %0
%17 = tail call i32 @closedir(i32* %4)
ret i32 undef
}