#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 dummy;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ printf(char *, char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int numberOfFiles(const char fnaFilesDirectory[]) {
  DIR *fnaFilesDirectoryPointer;
  struct dirent *direntFnaDirectory;
  fnaFilesDirectoryPointer = opendir(fnaFilesDirectory);
  int fnaFileCount = 0;
  if (fnaFilesDirectoryPointer) {
    while ((direntFnaDirectory = readdir(fnaFilesDirectoryPointer)) != NULL) {
      fnaFileCount++;
    }
    closedir(fnaFilesDirectoryPointer);
  } else {
    printf("%s", "Error:(numberOfFiles): fnaFilesDirectory[] is null\n");
    exit(EXIT_FAILURE);
  }
  return fnaFileCount;
}


x86 assembly (clang, -O0):
<numberOfFiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b3 <numberOfFiles+0x63>
jmp    1180 <numberOfFiles+0x30>
mov    -0x10(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11a5 <numberOfFiles+0x55>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1180 <numberOfFiles+0x30>
mov    -0x10(%rbp),%rdi
call   1050 <closedir@plt>
jmp    11d4 <numberOfFiles+0x84>
lea    0xe46(%rip),%rdi
lea    0xe42(%rip),%rsi
call   1040 <printf@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<numberOfFiles>:
push   %rbp
push   %rbx
push   %rax
call   1030 <opendir@plt>
test   %rax,%rax
je     1191 <numberOfFiles+0x41>
mov    %rax,%rbx
mov    $0xffffffff,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1060 <readdir@plt>
add    $0x1,%ebp
test   %rax,%rax
jne    1170 <numberOfFiles+0x20>
mov    %rbx,%rdi
call   1050 <closedir@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe68(%rip),%rdi
lea    0xe64(%rip),%rsi
call   1040 <printf@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [52 x i8] c"Error:(numberOfFiles): fnaFilesDirectory[] is null\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @numberOfFiles(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca %struct.dirent*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @opendir(i8* %6)
store i32* %7, i32** %3
store i32 0, i32* %5
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %21
10: ; preds = %1
br label %11
11: ; preds = %15, %10
%12 = load i32*, i32** %3
%13 = call %struct.dirent* @readdir(i32* %12)
store %struct.dirent* %13, %struct.dirent** %4
%14 = icmp ne %struct.dirent* %13, null
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* %5
%17 = add nsw i32 %16, 1
store i32 %17, i32* %5
br label %11
18: ; preds = %11
%19 = load i32*, i32** %3
%20 = call i32 @closedir(i32* %19)
br label %25
21: ; preds = %1
%22 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %18
%26 = load i32, i32* %5
ret i32 %26
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [3 x i8] c"%s\00"
@.str.1 = [52 x i8] c"Error:(numberOfFiles): fnaFilesDirectory[] is null\0A\00"
@EXIT_FAILURE = global i32 0
define i32 @numberOfFiles(i8* nocapture %0) {
%2 = tail call i32* @opendir(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %11, label %4
4: ; preds = %1, %4
%5 = phi i32 [ %8, %4 ], [ 0, %1 ]
%6 = tail call %struct.dirent* @readdir(i32* %2)
%7 = icmp eq %struct.dirent* %6, null
%8 = add nuw nsw i32 %5, 1
br i1 %7, label %9, label %4
9: ; preds = %4
%10 = tail call i32 @closedir(i32* %2)
ret i32 %5
11: ; preds = %1
%12 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.1, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = tail call i32 @exit(i32 %13)
unreachable
}