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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int main() {
  unsigned char isFolder = 0x4;
  DIR *dir;
  struct dirent *dirEntry;
  dir = opendir(".");
  while (dirEntry = readdir(dir)) {
    if (dirEntry->d_type == isFolder) {
      printf("%s\n", dirEntry->d_name);
    } else {
      printf("%s\n", dirEntry->d_name);
    }
  }
  closedir(dir);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x4,-0x5(%rbp)
lea    0xea6(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11bf <main+0x7f>
mov    -0x18(%rbp),%rax
movzbl (%rax),%eax
movzbl -0x5(%rbp),%ecx
cmp    %ecx,%eax
jne    11a6 <main+0x66>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
jmp    11ba <main+0x7a>
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe4d(%rip),%rdi
call   1040 <printf@plt>
jmp    1163 <main+0x23>
mov    -0x10(%rbp),%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     1189 <main+0x49>
lea    0xe9b(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    0x8(%rax),%rsi
mov    %r14,%rdi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
jne    1170 <main+0x30>
mov    %rbx,%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

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