#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*/ *);
void dodir(char *path) {
  DIR *dp;
  struct dirent *dirnode;
  if ((dp = opendir(path)) != NULL) {
    while ((dirnode = readdir(dp)) != NULL) {
      printf("%s\n", dirnode->d_name);
    }
  } else {
    printf("The directory %s does not exist\n", path);
  }
}


x86 assembly (clang, -O0):
<dodir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     118c <dodir+0x5c>
jmp    1158 <dodir+0x28>
mov    -0x10(%rbp),%rdi
call   1050 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1187 <dodir+0x57>
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
lea    0xe83(%rip),%rdi
call   1040 <printf@plt>
jmp    1158 <dodir+0x28>
jmp    119c <dodir+0x6c>
mov    -0x8(%rbp),%rsi
lea    0xe6d(%rip),%rdi
call   1040 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dodir>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
call   1030 <opendir@plt>
test   %rax,%rax
je     1180 <dodir+0x50>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
je     1178 <dodir+0x48>
lea    0xea8(%rip),%r14
nopl   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 <dodir+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe7d(%rip),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1040 <printf@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [4 x i8] c"%s\0A\00"
@.str.1 = [33 x i8] c"The directory %s does not exist\0A\00"
define void @dodir(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32* @opendir(i8* %5)
store i32* %6, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %8, label %19
8: ; preds = %1
br label %9
9: ; preds = %13, %8
%10 = load i32*, i32** %3
%11 = call %struct.dirent* @readdir(i32* %10)
store %struct.dirent* %11, %struct.dirent** %4
%12 = icmp ne %struct.dirent* %11, null
br i1 %12, label %13, label %18
13: ; preds = %9
%14 = load %struct.dirent*, %struct.dirent** %4
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %16)
br label %9
18: ; preds = %9
br label %22
19: ; preds = %1
%20 = load i8*, i8** %2
%21 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %19, %18
ret void
}

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