#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*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
void print_directory_contents(const char *path, char *flags[]) {
  DIR *this_dir = opendir(path);
  struct dirent *this_file;
  if (this_dir == NULL) {
    fprintf(stderr, "error opening %s\n", path);
    exit(1);
  }
  while ((this_file = readdir(this_dir)) != NULL) {
    if ('.' != this_file->d_name[0]) {
      printf("%s\n", this_file->d_name);
    }
  }
  closedir(this_dir);
}


x86 assembly (clang, -O0):
<print_directory_contents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11ab <print_directory_contents+0x4b>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe64(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    11b0 <print_directory_contents+0x50>
mov    -0x18(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11f6 <print_directory_contents+0x96>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%ecx
mov    $0x2e,%eax
cmp    %ecx,%eax
je     11f1 <print_directory_contents+0x91>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe22(%rip),%rdi
call   1040 <printf@plt>
jmp    11b0 <print_directory_contents+0x50>
mov    -0x18(%rbp),%rdi
call   1050 <closedir@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_directory_contents>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <opendir@plt>
test   %rax,%rax
je     11be <print_directory_contents+0x5e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11af <print_directory_contents+0x4f>
lea    0xe86(%rip),%r14
jmp    119d <print_directory_contents+0x3d>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11af <print_directory_contents+0x4f>
mov    (%rax),%rsi
cmpb   $0x2e,(%rsi)
je     1190 <print_directory_contents+0x30>
mov    %r14,%rdi
call   1040 <printf@plt>
jmp    1190 <print_directory_contents+0x30>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <closedir@plt>
mov    0x2e1b(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
mov    %r14,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

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

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