#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*/ *);
scalar_t__ ignore_maildir_entry(char *, struct dirent *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int count_entries(char *path) {
  DIR *mdir;
  struct dirent *entry;
  int count = 0;
  if ((mdir = opendir(path)) == NULL)
    return -1;
  while ((entry = readdir(mdir))) {
    if (ignore_maildir_entry(path, entry))
      continue;
    count++;
  }
  closedir(mdir);
  return count;
}


x86 assembly (clang, -O0):
<count_entries>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    1176 <count_entries+0x36>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cb <count_entries+0x8b>
jmp    117b <count_entries+0x3b>
mov    -0x18(%rbp),%rdi
call   1050 <readdir@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     11bc <count_entries+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <ignore_maildir_entry@plt>
cmp    $0x0,%rax
je     11ae <count_entries+0x6e>
jmp    117b <count_entries+0x3b>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    117b <count_entries+0x3b>
mov    -0x18(%rbp),%rdi
call   1040 <closedir@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_entries>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
call   1030 <opendir@plt>
test   %rax,%rax
je     1199 <count_entries+0x59>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <readdir@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     118f <count_entries+0x4f>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <ignore_maildir_entry@plt>
cmp    $0x1,%rax
adc    $0x0,%ebp
mov    %rbx,%rdi
call   1050 <readdir@plt>
test   %rax,%rax
jne    1170 <count_entries+0x30>
mov    %rbx,%rdi
call   1040 <closedir@plt>
jmp    119e <count_entries+0x5e>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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