#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*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  DIR *d;
  struct dirent *dir;
  d = opendir(".");
  if (d) {
    while ((dir = readdir(d)) != NULL)
      printf("%s\n", dir->d_name);
    closedir(d);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea3(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11ae <main+0x6e>
jmp    1176 <main+0x36>
mov    -0x18(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11a5 <main+0x65>
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
lea    0xe67(%rip),%rdi
call   1040 <printf@plt>
jmp    1176 <main+0x36>
mov    -0x18(%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>
test   %rax,%rax
je     1190 <main+0x50>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     1188 <main+0x48>
lea    0xe96(%rip),%r14
nopl   0x0(%rax)
mov    (%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* }
@.str = [2 x i8] c".\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca %struct.dirent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = call i32* @opendir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %6
%9 = load i32*, i32** %6
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %24
11: ; preds = %2
br label %12
12: ; preds = %16, %11
%13 = load i32*, i32** %6
%14 = call %struct.dirent* @readdir(i32* %13)
store %struct.dirent* %14, %struct.dirent** %7
%15 = icmp ne %struct.dirent* %14, null
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load %struct.dirent*, %struct.dirent** %7
%18 = getelementptr inbounds %struct.dirent, %struct.dirent* %17, i32 0, i32 0
%19 = load i8*, i8** %18
%20 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %12
21: ; preds = %12
%22 = load i32*, i32** %6
%23 = call i32 @closedir(i32* %22)
br label %24
24: ; preds = %21, %2
ret i32 0
}

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