#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 *);
struct dirent *readdir(int /*<<< orphan*/ *);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int is_dir_empty(char *dirname) {
  int empty = 1;
  struct dirent *d;
  DIR *dir = opendir(dirname);
  if (dir == NULL)
    return 1;
  while ((d = readdir(dir)) != NULL) {
    if (strcmp(d->d_name, ".") == 0)
      continue;
    if (strcmp(d->d_name, "..") == 0)
      continue;
    empty = 0;
    break;
  }
  closedir(dir);
  return empty;
}


x86 assembly (clang, -O0):
<is_dir_empty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1177 <is_dir_empty+0x37>
movl   $0x1,-0x4(%rbp)
jmp    11eb <is_dir_empty+0xab>
jmp    117c <is_dir_empty+0x3c>
mov    -0x28(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11dc <is_dir_empty+0x9c>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11b4 <is_dir_empty+0x74>
jmp    117c <is_dir_empty+0x3c>
mov    -0x20(%rbp),%rax
mov    (%rax),%edi
lea    0xe3f(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    11d5 <is_dir_empty+0x95>
jmp    117c <is_dir_empty+0x3c>
movl   $0x0,-0x14(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <closedir@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_dir_empty>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
call   1030 <opendir@plt>
test   %rax,%rax
je     11bd <is_dir_empty+0x7d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <readdir@plt>
mov    $0x1,%r14d
test   %rax,%rax
je     11b3 <is_dir_empty+0x73>
mov    %rax,%rbp
lea    0xe8f(%rip),%r12
lea    0xe87(%rip),%r15
jmp    1190 <is_dir_empty+0x50>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1060 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     11b3 <is_dir_empty+0x73>
mov    0x0(%rbp),%edi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1180 <is_dir_empty+0x40>
mov    0x0(%rbp),%edi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1180 <is_dir_empty+0x40>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1040 <closedir@plt>
jmp    11c3 <is_dir_empty+0x83>
mov    $0x1,%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 @is_dir_empty(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.dirent*
%6 = alloca i32*
store i8* %0, i8** %3
store i32 1, i32* %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 %36
12: ; preds = %1
br label %13
13: ; preds = %30, %23, %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 %32
17: ; preds = %13
%18 = load %struct.dirent*, %struct.dirent** %5
%19 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i64 @strcmp(i32 %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
br label %13
24: ; preds = %17
%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 i64 @strcmp(i32 %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%29 = icmp eq i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
br label %13
31: ; preds = %24
store i32 0, i32* %4
br label %32
32: ; preds = %31, %13
%33 = load i32*, i32** %6
%34 = call i32 @closedir(i32* %33)
%35 = load i32, i32* %4
store i32 %35, i32* %2
br label %36
36: ; preds = %32, %11
%37 = load i32, i32* %2
ret i32 %37
}

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