#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 *, ...);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
void listfile() {
  DIR *d = opendir("./files/");
  struct dirent *dir;
  if (d) {
    printf("Current list of files\n");
    while ((dir = readdir(d)) != NULL) {
      if (strcmp(dir->d_name, "..") == 0 || strcmp(dir->d_name, ".") == 0)
        continue;
      printf("%s\n", dir->d_name);
    }
    closedir(d);
  }
}


x86 assembly (clang, -O0):
<listfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11fa <listfile+0xaa>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11f1 <listfile+0xa1>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe7a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     11d2 <listfile+0x82>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe5e(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11d7 <listfile+0x87>
jmp    1181 <listfile+0x31>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1181 <listfile+0x31>
mov    -0x8(%rbp),%rdi
call   1050 <closedir@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<listfile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xea1(%rip),%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     11ed <listfile+0x9d>
mov    %rax,%r12
lea    0xe95(%rip),%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11da <listfile+0x8a>
mov    %rax,%rbx
lea    0xe76(%rip),%r14
lea    0xe70(%rip),%r15
jmp    11b0 <listfile+0x60>
nopl   0x0(%rax)
mov    %r12,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11da <listfile+0x8a>
mov    (%rbx),%rdi
mov    %r14,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11a0 <listfile+0x50>
mov    (%rbx),%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11a0 <listfile+0x50>
mov    (%rbx),%rdi
call   1030 <puts@plt>
jmp    11a0 <listfile+0x50>
mov    %r12,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <closedir@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [9 x i8] c"./files/\00"
@.str.1 = [23 x i8] c"Current list of files\0A\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [2 x i8] c".\00"
@.str.4 = [4 x i8] c"%s\0A\00"
define void @listfile() {
%1 = alloca i32*
%2 = alloca %struct.dirent*
%3 = call i32* @opendir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
store i32* %3, i32** %1
%4 = load i32*, i32** %1
%5 = icmp ne i32* %4, null
br i1 %5, label %6, label %33
6: ; preds = %0
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %25, %24, %6
%9 = load i32*, i32** %1
%10 = call %struct.dirent* @readdir(i32* %9)
store %struct.dirent* %10, %struct.dirent** %2
%11 = icmp ne %struct.dirent* %10, null
br i1 %11, label %12, label %30
12: ; preds = %8
%13 = load %struct.dirent*, %struct.dirent** %2
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i32 0, i32 0
%15 = load i8*, i8** %14
%16 = call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %24, label %18
18: ; preds = %12
%19 = load %struct.dirent*, %struct.dirent** %2
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %19, i32 0, i32 0
%21 = load i8*, i8** %20
%22 = call i64 @strcmp(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %18, %12
br label %8
25: ; preds = %18
%26 = load %struct.dirent*, %struct.dirent** %2
%27 = getelementptr inbounds %struct.dirent, %struct.dirent* %26, i32 0, i32 0
%28 = load i8*, i8** %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %28)
br label %8
30: ; preds = %8
%31 = load i32*, i32** %1
%32 = call i32 @closedir(i32* %31)
br label %33
33: ; preds = %30, %0
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [9 x i8] c"./files/\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [2 x i8] c".\00"
@str = [22 x i8] c"Current list of files\00"
define void @listfile() {
%1 = tail call i32* @opendir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %25, label %3
3: ; preds = %0
%4 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%5 = tail call %struct.dirent* @readdir(i32* %1)
%6 = icmp eq %struct.dirent* %5, null
br i1 %6, label %23, label %7
7: ; preds = %3, %17
%8 = phi %struct.dirent* [ %18, %17 ], [ %5, %3 ]
%9 = getelementptr inbounds %struct.dirent, %struct.dirent* %8, i64 0, i32 0
%10 = load i8*, i8** %9
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %7
%14 = load i8*, i8** %9
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %7, %13, %20
%18 = tail call %struct.dirent* @readdir(i32* %1)
%19 = icmp eq %struct.dirent* %18, null
br i1 %19, label %23, label %7
20: ; preds = %13
%21 = load i8*, i8** %9
%22 = tail call i32 @puts(i8* dereferenceable(1) %21)
br label %17
23: ; preds = %17, %3
%24 = tail call i32 @closedir(i32* %1)
br label %25
25: ; preds = %23, %0
ret void
}