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

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ puts(int /*<<< orphan*/);
struct dirent *readdir(int /*<<< orphan*/ *);
int main() {
  struct dirent *dp;
  DIR *dirp = NULL;
  dirp = opendir(".");
  while ((dp = readdir(dirp)) != NULL) {
    puts(dp->d_name);
  }
  closedir(dirp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xea2(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     118e <main+0x4e>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <puts@plt>
jmp    1167 <main+0x27>
mov    -0x18(%rbp),%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xeb8(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
call   1060 <readdir@plt>
test   %rax,%rax
je     1176 <main+0x36>
mov    (%rax),%edi
call   1030 <puts@plt>
mov    %rbx,%rdi
jmp    1160 <main+0x20>
mov    %rbx,%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.dirent*
%3 = alloca i32*
store i32 0, i32* %1
store i32* null, i32** %3
%4 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %3
br label %5
5: ; preds = %9, %0
%6 = load i32*, i32** %3
%7 = call %struct.dirent* @readdir(i32* %6)
store %struct.dirent* %7, %struct.dirent** %2
%8 = icmp ne %struct.dirent* %7, null
br i1 %8, label %9, label %14
9: ; preds = %5
%10 = load %struct.dirent*, %struct.dirent** %2
%11 = getelementptr inbounds %struct.dirent, %struct.dirent* %10, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @puts(i32 %12)
br label %5
14: ; preds = %5
%15 = load i32*, i32** %3
%16 = call i32 @closedir(i32* %15)
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [2 x i8] c".\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 0
%7 = load i32, i32* %6
%8 = tail call i32 @puts(i32 %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
}