#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*/ chdir(char const *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fileproperty(char *);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
void listFiles(const char *dirname) {
  DIR *dir = opendir(dirname);
  if (!dir) {
    printf("Error in Directory Name\n");
    exit(0);
  }
  struct dirent *file = readdir(dir);
  chdir(dirname);
  while (file) {
    if (file->d_name[0] != '.')
      fileproperty(file->d_name);
    file = readdir(dir);
  }
}


x86 assembly (clang, -O0):
<listFiles>:
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)
jne    1197 <listFiles+0x37>
lea    0xe75(%rip),%rdi
call   1050 <printf@plt>
xor    %edi,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <chdir@plt>
cmpq   $0x0,-0x18(%rbp)
je     11e9 <listFiles+0x89>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11d7 <listFiles+0x77>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1060 <fileproperty@plt>
mov    -0x10(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x18(%rbp)
jmp    11ad <listFiles+0x4d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listFiles>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1040 <opendir@plt>
test   %rax,%rax
je     11bf <listFiles+0x5f>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1050 <chdir@plt>
test   %rbx,%rbx
jne    11b0 <listFiles+0x50>
pop    %rbx
pop    %r14
pop    %r15
ret
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     118d <listFiles+0x2d>
mov    (%rbx),%rdi
cmpb   $0x2e,(%rdi)
je     11a0 <listFiles+0x40>
call   1060 <fileproperty@plt>
jmp    11a0 <listFiles+0x40>
lea    0xe3a(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [25 x i8] c"Error in Directory Name\0A\00"
define void @listFiles(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 %12, label %9
9: ; preds = %1
%10 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%11 = call i32 @exit(i32 0)
unreachable
12: ; preds = %1
%13 = load i32*, i32** %3
%14 = call %struct.dirent* @readdir(i32* %13)
store %struct.dirent* %14, %struct.dirent** %4
%15 = load i8*, i8** %2
%16 = call i32 @chdir(i8* %15)
br label %17
17: ; preds = %33, %12
%18 = load %struct.dirent*, %struct.dirent** %4
%19 = icmp ne %struct.dirent* %18, null
br i1 %19, label %20, label %36
20: ; preds = %17
%21 = load %struct.dirent*, %struct.dirent** %4
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i32 0, i32 0
%23 = load i8*, i8** %22
%24 = getelementptr inbounds i8, i8* %23, i64 0
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 46
br i1 %27, label %28, label %33
28: ; preds = %20
%29 = load %struct.dirent*, %struct.dirent** %4
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32 @fileproperty(i8* %31)
br label %33
33: ; preds = %28, %20
%34 = load i32*, i32** %3
%35 = call %struct.dirent* @readdir(i32* %34)
store %struct.dirent* %35, %struct.dirent** %4
br label %17
36: ; preds = %17
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@str = [24 x i8] c"Error in Directory Name\00"
define void @listFiles(i8* %0) {
%2 = tail call i32* @opendir(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%6 = tail call i32 @exit(i32 0)
unreachable
7: ; preds = %1
%8 = tail call %struct.dirent* @readdir(i32* %2)
%9 = tail call i32 @chdir(i8* %0)
%10 = icmp eq %struct.dirent* %8, null
br i1 %10, label %22, label %11
11: ; preds = %7, %19
%12 = phi %struct.dirent* [ %20, %19 ], [ %8, %7 ]
%13 = getelementptr inbounds %struct.dirent, %struct.dirent* %12, i64 0, i32 0
%14 = load i8*, i8** %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 46
br i1 %16, label %19, label %17
17: ; preds = %11
%18 = tail call i32 @fileproperty(i8* %14)
br label %19
19: ; preds = %17, %11
%20 = tail call %struct.dirent* @readdir(i32* %2)
%21 = icmp eq %struct.dirent* %20, null
br i1 %21, label %22, label %11
22: ; preds = %19, %7
ret void
}