#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*/ ace_fs_is_current_or_parent_directory(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int ace_tu_fs_get_number_of_files_in_directory(char *dirpath) {
  DIR *directory;
  struct dirent *entity;
  int number_of_files = 0;
  directory = opendir(dirpath);
  while ((entity = readdir(directory)) != NULL) {
    if (!ace_fs_is_current_or_parent_directory(entity->d_name)) {
      number_of_files++;
    }
  }
  closedir(directory);
  return number_of_files;
}


x86 assembly (clang, -O0):
<ace_tu_fs_get_number_of_files_in_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     1199 <ace_tu_fs_get_number_of_files_in_directory+0x59>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1060 <ace_fs_is_current_or_parent_directory@plt>
cmp    $0x0,%eax
jne    1194 <ace_tu_fs_get_number_of_files_in_directory+0x54>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1160 <ace_tu_fs_get_number_of_files_in_directory+0x20>
mov    -0x10(%rbp),%rdi
call   1040 <closedir@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ace_tu_fs_get_number_of_files_in_directory>:
push   %rbp
push   %rbx
push   %rax
call   1030 <opendir@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <readdir@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     117a <ace_tu_fs_get_number_of_files_in_directory+0x3a>
nopw   0x0(%rax,%rax,1)
mov    (%rax),%edi
call   1060 <ace_fs_is_current_or_parent_directory@plt>
cmp    $0x1,%eax
adc    $0x0,%ebp
mov    %rbx,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
jne    1160 <ace_tu_fs_get_number_of_files_in_directory+0x20>
mov    %rbx,%rdi
call   1040 <closedir@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
define i32 @ace_tu_fs_get_number_of_files_in_directory(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
%6 = load i8*, i8** %2
%7 = call i32* @opendir(i8* %6)
store i32* %7, i32** %3
br label %8
8: ; preds = %21, %1
%9 = load i32*, i32** %3
%10 = call %struct.dirent* @readdir(i32* %9)
store %struct.dirent* %10, %struct.dirent** %4
%11 = icmp ne %struct.dirent* %10, null
br i1 %11, label %12, label %22
12: ; preds = %8
%13 = load %struct.dirent*, %struct.dirent** %4
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = call i32 @ace_fs_is_current_or_parent_directory(i32 %15)
%17 = icmp ne i32 %16, 0
br i1 %17, label %21, label %18
18: ; preds = %12
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
br label %21
21: ; preds = %18, %12
br label %8
22: ; preds = %8
%23 = load i32*, i32** %3
%24 = call i32 @closedir(i32* %23)
%25 = load i32, i32* %5
ret i32 %25
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
define i32 @ace_tu_fs_get_number_of_files_in_directory(i8* nocapture %0) {
%2 = tail call i32* @opendir(i8* %0)
%3 = tail call %struct.dirent* @readdir(i32* %2)
%4 = icmp eq %struct.dirent* %3, null
br i1 %4, label %16, label %5
5: ; preds = %1, %5
%6 = phi %struct.dirent* [ %14, %5 ], [ %3, %1 ]
%7 = phi i32 [ %13, %5 ], [ 0, %1 ]
%8 = getelementptr inbounds %struct.dirent, %struct.dirent* %6, i64 0, i32 0
%9 = load i32, i32* %8
%10 = tail call i32 @ace_fs_is_current_or_parent_directory(i32 %9)
%11 = icmp eq i32 %10, 0
%12 = zext i1 %11 to i32
%13 = add nuw nsw i32 %7, %12
%14 = tail call %struct.dirent* @readdir(i32* %2)
%15 = icmp eq %struct.dirent* %14, null
br i1 %15, label %16, label %5
16: ; preds = %5, %1
%17 = phi i32 [ 0, %1 ], [ %13, %5 ]
%18 = tail call i32 @closedir(i32* %2)
ret i32 %17
}