#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 *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char *);
int getNbLevels() {
  unsigned int count = 0;
  DIR *dir;
  struct dirent *file;
  if ((dir = opendir("../data/map/")) != NULL) {
    while ((file = readdir(dir)) != NULL) {
      if (!strcmp(file->d_name, ".") || !strcmp(file->d_name, ".."))
        continue;
      count++;
    }
    closedir(dir);
  }
  return count;
}


x86 assembly (clang, -O0):
<getNbLevels>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11d7 <getNbLevels+0x97>
jmp    116e <getNbLevels+0x2e>
mov    -0x10(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11ce <getNbLevels+0x8e>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    0xe7c(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     11bb <getNbLevels+0x7b>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11c0 <getNbLevels+0x80>
jmp    116e <getNbLevels+0x2e>
mov    -0x4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
jmp    116e <getNbLevels+0x2e>
mov    -0x10(%rbp),%rdi
call   1040 <closedir@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getNbLevels>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
lea    0xeb1(%rip),%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11b4 <getNbLevels+0x74>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11b9 <getNbLevels+0x79>
mov    %rax,%rbp
xor    %r14d,%r14d
lea    0xe98(%rip),%r12
lea    0xe90(%rip),%r15
jmp    1190 <getNbLevels+0x50>
nop
mov    %rbx,%rdi
call   1060 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11bc <getNbLevels+0x7c>
mov    0x0(%rbp),%edi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1180 <getNbLevels+0x40>
mov    0x0(%rbp),%edi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1180 <getNbLevels+0x40>
add    $0x1,%r14d
jmp    1180 <getNbLevels+0x40>
xor    %r14d,%r14d
jmp    11c4 <getNbLevels+0x84>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1040 <closedir@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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