#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*/ perror(char *);
int /*<<< orphan*/ puts(int /*<<< orphan*/);
struct dirent *readdir(int /*<<< orphan*/ *);
int main(void) {
  DIR *dp;
  struct dirent *ep;
  dp = opendir("/home/elsuizo");
  if (dp != NULL) {
    while (ep = readdir(dp))
      puts(ep->d_name);
    (void)closedir(dp);
  } else
    perror("Couldn't open the directory");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b4 <main+0x64>
jmp    117f <main+0x2f>
mov    -0x10(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11a6 <main+0x56>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1030 <puts@plt>
jmp    117f <main+0x2f>
mov    -0x10(%rbp),%rdi
call   1050 <closedir@plt>
jmp    11c0 <main+0x70>
lea    0xe53(%rip),%rdi
call   1070 <perror@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xea8(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1192 <main+0x42>
mov    %rax,%rbx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     1186 <main+0x36>
mov    (%rax),%edi
call   1030 <puts@plt>
jmp    1170 <main+0x20>
mov    %rbx,%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe75(%rip),%rdi
call   1070 <perror@plt>
jmp    118e <main+0x3e>

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [14 x i8] c"/home/elsuizo\00"
@.str.1 = [28 x i8] c"Couldn't open the directory\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 ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %20
7: ; preds = %0
br label %8
8: ; preds = %12, %7
%9 = load i32*, i32** %2
%10 = call %struct.dirent* @readdir(i32* %9)
store %struct.dirent* %10, %struct.dirent** %3
%11 = icmp ne %struct.dirent* %10, null
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load %struct.dirent*, %struct.dirent** %3
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @puts(i32 %15)
br label %8
17: ; preds = %8
%18 = load i32*, i32** %2
%19 = call i32 @closedir(i32* %18)
br label %22
20: ; preds = %0
%21 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %17
ret i32 0
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [14 x i8] c"/home/elsuizo\00"
@.str.1 = [28 x i8] c"Couldn't open the directory\00"
define i32 @main() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %15, label %3
3: ; preds = %0
%4 = tail call %struct.dirent* @readdir(i32* %1)
%5 = icmp eq %struct.dirent* %4, null
br i1 %5, label %13, label %6
6: ; preds = %3, %6
%7 = phi %struct.dirent* [ %11, %6 ], [ %4, %3 ]
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %7, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 @puts(i32 %9)
%11 = tail call %struct.dirent* @readdir(i32* %1)
%12 = icmp eq %struct.dirent* %11, null
br i1 %12, label %13, label %6
13: ; preds = %6, %3
%14 = tail call i32 @closedir(i32* %1)
br label %17
15: ; preds = %0
%16 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %17
17: ; preds = %15, %13
ret i32 0
}