#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 const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcmp(int /*<<< orphan*/, char *);
int empty_directory(const char *path) {
  DIR *dp;
  struct dirent *de;
  if (!path)
    return -1;
  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)
cmpq   $0x0,-0x10(%rbp)
jne    1163 <empty_directory+0x23>
movl   $0xffffffff,-0x4(%rbp)
jmp    1203 <empty_directory+0xc3>
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1187 <empty_directory+0x47>
movl   $0xffffffff,-0x4(%rbp)
jmp    1203 <empty_directory+0xc3>
jmp    118c <empty_directory+0x4c>
mov    -0x18(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11f3 <empty_directory+0xb3>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xe51(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
je     11d9 <empty_directory+0x99>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    11de <empty_directory+0x9e>
jmp    118c <empty_directory+0x4c>
mov    -0x18(%rbp),%rdi
call   1040 <closedir@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1203 <empty_directory+0xc3>
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    $0xffffffff,%r14d
test   %rdi,%rdi
je     11cc <empty_directory+0x8c>
call   1030 <opendir@plt>
test   %rax,%rax
je     11cc <empty_directory+0x8c>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <readdir@plt>
xor    %r14d,%r14d
test   %rax,%rax
je     11c4 <empty_directory+0x84>
mov    %rax,%rbp
lea    0xe87(%rip),%r12
lea    0xe7f(%rip),%r15
jmp    11a0 <empty_directory+0x60>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
call   1060 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11c4 <empty_directory+0x84>
mov    0x0(%rbp),%edi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1190 <empty_directory+0x50>
mov    0x0(%rbp),%edi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %eax,%eax
je     1190 <empty_directory+0x50>
mov    $0xffffffff,%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 = [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 = icmp ne i8* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
store i32 -1, i32* %2
br label %39
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32* @opendir(i8* %10)
store i32* %11, i32** %4
%12 = load i32*, i32** %4
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %15
14: ; preds = %9
store i32 -1, i32* %2
br label %39
15: ; preds = %9
br label %16
16: ; preds = %32, %15
%17 = load i32*, i32** %4
%18 = call %struct.dirent* @readdir(i32* %17)
store %struct.dirent* %18, %struct.dirent** %5
%19 = icmp ne %struct.dirent* %18, null
br i1 %19, label %20, label %36
20: ; preds = %16
%21 = load %struct.dirent*, %struct.dirent** %5
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @strcmp(i32 %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %32
26: ; preds = %20
%27 = load %struct.dirent*, %struct.dirent** %5
%28 = getelementptr inbounds %struct.dirent, %struct.dirent* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @strcmp(i32 %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp ne i32 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %26, %20
br label %16
33: ; preds = %26
%34 = load i32*, i32** %4
%35 = call i32 @closedir(i32* %34)
store i32 -1, i32* %2
br label %39
36: ; preds = %16
%37 = load i32*, i32** %4
%38 = call i32 @closedir(i32* %37)
store i32 0, i32* %2
br label %39
39: ; preds = %36, %33, %14, %8
%40 = load i32, i32* %2
ret i32 %40
}

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 = icmp eq i8* %0, null
br i1 %2, label %25, label %3
3: ; preds = %1
%4 = tail call i32* @opendir(i8* %0)
%5 = icmp eq i32* %4, null
br i1 %5, label %25, label %6
6: ; preds = %3
%7 = tail call %struct.dirent* @readdir(i32* %4)
%8 = icmp eq %struct.dirent* %7, null
br i1 %8, label %22, label %9
9: ; preds = %6, %19
%10 = phi %struct.dirent* [ %20, %19 ], [ %7, %6 ]
%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, 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.1, 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* %4)
%21 = icmp eq %struct.dirent* %20, null
br i1 %21, label %22, label %9
22: ; preds = %19, %15, %6
%23 = phi i32 [ 0, %6 ], [ -1, %15 ], [ 0, %19 ]
%24 = tail call i32 @closedir(i32* %4)
br label %25
25: ; preds = %22, %3, %1
%26 = phi i32 [ -1, %1 ], [ -1, %3 ], [ %23, %22 ]
ret i32 %26
}