#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 {
  char *d_name;
};
typedef int /*<<< orphan*/ dir;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int count_entries(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
scalar_t__ ignore_maildir_entry(char *, struct dirent *);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int /*<<< orphan*/ stderr;
char *strchr(char *, char);
int check_maildir(const char *path, int *new, int *read, int *unread) {
  char dir[(2048)];
  DIR *mdir;
  struct dirent *entry;
  char *pos;
  snprintf(dir, sizeof(dir), "%s/new", path);
  *new = count_entries(dir);
  if (*new == -1)
    return -1;
  snprintf(dir, sizeof(dir), "%s/cur", path);
  if ((mdir = opendir(dir)) == NULL)
    return -1;
  *read = 0;
  *unread = 0;
  while ((entry = readdir(mdir))) {
    if (ignore_maildir_entry(dir, entry))
      continue;
    if ((pos = strchr(entry->d_name, ':')) == NULL) {
      (*unread)++;
    } else if (*(pos + 1) != '2') {
      fprintf(stderr,
              "mailcheck: ooops, unsupported experimental info "
              "semantics on %s/%s\n",
              dir, entry->d_name);
      continue;
    } else if (strchr(pos, 'S') == NULL) {
      (*unread)++;
    } else {
      (*read)++;
    }
  }
  closedir(mdir);
  return 0;
}


x86 assembly (clang, -O0):
<check_maildir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    -0x830(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x800,%esi
lea    0xe4e(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x830(%rbp),%rdi
call   1030 <count_entries@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
cmpl   $0xffffffff,(%rax)
jne    11e4 <check_maildir+0x64>
movl   $0xffffffff,-0x4(%rbp)
jmp    1348 <check_maildir+0x1c8>
lea    -0x830(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x800,%esi
lea    0xe0c(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x830(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x838(%rbp)
cmp    $0x0,%rax
jne    1229 <check_maildir+0xa9>
movl   $0xffffffff,-0x4(%rbp)
jmp    1348 <check_maildir+0x1c8>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x838(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x840(%rbp)
cmp    $0x0,%rax
je     1335 <check_maildir+0x1b5>
lea    -0x830(%rbp),%rdi
mov    -0x840(%rbp),%rsi
call   10a0 <ignore_maildir_entry@plt>
cmp    $0x0,%rax
je     127c <check_maildir+0xfc>
jmp    123d <check_maildir+0xbd>
mov    -0x840(%rbp),%rax
mov    (%rax),%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
mov    %rax,-0x848(%rbp)
cmp    $0x0,%rax
jne    12b1 <check_maildir+0x131>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1330 <check_maildir+0x1b0>
mov    -0x848(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x32,%eax
je     12f0 <check_maildir+0x170>
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
lea    -0x830(%rbp),%rdx
mov    -0x840(%rbp),%rax
mov    (%rax),%rcx
lea    0xd28(%rip),%rsi
call   1080 <fprintf@plt>
jmp    123d <check_maildir+0xbd>
mov    -0x848(%rbp),%rdi
mov    $0x53,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
jne    131b <check_maildir+0x19b>
mov    -0x28(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1326 <check_maildir+0x1a6>
mov    -0x20(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    132b <check_maildir+0x1ab>
jmp    1330 <check_maildir+0x1b0>
jmp    123d <check_maildir+0xbd>
mov    -0x838(%rbp),%rdi
call   1070 <closedir@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_maildir>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%rbx
lea    0xe5c(%rip),%rdx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x800,%esi
mov    %rbx,%rcx
call   1060 <snprintf@plt>
mov    %r12,%rdi
call   1030 <count_entries@plt>
mov    %eax,0x0(%rbp)
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     12a7 <check_maildir+0x127>
lea    0xe30(%rip),%rdx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0x800,%esi
mov    %rbx,%rcx
call   1060 <snprintf@plt>
mov    %r12,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     12a7 <check_maildir+0x127>
mov    %rax,%rbx
movl   $0x0,(%r14)
movl   $0x0,(%r15)
mov    %rax,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     129d <check_maildir+0x11d>
mov    %rax,%rbp
mov    %rsp,%r12
lea    0xde4(%rip),%r13
jmp    1240 <check_maildir+0xc0>
addl   $0x1,(%r15)
mov    %rbx,%rdi
call   1090 <readdir@plt>
mov    %rax,%rbp
test   %rax,%rax
je     129d <check_maildir+0x11d>
mov    %r12,%rdi
mov    %rbp,%rsi
call   10a0 <ignore_maildir_entry@plt>
test   %rax,%rax
jne    1230 <check_maildir+0xb0>
mov    0x0(%rbp),%rbp
mov    %rbp,%rdi
mov    $0x3a,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     122c <check_maildir+0xac>
cmpb   $0x32,0x1(%rax)
jne    1284 <check_maildir+0x104>
mov    %rax,%rdi
mov    $0x53,%esi
call   1050 <strchr@plt>
test   %rax,%rax
je     122c <check_maildir+0xac>
addl   $0x1,(%r14)
jmp    1230 <check_maildir+0xb0>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
mov    %r13,%rsi
mov    %r12,%rdx
mov    %rbp,%rcx
call   1080 <fprintf@plt>
jmp    1230 <check_maildir+0xb0>
mov    %rbx,%rdi
call   1070 <closedir@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i8* }
@.str = [7 x i8] c"%s/new\00"
@.str.1 = [7 x i8] c"%s/cur\00"
@stderr = global i32 0
@.str.2 = [68 x i8] c"mailcheck: ooops, unsupported experimental info semantics on %s/%s\0A\00"
define i32 @check_maildir(i8* %0, i32* %1, i32* %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca [2048 x i8]
%11 = alloca i32*
%12 = alloca %struct.dirent*
%13 = alloca i8*
store i8* %0, i8** %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i32* %3, i32** %9
%14 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%15 = load i8*, i8** %6
%16 = call i32 @snprintf(i8* %14, i32 2048, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%18 = call i32 @count_entries(i8* %17)
%19 = load i32*, i32** %7
store i32 %18, i32* %19
%20 = load i32*, i32** %7
%21 = load i32, i32* %20
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %4
store i32 -1, i32* %5
br label %86
24: ; preds = %4
%25 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%26 = load i8*, i8** %6
%27 = call i32 @snprintf(i8* %25, i32 2048, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%29 = call i32* @opendir(i8* %28)
store i32* %29, i32** %11
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %32
31: ; preds = %24
store i32 -1, i32* %5
br label %86
32: ; preds = %24
%33 = load i32*, i32** %8
store i32 0, i32* %33
%34 = load i32*, i32** %9
store i32 0, i32* %34
br label %35
35: ; preds = %82, %61, %44, %32
%36 = load i32*, i32** %11
%37 = call %struct.dirent* @readdir(i32* %36)
store %struct.dirent* %37, %struct.dirent** %12
%38 = icmp ne %struct.dirent* %37, null
br i1 %38, label %39, label %83
39: ; preds = %35
%40 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%41 = load %struct.dirent*, %struct.dirent** %12
%42 = call i64 @ignore_maildir_entry(i8* %40, %struct.dirent* %41)
%43 = icmp ne i64 %42, 0
br i1 %43, label %44, label %45
44: ; preds = %39
br label %35
45: ; preds = %39
%46 = load %struct.dirent*, %struct.dirent** %12
%47 = getelementptr inbounds %struct.dirent, %struct.dirent* %46, i32 0, i32 0
%48 = load i8*, i8** %47
%49 = call i8* @strchr(i8* %48, i8 signext 58)
store i8* %49, i8** %13
%50 = icmp eq i8* %49, null
br i1 %50, label %51, label %55
51: ; preds = %45
%52 = load i32*, i32** %9
%53 = load i32, i32* %52
%54 = add nsw i32 %53, 1
store i32 %54, i32* %52
br label %82
55: ; preds = %45
%56 = load i8*, i8** %13
%57 = getelementptr inbounds i8, i8* %56, i64 1
%58 = load i8, i8* %57
%59 = sext i8 %58 to i32
%60 = icmp ne i32 %59, 50
br i1 %60, label %61, label %68
61: ; preds = %55
%62 = load i32, i32* @stderr
%63 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%64 = load %struct.dirent*, %struct.dirent** %12
%65 = getelementptr inbounds %struct.dirent, %struct.dirent* %64, i32 0, i32 0
%66 = load i8*, i8** %65
%67 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.2, i64 0, i64 0), i8* %63, i8* %66)
br label %35
68: ; preds = %55
%69 = load i8*, i8** %13
%70 = call i8* @strchr(i8* %69, i8 signext 83)
%71 = icmp eq i8* %70, null
br i1 %71, label %72, label %76
72: ; preds = %68
%73 = load i32*, i32** %9
%74 = load i32, i32* %73
%75 = add nsw i32 %74, 1
store i32 %75, i32* %73
br label %80
76: ; preds = %68
%77 = load i32*, i32** %8
%78 = load i32, i32* %77
%79 = add nsw i32 %78, 1
store i32 %79, i32* %77
br label %80
80: ; preds = %76, %72
br label %81
81: ; preds = %80
br label %82
82: ; preds = %81, %51
br label %35
83: ; preds = %35
%84 = load i32*, i32** %11
%85 = call i32 @closedir(i32* %84)
store i32 0, i32* %5
br label %86
86: ; preds = %83, %31, %23
%87 = load i32, i32* %5
ret i32 %87
}

LLVM IR (-O2):
%struct.dirent = type { i8* }
@.str = [7 x i8] c"%s/new\00"
@.str.1 = [7 x i8] c"%s/cur\00"
@stderr = global i32 0
@.str.2 = [68 x i8] c"mailcheck: ooops, unsupported experimental info semantics on %s/%s\0A\00"
define i32 @check_maildir(i8* %0, i32* nocapture writeonly %1, i32* nocapture %2, i32* nocapture %3) {
%5 = alloca [2048 x i8]
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %5, i64 0, i64 0
%7 = call i32 @snprintf(i8* %6, i32 2048, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0)
%8 = call i32 @count_entries(i8* %6)
store i32 %8, i32* %1
%9 = icmp eq i32 %8, -1
br i1 %9, label %50, label %10
10: ; preds = %4
%11 = call i32 @snprintf(i8* %6, i32 2048, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%12 = call i32* @opendir(i8* %6)
%13 = icmp eq i32* %12, null
br i1 %13, label %50, label %14
14: ; preds = %10
store i32 0, i32* %2
store i32 0, i32* %3
%15 = call %struct.dirent* @readdir(i32* %12)
%16 = icmp eq %struct.dirent* %15, null
br i1 %16, label %48, label %17
17: ; preds = %14, %36
%18 = phi %struct.dirent* [ %37, %36 ], [ %15, %14 ]
%19 = call i64 @ignore_maildir_entry(i8* %6, %struct.dirent* %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %36
21: ; preds = %17
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %18, i64 0, i32 0
%23 = load i8*, i8** %22
%24 = call i8* @strchr(i8* dereferenceable(1) %23, i8 signext 58)
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %36
29: ; preds = %21
%30 = getelementptr inbounds i8, i8* %24, i64 1
%31 = load i8, i8* %30
%32 = icmp eq i8 %31, 50
br i1 %32, label %39, label %33
33: ; preds = %29
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([68 x i8], [68 x i8]* @.str.2, i64 0, i64 0), i8* %6, i8* %23)
br label %36
36: ; preds = %26, %42, %45, %33, %17
%37 = call %struct.dirent* @readdir(i32* %12)
%38 = icmp eq %struct.dirent* %37, null
br i1 %38, label %48, label %17
39: ; preds = %29
%40 = call i8* @strchr(i8* %24, i8 signext 83)
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %45
42: ; preds = %39
%43 = load i32, i32* %3
%44 = add nsw i32 %43, 1
store i32 %44, i32* %3
br label %36
45: ; preds = %39
%46 = load i32, i32* %2
%47 = add nsw i32 %46, 1
store i32 %47, i32* %2
br label %36
48: ; preds = %36, %14
%49 = call i32 @closedir(i32* %12)
br label %50
50: ; preds = %10, %4, %48
%51 = phi i32 [ 0, %48 ], [ -1, %4 ], [ -1, %10 ]
ret i32 %51
}