#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*/ assert(char const *);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char *);
int empty_directory(const char *path) {
  DIR *dp;
  struct dirent *de;
  assert(path);
  dp = opendir(path);
  if (dp == NULL)
    return -1;
  while ((de = readdir(dp)) != NULL) {
    if ((!strcmp(de->d_name, ".") || !strcmp(de->d_name, "..")))
      continue;
    closedir(dp);
    return -1;
  }
  closedir(dp);
  return 0;
}


x86 assembly (clang, -O0):
<empty_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1189 <empty_directory+0x39>
movl   $0xffffffff,-0x4(%rbp)
jmp    1205 <empty_directory+0xb5>
jmp    118e <empty_directory+0x3e>
mov    -0x18(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11f5 <empty_directory+0xa5>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xe4f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     11db <empty_directory+0x8b>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xe33(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11e0 <empty_directory+0x90>
jmp    118e <empty_directory+0x3e>
mov    -0x18(%rbp),%rdi
call   1040 <closedir@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1205 <empty_directory+0xb5>
mov    -0x18(%rbp),%rdi
call   1040 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<empty_directory>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%rbx
call   1060 <assert@plt>
mov    %rbx,%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     11de <empty_directory+0x8e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <readdir@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11d4 <empty_directory+0x84>
mov    %rax,%rbp
lea    0xe77(%rip),%r12
lea    0xe6f(%rip),%r15
jmp    11b0 <empty_directory+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1070 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11d4 <empty_directory+0x84>
mov    0x0(%rbp),%edi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11a0 <empty_directory+0x50>
mov    0x0(%rbp),%edi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     11a0 <empty_directory+0x50>
mov    $0xffffffff,%r14d
mov    %rbx,%rdi
call   1040 <closedir@plt>
jmp    11e4 <empty_directory+0x94>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

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