#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 */
typedef int /*<<< orphan*/ atom;

/* Variables and functions */
int /*<<< orphan*/ FNM_PATHNAME;
int /*<<< orphan*/ cctools_debug(long long, char *, char const *, char const *,
                                 ...);
int fnmatch(char *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *strchr(char const *, char);
int /*<<< orphan*/ strcpy(char *, char const *);
int /*<<< orphan*/ strncpy(char *, char const *, size_t);
char *strrchr(char *, char);
int search_should_recurse(const char *base, const char *pattern) {
  cctools_debug((1LL << 3),
                "search_should_recurse(base = `%s', pattern = `%s')", base,
                pattern);
  while (1) {
    char atom[1024];
    if (*pattern != '/')
      return 1;
    const char *end = strchr(pattern, '|');
    memset(atom, 0, sizeof(atom));
    if (end)
      strncpy(atom, pattern, (size_t)(end - pattern));
    else
      strcpy(atom, pattern);
    while (*atom) {
      int result = fnmatch(atom, base, FNM_PATHNAME);
      cctools_debug((1LL << 3), "fnmatch(`%s', `%s', FNM_PATHNAME) = %d", atom,
                    base, result);
      if (result == 0) {
        return 1;
      }
      char *last = strrchr(atom, '/');
      if (last) {
        *last = '\0';
      } else {
        break;
      }
    }
    if (end)
      pattern = end + 1;
    else
      break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<search_should_recurse>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x8,%edi
lea    0xe69(%rip),%rsi
mov    $0x0,%al
call   1090 <cctools_debug@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     11ba <search_should_recurse+0x4a>
movl   $0x1,-0x4(%rbp)
jmp    1304 <search_should_recurse+0x194>
mov    -0x18(%rbp),%rdi
mov    $0x7c,%esi
call   1050 <strchr@plt>
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
cmpq   $0x0,-0x428(%rbp)
je     1213 <search_should_recurse+0xa3>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x428(%rbp),%rdx
mov    -0x18(%rbp),%rax
sub    %rax,%rdx
call   1030 <strncpy@plt>
jmp    1223 <search_should_recurse+0xb3>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
jmp    1228 <search_should_recurse+0xb8>
cmpb   $0x0,-0x420(%rbp)
je     12d1 <search_should_recurse+0x161>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2d91(%rip),%rax
mov    (%rax),%edx
call   1070 <fnmatch@plt>
mov    %eax,-0x42c(%rbp)
lea    -0x420(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x42c(%rbp),%r8d
mov    $0x8,%edi
lea    0xdc1(%rip),%rsi
mov    $0x0,%al
call   1090 <cctools_debug@plt>
cmpl   $0x0,-0x42c(%rbp)
jne    1292 <search_should_recurse+0x122>
movl   $0x1,-0x4(%rbp)
jmp    1304 <search_should_recurse+0x194>
lea    -0x420(%rbp),%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
mov    %rax,-0x438(%rbp)
cmpq   $0x0,-0x438(%rbp)
je     12c7 <search_should_recurse+0x157>
mov    -0x438(%rbp),%rax
movb   $0x0,(%rax)
jmp    12cc <search_should_recurse+0x15c>
jmp    12d1 <search_should_recurse+0x161>
jmp    1228 <search_should_recurse+0xb8>
cmpq   $0x0,-0x428(%rbp)
je     12f3 <search_should_recurse+0x183>
mov    -0x428(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    12f8 <search_should_recurse+0x188>
jmp    12fd <search_should_recurse+0x18d>
jmp    119e <search_should_recurse+0x2e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_should_recurse>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%rbx
mov    %rdi,%r13
lea    0xe72(%rip),%rsi
mov    $0x8,%edi
mov    %r13,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1090 <cctools_debug@plt>
cmpb   $0x2f,(%rbx)
jne    127f <search_should_recurse+0x10f>
mov    %rsp,%r14
mov    0x2e25(%rip),%rbp
lea    0xe79(%rip),%r15
mov    %rbx,%rdi
mov    $0x7c,%esi
call   1050 <strchr@plt>
mov    %rax,%r12
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1080 <memset@plt>
test   %r12,%r12
je     1200 <search_should_recurse+0x90>
mov    %r12,%rdx
sub    %rbx,%rdx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strncpy@plt>
cmpb   $0x0,(%rsp)
jne    1220 <search_should_recurse+0xb0>
jmp    1267 <search_should_recurse+0xf7>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
cmpb   $0x0,(%rsp)
je     1267 <search_should_recurse+0xf7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edx
mov    %r14,%rdi
mov    %r13,%rsi
call   1070 <fnmatch@plt>
mov    %eax,%ebx
mov    $0x8,%edi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %r13,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1090 <cctools_debug@plt>
test   %ebx,%ebx
je     127f <search_should_recurse+0x10f>
mov    %r14,%rdi
mov    $0x2f,%esi
call   1060 <strrchr@plt>
test   %rax,%rax
je     1267 <search_should_recurse+0xf7>
movb   $0x0,(%rax)
cmpb   $0x0,(%rsp)
jne    1220 <search_should_recurse+0xb0>
test   %r12,%r12
je     1296 <search_should_recurse+0x126>
mov    %r12,%rbx
add    $0x1,%rbx
cmpb   $0x2f,0x1(%r12)
je     11ba <search_should_recurse+0x4a>
mov    $0x1,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    1284 <search_should_recurse+0x114>

LLVM IR (-O0):
@.str = [51 x i8] c"search_should_recurse(base = `%s', pattern = `%s')\00"
@FNM_PATHNAME = global i32 0
@.str.1 = [39 x i8] c"fnmatch(`%s', `%s', FNM_PATHNAME) = %d\00"
define i32 @search_should_recurse(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%10 = load i8*, i8** %4
%11 = load i8*, i8** %5
%12 = call i32 (i64, i8*, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %10, i8* %11)
br label %13
13: ; preds = %2, %72
%14 = load i8*, i8** %5
%15 = load i8, i8* %14
%16 = sext i8 %15 to i32
%17 = icmp ne i32 %16, 47
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 1, i32* %3
br label %74
19: ; preds = %13
%20 = load i8*, i8** %5
%21 = call i8* @strchr(i8* %20, i8 signext 124)
store i8* %21, i8** %7
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%23 = call i32 @memset(i8* %22, i32 0, i32 1024)
%24 = load i8*, i8** %7
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %35
26: ; preds = %19
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%28 = load i8*, i8** %5
%29 = load i8*, i8** %7
%30 = load i8*, i8** %5
%31 = ptrtoint i8* %29 to i64
%32 = ptrtoint i8* %30 to i64
%33 = sub i64 %31, %32
%34 = call i32 @strncpy(i8* %27, i8* %28, i64 %33)
br label %39
35: ; preds = %19
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%37 = load i8*, i8** %5
%38 = call i32 @strcpy(i8* %36, i8* %37)
br label %39
39: ; preds = %35, %26
br label %40
40: ; preds = %64, %39
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%42 = load i8, i8* %41
%43 = icmp ne i8 %42, 0
br i1 %43, label %44, label %65
44: ; preds = %40
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%46 = load i8*, i8** %4
%47 = load i32, i32* @FNM_PATHNAME
%48 = call i32 @fnmatch(i8* %45, i8* %46, i32 %47)
store i32 %48, i32* %8
%49 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%50 = load i8*, i8** %4
%51 = load i32, i32* %8
%52 = call i32 (i64, i8*, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %49, i8* %50, i32 %51)
%53 = load i32, i32* %8
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %44
store i32 1, i32* %3
br label %74
56: ; preds = %44
%57 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%58 = call i8* @strrchr(i8* %57, i8 signext 47)
store i8* %58, i8** %9
%59 = load i8*, i8** %9
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %63
61: ; preds = %56
%62 = load i8*, i8** %9
store i8 0, i8* %62
br label %64
63: ; preds = %56
br label %65
64: ; preds = %61
br label %40
65: ; preds = %63, %40
%66 = load i8*, i8** %7
%67 = icmp ne i8* %66, null
br i1 %67, label %68, label %71
68: ; preds = %65
%69 = load i8*, i8** %7
%70 = getelementptr inbounds i8, i8* %69, i64 1
store i8* %70, i8** %5
br label %72
71: ; preds = %65
br label %73
72: ; preds = %68
br label %13
73: ; preds = %71
store i32 0, i32* %3
br label %74
74: ; preds = %73, %55, %18
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@.str = [51 x i8] c"search_should_recurse(base = `%s', pattern = `%s')\00"
@FNM_PATHNAME = global i32 0
@.str.1 = [39 x i8] c"fnmatch(`%s', `%s', FNM_PATHNAME) = %d\00"
define i32 @search_should_recurse(i8* %0, i8* %1) {
%3 = alloca [1024 x i8]
%4 = tail call i32 (i64, i8*, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = load i8, i8* %1
%7 = icmp eq i8 %6, 47
br i1 %7, label %8, label %35
8: ; preds = %2, %36
%9 = phi i8* [ %37, %36 ], [ %1, %2 ]
%10 = call i8* @strchr(i8* %9, i8 signext 124)
%11 = call i32 @memset(i8* %5, i32 0, i32 1024)
%12 = icmp eq i8* %10, null
br i1 %12, label %18, label %13
13: ; preds = %8
%14 = ptrtoint i8* %10 to i64
%15 = ptrtoint i8* %9 to i64
%16 = sub i64 %14, %15
%17 = call i32 @strncpy(i8* %5, i8* %9, i64 %16)
br label %20
18: ; preds = %8
%19 = call i32 @strcpy(i8* %5, i8* %9)
br label %20
20: ; preds = %18, %13
%21 = load i8, i8* %5
%22 = icmp eq i8 %21, 0
br i1 %22, label %34, label %23
23: ; preds = %20, %31
%24 = load i32, i32* @FNM_PATHNAME
%25 = call i32 @fnmatch(i8* %5, i8* %0, i32 %24)
%26 = call i32 (i64, i8*, i8*, i8*, ...) @cctools_debug(i64 8, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %0, i32 %25)
%27 = icmp eq i32 %25, 0
br i1 %27, label %35, label %28
28: ; preds = %23
%29 = call i8* @strrchr(i8* %5, i8 signext 47)
%30 = icmp eq i8* %29, null
br i1 %30, label %34, label %31
31: ; preds = %28
store i8 0, i8* %29
%32 = load i8, i8* %5
%33 = icmp eq i8 %32, 0
br i1 %33, label %34, label %23
34: ; preds = %31, %28, %20
br i1 %12, label %40, label %36
35: ; preds = %36, %23, %2
br label %41
36: ; preds = %34
%37 = getelementptr inbounds i8, i8* %10, i64 1
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 47
br i1 %39, label %8, label %35
40: ; preds = %34
br label %41
41: ; preds = %35, %40
%42 = phi i32 [ 0, %40 ], [ 1, %35 ]
ret i32 %42
}