#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 */
int /*<<< orphan*/ 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 *);
void stub1(void *, char const *);
void util_exec_on_files(const char *directory, int hidden_files, void *data,
                        void (*callback)(void *data, const char *filename)) {
  char complete_filename[1024];
  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) - 1, "%s/%s",
                 directory, entry->d_name);
        lstat(complete_filename, &statbuf);
        if (!S_ISDIR(statbuf.st_mode)) {
          (*callback)(data, complete_filename);
        }
      }
    }
    closedir(dir);
  }
}


x86 assembly (clang, -O0):
<util_exec_on_files>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1190 <util_exec_on_files+0x30>
cmpq   $0x0,-0x20(%rbp)
jne    1195 <util_exec_on_files+0x35>
jmp    1269 <util_exec_on_files+0x109>
mov    -0x8(%rbp),%rdi
call   1030 <opendir@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
je     1269 <util_exec_on_files+0x109>
jmp    11b8 <util_exec_on_files+0x58>
mov    -0x428(%rbp),%rdi
call   1080 <readdir@plt>
mov    %rax,-0x430(%rbp)
cmp    $0x0,%rax
je     125d <util_exec_on_files+0xfd>
cmpl   $0x0,-0xc(%rbp)
jne    11f5 <util_exec_on_files+0x95>
mov    -0x430(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
je     1258 <util_exec_on_files+0xf8>
lea    -0x420(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    -0x430(%rbp),%rax
mov    (%rax),%r8
mov    $0x3ff,%esi
lea    0xdea(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x420(%rbp),%rdi
lea    -0x438(%rbp),%rsi
call   1070 <lstat@plt>
mov    -0x438(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    1253 <util_exec_on_files+0xf3>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   *%rax
jmp    1258 <util_exec_on_files+0xf8>
jmp    11b8 <util_exec_on_files+0x58>
mov    -0x428(%rbp),%rdi
call   1060 <closedir@plt>
add    $0x440,%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    $0x428,%rsp
mov    %rcx,0x10(%rsp)
mov    %rdx,0x18(%rsp)
test   %rdi,%rdi
je     122c <util_exec_on_files+0xcc>
cmpq   $0x0,0x10(%rsp)
je     122c <util_exec_on_files+0xcc>
mov    %esi,%r12d
mov    %rdi,%rbx
call   1030 <opendir@plt>
test   %rax,%rax
je     122c <util_exec_on_files+0xcc>
mov    %rax,%rbp
mov    %rax,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     1224 <util_exec_on_files+0xc4>
lea    0xe45(%rip),%r13
lea    0x20(%rsp),%r14
lea    0x8(%rsp),%r15
jmp    11dd <util_exec_on_files+0x7d>
nopw   0x0(%rax,%rax,1)
mov    %rbp,%rdi
call   1080 <readdir@plt>
test   %rax,%rax
je     1224 <util_exec_on_files+0xc4>
mov    (%rax),%r8
test   %r12d,%r12d
jne    11eb <util_exec_on_files+0x8b>
cmpb   $0x2e,(%r8)
je     11d0 <util_exec_on_files+0x70>
mov    %r14,%rdi
mov    $0x3ff,%esi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1050 <snprintf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <lstat@plt>
mov    0x8(%rsp),%edi
call   1040 <S_ISDIR@plt>
test   %eax,%eax
jne    11d0 <util_exec_on_files+0x70>
mov    0x18(%rsp),%rdi
mov    %r14,%rsi
call   *0x10(%rsp)
jmp    11d0 <util_exec_on_files+0x70>
mov    %rbp,%rdi
call   1060 <closedir@plt>
add    $0x428,%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"
define void @util_exec_on_files(i8* %0, i32 %1, i8* %2, void (i8*, i8*)* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca void (i8*, i8*)*
%9 = alloca [1024 x i8]
%10 = alloca i32*
%11 = alloca %struct.dirent*
%12 = alloca %struct.stat
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store void (i8*, i8*)* %3, void (i8*, i8*)** %8
%13 = load i8*, i8** %5
%14 = icmp ne i8* %13, null
br i1 %14, label %15, label %18
15: ; preds = %4
%16 = load void (i8*, i8*)*, void (i8*, i8*)** %8
%17 = icmp ne void (i8*, i8*)* %16, null
br i1 %17, label %19, label %18
18: ; preds = %15, %4
br label %62
19: ; preds = %15
%20 = load i8*, i8** %5
%21 = call i32* @opendir(i8* %20)
store i32* %21, i32** %10
%22 = load i32*, i32** %10
%23 = icmp ne i32* %22, null
br i1 %23, label %24, label %62
24: ; preds = %19
br label %25
25: ; preds = %58, %24
%26 = load i32*, i32** %10
%27 = call %struct.dirent* @readdir(i32* %26)
store %struct.dirent* %27, %struct.dirent** %11
%28 = icmp ne %struct.dirent* %27, null
br i1 %28, label %29, label %59
29: ; preds = %25
%30 = load i32, i32* %6
%31 = icmp ne i32 %30, 0
br i1 %31, label %40, label %32
32: ; preds = %29
%33 = load %struct.dirent*, %struct.dirent** %11
%34 = getelementptr inbounds %struct.dirent, %struct.dirent* %33, i32 0, i32 0
%35 = load i8*, i8** %34
%36 = getelementptr inbounds i8, i8* %35, i64 0
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 46
br i1 %39, label %40, label %58
40: ; preds = %32, %29
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%42 = load i8*, i8** %5
%43 = load %struct.dirent*, %struct.dirent** %11
%44 = getelementptr inbounds %struct.dirent, %struct.dirent* %43, i32 0, i32 0
%45 = load i8*, i8** %44
%46 = call i32 @snprintf(i8* %41, i32 1023, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %42, i8* %45)
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%48 = call i32 @lstat(i8* %47, %struct.stat* %12)
%49 = getelementptr inbounds %struct.stat, %struct.stat* %12, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i32 @S_ISDIR(i32 %50)
%52 = icmp ne i32 %51, 0
br i1 %52, label %57, label %53
53: ; preds = %40
%54 = load void (i8*, i8*)*, void (i8*, i8*)** %8
%55 = load i8*, i8** %7
%56 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
br label %57
57: ; preds = %53, %40
br label %58
58: ; preds = %57, %32
br label %25
59: ; preds = %25
%60 = load i32*, i32** %10
%61 = call i32 @closedir(i32* %60)
br label %62
62: ; preds = %18, %59, %19
ret void
}

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