#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*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
void print_levels() {
  printf("Levels installed: (%s)\n", "./levels");
  DIR *dir;
  if (!(dir = opendir("./levels"))) {
    perror("list_levels");
    return;
  }
  struct dirent *dent;
  while ((dent = readdir(dir))) {
    if (dent->d_name[0] != '.') {
      printf("%s\n", dent->d_name);
    }
  }
}


x86 assembly (clang, -O0):
<print_levels>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
lea    0xec2(%rip),%rsi
call   1040 <printf@plt>
lea    0xeb6(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x8(%rbp)
cmp    $0x0,%rax
jne    1186 <print_levels+0x46>
lea    0xea5(%rip),%rdi
call   1060 <perror@plt>
jmp    11cd <print_levels+0x8d>
jmp    118b <print_levels+0x4b>
mov    -0x8(%rbp),%rdi
call   1050 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11cd <print_levels+0x8d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     11c8 <print_levels+0x88>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe6a(%rip),%rdi
call   1040 <printf@plt>
jmp    118b <print_levels+0x4b>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_levels>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rdi
lea    0xec6(%rip),%rbx
mov    %rbx,%rsi
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11a7 <print_levels+0x67>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
je     119f <print_levels+0x5f>
lea    0xeaf(%rip),%r14
jmp    118d <print_levels+0x4d>
mov    %rbx,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
je     119f <print_levels+0x5f>
mov    (%rax),%rsi
cmpb   $0x2e,(%rsi)
je     1180 <print_levels+0x40>
mov    %r14,%rdi
call   1040 <printf@plt>
jmp    1180 <print_levels+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe73(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1060 <perror@plt>

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [24 x i8] c"Levels installed: (%s)\0A\00"
@.str.1 = [9 x i8] c"./levels\00"
@.str.2 = [12 x i8] c"list_levels\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define void @print_levels() {
%1 = alloca i32*
%2 = alloca %struct.dirent*
%3 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%4 = call i32* @opendir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %1
%5 = icmp ne i32* %4, null
br i1 %5, label %8, label %6
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %27
8: ; preds = %0
br label %9
9: ; preds = %26, %8
%10 = load i32*, i32** %1
%11 = call %struct.dirent* @readdir(i32* %10)
store %struct.dirent* %11, %struct.dirent** %2
%12 = icmp ne %struct.dirent* %11, null
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = load %struct.dirent*, %struct.dirent** %2
%15 = getelementptr inbounds %struct.dirent, %struct.dirent* %14, i32 0, i32 0
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8, i8* %16, i64 0
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = icmp ne i32 %19, 46
br i1 %20, label %21, label %26
21: ; preds = %13
%22 = load %struct.dirent*, %struct.dirent** %2
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %21, %13
br label %9
27: ; preds = %6, %9
ret void
}

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