#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*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int main() {
  DIR *dirp;
  struct dirent *dentry;
  dirp = opendir("/home");
  while ((dentry = readdir(dirp)) != NULL) {
    printf("Name : %s ", dentry->d_name);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeba(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     117e <main+0x4e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe92(%rip),%rdi
call   1040 <printf@plt>
jmp    114f <main+0x1f>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

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

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

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [6 x i8] c"/home\00"
@.str.1 = [11 x i8] c"Name : %s \00"
define i32 @main() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([6 x i8], [6 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 i8*, i8** %6
%8 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 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
ret i32 0
}