#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);
int search_match_file(const char *pattern, const char *name) {
  cctools_debug((1LL << 3), "search_match_file(`%s', `%s')", pattern, name);
  while (1) {
    char atom[1024];
    const char *end = strchr(pattern, '|');
    memset(atom, 0, sizeof(atom));
    if (end)
      strncpy(atom, pattern, (size_t)(end - pattern));
    else
      strcpy(atom, pattern);
    const char *test = name;
    do {
      int result = fnmatch(atom, test, FNM_PATHNAME);
      cctools_debug((1LL << 3), "fnmatch(`%s', `%s', FNM_PATHNAME) = %d", atom,
                    test, result);
      if (result == 0) {
        return 1;
      }
      test = strchr(test, '/');
      if (test)
        test += 1;
    } while (test);
    if (end)
      pattern = end + 1;
    else
      break;
  }
  return 0;
}


x86 assembly (clang, -O0):
<search_match_file>:
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    0xe79(%rip),%rsi
mov    $0x0,%al
call   1080 <cctools_debug@plt>
mov    -0x10(%rbp),%rdi
mov    $0x7c,%esi
call   1050 <strchr@plt>
mov    %rax,-0x428(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
cmpq   $0x0,-0x428(%rbp)
je     11e7 <search_match_file+0x87>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x428(%rbp),%rdx
mov    -0x10(%rbp),%rax
sub    %rax,%rdx
call   1030 <strncpy@plt>
jmp    11f7 <search_match_file+0x97>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x430(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x430(%rbp),%rsi
mov    0x2dc1(%rip),%rax
mov    (%rax),%edx
call   1060 <fnmatch@plt>
mov    %eax,-0x434(%rbp)
lea    -0x420(%rbp),%rdx
mov    -0x430(%rbp),%rcx
mov    -0x434(%rbp),%r8d
mov    $0x8,%edi
lea    0xdd9(%rip),%rsi
mov    $0x0,%al
call   1080 <cctools_debug@plt>
cmpl   $0x0,-0x434(%rbp)
jne    1265 <search_match_file+0x105>
movl   $0x1,-0x4(%rbp)
jmp    12e3 <search_match_file+0x183>
mov    -0x430(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
mov    %rax,-0x430(%rbp)
cmpq   $0x0,-0x430(%rbp)
je     129d <search_match_file+0x13d>
mov    -0x430(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x430(%rbp)
jmp    12a2 <search_match_file+0x142>
cmpq   $0x0,-0x430(%rbp)
jne    1202 <search_match_file+0xa2>
cmpq   $0x0,-0x428(%rbp)
je     12d2 <search_match_file+0x172>
mov    -0x428(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    12d7 <search_match_file+0x177>
jmp    12dc <search_match_file+0x17c>
jmp    118e <search_match_file+0x2e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<search_match_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbx
mov    %rdi,%r13
lea    0xe82(%rip),%rsi
mov    $0x8,%edi
mov    %r13,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1080 <cctools_debug@plt>
lea    0x10(%rsp),%r14
mov    0x2e3c(%rip),%r12
lea    0xe7b(%rip),%r15
mov    %rbx,(%rsp)
mov    %r13,%rdi
mov    $0x7c,%esi
call   1050 <strchr@plt>
mov    %rax,%rbp
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
test   %rbp,%rbp
mov    %rbp,0x8(%rsp)
je     11f0 <search_match_file+0x90>
sub    %r13,%rbp
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1030 <strncpy@plt>
jmp    1200 <search_match_file+0xa0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
nopl   0x0(%rax,%rax,1)
mov    (%r12),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <fnmatch@plt>
mov    %eax,%ebp
mov    $0x8,%edi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   1080 <cctools_debug@plt>
test   %ebp,%ebp
je     125a <search_match_file+0xfa>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strchr@plt>
lea    0x1(%rax),%rbx
test   %rax,%rax
jne    1200 <search_match_file+0xa0>
mov    0x8(%rsp),%r13
test   %r13,%r13
je     1271 <search_match_file+0x111>
add    $0x1,%r13
mov    (%rsp),%rbx
jmp    11a7 <search_match_file+0x47>
mov    $0x1,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %eax,%eax
jmp    125f <search_match_file+0xff>

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

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