#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 stat {
  int st_mode;
};
struct dirent {
  char *d_name;
};
typedef int /*<<< orphan*/ name;
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int S_IFDIR;
int S_IFMT;
int S_IFREG;
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ *opendir(char *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
int stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
void stub1(char *);
void aml_fio_dirwalk_files_only_recurse(char *dir, void (*fcn)(char *)) {
  char name[4096];
  struct dirent *dp;
  struct stat stbuf;
  DIR *dfd;
  if ((dfd = opendir(dir)) == NULL) {
    fprintf(stderr, "dirwalk: can't open %s\n", dir);
    exit(1);
  }
  while ((dp = readdir(dfd)) != NULL) {
    if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
      continue;
    if (strlen(dir) + strlen(dp->d_name) + 2 > sizeof(name)) {
      fprintf(stderr, "dirwalk: name %s/%s to long\n", dir, dp->d_name);
      exit(1);
    } else {
      sprintf(name, "%s/%s", dir, dp->d_name);
      if (stat(name, &stbuf) == -1) {
        fprintf(stderr, "fileops: cannot access %s\n", name);
        exit(1);
      }
      if ((stbuf.st_mode & S_IFMT) == S_IFREG)
        (*fcn)(name);
      else if ((stbuf.st_mode & S_IFMT) == S_IFDIR)
        aml_fio_dirwalk_files_only_recurse(name, fcn);
    }
  }
  closedir(dfd);
}


x86 assembly (clang, -O0):
<aml_fio_dirwalk_files_only_recurse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <opendir@plt>
mov    %rax,-0x1028(%rbp)
cmp    $0x0,%rax
jne    11f2 <aml_fio_dirwalk_files_only_recurse+0x52>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe1f(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
jmp    11f7 <aml_fio_dirwalk_files_only_recurse+0x57>
mov    -0x1028(%rbp),%rdi
call   10a0 <readdir@plt>
mov    %rax,-0x1018(%rbp)
cmp    $0x0,%rax
je     1391 <aml_fio_dirwalk_files_only_recurse+0x1f1>
mov    -0x1018(%rbp),%rax
mov    (%rax),%rdi
lea    0xdf4(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     1252 <aml_fio_dirwalk_files_only_recurse+0xb2>
mov    -0x1018(%rbp),%rax
mov    (%rax),%rdi
lea    0xdd4(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
jne    1257 <aml_fio_dirwalk_files_only_recurse+0xb7>
jmp    11f7 <aml_fio_dirwalk_files_only_recurse+0x57>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,-0x102c(%rbp)
mov    -0x1018(%rbp),%rax
mov    (%rax),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    -0x102c(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
cmp    $0x1000,%rax
jbe    12bf <aml_fio_dirwalk_files_only_recurse+0x11f>
mov    0x2d39(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x1018(%rbp),%rax
mov    (%rax),%rcx
lea    0xd6d(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
lea    -0x1010(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x1018(%rbp),%rax
mov    (%rax),%rcx
lea    0xd5d(%rip),%rsi
call   10b0 <sprintf@plt>
lea    -0x1010(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0xffffffff,%eax
jne    1324 <aml_fio_dirwalk_files_only_recurse+0x184>
mov    0x2ccd(%rip),%rax
mov    (%rax),%edi
lea    -0x1010(%rbp),%rdx
lea    0xd2b(%rip),%rsi
mov    $0x0,%al
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x1020(%rbp),%eax
mov    0x2ca7(%rip),%rcx
and    (%rcx),%eax
mov    0x2cae(%rip),%rcx
cmp    (%rcx),%eax
jne    1354 <aml_fio_dirwalk_files_only_recurse+0x1b4>
mov    -0x10(%rbp),%rax
lea    -0x1010(%rbp),%rdi
call   *%rax
jmp    1387 <aml_fio_dirwalk_files_only_recurse+0x1e7>
mov    -0x1020(%rbp),%eax
mov    0x2c77(%rip),%rcx
and    (%rcx),%eax
mov    0x2c56(%rip),%rcx
cmp    (%rcx),%eax
jne    1382 <aml_fio_dirwalk_files_only_recurse+0x1e2>
lea    -0x1010(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <aml_fio_dirwalk_files_only_recurse@plt>
jmp    1387 <aml_fio_dirwalk_files_only_recurse+0x1e7>
jmp    138c <aml_fio_dirwalk_files_only_recurse+0x1ec>
jmp    11f7 <aml_fio_dirwalk_files_only_recurse+0x57>
mov    -0x1028(%rbp),%rdi
call   1060 <closedir@plt>
add    $0x1030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aml_fio_dirwalk_files_only_recurse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %rsi,0x8(%rsp)
mov    %rdi,%r15
call   1040 <opendir@plt>
test   %rax,%rax
je     131c <aml_fio_dirwalk_files_only_recurse+0x17c>
mov    %rax,%r12
mov    %rax,%rdi
call   10a0 <readdir@plt>
test   %rax,%rax
je     12b5 <aml_fio_dirwalk_files_only_recurse+0x115>
mov    %rax,%r14
lea    0xe34(%rip),%rbp
jmp    1204 <aml_fio_dirwalk_files_only_recurse+0x64>
lea    0x10(%rsp),%rdi
call   *0x8(%rsp)
mov    %r12,%rdi
call   10a0 <readdir@plt>
mov    %rax,%r14
test   %rax,%rax
je     12b5 <aml_fio_dirwalk_files_only_recurse+0x115>
mov    (%r14),%r13
mov    %r13,%rdi
mov    %rbp,%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     11f0 <aml_fio_dirwalk_files_only_recurse+0x50>
mov    %r13,%rdi
lea    0xdf8(%rip),%rsi
call   1070 <strcmp@plt>
test   %eax,%eax
je     11f0 <aml_fio_dirwalk_files_only_recurse+0x50>
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %eax,%ebx
mov    (%r14),%rdi
call   1050 <strlen@plt>
add    %ebx,%eax
add    $0xfffff001,%eax
cmp    $0xffffeffe,%eax
jbe    12cf <aml_fio_dirwalk_files_only_recurse+0x12f>
mov    (%r14),%rcx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
lea    0xdd9(%rip),%rsi
mov    %r15,%rdx
call   10b0 <sprintf@plt>
mov    %rbx,%rdi
mov    %rsp,%rsi
call   1090 <stat@plt>
cmp    $0xffffffff,%eax
je     12f6 <aml_fio_dirwalk_files_only_recurse+0x156>
mov    0x2d5a(%rip),%rax
mov    (%rax),%eax
and    (%rsp),%eax
mov    0x2d5e(%rip),%rcx
cmp    (%rcx),%eax
je     11e7 <aml_fio_dirwalk_files_only_recurse+0x47>
mov    0x2d27(%rip),%rcx
cmp    (%rcx),%eax
jne    11f0 <aml_fio_dirwalk_files_only_recurse+0x50>
lea    0x10(%rsp),%rdi
mov    0x8(%rsp),%rsi
call   1030 <aml_fio_dirwalk_files_only_recurse@plt>
jmp    11f0 <aml_fio_dirwalk_files_only_recurse+0x50>
mov    %r12,%rdi
call   1060 <closedir@plt>
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2cfa(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rcx
lea    0xd39(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
lea    0xd38(%rip),%rsi
lea    0x10(%rsp),%rdx
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    0x2cad(%rip),%rax
mov    (%rax),%edi
lea    0xcd4(%rip),%rsi
mov    %r15,%rdx
jmp    130b <aml_fio_dirwalk_files_only_recurse+0x16b>

LLVM IR (-O0):
%struct.dirent = type { i8* }
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [24 x i8] c"dirwalk: can't open %s\0A\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [29 x i8] c"dirwalk: name %s/%s to long\0A\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [27 x i8] c"fileops: cannot access %s\0A\00"
@S_IFMT = global i32 0
@S_IFREG = global i32 0
@S_IFDIR = global i32 0
define void @aml_fio_dirwalk_files_only_recurse(i8* %0, void (i8*)* %1) {
%3 = alloca i8*
%4 = alloca void (i8*)*
%5 = alloca [4096 x i8]
%6 = alloca %struct.dirent*
%7 = alloca %struct.stat
%8 = alloca i32*
store i8* %0, i8** %3
store void (i8*)* %1, void (i8*)** %4
%9 = load i8*, i8** %3
%10 = call i32* @opendir(i8* %9)
store i32* %10, i32** %8
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %3
%15 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
br label %18
18: ; preds = %91, %34, %17
%19 = load i32*, i32** %8
%20 = call %struct.dirent* @readdir(i32* %19)
store %struct.dirent* %20, %struct.dirent** %6
%21 = icmp ne %struct.dirent* %20, null
br i1 %21, label %22, label %92
22: ; preds = %18
%23 = load %struct.dirent*, %struct.dirent** %6
%24 = getelementptr inbounds %struct.dirent, %struct.dirent* %23, i32 0, i32 0
%25 = load i8*, i8** %24
%26 = call i32 @strcmp(i8* %25, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %34
28: ; preds = %22
%29 = load %struct.dirent*, %struct.dirent** %6
%30 = getelementptr inbounds %struct.dirent, %struct.dirent* %29, i32 0, i32 0
%31 = load i8*, i8** %30
%32 = call i32 @strcmp(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%33 = icmp ne i32 %32, 0
br i1 %33, label %35, label %34
34: ; preds = %28, %22
br label %18
35: ; preds = %28
%36 = load i8*, i8** %3
%37 = call i32 @strlen(i8* %36)
%38 = load %struct.dirent*, %struct.dirent** %6
%39 = getelementptr inbounds %struct.dirent, %struct.dirent* %38, i32 0, i32 0
%40 = load i8*, i8** %39
%41 = call i32 @strlen(i8* %40)
%42 = add nsw i32 %37, %41
%43 = add nsw i32 %42, 2
%44 = sext i32 %43 to i64
%45 = icmp ugt i64 %44, 4096
br i1 %45, label %46, label %54
46: ; preds = %35
%47 = load i32, i32* @stderr
%48 = load i8*, i8** %3
%49 = load %struct.dirent*, %struct.dirent** %6
%50 = getelementptr inbounds %struct.dirent, %struct.dirent* %49, i32 0, i32 0
%51 = load i8*, i8** %50
%52 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %48, i8* %51)
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %35
%55 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%56 = load i8*, i8** %3
%57 = load %struct.dirent*, %struct.dirent** %6
%58 = getelementptr inbounds %struct.dirent, %struct.dirent* %57, i32 0, i32 0
%59 = load i8*, i8** %58
%60 = call i32 @sprintf(i8* %55, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %56, i8* %59)
%61 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%62 = call i32 @stat(i8* %61, %struct.stat* %7)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %69
64: ; preds = %54
%65 = load i32, i32* @stderr
%66 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%67 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %66)
%68 = call i32 @exit(i32 1)
unreachable
69: ; preds = %54
%70 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%71 = load i32, i32* %70
%72 = load i32, i32* @S_IFMT
%73 = and i32 %71, %72
%74 = load i32, i32* @S_IFREG
%75 = icmp eq i32 %73, %74
br i1 %75, label %76, label %79
76: ; preds = %69
%77 = load void (i8*)*, void (i8*)** %4
%78 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
br label %90
79: ; preds = %69
%80 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%81 = load i32, i32* %80
%82 = load i32, i32* @S_IFMT
%83 = and i32 %81, %82
%84 = load i32, i32* @S_IFDIR
%85 = icmp eq i32 %83, %84
br i1 %85, label %86, label %89
86: ; preds = %79
%87 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%88 = load void (i8*)*, void (i8*)** %4
br label %89
89: ; preds = %86, %79
br label %90
90: ; preds = %89, %76
br label %91
91: ; preds = %90
br label %18
92: ; preds = %18
%93 = load i32*, i32** %8
%94 = call i32 @closedir(i32* %93)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@stderr = global i32 0
@.str = [24 x i8] c"dirwalk: can't open %s\0A\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [29 x i8] c"dirwalk: name %s/%s to long\0A\00"
@.str.4 = [6 x i8] c"%s/%s\00"
@.str.5 = [27 x i8] c"fileops: cannot access %s\0A\00"
@S_IFMT = global i32 0
@S_IFREG = global i32 0
@S_IFDIR = global i32 0
define void @aml_fio_dirwalk_files_only_recurse(i8* %0, void (i8*)* nocapture %1) {
%3 = alloca [4096 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = tail call i32* @opendir(i8* %0)
%8 = icmp eq i32* %7, null
br i1 %8, label %14, label %9
9: ; preds = %2
%10 = call %struct.dirent* @readdir(i32* %7)
%11 = icmp eq %struct.dirent* %10, null
br i1 %11, label %62, label %12
12: ; preds = %9
%13 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
br label %18
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %0)
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %12, %27
%19 = phi %struct.dirent* [ %10, %12 ], [ %28, %27 ]
%20 = getelementptr inbounds %struct.dirent, %struct.dirent* %19, i64 0, i32 0
%21 = load i8*, i8** %20
%22 = call i32 @strcmp(i8* dereferenceable(1) %21, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = icmp eq i32 %22, 0
br i1 %23, label %27, label %24
24: ; preds = %18
%25 = call i32 @strcmp(i8* dereferenceable(1) %21, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %58, %61, %57, %18, %24
%28 = call %struct.dirent* @readdir(i32* %7)
%29 = icmp eq %struct.dirent* %28, null
br i1 %29, label %62, label %18
30: ; preds = %24
%31 = call i32 @strlen(i8* %0)
%32 = load i8*, i8** %20
%33 = call i32 @strlen(i8* %32)
%34 = add i32 %31, -4095
%35 = add i32 %34, %33
%36 = icmp ult i32 %35, -4097
br i1 %36, label %37, label %42
37: ; preds = %30
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %20
%40 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %30
%43 = load i8*, i8** %20
%44 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %43)
%45 = call i32 @stat(i8* %5, %struct.stat* %4)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %51
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %48, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.5, i64 0, i64 0), i8* %5)
%50 = call i32 @exit(i32 1)
unreachable
51: ; preds = %42
%52 = load i32, i32* %13
%53 = load i32, i32* @S_IFMT
%54 = and i32 %53, %52
%55 = load i32, i32* @S_IFREG
%56 = icmp eq i32 %54, %55
br i1 %56, label %57, label %58
57: ; preds = %51
br label %27
58: ; preds = %51
%59 = load i32, i32* @S_IFDIR
%60 = icmp eq i32 %54, %59
br i1 %60, label %61, label %27
61: ; preds = %58
br label %27
62: ; preds = %27, %9
%63 = call i32 @closedir(i32* %7)
ret void
}