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

/* Variables and functions */
scalar_t__ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ lstat(char *, struct stat *);
int /*<<< orphan*/ *opendir(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char *);
scalar_t__ strcmp(char *, char *);
void stub1(void *, char const *);
void util_exec_on_files(const char *directory, int recurse_subdirs,
                        int hidden_files,
                        void (*callback)(void *data, const char *filename),
                        void *callback_data) {
  char complete_filename[4096];
  DIR *dir;
  struct dirent *entry;
  struct stat statbuf;
  if (!directory || !callback)
    return;
  dir = opendir(directory);
  if (dir) {
    while ((entry = readdir(dir))) {
      if (hidden_files || (entry->d_name[0] != '.')) {
        snprintf(complete_filename, sizeof(complete_filename), "%s/%s",
                 directory, entry->d_name);
        lstat(complete_filename, &statbuf);
        if (S_ISDIR(statbuf.st_mode)) {
          if (recurse_subdirs && (strcmp(entry->d_name, ".") != 0) &&
              (strcmp(entry->d_name, "..") != 0)) {
            util_exec_on_files(complete_filename, 1, hidden_files, callback,
                               callback_data);
          }
        } else {
          (*callback)(callback_data, complete_filename);
        }
      }
    }
    closedir(dir);
  }
}


x86 assembly (clang, -O0):
<util_exec_on_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11b3 <util_exec_on_files+0x33>
cmpq   $0x0,-0x18(%rbp)
jne    11b8 <util_exec_on_files+0x38>
jmp    12f8 <util_exec_on_files+0x178>
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x1028(%rbp)
cmpq   $0x0,-0x1028(%rbp)
je     12f8 <util_exec_on_files+0x178>
jmp    11db <util_exec_on_files+0x5b>
mov    -0x1028(%rbp),%rdi
call   1090 <readdir@plt>
mov    %rax,-0x1030(%rbp)
cmp    $0x0,%rax
je     12ec <util_exec_on_files+0x16c>
cmpl   $0x0,-0x10(%rbp)
jne    1218 <util_exec_on_files+0x98>
mov    -0x1030(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     12e7 <util_exec_on_files+0x167>
lea    -0x1020(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    -0x1030(%rbp),%rax
mov    (%rax),%r8
mov    $0x1000,%esi
lea    0xdc7(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x1020(%rbp),%rdi
lea    -0x1038(%rbp),%rsi
call   1070 <lstat@plt>
mov    -0x1038(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     12d1 <util_exec_on_files+0x151>
cmpl   $0x0,-0xc(%rbp)
je     12cc <util_exec_on_files+0x14c>
mov    -0x1030(%rbp),%rax
mov    (%rax),%rdi
lea    0xd86(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     12cc <util_exec_on_files+0x14c>
mov    -0x1030(%rbp),%rax
mov    (%rax),%rdi
lea    0xd65(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     12cc <util_exec_on_files+0x14c>
lea    -0x1020(%rbp),%rdi
mov    -0x10(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    $0x1,%esi
call   10a0 <util_exec_on_files@plt>
jmp    12e2 <util_exec_on_files+0x162>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rdi
lea    -0x1020(%rbp),%rsi
call   *%rax
jmp    12e7 <util_exec_on_files+0x167>
jmp    11db <util_exec_on_files+0x5b>
mov    -0x1028(%rbp),%rdi
call   1060 <closedir@plt>
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<util_exec_on_files>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1018,%rsp
mov    %r8,0x8(%rsp)
mov    %esi,0x4(%rsp)
test   %rdi,%rdi
je     128e <util_exec_on_files+0x10e>
mov    %rcx,%r12
test   %rcx,%rcx
je     128e <util_exec_on_files+0x10e>
mov    %edx,%ebp
mov    %rdi,%r13
call   1030 <opendir@plt>
test   %rax,%rax
je     128e <util_exec_on_files+0x10e>
mov    %rax,%rbx
mov    %rax,%rdi
call   1090 <readdir@plt>
test   %rax,%rax
je     1286 <util_exec_on_files+0x106>
mov    %rax,%r15
lea    0x10(%rsp),%r14
jmp    11ff <util_exec_on_files+0x7f>
mov    0x8(%rsp),%rdi
mov    %r14,%rsi
call   *%r12
mov    %rbx,%rdi
call   1090 <readdir@plt>
mov    %rax,%r15
test   %rax,%rax
je     1286 <util_exec_on_files+0x106>
mov    (%r15),%r8
test   %ebp,%ebp
jne    120c <util_exec_on_files+0x8c>
cmpb   $0x2e,(%r8)
je     11eb <util_exec_on_files+0x6b>
mov    %r14,%rdi
mov    $0x1000,%esi
lea    0xde5(%rip),%rdx
mov    %r13,%rcx
call   1050 <snprintf@plt>
mov    %r14,%rdi
mov    %rsp,%rsi
call   1070 <lstat@plt>
mov    (%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %rax,%rax
je     11e0 <util_exec_on_files+0x60>
cmpl   $0x0,0x4(%rsp)
je     11eb <util_exec_on_files+0x6b>
mov    (%r15),%rdi
lea    0xdbb(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11eb <util_exec_on_files+0x6b>
mov    (%r15),%rdi
lea    0xda6(%rip),%rsi
call   1080 <strcmp@plt>
test   %rax,%rax
je     11eb <util_exec_on_files+0x6b>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r12,%rcx
mov    0x8(%rsp),%r8
call   10a0 <util_exec_on_files@plt>
jmp    11eb <util_exec_on_files+0x6b>
mov    %rbx,%rdi
call   1060 <closedir@plt>
add    $0x1018,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
define void @util_exec_on_files(i8* %0, i32 %1, i32 %2, void (i8*, i8*)* %3, i8* %4) {
%6 = alloca [4096 x i8]
%7 = alloca %struct.stat
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%9 = bitcast %struct.stat* %7 to i8*
%10 = icmp ne i8* %0, null
%11 = icmp ne void (i8*, i8*)* %3, null
%12 = and i1 %10, %11
br i1 %12, label %13, label %53
13: ; preds = %5
%14 = tail call i32* @opendir(i8* %0)
%15 = icmp eq i32* %14, null
br i1 %15, label %53, label %16
16: ; preds = %13
%17 = call %struct.dirent* @readdir(i32* %14)
%18 = icmp eq %struct.dirent* %17, null
br i1 %18, label %51, label %19
19: ; preds = %16
%20 = icmp eq i32 %2, 0
%21 = getelementptr inbounds %struct.stat, %struct.stat* %7, i64 0, i32 0
%22 = icmp eq i32 %1, 0
br label %23
23: ; preds = %19, %48
%24 = phi %struct.dirent* [ %17, %19 ], [ %49, %48 ]
%25 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i64 0, i32 0
%26 = load i8*, i8** %25
br i1 %20, label %27, label %30
27: ; preds = %23
%28 = load i8, i8* %26
%29 = icmp eq i8 %28, 46
br i1 %29, label %48, label %30
30: ; preds = %23, %27
%31 = getelementptr inbounds %struct.dirent, %struct.dirent* %24, i64 0, i32 0
%32 = call i32 @snprintf(i8* %8, i32 4096, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %26)
%33 = call i32 @lstat(i8* %8, %struct.stat* %7)
%34 = load i32, i32* %21
%35 = call i64 @S_ISDIR(i32 %34)
%36 = icmp eq i64 %35, 0
br i1 %36, label %47, label %37
37: ; preds = %30
br i1 %22, label %48, label %38
38: ; preds = %37
%39 = load i8*, i8** %31
%40 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%41 = icmp eq i64 %40, 0
br i1 %41, label %48, label %42
42: ; preds = %38
%43 = load i8*, i8** %31
%44 = call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %48, label %46
46: ; preds = %42
br label %48
47: ; preds = %30
br label %48
48: ; preds = %47, %46, %42, %38, %37, %27
%49 = call %struct.dirent* @readdir(i32* %14)
%50 = icmp eq %struct.dirent* %49, null
br i1 %50, label %51, label %23
51: ; preds = %48, %16
%52 = call i32 @closedir(i32* %14)
br label %53
53: ; preds = %13, %51, %5
ret void
}