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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void dir_content_list(char *dir) {
  DIR *dp = NULL;
  struct dirent *dptr = NULL;
  struct stat st;
  char *newdir;
  if (NULL == (dp = opendir(dir))) {
    fprintf(stderr, "Can not open Input Directory [%s]\n", dir);
    exit(-1);
  } else {
    printf("Directory [%s] Content List: \n", dir);
    while (NULL != (dptr = readdir(dp))) {
      printf("inode-number: %-10ld \t filename: %s\n", dptr->d_ino,
             dptr->d_name);
    }
  }
  closedir(dp);
}


x86 assembly (clang, -O0):
<dir_content_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,%rcx
mov    %rcx,-0x10(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    11ba <dir_content_list+0x5a>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe55(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rsi
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
je     1208 <dir_content_list+0xa8>
mov    -0x18(%rbp),%rax
movslq 0x4(%rax),%rsi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11cc <dir_content_list+0x6c>
jmp    120d <dir_content_list+0xad>
mov    -0x10(%rbp),%rdi
call   1050 <closedir@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dir_content_list>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <opendir@plt>
test   %rax,%rax
je     11cc <dir_content_list+0x6c>
mov    %rax,%rbx
lea    0xea8(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11bd <dir_content_list+0x5d>
lea    0xea9(%rip),%r14
nopl   0x0(%rax)
movslq 0x4(%rax),%rsi
mov    (%rax),%edx
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
jne    11a0 <dir_content_list+0x40>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <closedir@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i32, i32 }
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"Can not open Input Directory [%s]\0A\00"
@.str.1 = [31 x i8] c"Directory [%s] Content List: \0A\00"
@.str.2 = [37 x i8] c"inode-number: %-10ld \09 filename: %s\0A\00"
define void @dir_content_list(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca %struct.stat
%6 = alloca i8*
store i8* %0, i8** %2
store i32* null, i32** %3
store %struct.dirent* null, %struct.dirent** %4
%7 = load i8*, i8** %2
%8 = call i32* @opendir(i8* %7)
store i32* %8, i32** %3
%9 = icmp eq i32* null, %8
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = load i8*, i8** %2
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %1
%16 = load i8*, i8** %2
%17 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %16)
br label %18
18: ; preds = %22, %15
%19 = load i32*, i32** %3
%20 = call %struct.dirent* @readdir(i32* %19)
store %struct.dirent* %20, %struct.dirent** %4
%21 = icmp ne %struct.dirent* null, %20
br i1 %21, label %22, label %32
22: ; preds = %18
%23 = load %struct.dirent*, %struct.dirent** %4
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i32 0, i32 1
%25 = load i32, i32* %24
%26 = sext i32 %25 to i64
%27 = inttoptr i64 %26 to i8*
%28 = load %struct.dirent*, %struct.dirent** %4
%29 = getelementptr inbounds %struct.dirent, %struct.dirent* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %27, i32 %30)
br label %18
32: ; preds = %18
br label %33
33: ; preds = %32
%34 = load i32*, i32** %3
%35 = call i32 @closedir(i32* %34)
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i32, i32 }
@stderr = global i32 0
@.str = [35 x i8] c"Can not open Input Directory [%s]\0A\00"
@.str.1 = [31 x i8] c"Directory [%s] Content List: \0A\00"
@.str.2 = [37 x i8] c"inode-number: %-10ld \09 filename: %s\0A\00"
define void @dir_content_list(i8* %0) {
%2 = tail call i32* @opendir(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %8
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = tail call i32 @exit(i32 -1)
unreachable
8: ; preds = %1
%9 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%10 = tail call %struct.dirent* @readdir(i32* %2)
%11 = icmp eq %struct.dirent* %10, null
br i1 %11, label %23, label %12
12: ; preds = %8, %12
%13 = phi %struct.dirent* [ %21, %12 ], [ %10, %8 ]
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i64 0, i32 1
%15 = load i32, i32* %14
%16 = sext i32 %15 to i64
%17 = inttoptr i64 %16 to i8*
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i64 0, i32 0
%19 = load i32, i32* %18
%20 = tail call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.2, i64 0, i64 0), i8* %17, i32 %19)
%21 = tail call %struct.dirent* @readdir(i32* %2)
%22 = icmp eq %struct.dirent* %21, null
br i1 %22, label %23, label %12
23: ; preds = %12, %8
%24 = tail call i32 @closedir(i32* %2)
ret void
}