#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*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
bool is_directory_empty(char *directoryPath) {
  size_t fileCount = 0;
  struct dirent *aFile;
  DIR *directory = opendir(directoryPath);
  if (directory == NULL) {
    return true;
  }
  while ((aFile = readdir(directory)) != NULL) {
    if (++fileCount > 2) {
      break;
    }
  }
  closedir(directory);
  if (fileCount <= 2) {
    return true;
  } else {
    return false;
  }
}


x86 assembly (clang, -O0):
<is_directory_empty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1168 <is_directory_empty+0x38>
movl   $0x1,-0x4(%rbp)
jmp    11cb <is_directory_empty+0x9b>
jmp    116d <is_directory_empty+0x3d>
mov    -0x28(%rbp),%rdi
call   1050 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11a4 <is_directory_empty+0x74>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmp    $0x2,%rax
jbe    119f <is_directory_empty+0x6f>
jmp    11a4 <is_directory_empty+0x74>
jmp    116d <is_directory_empty+0x3d>
mov    -0x28(%rbp),%rdi
call   1040 <closedir@plt>
cmpq   $0x2,-0x18(%rbp)
ja     11c4 <is_directory_empty+0x94>
movl   $0x1,-0x4(%rbp)
jmp    11cb <is_directory_empty+0x9b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_directory_empty>:
push   %rbp
push   %rbx
push   %rax
call   1030 <opendir@plt>
test   %rax,%rax
je     1178 <is_directory_empty+0x48>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
je     1169 <is_directory_empty+0x39>
mov    %rbx,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
je     1169 <is_directory_empty+0x39>
mov    %rbx,%rdi
call   1050 <readdir@plt>
xor    %ebp,%ebp
test   %rax,%rax
jne    116e <is_directory_empty+0x3e>
mov    $0x1,%ebp
mov    %rbx,%rdi
call   1040 <closedir@plt>
jmp    117d <is_directory_empty+0x4d>
mov    $0x1,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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