#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*/ *);
int /*<<< orphan*/ set_logentry(char *, int /*<<< orphan*/);
scalar_t__ strstr(int /*<<< orphan*/, char *);
long getLogFiles(char *path, int countonly) {
  long ctr = 0;
  char *pos;
  DIR *pdir = NULL;
  char buffer[150];
  pdir = opendir(path);
  if (pdir) {
    struct dirent *pent = NULL;
    while (pent = readdir(pdir)) {
      if (strstr(pent->d_name, ".ael")) {
        if (!countonly) {
          set_logentry(path, pent->d_name);
        }
        ctr++;
      }
    }
  }
  closedir(pdir);
  return ctr;
}


x86 assembly (clang, -O0):
<getLogFiles>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1200 <getLogFiles+0xb0>
movq   $0x0,-0xc8(%rbp)
mov    -0x28(%rbp),%rdi
call   1060 <readdir@plt>
mov    %rax,-0xc8(%rbp)
cmp    $0x0,%rax
je     11fb <getLogFiles+0xab>
mov    -0xc8(%rbp),%rax
mov    (%rax),%edi
lea    0xe41(%rip),%rsi
call   1070 <strstr@plt>
cmp    $0x0,%rax
je     11f6 <getLogFiles+0xa6>
cmpl   $0x0,-0xc(%rbp)
jne    11ea <getLogFiles+0x9a>
mov    -0x8(%rbp),%rdi
mov    -0xc8(%rbp),%rax
mov    (%rax),%esi
call   1030 <set_logentry@plt>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1195 <getLogFiles+0x45>
jmp    1200 <getLogFiles+0xb0>
mov    -0x28(%rbp),%rdi
call   1050 <closedir@plt>
mov    -0x18(%rbp),%rax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLogFiles>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r15d
mov    %rdi,%r14
call   1040 <opendir@plt>
mov    %rax,%r13
test   %rax,%rax
je     11c4 <getLogFiles+0x74>
mov    %r13,%rdi
call   1060 <readdir@plt>
test   %rax,%rax
je     11c4 <getLogFiles+0x74>
mov    %rax,%rbx
xor    %ebp,%ebp
lea    0xe79(%rip),%r12
jmp    11a4 <getLogFiles+0x54>
nopl   0x0(%rax)
add    $0x1,%rbp
mov    %r13,%rdi
call   1060 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11c6 <getLogFiles+0x76>
mov    (%rbx),%edi
mov    %r12,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     1194 <getLogFiles+0x44>
test   %r15d,%r15d
jne    1190 <getLogFiles+0x40>
mov    (%rbx),%esi
mov    %r14,%rdi
call   1030 <set_logentry@plt>
jmp    1190 <getLogFiles+0x40>
xor    %ebp,%ebp
mov    %r13,%rdi
call   1050 <closedir@plt>
mov    %rbp,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [5 x i8] c".ael\00"
define i64 @getLogFiles(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [150 x i8]
%9 = alloca %struct.dirent*
store i8* %0, i8** %3
store i32 %1, i32* %4
store i64 0, i64* %5
store i32* null, i32** %7
%10 = load i8*, i8** %3
%11 = call i32* @opendir(i8* %10)
store i32* %11, i32** %7
%12 = load i32*, i32** %7
%13 = icmp ne i32* %12, null
br i1 %13, label %14, label %39
14: ; preds = %2
store %struct.dirent* null, %struct.dirent** %9
br label %15
15: ; preds = %37, %14
%16 = load i32*, i32** %7
%17 = call %struct.dirent* @readdir(i32* %16)
store %struct.dirent* %17, %struct.dirent** %9
%18 = icmp ne %struct.dirent* %17, null
br i1 %18, label %19, label %38
19: ; preds = %15
%20 = load %struct.dirent*, %struct.dirent** %9
%21 = getelementptr inbounds %struct.dirent, %struct.dirent* %20, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i64 @strstr(i32 %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %37
25: ; preds = %19
%26 = load i32, i32* %4
%27 = icmp ne i32 %26, 0
br i1 %27, label %34, label %28
28: ; preds = %25
%29 = load i8*, i8** %3
%30 = load %struct.dirent*, %struct.dirent** %9
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %30, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i32 @set_logentry(i8* %29, i32 %32)
br label %34
34: ; preds = %28, %25
%35 = load i64, i64* %5
%36 = add nsw i64 %35, 1
store i64 %36, i64* %5
br label %37
37: ; preds = %34, %19
br label %15
38: ; preds = %15
br label %39
39: ; preds = %38, %2
%40 = load i32*, i32** %7
%41 = call i32 @closedir(i32* %40)
%42 = load i64, i64* %5
ret i64 %42
}

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