#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 scalar_t__ off_t;
typedef int /*<<< orphan*/ mode_t;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ *opendir(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(int /*<<< orphan*/, char *);
char *strerror(int /*<<< orphan*/);
int fuse_mnt_check_empty(const char *progname, const char *mnt, mode_t rootmode,
                         off_t rootsize) {
  int isempty = 1;
  if (S_ISDIR(rootmode)) {
    struct dirent *ent;
    DIR *dp = opendir(mnt);
    if (dp == NULL) {
      fprintf(stderr, "%s: failed to open mountpoint for reading: %s\n",
              progname, strerror(errno));
      return -1;
    }
    while ((ent = readdir(dp)) != NULL) {
      if (strcmp(ent->d_name, ".") != 0 && strcmp(ent->d_name, "..") != 0) {
        isempty = 0;
        break;
      }
    }
    closedir(dp);
  } else if (rootsize)
    isempty = 0;
  if (!isempty) {
    fprintf(stderr, "%s: mountpoint is not empty\n", progname);
    fprintf(
        stderr,
        "%s: if you are sure this is safe, use the 'nonempty' mount option\n",
        progname);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<fuse_mnt_check_empty>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
movl   $0x1,-0x2c(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1271 <fuse_mnt_check_empty+0x101>
mov    -0x18(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11fe <fuse_mnt_check_empty+0x8e>
mov    0x2e21(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    %rax,%rcx
lea    0xe15(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12db <fuse_mnt_check_empty+0x16b>
jmp    1203 <fuse_mnt_check_empty+0x93>
mov    -0x40(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     1263 <fuse_mnt_check_empty+0xf3>
mov    -0x38(%rbp),%rax
mov    (%rax),%edi
lea    0xe09(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     125e <fuse_mnt_check_empty+0xee>
mov    -0x38(%rbp),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     125e <fuse_mnt_check_empty+0xee>
movl   $0x0,-0x2c(%rbp)
jmp    1263 <fuse_mnt_check_empty+0xf3>
jmp    1203 <fuse_mnt_check_empty+0x93>
mov    -0x40(%rbp),%rdi
call   1050 <closedir@plt>
jmp    1288 <fuse_mnt_check_empty+0x118>
cmpq   $0x0,-0x28(%rbp)
je     1283 <fuse_mnt_check_empty+0x113>
movl   $0x0,-0x2c(%rbp)
jmp    1288 <fuse_mnt_check_empty+0x118>
cmpl   $0x0,-0x2c(%rbp)
jne    12d4 <fuse_mnt_check_empty+0x164>
mov    0x2d47(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd8c(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d2c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd8e(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12db <fuse_mnt_check_empty+0x16b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fuse_mnt_check_empty>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %edx,%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     1208 <fuse_mnt_check_empty+0x98>
mov    %rbx,%rdi
call   1030 <opendir@plt>
test   %rax,%rax
je     1248 <fuse_mnt_check_empty+0xd8>
mov    %rax,%r13
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     123c <fuse_mnt_check_empty+0xcc>
mov    %rax,%rbx
lea    0xe73(%rip),%r15
lea    0xe6b(%rip),%r12
jmp    11e0 <fuse_mnt_check_empty+0x70>
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1080 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     123c <fuse_mnt_check_empty+0xcc>
mov    (%rbx),%edi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11d0 <fuse_mnt_check_empty+0x60>
mov    (%rbx),%edi
mov    %r12,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     11d0 <fuse_mnt_check_empty+0x60>
mov    %r13,%rdi
call   1050 <closedir@plt>
jmp    120d <fuse_mnt_check_empty+0x9d>
test   %r15,%r15
je     1284 <fuse_mnt_check_empty+0x114>
mov    0x2dcc(%rip),%rbx
mov    (%rbx),%edi
lea    0xe15(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe1f(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    1275 <fuse_mnt_check_empty+0x105>
mov    %r13,%rdi
call   1050 <closedir@plt>
xor    %eax,%eax
jmp    127a <fuse_mnt_check_empty+0x10a>
mov    0x2d91(%rip),%rax
mov    (%rax),%ebx
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd9a(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
xor    %eax,%eax
jmp    127a <fuse_mnt_check_empty+0x10a>

LLVM IR (-O0):
%struct.dirent = type { i32 }
@stderr = global i32 0
@.str = [47 x i8] c"%s: failed to open mountpoint for reading: %s\0A\00"
@errno = global i32 0
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [29 x i8] c"%s: mountpoint is not empty\0A\00"
@.str.4 = [67 x i8] c"%s: if you are sure this is safe, use the 'nonempty' mount option\0A\00"
define i32 @fuse_mnt_check_empty(i8* %0, i8* %1, i32 %2, i64 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i32
%11 = alloca %struct.dirent*
%12 = alloca i32*
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i64 %3, i64* %9
store i32 1, i32* %10
%13 = load i32, i32* %8
%14 = call i64 @S_ISDIR(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %49
16: ; preds = %4
%17 = load i8*, i8** %7
%18 = call i32* @opendir(i8* %17)
store i32* %18, i32** %12
%19 = load i32*, i32** %12
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %27
21: ; preds = %16
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %6
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %23, i8* %25)
store i32 -1, i32* %5
br label %65
27: ; preds = %16
br label %28
28: ; preds = %45, %27
%29 = load i32*, i32** %12
%30 = call %struct.dirent* @readdir(i32* %29)
store %struct.dirent* %30, %struct.dirent** %11
%31 = icmp ne %struct.dirent* %30, null
br i1 %31, label %32, label %46
32: ; preds = %28
%33 = load %struct.dirent*, %struct.dirent** %11
%34 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i32 0, i32 0
%35 = load i32, i32* %34
%36 = call i64 @strcmp(i32 %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %45
38: ; preds = %32
%39 = load %struct.dirent*, %struct.dirent** %11
%40 = getelementptr inbounds %struct.dirent, %struct.dirent* %39, i32 0, i32 0
%41 = load i32, i32* %40
%42 = call i64 @strcmp(i32 %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %38
store i32 0, i32* %10
br label %46
45: ; preds = %38, %32
br label %28
46: ; preds = %44, %28
%47 = load i32*, i32** %12
%48 = call i32 @closedir(i32* %47)
br label %54
49: ; preds = %4
%50 = load i64, i64* %9
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %49
store i32 0, i32* %10
br label %53
53: ; preds = %52, %49
br label %54
54: ; preds = %53, %46
%55 = load i32, i32* %10
%56 = icmp ne i32 %55, 0
br i1 %56, label %64, label %57
57: ; preds = %54
%58 = load i32, i32* @stderr
%59 = load i8*, i8** %6
%60 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %59)
%61 = load i32, i32* @stderr
%62 = load i8*, i8** %6
%63 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.4, i64 0, i64 0), i8* %62)
store i32 -1, i32* %5
br label %65
64: ; preds = %54
store i32 0, i32* %5
br label %65
65: ; preds = %64, %57, %21
%66 = load i32, i32* %5
ret i32 %66
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@stderr = global i32 0
@.str = [47 x i8] c"%s: failed to open mountpoint for reading: %s\0A\00"
@errno = global i32 0
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [29 x i8] c"%s: mountpoint is not empty\0A\00"
@.str.4 = [67 x i8] c"%s: if you are sure this is safe, use the 'nonempty' mount option\0A\00"
define i32 @fuse_mnt_check_empty(i8* %0, i8* nocapture %1, i32 %2, i64 %3) {
%5 = tail call i64 @S_ISDIR(i32 %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %35, label %7
7: ; preds = %4
%8 = tail call i32* @opendir(i8* %1)
%9 = icmp eq i32* %8, null
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call %struct.dirent* @readdir(i32* %8)
%12 = icmp eq %struct.dirent* %11, null
br i1 %12, label %31, label %18
13: ; preds = %7
%14 = load i32, i32* @stderr
%15 = load i32, i32* @errno
%16 = tail call i8* @strerror(i32 %15)
%17 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %16)
br label %42
18: ; preds = %10, %28
%19 = phi %struct.dirent* [ %29, %28 ], [ %11, %10 ]
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %19, i64 0, i32 0
%21 = load i32, i32* %20
%22 = tail call i64 @strcmp(i32 %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %18
%25 = load i32, i32* %20
%26 = tail call i64 @strcmp(i32 %25, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %33
28: ; preds = %24, %18
%29 = tail call %struct.dirent* @readdir(i32* %8)
%30 = icmp eq %struct.dirent* %29, null
br i1 %30, label %31, label %18
31: ; preds = %28, %10
%32 = tail call i32 @closedir(i32* %8)
br label %42
33: ; preds = %24
%34 = tail call i32 @closedir(i32* %8)
br label %37
35: ; preds = %4
%36 = icmp eq i64 %3, 0
br i1 %36, label %42, label %37
37: ; preds = %33, %35
%38 = load i32, i32* @stderr
%39 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%40 = load i32, i32* @stderr
%41 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %42
42: ; preds = %31, %35, %13, %37
%43 = phi i32 [ -1, %37 ], [ -1, %13 ], [ 0, %35 ], [ 0, %31 ]
ret i32 %43
}