#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 const *d_name;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int O_RDONLY;
int /*<<< orphan*/ S_ISDIR(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int open(char const *, int);
int /*<<< orphan*/ *opendir(char const *);
int /*<<< orphan*/ perror(char const *);
struct dirent *readdir(int /*<<< orphan*/ *);
int /*<<< orphan*/ searchfile(char const *, int, unsigned char const *,
                              unsigned char const *, int);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strcmp(char const *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
scalar_t__ strlen(char const *);
void recurse(const char *path, const unsigned char *value,
             const unsigned char *mask, int len) {
  struct stat s;
  if (stat(path, &s)) {
    perror("stat");
    return;
  }
  if (!S_ISDIR(s.st_mode)) {
    int fd = open(path, O_RDONLY | 0);
    if (fd < 0)
      perror(path);
    else {
      searchfile(path, fd, value, mask, len);
      close(fd);
    }
    return;
  }
  DIR *dir = opendir(path);
  if (!dir) {
    perror(path);
    exit(3);
  }
  struct dirent *d;
  while ((d = readdir(dir))) {
    if (!(strcmp(d->d_name, ".") && strcmp(d->d_name, "..")))
      continue;
    char newpath[strlen(path) + strlen(d->d_name) + 1];
    strcpy(newpath, path);
    strcat(newpath, "/");
    strcat(newpath, d->d_name);
    recurse(newpath, value, mask, len);
  }
  closedir(dir);
}


x86 assembly (clang, -O0):
<recurse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10b0 <stat@plt>
cmp    $0x0,%rax
je     122f <recurse+0x3f>
lea    0xddb(%rip),%rdi
call   10f0 <perror@plt>
jmp    13b3 <recurse+0x1c3>
mov    -0x20(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    1295 <recurse+0xa5>
mov    -0x8(%rbp),%rdi
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
or     $0x0,%esi
call   10e0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    1270 <recurse+0x80>
mov    -0x8(%rbp),%rdi
call   10f0 <perror@plt>
jmp    1290 <recurse+0xa0>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    -0x1c(%rbp),%r8d
call   10d0 <searchfile@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
jmp    13b3 <recurse+0x1c3>
mov    -0x8(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12c0 <recurse+0xd0>
mov    -0x8(%rbp),%rdi
call   10f0 <perror@plt>
mov    $0x3,%edi
call   1110 <exit@plt>
jmp    12c5 <recurse+0xd5>
mov    -0x30(%rbp),%rdi
call   10c0 <readdir@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     13aa <recurse+0x1ba>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    0xd1c(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1316 <recurse+0x126>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    0xcfe(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    131b <recurse+0x12b>
jmp    12c5 <recurse+0xd5>
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,-0x58(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
call   1060 <strlen@plt>
mov    -0x58(%rbp),%rcx
mov    %rax,%rdx
lea    0x1(%rcx,%rdx,1),%rax
mov    %rsp,%rsi
mov    %rsi,-0x40(%rbp)
lea    0x10(%rcx,%rdx,1),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x48(%rbp)
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x50(%rbp),%rdi
lea    0xc93(%rip),%rsi
call   1100 <strcat@plt>
mov    -0x50(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    (%rax),%rsi
call   1100 <strcat@plt>
mov    -0x50(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <recurse@plt>
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
jmp    12c5 <recurse+0xd5>
mov    -0x30(%rbp),%rdi
call   1090 <closedir@plt>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<recurse>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,-0x2c(%rbp)
mov    %rdx,-0x40(%rbp)
mov    %rsi,-0x38(%rbp)
mov    %rdi,%r15
lea    -0x30(%rbp),%rsi
call   10b0 <stat@plt>
test   %rax,%rax
jne    1373 <recurse+0x183>
mov    -0x30(%rbp),%edi
call   1070 <S_ISDIR@plt>
test   %eax,%eax
je     1330 <recurse+0x140>
mov    %r15,%rdi
call   1050 <opendir@plt>
test   %rax,%rax
je     138b <recurse+0x19b>
mov    %rax,%r14
mov    %rax,%rdi
call   10c0 <readdir@plt>
test   %rax,%rax
je     1326 <recurse+0x136>
mov    %rax,%r12
lea    0xda6(%rip),%rbx
mov    %r14,-0x48(%rbp)
jmp    1284 <recurse+0x94>
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
call   10c0 <readdir@plt>
mov    %rax,%r12
test   %rax,%rax
je     1326 <recurse+0x136>
mov    (%r12),%rdi
mov    %rbx,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1270 <recurse+0x80>
mov    (%r12),%rdi
lea    0xd65(%rip),%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1270 <recurse+0x80>
mov    %r15,%rdi
call   1060 <strlen@plt>
mov    %rbx,%r14
mov    %r15,%rbx
mov    %rax,%r15
mov    (%r12),%rdi
call   1060 <strlen@plt>
mov    %rsp,%r13
add    %r15,%rax
add    $0x10,%rax
mov    %rbx,%r15
and    $0xfffffffffffffff0,%rax
mov    %rsp,%rbx
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
lea    0xd15(%rip),%rsi
call   1100 <strcat@plt>
mov    (%r12),%rsi
mov    %rbx,%rdi
call   1100 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rbx
mov    -0x48(%rbp),%r14
mov    -0x38(%rbp),%rsi
mov    -0x40(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
call   1030 <recurse@plt>
mov    %r13,%rsp
jmp    1270 <recurse+0x80>
mov    %r14,%rdi
call   1090 <closedir@plt>
jmp    1364 <recurse+0x174>
mov    0x2cb1(%rip),%rax
mov    (%rax),%esi
mov    %r15,%rdi
call   10e0 <open@plt>
test   %eax,%eax
js     1381 <recurse+0x191>
mov    %eax,%ebx
mov    %r15,%rdi
mov    %eax,%esi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x2c(%rbp),%r8d
call   10d0 <searchfile@plt>
mov    %ebx,%edi
call   1080 <close@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc86(%rip),%rdi
call   10f0 <perror@plt>
jmp    1364 <recurse+0x174>
mov    %r15,%rdi
call   10f0 <perror@plt>
jmp    1364 <recurse+0x174>
mov    %r15,%rdi
call   10f0 <perror@plt>
mov    $0x3,%edi
call   1110 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [5 x i8] c"stat\00"
@O_RDONLY = global i32 0
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [2 x i8] c"/\00"
define void @recurse(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca %struct.stat
%10 = alloca i32
%11 = alloca i32*
%12 = alloca %struct.dirent*
%13 = alloca i8*
%14 = alloca i64
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%15 = load i8*, i8** %5
%16 = call i64 @stat(i8* %15, %struct.stat* %9)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %4
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %97
20: ; preds = %4
%21 = getelementptr inbounds %struct.stat, %struct.stat* %9, i32 0, i32 0
%22 = load i32, i32* %21
%23 = call i32 @S_ISDIR(i32 %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %45, label %25
25: ; preds = %20
%26 = load i8*, i8** %5
%27 = load i32, i32* @O_RDONLY
%28 = or i32 %27, 0
%29 = call i32 @open(i8* %26, i32 %28)
store i32 %29, i32* %10
%30 = load i32, i32* %10
%31 = icmp slt i32 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %25
%33 = load i8*, i8** %5
%34 = call i32 @perror(i8* %33)
br label %44
35: ; preds = %25
%36 = load i8*, i8** %5
%37 = load i32, i32* %10
%38 = load i8*, i8** %6
%39 = load i8*, i8** %7
%40 = load i32, i32* %8
%41 = call i32 @searchfile(i8* %36, i32 %37, i8* %38, i8* %39, i32 %40)
%42 = load i32, i32* %10
%43 = call i32 @close(i32 %42)
br label %44
44: ; preds = %35, %32
br label %97
45: ; preds = %20
%46 = load i8*, i8** %5
%47 = call i32* @opendir(i8* %46)
store i32* %47, i32** %11
%48 = load i32*, i32** %11
%49 = icmp ne i32* %48, null
br i1 %49, label %54, label %50
50: ; preds = %45
%51 = load i8*, i8** %5
%52 = call i32 @perror(i8* %51)
%53 = call i32 @exit(i32 3)
unreachable
54: ; preds = %45
br label %55
55: ; preds = %72, %71, %54
%56 = load i32*, i32** %11
%57 = call %struct.dirent* @readdir(i32* %56)
store %struct.dirent* %57, %struct.dirent** %12
%58 = icmp ne %struct.dirent* %57, null
br i1 %58, label %59, label %94
59: ; preds = %55
%60 = load %struct.dirent*, %struct.dirent** %12
%61 = getelementptr inbounds %struct.dirent, %struct.dirent* %60, i32 0, i32 0
%62 = load i8*, i8** %61
%63 = call i64 @strcmp(i8* %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%64 = icmp ne i64 %63, 0
br i1 %64, label %65, label %71
65: ; preds = %59
%66 = load %struct.dirent*, %struct.dirent** %12
%67 = getelementptr inbounds %struct.dirent, %struct.dirent* %66, i32 0, i32 0
%68 = load i8*, i8** %67
%69 = call i64 @strcmp(i8* %68, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%70 = icmp ne i64 %69, 0
br i1 %70, label %72, label %71
71: ; preds = %65, %59
br label %55
72: ; preds = %65
%73 = load i8*, i8** %5
%74 = call i64 @strlen(i8* %73)
%75 = load %struct.dirent*, %struct.dirent** %12
%76 = getelementptr inbounds %struct.dirent, %struct.dirent* %75, i32 0, i32 0
%77 = load i8*, i8** %76
%78 = call i64 @strlen(i8* %77)
%79 = add nsw i64 %74, %78
%80 = add nsw i64 %79, 1
%81 = call i8* @llvm.stacksave()
store i8* %81, i8** %13
%82 = alloca i8, i64 %80
store i64 %80, i64* %14
%83 = load i8*, i8** %5
%84 = call i32 @strcpy(i8* %82, i8* %83)
%85 = call i32 @strcat(i8* %82, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%86 = load %struct.dirent*, %struct.dirent** %12
%87 = getelementptr inbounds %struct.dirent, %struct.dirent* %86, i32 0, i32 0
%88 = load i8*, i8** %87
%89 = call i32 @strcat(i8* %82, i8* %88)
%90 = load i8*, i8** %6
%91 = load i8*, i8** %7
%92 = load i32, i32* %8
%93 = load i8*, i8** %13
br label %55
94: ; preds = %55
%95 = load i32*, i32** %11
%96 = call i32 @closedir(i32* %95)
br label %97
97: ; preds = %94, %44, %18
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
%struct.dirent = type { i8* }
@.str = [5 x i8] c"stat\00"
@O_RDONLY = global i32 0
@.str.1 = [2 x i8] c".\00"
@.str.2 = [3 x i8] c"..\00"
@.str.3 = [2 x i8] c"/\00"
define void @recurse(i8* %0, i8* %1, i8* %2, i32 %3) {
%5 = alloca %struct.stat
%6 = bitcast %struct.stat* %5 to i8*
%7 = call i64 @stat(i8* %0, %struct.stat* %5)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %61
11: ; preds = %4
%12 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
%13 = load i32, i32* %12
%14 = call i32 @S_ISDIR(i32 %13)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %25
16: ; preds = %11
%17 = load i32, i32* @O_RDONLY
%18 = call i32 @open(i8* %0, i32 %17)
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @perror(i8* %0)
br label %61
22: ; preds = %16
%23 = call i32 @searchfile(i8* %0, i32 %18, i8* %1, i8* %2, i32 %3)
%24 = call i32 @close(i32 %18)
br label %61
25: ; preds = %11
%26 = call i32* @opendir(i8* %0)
%27 = icmp eq i32* %26, null
br i1 %27, label %31, label %28
28: ; preds = %25
%29 = call %struct.dirent* @readdir(i32* %26)
%30 = icmp eq %struct.dirent* %29, null
br i1 %30, label %59, label %34
31: ; preds = %25
%32 = call i32 @perror(i8* %0)
%33 = call i32 @exit(i32 3)
unreachable
34: ; preds = %28, %44
%35 = phi %struct.dirent* [ %45, %44 ], [ %29, %28 ]
%36 = getelementptr inbounds %struct.dirent, %struct.dirent* %35, i64 0, i32 0
%37 = load i8*, i8** %36
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %44, label %40
40: ; preds = %34
%41 = load i8*, i8** %36
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %34, %40, %47
%45 = call %struct.dirent* @readdir(i32* %26)
%46 = icmp eq %struct.dirent* %45, null
br i1 %46, label %59, label %34
47: ; preds = %40
%48 = call i64 @strlen(i8* dereferenceable(1) %0)
%49 = load i8*, i8** %36
%50 = call i64 @strlen(i8* dereferenceable(1) %49)
%51 = add i64 %48, 1
%52 = add i64 %51, %50
%53 = call i8* @llvm.stacksave()
%54 = alloca i8, i64 %52
%55 = call i32 @strcpy(i8* %54, i8* %0)
%56 = call i32 @strcat(i8* %54, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%57 = load i8*, i8** %36
%58 = call i32 @strcat(i8* %54, i8* %57)
br label %44
59: ; preds = %44, %28
%60 = call i32 @closedir(i32* %26)
br label %61
61: ; preds = %20, %22, %59, %9
ret void
}