#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 /*<<< orphan*/ 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 /*<<< orphan*/);
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);
    if (fd >= 0) {
      searchfile(path, fd, value, mask, len);
      close(fd);
    } else
      perror(path);
    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    13b0 <recurse+0x1c0>
mov    -0x20(%rbp),%edi
call   1070 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    1292 <recurse+0xa2>
mov    -0x8(%rbp),%rdi
mov    0x2d9d(%rip),%rax
mov    (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     1284 <recurse+0x94>
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    128d <recurse+0x9d>
mov    -0x8(%rbp),%rdi
call   10f0 <perror@plt>
jmp    13b0 <recurse+0x1c0>
mov    -0x8(%rbp),%rdi
call   1050 <opendir@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    12bd <recurse+0xcd>
mov    -0x8(%rbp),%rdi
call   10f0 <perror@plt>
mov    $0x3,%edi
call   1110 <exit@plt>
jmp    12c2 <recurse+0xd2>
mov    -0x30(%rbp),%rdi
call   10c0 <readdir@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
je     13a7 <recurse+0x1b7>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    0xd1f(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1313 <recurse+0x123>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
lea    0xd01(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
jne    1318 <recurse+0x128>
jmp    12c2 <recurse+0xd2>
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    0xc96(%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    12c2 <recurse+0xd2>
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 %96
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 %44, label %25
25: ; preds = %20
%26 = load i8*, i8** %5
%27 = load i32, i32* @O_RDONLY
%28 = call i32 @open(i8* %26, i32 %27)
store i32 %28, i32* %10
%29 = load i32, i32* %10
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %40
31: ; preds = %25
%32 = load i8*, i8** %5
%33 = load i32, i32* %10
%34 = load i8*, i8** %6
%35 = load i8*, i8** %7
%36 = load i32, i32* %8
%37 = call i32 @searchfile(i8* %32, i32 %33, i8* %34, i8* %35, i32 %36)
%38 = load i32, i32* %10
%39 = call i32 @close(i32 %38)
br label %43
40: ; preds = %25
%41 = load i8*, i8** %5
%42 = call i32 @perror(i8* %41)
br label %43
43: ; preds = %40, %31
br label %96
44: ; preds = %20
%45 = load i8*, i8** %5
%46 = call i32* @opendir(i8* %45)
store i32* %46, i32** %11
%47 = load i32*, i32** %11
%48 = icmp ne i32* %47, null
br i1 %48, label %53, label %49
49: ; preds = %44
%50 = load i8*, i8** %5
%51 = call i32 @perror(i8* %50)
%52 = call i32 @exit(i32 3)
unreachable
53: ; preds = %44
br label %54
54: ; preds = %71, %70, %53
%55 = load i32*, i32** %11
%56 = call %struct.dirent* @readdir(i32* %55)
store %struct.dirent* %56, %struct.dirent** %12
%57 = icmp ne %struct.dirent* %56, null
br i1 %57, label %58, label %93
58: ; preds = %54
%59 = load %struct.dirent*, %struct.dirent** %12
%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 %70
64: ; preds = %58
%65 = load %struct.dirent*, %struct.dirent** %12
%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 %71, label %70
70: ; preds = %64, %58
br label %54
71: ; preds = %64
%72 = load i8*, i8** %5
%73 = call i64 @strlen(i8* %72)
%74 = load %struct.dirent*, %struct.dirent** %12
%75 = getelementptr inbounds %struct.dirent, %struct.dirent* %74, i32 0, i32 0
%76 = load i8*, i8** %75
%77 = call i64 @strlen(i8* %76)
%78 = add nsw i64 %73, %77
%79 = add nsw i64 %78, 1
%80 = call i8* @llvm.stacksave()
store i8* %80, i8** %13
%81 = alloca i8, i64 %79
store i64 %79, i64* %14
%82 = load i8*, i8** %5
%83 = call i32 @strcpy(i8* %81, i8* %82)
%84 = call i32 @strcat(i8* %81, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%85 = load %struct.dirent*, %struct.dirent** %12
%86 = getelementptr inbounds %struct.dirent, %struct.dirent* %85, i32 0, i32 0
%87 = load i8*, i8** %86
%88 = call i32 @strcat(i8* %81, i8* %87)
%89 = load i8*, i8** %6
%90 = load i8*, i8** %7
%91 = load i32, i32* %8
%92 = load i8*, i8** %13
br label %54
93: ; preds = %54
%94 = load i32*, i32** %11
%95 = call i32 @closedir(i32* %94)
br label %96
96: ; preds = %93, %43, %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 sgt i32 %18, -1
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = call i32 @searchfile(i8* %0, i32 %18, i8* %1, i8* %2, i32 %3)
%22 = call i32 @close(i32 %18)
br label %61
23: ; preds = %16
%24 = call i32 @perror(i8* %0)
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, %23, %59, %9
ret void
}