#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 */
scalar_t__ CheckExtension(int /*<<< orphan*/, char *);
int /*<<< orphan*/ FixFilename(char *, char *);
int /*<<< orphan*/ ShowRefs(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ *opendir(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ puts(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void ShowAllRefs(void) {
  DIR *d;
  struct dirent *de;
  char logdir[256];
  char *s;
  if ("logs/"[0] != '/')
    FixFilename("logs/", logdir);
  else
    strcpy(logdir, "logs/");
  s = logdir + strlen(logdir) - 1;
  if (*s != '/')
    strcat(logdir, "/");
  d = opendir(logdir);
  if (!d) {
    puts("PHPLMON Error<p>");
    printf("Unable to open log directory (%s)\n<p>", logdir);
    return;
  }
  while ((de = readdir(d))) {
    if (CheckExtension(de->d_name, ".ref")) {
      ShowRefs(de->d_name);
    }
  }
  closedir(d);
}


x86 assembly (clang, -O0):
<ShowAllRefs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
lea    -0x110(%rbp),%rsi
lea    0xe47(%rip),%rdi
call   10c0 <FixFilename@plt>
lea    -0x110(%rbp),%rax
mov    %rax,-0x120(%rbp)
lea    -0x110(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x120(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x118(%rbp)
mov    -0x118(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1218 <ShowAllRefs+0x78>
lea    -0x110(%rbp),%rdi
lea    0xdf1(%rip),%rsi
call   10a0 <strcat@plt>
lea    -0x110(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1257 <ShowAllRefs+0xb7>
lea    0xdcc(%rip),%rdi
call   1030 <puts@plt>
lea    -0x110(%rbp),%rsi
lea    0xdca(%rip),%rdi
call   1060 <printf@plt>
jmp    12a8 <ShowAllRefs+0x108>
jmp    125c <ShowAllRefs+0xbc>
mov    -0x8(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     129f <ShowAllRefs+0xff>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
lea    0xdbd(%rip),%rsi
call   1080 <CheckExtension@plt>
cmp    $0x0,%rax
je     129a <ShowAllRefs+0xfa>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   10b0 <ShowRefs@plt>
jmp    125c <ShowAllRefs+0xbc>
mov    -0x8(%rbp),%rdi
call   1070 <closedir@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ShowAllRefs>:
push   %r15
push   %r14
push   %rbx
sub    $0x100,%rsp
lea    0xe4d(%rip),%rdi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   10c0 <FixFilename@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rsp,%rax,1)
je     11de <ShowAllRefs+0x3e>
lea    0xe2e(%rip),%rsi
mov    %rsp,%rdi
call   10a0 <strcat@plt>
mov    %rsp,%rdi
call   1040 <opendir@plt>
test   %rax,%rax
je     1242 <ShowAllRefs+0xa2>
mov    %rax,%r15
mov    %rax,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     1238 <ShowAllRefs+0x98>
mov    %rax,%rbx
lea    0xe38(%rip),%r14
jmp    1220 <ShowAllRefs+0x80>
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1090 <readdir@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1238 <ShowAllRefs+0x98>
mov    (%rbx),%edi
mov    %r14,%rsi
call   1080 <CheckExtension@plt>
test   %rax,%rax
je     1210 <ShowAllRefs+0x70>
mov    (%rbx),%edi
call   10b0 <ShowRefs@plt>
jmp    1210 <ShowAllRefs+0x70>
mov    %r15,%rdi
call   1070 <closedir@plt>
jmp    125d <ShowAllRefs+0xbd>
lea    0xdbd(%rip),%rdi
call   1030 <puts@plt>
lea    0xdc2(%rip),%rdi
mov    %rsp,%rsi
call   1060 <printf@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.dirent = type { i32 }
@.str = [6 x i8] c"logs/\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [17 x i8] c"PHPLMON Error<p>\00"
@.str.3 = [38 x i8] c"Unable to open log directory (%s)\0A<p>\00"
@.str.4 = [5 x i8] c".ref\00"
define void @ShowAllRefs() {
%1 = alloca i32*
%2 = alloca %struct.dirent*
%3 = alloca [256 x i8]
%4 = alloca i8*
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%6 = call i32 @FixFilename(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%9 = call i32 @strlen(i8* %8)
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %7, i64 %10
%12 = getelementptr inbounds i8, i8* %11, i64 -1
store i8* %12, i8** %4
%13 = load i8*, i8** %4
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 47
br i1 %16, label %17, label %20
17: ; preds = %0
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%19 = call i32 @strcat(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %17, %0
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%22 = call i32* @opendir(i8* %21)
store i32* %22, i32** %1
%23 = load i32*, i32** %1
%24 = icmp ne i32* %23, null
br i1 %24, label %29, label %25
25: ; preds = %20
%26 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%28 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %27)
br label %49
29: ; preds = %20
br label %30
30: ; preds = %45, %29
%31 = load i32*, i32** %1
%32 = call %struct.dirent* @readdir(i32* %31)
store %struct.dirent* %32, %struct.dirent** %2
%33 = icmp ne %struct.dirent* %32, null
br i1 %33, label %34, label %46
34: ; preds = %30
%35 = load %struct.dirent*, %struct.dirent** %2
%36 = getelementptr inbounds %struct.dirent, %struct.dirent* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = call i64 @CheckExtension(i32 %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %45
40: ; preds = %34
%41 = load %struct.dirent*, %struct.dirent** %2
%42 = getelementptr inbounds %struct.dirent, %struct.dirent* %41, i32 0, i32 0
%43 = load i32, i32* %42
%44 = call i32 @ShowRefs(i32 %43)
br label %45
45: ; preds = %40, %34
br label %30
46: ; preds = %30
%47 = load i32*, i32** %1
%48 = call i32 @closedir(i32* %47)
br label %49
49: ; preds = %46, %25
ret void
}

LLVM IR (-O2):
%struct.dirent = type { i32 }
@.str = [6 x i8] c"logs/\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [17 x i8] c"PHPLMON Error<p>\00"
@.str.3 = [38 x i8] c"Unable to open log directory (%s)\0A<p>\00"
@.str.4 = [5 x i8] c".ref\00"
define void @ShowAllRefs() {
%1 = alloca [256 x i8]
%2 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%3 = call i32 @FixFilename(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %2)
%4 = call i32 @strlen(i8* %2)
%5 = sext i32 %4 to i64
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 %5
%7 = getelementptr inbounds i8, i8* %6, i64 -1
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 47
br i1 %9, label %12, label %10
10: ; preds = %0
%11 = call i32 @strcat(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %12
12: ; preds = %10, %0
%13 = call i32* @opendir(i8* %2)
%14 = icmp eq i32* %13, null
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = call %struct.dirent* @readdir(i32* %13)
%17 = icmp eq %struct.dirent* %16, null
br i1 %17, label %33, label %21
18: ; preds = %12
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* %2)
br label %35
21: ; preds = %15, %30
%22 = phi %struct.dirent* [ %31, %30 ], [ %16, %15 ]
%23 = getelementptr inbounds %struct.dirent, %struct.dirent* %22, i64 0, i32 0
%24 = load i32, i32* %23
%25 = call i64 @CheckExtension(i32 %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %21
%28 = load i32, i32* %23
%29 = call i32 @ShowRefs(i32 %28)
br label %30
30: ; preds = %27, %21
%31 = call %struct.dirent* @readdir(i32* %13)
%32 = icmp eq %struct.dirent* %31, null
br i1 %32, label %33, label %21
33: ; preds = %30, %15
%34 = call i32 @closedir(i32* %13)
br label %35
35: ; preds = %33, %18
ret void
}