#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*/ *);
char *rindex(int /*<<< orphan*/, char);
int /*<<< orphan*/ *strchr(char *, char);
int strlen(int /*<<< orphan*/);
int get_file_count(char *pathname, int checkflags) {
  DIR *dir;
  struct dirent *entry;
  int found = 0;
  char *comma;
  dir = opendir(pathname);
  if (!dir)
    return -1;
  while ((entry = readdir(dir)) != NULL) {
    if (strlen(entry->d_name) < 10)
      continue;
    if (checkflags) {
      comma = rindex(entry->d_name, ',');
      if (comma && strchr(comma, 'S') == NULL)
        found++;
    } else {
      found++;
    }
  }
  closedir(dir);
  return found;
}


x86 assembly (clang, -O0):
<get_file_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119a <get_file_count+0x3a>
movl   $0xffffffff,-0x4(%rbp)
jmp    123b <get_file_count+0xdb>
jmp    119f <get_file_count+0x3f>
mov    -0x20(%rbp),%rdi
call   1070 <readdir@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
je     122c <get_file_count+0xcc>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
call   1040 <strlen@plt>
cmp    $0xa,%eax
jge    11cf <get_file_count+0x6f>
jmp    119f <get_file_count+0x3f>
cmpl   $0x0,-0x14(%rbp)
je     121e <get_file_count+0xbe>
mov    -0x28(%rbp),%rax
mov    (%rax),%edi
mov    $0x2c,%esi
call   1080 <rindex@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
je     1219 <get_file_count+0xb9>
mov    -0x38(%rbp),%rdi
mov    $0x53,%esi
call   1050 <strchr@plt>
cmp    $0x0,%rax
jne    1219 <get_file_count+0xb9>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1227 <get_file_count+0xc7>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119f <get_file_count+0x3f>
mov    -0x20(%rbp),%rdi
call   1060 <closedir@plt>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_count>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
call   1030 <opendir@plt>
test   %rax,%rax
je     11e1 <get_file_count+0x81>
mov    %rax,%rbx
xor    %r15d,%r15d
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1070 <readdir@plt>
test   %rax,%rax
je     11d7 <get_file_count+0x77>
mov    %rax,%rbp
mov    (%rax),%edi
call   1040 <strlen@plt>
cmp    $0xa,%eax
jl     1180 <get_file_count+0x20>
test   %r14d,%r14d
je     11cd <get_file_count+0x6d>
mov    0x0(%rbp),%edi
mov    $0x2c,%esi
call   1080 <rindex@plt>
test   %rax,%rax
je     1180 <get_file_count+0x20>
mov    %rax,%rdi
mov    $0x53,%esi
call   1050 <strchr@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
add    %ecx,%r15d
jmp    1180 <get_file_count+0x20>
mov    $0x1,%ecx
add    %ecx,%r15d
jmp    1180 <get_file_count+0x20>
mov    %rbx,%rdi
call   1060 <closedir@plt>
jmp    11e7 <get_file_count+0x87>
mov    $0xffffffff,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
define i32 @get_file_count(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca %struct.dirent*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 0, i32* %8
%10 = load i8*, i8** %4
%11 = call i32* @opendir(i8* %10)
store i32* %11, i32** %6
%12 = load i32*, i32** %6
%13 = icmp ne i32* %12, null
br i1 %13, label %15, label %14
14: ; preds = %2
store i32 -1, i32* %3
br label %53
15: ; preds = %2
br label %16
16: ; preds = %48, %26, %15
%17 = load i32*, i32** %6
%18 = call %struct.dirent* @readdir(i32* %17)
store %struct.dirent* %18, %struct.dirent** %7
%19 = icmp ne %struct.dirent* %18, null
br i1 %19, label %20, label %49
20: ; preds = %16
%21 = load %struct.dirent*, %struct.dirent** %7
%22 = getelementptr inbounds %struct.dirent, %struct.dirent* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = call i32 @strlen(i32 %23)
%25 = icmp slt i32 %24, 10
br i1 %25, label %26, label %27
26: ; preds = %20
br label %16
27: ; preds = %20
%28 = load i32, i32* %5
%29 = icmp ne i32 %28, 0
br i1 %29, label %30, label %45
30: ; preds = %27
%31 = load %struct.dirent*, %struct.dirent** %7
%32 = getelementptr inbounds %struct.dirent, %struct.dirent* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i8* @rindex(i32 %33, i8 signext 44)
store i8* %34, i8** %9
%35 = load i8*, i8** %9
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %44
37: ; preds = %30
%38 = load i8*, i8** %9
%39 = call i32* @strchr(i8* %38, i8 signext 83)
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %44
41: ; preds = %37
%42 = load i32, i32* %8
%43 = add nsw i32 %42, 1
store i32 %43, i32* %8
br label %44
44: ; preds = %41, %37, %30
br label %48
45: ; preds = %27
%46 = load i32, i32* %8
%47 = add nsw i32 %46, 1
store i32 %47, i32* %8
br label %48
48: ; preds = %45, %44
br label %16
49: ; preds = %16
%50 = load i32*, i32** %6
%51 = call i32 @closedir(i32* %50)
%52 = load i32, i32* %8
store i32 %52, i32* %3
br label %53
53: ; preds = %49, %14
%54 = load i32, i32* %3
ret i32 %54
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
define i32 @get_file_count(i8* nocapture %0, i32 %1) {
%3 = tail call i32* @opendir(i8* %0)
%4 = icmp eq i32* %3, null
br i1 %4, label %33, label %5
5: ; preds = %2
%6 = icmp eq i32 %1, 0
br label %7
7: ; preds = %28, %5
%8 = phi i32 [ 0, %5 ], [ %30, %28 ]
br label %9
9: ; preds = %7, %19
br label %10
10: ; preds = %9, %13
%11 = tail call %struct.dirent* @readdir(i32* %3)
%12 = icmp eq %struct.dirent* %11, null
br i1 %12, label %31, label %13
13: ; preds = %10
%14 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i64 0, i32 0
%15 = load i32, i32* %14
%16 = tail call i32 @strlen(i32 %15)
%17 = icmp slt i32 %16, 10
br i1 %17, label %10, label %18
18: ; preds = %13
br i1 %6, label %28, label %19
19: ; preds = %18
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %11, i64 0, i32 0
%21 = load i32, i32* %20
%22 = tail call i8* @rindex(i32 %21, i8 signext 44)
%23 = icmp eq i8* %22, null
br i1 %23, label %9, label %24
24: ; preds = %19
%25 = tail call i32* @strchr(i8* %22, i8 signext 83)
%26 = icmp eq i32* %25, null
%27 = zext i1 %26 to i32
br label %28
28: ; preds = %18, %24
%29 = phi i32 [ %27, %24 ], [ 1, %18 ]
%30 = add nuw nsw i32 %8, %29
br label %7
31: ; preds = %10
%32 = tail call i32 @closedir(i32* %3)
br label %33
33: ; preds = %2, %31
%34 = phi i32 [ %8, %31 ], [ -1, %2 ]
ret i32 %34
}