#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 st_mode;
};
struct match {
  int dummy;
};
struct dirent {
  size_t d_reclen;
  char const *d_name;
  int d_type;
};
typedef int /*<<< orphan*/ DIR;

/* Variables and functions */
int EACCES;
int ENOTDIR;
int FNM_NOESCAPE;
int FNM_PERIOD;
int GLOB_ABORTED;
int GLOB_ERR;
int GLOB_MARK;
int GLOB_NOESCAPE;
int GLOB_NOSPACE;
int GLOB_PERIOD;
int S_ISDIR(int);
int /*<<< orphan*/ S_ISLNK(int);
scalar_t__ append(struct match **, char const *, size_t, int);
int /*<<< orphan*/ closedir(int /*<<< orphan*/ *);
int errno;
scalar_t__ fnmatch(char const *, char const *, int);
int is_literal(char const *, int);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
int /*<<< orphan*/ *opendir(char const *);
int readdir_r(int /*<<< orphan*/ *, struct dirent *, struct dirent **);
int /*<<< orphan*/ stat(char const *, struct stat *);
char *strchr(char const *, char);
scalar_t__ strcmp(char const *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
int match_in_dir(const char *d, const char *p, int flags,
                 int (*errfunc)(const char *path, int err),
                 struct match **tail) {
  DIR *dir;
  struct dirent de_buf, *de;
  char pat[strlen(p) + 1];
  char *p2;
  size_t l = strlen(d);
  int literal;
  int fnm_flags = ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0) |
                  ((!(flags & GLOB_PERIOD)) ? FNM_PERIOD : 0);
  int error;
  if ((p2 = strchr(p, '/'))) {
    strcpy(pat, p);
    pat[p2 - p] = 0;
    for (; *p2 == '/'; p2++)
      ;
    p = pat;
  }
  literal = is_literal(p, !(flags & GLOB_NOESCAPE));
  if (*d == '/' && !*(d + 1))
    l = 0;
  dir = opendir(*d ? d : ".");
  error = errno;
  if (!dir) {
    if (error == ENOTDIR)
      return 0;
    if (error == EACCES && !*p) {
      struct stat st;
      if (!stat(d, &st) && S_ISDIR(st.st_mode)) {
        if (append(tail, d, l, l))
          return GLOB_NOSPACE;
        return 0;
      }
    }
    if (errfunc(d, error) || (flags & GLOB_ERR))
      return GLOB_ABORTED;
    return 0;
  }
  if (!*p) {
    error = append(tail, d, l, l) ? GLOB_NOSPACE : 0;
    closedir(dir);
    return error;
  }
  while (!(error = readdir_r(dir, &de_buf, &de)) && de) {
    char namebuf[l + de->d_reclen + 2], *name = namebuf;
    if (!literal && fnmatch(p, de->d_name, fnm_flags))
      continue;
    if (literal && strcmp(p, de->d_name))
      continue;
    if (p2 && de->d_type && !S_ISDIR(de->d_type << 12) &&
        !S_ISLNK(de->d_type << 12))
      continue;
    if (*d) {
      memcpy(name, d, l);
      name[l] = '/';
      strcpy(name + l + 1, de->d_name);
    } else {
      name = de->d_name;
    }
    if (p2) {
      if ((error = match_in_dir(name, p2, flags, errfunc, tail))) {
        closedir(dir);
        return error;
      }
    } else {
      int mark = 0;
      if (flags & GLOB_MARK) {
        if (de->d_type && !S_ISLNK(de->d_type << 12))
          mark = S_ISDIR(de->d_type << 12);
        else {
          struct stat st;
          stat(name, &st);
          mark = S_ISDIR(st.st_mode);
        }
      }
      if (append(tail, name, l + de->d_reclen + 1, mark)) {
        closedir(dir);
        return GLOB_NOSPACE;
      }
    }
  }
  closedir(dir);
  if (error && (errfunc(d, error) || (flags & GLOB_ERR)))
    return GLOB_ABORTED;
  return 0;
}


x86 assembly (clang, -O0):
<match_in_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1080 <strlen@plt>
add    $0x1,%eax
mov    %rsp,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0xb8(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <strlen@plt>
cltq
mov    %rax,-0x78(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2d77(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     1278 <match_in_dir+0x88>
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xbc(%rbp)
jmp    1285 <match_in_dir+0x95>
xor    %eax,%eax
mov    %eax,-0xbc(%rbp)
jmp    1285 <match_in_dir+0x95>
mov    -0xbc(%rbp),%eax
mov    %eax,-0xc0(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2d05(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
jne    12ba <match_in_dir+0xca>
mov    0x2cfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc4(%rbp)
jmp    12c7 <match_in_dir+0xd7>
xor    %eax,%eax
mov    %eax,-0xc4(%rbp)
jmp    12c7 <match_in_dir+0xd7>
mov    -0xc0(%rbp),%eax
mov    -0xc4(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x80(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1090 <strchr@plt>
mov    %rax,-0x70(%rbp)
cmp    $0x0,%rax
je     134b <match_in_dir+0x15b>
mov    -0xb8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0xb8(%rbp),%rax
mov    -0x70(%rbp),%rcx
mov    -0x18(%rbp),%rdx
sub    %rdx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x70(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1340 <match_in_dir+0x150>
jmp    132f <match_in_dir+0x13f>
mov    -0x70(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x70(%rbp)
jmp    131a <match_in_dir+0x12a>
mov    -0xb8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%eax
mov    0x2c77(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%esi
call   1110 <is_literal@plt>
mov    %eax,-0x7c(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
jne    1396 <match_in_dir+0x1a6>
mov    -0x10(%rbp),%rax
cmpb   $0x0,0x1(%rax)
jne    1396 <match_in_dir+0x1a6>
movq   $0x0,-0x78(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     13b6 <match_in_dir+0x1c6>
mov    -0x10(%rbp),%rax
mov    %rax,-0xd0(%rbp)
jmp    13c9 <match_in_dir+0x1d9>
lea    0xc43(%rip),%rax
mov    %rax,-0xd0(%rbp)
jmp    13c9 <match_in_dir+0x1d9>
mov    -0xd0(%rbp),%rdi
call   1070 <opendir@plt>
mov    %rax,-0x38(%rbp)
mov    0x2bb8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x84(%rbp)
cmpq   $0x0,-0x38(%rbp)
jne    1523 <match_in_dir+0x333>
mov    -0x84(%rbp),%eax
mov    0x2bf0(%rip),%rcx
cmp    (%rcx),%eax
jne    141e <match_in_dir+0x22e>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x88(%rbp)
jmp    193d <match_in_dir+0x74d>
mov    -0x84(%rbp),%eax
mov    0x2b8d(%rip),%rcx
cmp    (%rcx),%eax
jne    14c4 <match_in_dir+0x2d4>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    14c4 <match_in_dir+0x2d4>
mov    -0x10(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   10f0 <stat@plt>
cmp    $0x0,%eax
jne    14bf <match_in_dir+0x2cf>
mov    -0x90(%rbp),%edi
call   10a0 <S_ISDIR@plt>
cmp    $0x0,%eax
je     14bf <match_in_dir+0x2cf>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x78(%rbp),%rdx
mov    -0x78(%rbp),%rax
mov    %eax,%ecx
call   1030 <append@plt>
cmp    $0x0,%rax
je     14a9 <match_in_dir+0x2b9>
mov    0x2b2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x88(%rbp)
jmp    193d <match_in_dir+0x74d>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x88(%rbp)
jmp    193d <match_in_dir+0x74d>
jmp    14c4 <match_in_dir+0x2d4>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x84(%rbp),%esi
call   *%rax
cmp    $0x0,%eax
jne    14f2 <match_in_dir+0x302>
mov    -0x1c(%rbp),%eax
mov    0x2af9(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     150d <match_in_dir+0x31d>
mov    0x2a97(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x88(%rbp)
jmp    193d <match_in_dir+0x74d>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x88(%rbp)
jmp    193d <match_in_dir+0x74d>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    159f <match_in_dir+0x3af>
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x78(%rbp),%rdx
mov    -0x78(%rbp),%rax
mov    %eax,%ecx
call   1030 <append@plt>
cmp    $0x0,%rax
je     1565 <match_in_dir+0x375>
mov    0x2a68(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd4(%rbp)
jmp    1572 <match_in_dir+0x382>
xor    %eax,%eax
mov    %eax,-0xd4(%rbp)
jmp    1572 <match_in_dir+0x382>
mov    -0xd4(%rbp),%eax
mov    %eax,-0x84(%rbp)
mov    -0x38(%rbp),%rdi
call   10c0 <closedir@plt>
mov    -0x84(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x88(%rbp)
jmp    193d <match_in_dir+0x74d>
jmp    15a4 <match_in_dir+0x3b4>
mov    -0x38(%rbp),%rdi
lea    -0x50(%rbp),%rsi
lea    -0x58(%rbp),%rdx
call   1060 <readdir_r@plt>
mov    %eax,%ecx
mov    %ecx,-0x84(%rbp)
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xd5(%rbp)
jne    15dc <match_in_dir+0x3ec>
cmpq   $0x0,-0x58(%rbp)
setne  %al
mov    %al,-0xd5(%rbp)
mov    -0xd5(%rbp),%al
test   $0x1,%al
jne    15ef <match_in_dir+0x3ff>
jmp    18cd <match_in_dir+0x6dd>
mov    -0x78(%rbp),%rax
mov    -0x58(%rbp),%rcx
mov    (%rcx),%rdx
lea    0x2(%rax,%rdx,1),%rcx
mov    %rsp,%rsi
mov    %rsi,-0x98(%rbp)
lea    0x11(%rax,%rdx,1),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rax
sub    %rdx,%rax
mov    %rax,%rsp
mov    %rcx,-0xa0(%rbp)
mov    %rax,-0xa8(%rbp)
cmpl   $0x0,-0x7c(%rbp)
jne    1660 <match_in_dir+0x470>
mov    -0x18(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x80(%rbp),%edx
call   10b0 <fnmatch@plt>
cmp    $0x0,%rax
je     1660 <match_in_dir+0x470>
movl   $0x5,-0x88(%rbp)
jmp    1891 <match_in_dir+0x6a1>
cmpl   $0x0,-0x7c(%rbp)
je     1694 <match_in_dir+0x4a4>
mov    -0x18(%rbp),%rdi
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%rsi
call   10e0 <strcmp@plt>
cmp    $0x0,%rax
je     1694 <match_in_dir+0x4a4>
movl   $0x5,-0x88(%rbp)
jmp    1891 <match_in_dir+0x6a1>
cmpq   $0x0,-0x70(%rbp)
je     16ec <match_in_dir+0x4fc>
mov    -0x58(%rbp),%rax
cmpl   $0x0,0x10(%rax)
je     16ec <match_in_dir+0x4fc>
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%edi
shl    $0xc,%edi
call   10a0 <S_ISDIR@plt>
cmp    $0x0,%eax
jne    16ec <match_in_dir+0x4fc>
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%edi
shl    $0xc,%edi
call   1050 <S_ISLNK@plt>
cmp    $0x0,%eax
jne    16ec <match_in_dir+0x4fc>
movl   $0x5,-0x88(%rbp)
jmp    1891 <match_in_dir+0x6a1>
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     173d <match_in_dir+0x54d>
mov    -0xa8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x78(%rbp),%rdx
call   1100 <memcpy@plt>
mov    -0xa8(%rbp),%rax
mov    -0x78(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0xa8(%rbp),%rdi
add    -0x78(%rbp),%rdi
add    $0x1,%rdi
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
jmp    174c <match_in_dir+0x55c>
mov    -0x58(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0xa8(%rbp)
cmpq   $0x0,-0x70(%rbp)
je     17a7 <match_in_dir+0x5b7>
mov    -0xa8(%rbp),%rdi
mov    -0x70(%rbp),%rsi
mov    -0x1c(%rbp),%edx
mov    -0x28(%rbp),%rcx
mov    -0x30(%rbp),%r8
call   10d0 <match_in_dir@plt>
mov    %eax,-0x84(%rbp)
cmp    $0x0,%eax
je     17a2 <match_in_dir+0x5b2>
mov    -0x38(%rbp),%rdi
call   10c0 <closedir@plt>
mov    -0x84(%rbp),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x88(%rbp)
jmp    1891 <match_in_dir+0x6a1>
jmp    1887 <match_in_dir+0x697>
movl   $0x0,-0xac(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x280d(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     182f <match_in_dir+0x63f>
mov    -0x58(%rbp),%rax
cmpl   $0x0,0x10(%rax)
je     1806 <match_in_dir+0x616>
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%edi
shl    $0xc,%edi
call   1050 <S_ISLNK@plt>
cmp    $0x0,%eax
jne    1806 <match_in_dir+0x616>
mov    -0x58(%rbp),%rax
mov    0x10(%rax),%edi
shl    $0xc,%edi
call   10a0 <S_ISDIR@plt>
mov    %eax,-0xac(%rbp)
jmp    182a <match_in_dir+0x63a>
mov    -0xa8(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   10f0 <stat@plt>
mov    -0xb0(%rbp),%edi
call   10a0 <S_ISDIR@plt>
mov    %eax,-0xac(%rbp)
jmp    182f <match_in_dir+0x63f>
mov    -0x30(%rbp),%rdi
mov    -0xa8(%rbp),%rsi
mov    -0x78(%rbp),%rdx
mov    -0x58(%rbp),%rax
add    (%rax),%rdx
add    $0x1,%rdx
mov    -0xac(%rbp),%ecx
call   1030 <append@plt>
cmp    $0x0,%rax
je     1882 <match_in_dir+0x692>
mov    -0x38(%rbp),%rdi
call   10c0 <closedir@plt>
mov    0x2752(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x88(%rbp)
jmp    1891 <match_in_dir+0x6a1>
jmp    1887 <match_in_dir+0x697>
movl   $0x0,-0x88(%rbp)
mov    -0x98(%rbp),%rax
mov    %rax,%rsp
mov    -0x88(%rbp),%eax
mov    %eax,-0xdc(%rbp)
test   %eax,%eax
je     18c8 <match_in_dir+0x6d8>
jmp    18b4 <match_in_dir+0x6c4>
mov    -0xdc(%rbp),%eax
sub    $0x5,%eax
je     15a4 <match_in_dir+0x3b4>
jmp    193d <match_in_dir+0x74d>
jmp    15a4 <match_in_dir+0x3b4>
mov    -0x38(%rbp),%rdi
call   10c0 <closedir@plt>
cmpl   $0x0,-0x84(%rbp)
je     192c <match_in_dir+0x73c>
mov    -0x28(%rbp),%rax
mov    -0x10(%rbp),%rdi
mov    -0x84(%rbp),%esi
call   *%rax
cmp    $0x0,%eax
jne    1911 <match_in_dir+0x721>
mov    -0x1c(%rbp),%eax
mov    0x26da(%rip),%rcx
and    (%rcx),%eax
cmp    $0x0,%eax
je     192c <match_in_dir+0x73c>
mov    0x2678(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x88(%rbp)
jmp    193d <match_in_dir+0x74d>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x88(%rbp)
mov    -0x60(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<match_in_dir>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %r8,-0x58(%rbp)
mov    %rcx,-0x68(%rbp)
mov    %edx,%r13d
mov    %rdi,%rbx
mov    %rsi,-0x60(%rbp)
mov    %rsi,%rdi
call   1080 <strlen@plt>
mov    %rsp,-0x40(%rbp)
add    $0x1,%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
mov    %rbx,-0x70(%rbp)
mov    %rbx,%rdi
call   1080 <strlen@plt>
mov    %eax,-0x48(%rbp)
mov    0x2d87(%rip),%rax
xor    %r15d,%r15d
mov    (%rax),%r14d
mov    $0x0,%eax
and    %r13d,%r14d
je     1262 <match_in_dir+0x72>
mov    0x2d98(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x78(%rbp)
mov    0x2d34(%rip),%rax
mov    (%rax),%eax
movl   $0x0,-0x44(%rbp)
mov    %r13d,-0x34(%rbp)
and    %r13d,%eax
jne    128a <match_in_dir+0x9a>
mov    0x2d23(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x60(%rbp),%r13
mov    %r13,%rdi
mov    $0x2f,%esi
call   1090 <strchr@plt>
test   %rax,%rax
je     12db <match_in_dir+0xeb>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %r13,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rax
sub    %r13,%rax
movb   $0x0,(%r12,%rax,1)
add    $0xffffffffffffffff,%rbx
mov    %rbx,%r15
cmpb   $0x2f,0x1(%r15)
lea    0x1(%r15),%r15
je     12c0 <match_in_dir+0xd0>
mov    0x2cfe(%rip),%rax
mov    (%rax),%r14d
and    -0x34(%rbp),%r14d
jmp    12de <match_in_dir+0xee>
mov    %r13,%r12
movslq -0x48(%rbp),%rbx
xor    %esi,%esi
test   %r14d,%r14d
sete   %sil
mov    %r12,%rdi
call   1110 <is_literal@plt>
mov    %eax,-0x48(%rbp)
mov    -0x70(%rbp),%r14
mov    (%r14),%al
cmp    $0x2f,%al
jne    130c <match_in_dir+0x11c>
xor    %ecx,%ecx
cmpb   $0x0,0x1(%r14)
cmove  %rcx,%rbx
mov    %rbx,-0x50(%rbp)
test   %al,%al
lea    0xce7(%rip),%rdi
cmovne %r14,%rdi
call   1070 <opendir@plt>
test   %rax,%rax
je     1543 <match_in_dir+0x353>
mov    %rax,%r13
cmpb   $0x0,(%r12)
je     1563 <match_in_dir+0x373>
lea    -0xa0(%rbp),%rsi
lea    -0x30(%rbp),%rdx
mov    %r13,%rdi
call   1060 <readdir_r@plt>
mov    %eax,%ebx
test   %eax,%eax
sete   %r14b
jne    152d <match_in_dir+0x33d>
mov    %r12,-0x60(%rbp)
mov    -0x30(%rbp),%rax
test   %rax,%rax
je     152d <match_in_dir+0x33d>
mov    -0x78(%rbp),%ecx
or     %ecx,-0x44(%rbp)
mov    -0x50(%rbp),%rcx
lea    0x2(%rcx),%rdx
mov    %rdx,-0x78(%rbp)
add    $0x1,%rcx
mov    %rcx,-0x88(%rbp)
nopl   0x0(%rax,%rax,1)
mov    %rsp,%r14
mov    (%rax),%rax
mov    -0x78(%rbp),%rcx
add    %rcx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
mov    %rsp,%r12
sub    %rax,%r12
mov    %r12,%rsp
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rsi
cmpl   $0x0,-0x48(%rbp)
je     13d0 <match_in_dir+0x1e0>
mov    -0x60(%rbp),%rdi
call   10e0 <strcmp@plt>
test   %rax,%rax
jne    1500 <match_in_dir+0x310>
jmp    13e5 <match_in_dir+0x1f5>
mov    -0x60(%rbp),%rdi
mov    -0x44(%rbp),%edx
call   10b0 <fnmatch@plt>
test   %rax,%rax
jne    1500 <match_in_dir+0x310>
test   %r15,%r15
je     1420 <match_in_dir+0x230>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%edi
test   %edi,%edi
je     1420 <match_in_dir+0x230>
shl    $0xc,%edi
call   10a0 <S_ISDIR@plt>
test   %eax,%eax
jne    1420 <match_in_dir+0x230>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%edi
shl    $0xc,%edi
call   1050 <S_ISLNK@plt>
test   %eax,%eax
je     1500 <match_in_dir+0x310>
nopl   0x0(%rax,%rax,1)
mov    -0x70(%rbp),%rsi
cmpb   $0x0,(%rsi)
je     147a <match_in_dir+0x28a>
mov    %r12,%rdi
mov    -0x50(%rbp),%rbx
mov    %rbx,%rdx
call   1100 <memcpy@plt>
movb   $0x2f,(%r12,%rbx,1)
lea    (%r12,%rbx,1),%rdi
add    $0x1,%rdi
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
test   %r15,%r15
je     1487 <match_in_dir+0x297>
mov    %r12,%rdi
mov    %r15,%rsi
mov    -0x34(%rbp),%edx
mov    -0x68(%rbp),%rcx
mov    -0x58(%rbp),%r8
call   10d0 <match_in_dir@plt>
test   %eax,%eax
je     1500 <match_in_dir+0x310>
jmp    15f6 <match_in_dir+0x406>
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%r12
test   %r15,%r15
jne    1457 <match_in_dir+0x267>
mov    -0x34(%rbp),%eax
mov    0x2b37(%rip),%rcx
test   %eax,(%rcx)
je     14bd <match_in_dir+0x2cd>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%edi
test   %edi,%edi
je     14ac <match_in_dir+0x2bc>
shl    $0xc,%edi
call   1050 <S_ISLNK@plt>
test   %eax,%eax
je     14c1 <match_in_dir+0x2d1>
mov    %r12,%rdi
lea    -0x80(%rbp),%rsi
call   10f0 <stat@plt>
mov    -0x80(%rbp),%edi
jmp    14cb <match_in_dir+0x2db>
xor    %ecx,%ecx
jmp    14d2 <match_in_dir+0x2e2>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%edi
shl    $0xc,%edi
call   10a0 <S_ISDIR@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
mov    (%rax),%rdx
add    -0x88(%rbp),%rdx
mov    -0x58(%rbp),%rdi
mov    %r12,%rsi
call   1030 <append@plt>
test   %rax,%rax
jne    1603 <match_in_dir+0x413>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r14,%rsp
mov    %r13,%rdi
lea    -0xa0(%rbp),%rsi
lea    -0x30(%rbp),%rdx
call   1060 <readdir_r@plt>
mov    %eax,%ebx
test   %eax,%eax
sete   %r14b
jne    152d <match_in_dir+0x33d>
mov    -0x30(%rbp),%rax
test   %rax,%rax
jne    1390 <match_in_dir+0x1a0>
mov    %r13,%rdi
call   10c0 <closedir@plt>
xor    %r12d,%r12d
test   %r14b,%r14b
jne    155d <match_in_dir+0x36d>
mov    -0x70(%rbp),%rdi
jmp    15bc <match_in_dir+0x3cc>
mov    %r12,%rcx
mov    0x2a4b(%rip),%rax
mov    (%rax),%ebx
mov    0x2a9a(%rip),%rax
xor    %r12d,%r12d
cmp    (%rax),%ebx
jne    1596 <match_in_dir+0x3a6>
mov    -0x40(%rbp),%rcx
jmp    15e1 <match_in_dir+0x3f1>
mov    -0x58(%rbp),%rdi
mov    %r14,%rsi
mov    -0x50(%rbp),%rcx
mov    %rcx,%rdx
call   1030 <append@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     1588 <match_in_dir+0x398>
mov    0x2a3b(%rip),%rax
mov    (%rax),%r12d
mov    %r13,%rdi
call   10c0 <closedir@plt>
mov    -0x40(%rbp),%rcx
jmp    15e1 <match_in_dir+0x3f1>
mov    0x2a1b(%rip),%rax
cmp    (%rax),%ebx
jne    15b9 <match_in_dir+0x3c9>
cmpb   $0x0,(%rcx)
jne    15b9 <match_in_dir+0x3c9>
lea    -0xa0(%rbp),%rsi
mov    %r14,%rdi
call   10f0 <stat@plt>
test   %eax,%eax
je     161e <match_in_dir+0x42e>
mov    %r14,%rdi
mov    %ebx,%esi
call   *-0x68(%rbp)
test   %eax,%eax
mov    -0x40(%rbp),%rcx
jne    15d7 <match_in_dir+0x3e7>
mov    0x2a10(%rip),%rax
mov    -0x34(%rbp),%edx
test   %edx,(%rax)
je     15e1 <match_in_dir+0x3f1>
mov    0x29b2(%rip),%rax
mov    (%rax),%r12d
mov    %rcx,%rsp
mov    %r12d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %eax,%r12d
mov    %r13,%rdi
call   10c0 <closedir@plt>
jmp    1615 <match_in_dir+0x425>
mov    %r13,%rdi
call   10c0 <closedir@plt>
mov    0x29ae(%rip),%rax
mov    (%rax),%r12d
mov    %r14,%rsp
mov    -0x40(%rbp),%rcx
jmp    15e1 <match_in_dir+0x3f1>
mov    -0xa0(%rbp),%edi
call   10a0 <S_ISDIR@plt>
test   %eax,%eax
je     15b9 <match_in_dir+0x3c9>
mov    -0x58(%rbp),%rdi
mov    %r14,%rsi
mov    -0x50(%rbp),%rcx
mov    %rcx,%rdx
call   1030 <append@plt>
xor    %r12d,%r12d
test   %rax,%rax
je     155d <match_in_dir+0x36d>
mov    0x296d(%rip),%rax
mov    (%rax),%r12d
jmp    155d <match_in_dir+0x36d>

LLVM IR (-O0):
%struct.match = type { i32 }
%struct.dirent = type { i64, i8*, i32 }
%struct.stat = type { i32 }
@GLOB_NOESCAPE = global i32 0
@FNM_NOESCAPE = global i32 0
@GLOB_PERIOD = global i32 0
@FNM_PERIOD = global i32 0
@.str = [2 x i8] c".\00"
@errno = global i32 0
@ENOTDIR = global i32 0
@EACCES = global i32 0
@GLOB_NOSPACE = global i32 0
@GLOB_ERR = global i32 0
@GLOB_ABORTED = global i32 0
@GLOB_MARK = global i32 0
define i32 @match_in_dir(i8* %0, i8* %1, i32 %2, i32 (i8*, i32)* %3, %struct.match** %4) {
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32 (i8*, i32)*
%11 = alloca %struct.match**
%12 = alloca i32*
%13 = alloca %struct.dirent
%14 = alloca %struct.dirent*
%15 = alloca i8*
%16 = alloca i64
%17 = alloca i8*
%18 = alloca i64
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca %struct.stat
%24 = alloca i8*
%25 = alloca i64
%26 = alloca i8*
%27 = alloca i32
%28 = alloca %struct.stat
store i8* %0, i8** %7
store i8* %1, i8** %8
store i32 %2, i32* %9
store i32 (i8*, i32)* %3, i32 (i8*, i32)** %10
store %struct.match** %4, %struct.match*** %11
%29 = load i8*, i8** %8
%30 = call i32 @strlen(i8* %29)
%31 = add nsw i32 %30, 1
%32 = zext i32 %31 to i64
%33 = call i8* @llvm.stacksave()
store i8* %33, i8** %15
%34 = alloca i8, i64 %32
store i64 %32, i64* %16
%35 = load i8*, i8** %7
%36 = call i32 @strlen(i8* %35)
%37 = sext i32 %36 to i64
store i64 %37, i64* %18
%38 = load i32, i32* %9
%39 = load i32, i32* @GLOB_NOESCAPE
%40 = and i32 %38, %39
%41 = icmp ne i32 %40, 0
br i1 %41, label %42, label %44
42: ; preds = %5
%43 = load i32, i32* @FNM_NOESCAPE
br label %45
44: ; preds = %5
br label %45
45: ; preds = %44, %42
%46 = phi i32 [ %43, %42 ], [ 0, %44 ]
%47 = load i32, i32* %9
%48 = load i32, i32* @GLOB_PERIOD
%49 = and i32 %47, %48
%50 = icmp ne i32 %49, 0
br i1 %50, label %53, label %51
51: ; preds = %45
%52 = load i32, i32* @FNM_PERIOD
br label %54
53: ; preds = %45
br label %54
54: ; preds = %53, %51
%55 = phi i32 [ %52, %51 ], [ 0, %53 ]
%56 = or i32 %46, %55
store i32 %56, i32* %20
%57 = load i8*, i8** %8
%58 = call i8* @strchr(i8* %57, i8 signext 47)
store i8* %58, i8** %17
%59 = icmp ne i8* %58, null
br i1 %59, label %60, label %79
60: ; preds = %54
%61 = load i8*, i8** %8
%62 = call i32 @strcpy(i8* %34, i8* %61)
%63 = load i8*, i8** %17
%64 = load i8*, i8** %8
%65 = ptrtoint i8* %63 to i64
%66 = ptrtoint i8* %64 to i64
%67 = sub i64 %65, %66
%68 = getelementptr inbounds i8, i8* %34, i64 %67
store i8 0, i8* %68
br label %69
69: ; preds = %75, %60
%70 = load i8*, i8** %17
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp eq i32 %72, 47
br i1 %73, label %74, label %78
74: ; preds = %69
br label %75
75: ; preds = %74
%76 = load i8*, i8** %17
%77 = getelementptr inbounds i8, i8* %76, i32 1
store i8* %77, i8** %17
br label %69
78: ; preds = %69
store i8* %34, i8** %8
br label %79
79: ; preds = %78, %54
%80 = load i8*, i8** %8
%81 = load i32, i32* %9
%82 = load i32, i32* @GLOB_NOESCAPE
%83 = and i32 %81, %82
%84 = icmp ne i32 %83, 0
%85 = xor i1 %84, true
%86 = zext i1 %85 to i32
%87 = call i32 @is_literal(i8* %80, i32 %86)
store i32 %87, i32* %19
%88 = load i8*, i8** %7
%89 = load i8, i8* %88
%90 = sext i8 %89 to i32
%91 = icmp eq i32 %90, 47
br i1 %91, label %92, label %98
92: ; preds = %79
%93 = load i8*, i8** %7
%94 = getelementptr inbounds i8, i8* %93, i64 1
%95 = load i8, i8* %94
%96 = icmp ne i8 %95, 0
br i1 %96, label %98, label %97
97: ; preds = %92
store i64 0, i64* %18
br label %98
98: ; preds = %97, %92, %79
%99 = load i8*, i8** %7
%100 = load i8, i8* %99
%101 = sext i8 %100 to i32
%102 = icmp ne i32 %101, 0
br i1 %102, label %103, label %105
103: ; preds = %98
%104 = load i8*, i8** %7
br label %106
105: ; preds = %98
br label %106
106: ; preds = %105, %103
%107 = phi i8* [ %104, %103 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), %105 ]
%108 = call i32* @opendir(i8* %107)
store i32* %108, i32** %12
%109 = load i32, i32* @errno
store i32 %109, i32* %21
%110 = load i32*, i32** %12
%111 = icmp ne i32* %110, null
br i1 %111, label %160, label %112
112: ; preds = %106
%113 = load i32, i32* %21
%114 = load i32, i32* @ENOTDIR
%115 = icmp eq i32 %113, %114
br i1 %115, label %116, label %117
116: ; preds = %112
store i32 0, i32* %6
store i32 1, i32* %22
br label %355
117: ; preds = %112
%118 = load i32, i32* %21
%119 = load i32, i32* @EACCES
%120 = icmp eq i32 %118, %119
br i1 %120, label %121, label %146
121: ; preds = %117
%122 = load i8*, i8** %8
%123 = load i8, i8* %122
%124 = icmp ne i8 %123, 0
br i1 %124, label %146, label %125
125: ; preds = %121
%126 = load i8*, i8** %7
%127 = call i32 @stat(i8* %126, %struct.stat* %23)
%128 = icmp ne i32 %127, 0
br i1 %128, label %145, label %129
129: ; preds = %125
%130 = getelementptr inbounds %struct.stat, %struct.stat* %23, i32 0, i32 0
%131 = load i32, i32* %130
%132 = call i32 @S_ISDIR(i32 %131)
%133 = icmp ne i32 %132, 0
br i1 %133, label %134, label %145
134: ; preds = %129
%135 = load %struct.match**, %struct.match*** %11
%136 = load i8*, i8** %7
%137 = load i64, i64* %18
%138 = load i64, i64* %18
%139 = trunc i64 %138 to i32
%140 = call i64 @append(%struct.match** %135, i8* %136, i64 %137, i32 %139)
%141 = icmp ne i64 %140, 0
br i1 %141, label %142, label %144
142: ; preds = %134
%143 = load i32, i32* @GLOB_NOSPACE
store i32 %143, i32* %6
store i32 1, i32* %22
br label %355
144: ; preds = %134
store i32 0, i32* %6
store i32 1, i32* %22
br label %355
145: ; preds = %129, %125
br label %146
146: ; preds = %145, %121, %117
%147 = load i32 (i8*, i32)*, i32 (i8*, i32)** %10
%148 = load i8*, i8** %7
%149 = load i32, i32* %21
%150 = call i32 %147(i8* %148, i32 %149)
%151 = icmp ne i32 %150, 0
br i1 %151, label %157, label %152
152: ; preds = %146
%153 = load i32, i32* %9
%154 = load i32, i32* @GLOB_ERR
%155 = and i32 %153, %154
%156 = icmp ne i32 %155, 0
br i1 %156, label %157, label %159
157: ; preds = %152, %146
%158 = load i32, i32* @GLOB_ABORTED
store i32 %158, i32* %6
store i32 1, i32* %22
br label %355
159: ; preds = %152
store i32 0, i32* %6
store i32 1, i32* %22
br label %355
160: ; preds = %106
%161 = load i8*, i8** %8
%162 = load i8, i8* %161
%163 = icmp ne i8 %162, 0
br i1 %163, label %180, label %164
164: ; preds = %160
%165 = load %struct.match**, %struct.match*** %11
%166 = load i8*, i8** %7
%167 = load i64, i64* %18
%168 = load i64, i64* %18
%169 = trunc i64 %168 to i32
%170 = call i64 @append(%struct.match** %165, i8* %166, i64 %167, i32 %169)
%171 = icmp ne i64 %170, 0
br i1 %171, label %172, label %174
172: ; preds = %164
%173 = load i32, i32* @GLOB_NOSPACE
br label %175
174: ; preds = %164
br label %175
175: ; preds = %174, %172
%176 = phi i32 [ %173, %172 ], [ 0, %174 ]
store i32 %176, i32* %21
%177 = load i32*, i32** %12
%178 = call i32 @closedir(i32* %177)
%179 = load i32, i32* %21
store i32 %179, i32* %6
store i32 1, i32* %22
br label %355
180: ; preds = %160
br label %181
181: ; preds = %335, %332, %180
%182 = load i32*, i32** %12
%183 = call i32 @readdir_r(i32* %182, %struct.dirent* %13, %struct.dirent** %14)
store i32 %183, i32* %21
%184 = icmp ne i32 %183, 0
br i1 %184, label %188, label %185
185: ; preds = %181
%186 = load %struct.dirent*, %struct.dirent** %14
%187 = icmp ne %struct.dirent* %186, null
br label %188
188: ; preds = %185, %181
%189 = phi i1 [ false, %181 ], [ %187, %185 ]
br i1 %189, label %190, label %336
190: ; preds = %188
%191 = load i64, i64* %18
%192 = load %struct.dirent*, %struct.dirent** %14
%193 = getelementptr inbounds %struct.dirent, %struct.dirent* %192, i32 0, i32 0
%194 = load i64, i64* %193
%195 = add i64 %191, %194
%196 = add i64 %195, 2
%197 = call i8* @llvm.stacksave()
store i8* %197, i8** %24
%198 = alloca i8, i64 %196
store i64 %196, i64* %25
store i8* %198, i8** %26
%199 = load i32, i32* %19
%200 = icmp ne i32 %199, 0
br i1 %200, label %210, label %201
201: ; preds = %190
%202 = load i8*, i8** %8
%203 = load %struct.dirent*, %struct.dirent** %14
%204 = getelementptr inbounds %struct.dirent, %struct.dirent* %203, i32 0, i32 1
%205 = load i8*, i8** %204
%206 = load i32, i32* %20
%207 = call i64 @fnmatch(i8* %202, i8* %205, i32 %206)
%208 = icmp ne i64 %207, 0
br i1 %208, label %209, label %210
209: ; preds = %201
store i32 5, i32* %22
br label %332
210: ; preds = %201, %190
%211 = load i32, i32* %19
%212 = icmp ne i32 %211, 0
br i1 %212, label %213, label %221
213: ; preds = %210
%214 = load i8*, i8** %8
%215 = load %struct.dirent*, %struct.dirent** %14
%216 = getelementptr inbounds %struct.dirent, %struct.dirent* %215, i32 0, i32 1
%217 = load i8*, i8** %216
%218 = call i64 @strcmp(i8* %214, i8* %217)
%219 = icmp ne i64 %218, 0
br i1 %219, label %220, label %221
220: ; preds = %213
store i32 5, i32* %22
br label %332
221: ; preds = %213, %210
%222 = load i8*, i8** %17
%223 = icmp ne i8* %222, null
br i1 %223, label %224, label %244
224: ; preds = %221
%225 = load %struct.dirent*, %struct.dirent** %14
%226 = getelementptr inbounds %struct.dirent, %struct.dirent* %225, i32 0, i32 2
%227 = load i32, i32* %226
%228 = icmp ne i32 %227, 0
br i1 %228, label %229, label %244
229: ; preds = %224
%230 = load %struct.dirent*, %struct.dirent** %14
%231 = getelementptr inbounds %struct.dirent, %struct.dirent* %230, i32 0, i32 2
%232 = load i32, i32* %231
%233 = shl i32 %232, 12
%234 = call i32 @S_ISDIR(i32 %233)
%235 = icmp ne i32 %234, 0
br i1 %235, label %244, label %236
236: ; preds = %229
%237 = load %struct.dirent*, %struct.dirent** %14
%238 = getelementptr inbounds %struct.dirent, %struct.dirent* %237, i32 0, i32 2
%239 = load i32, i32* %238
%240 = shl i32 %239, 12
%241 = call i32 @S_ISLNK(i32 %240)
%242 = icmp ne i32 %241, 0
br i1 %242, label %244, label %243
243: ; preds = %236
store i32 5, i32* %22
br label %332
244: ; preds = %236, %229, %224, %221
%245 = load i8*, i8** %7
%246 = load i8, i8* %245
%247 = icmp ne i8 %246, 0
br i1 %247, label %248, label %264
248: ; preds = %244
%249 = load i8*, i8** %26
%250 = load i8*, i8** %7
%251 = load i64, i64* %18
%252 = call i32 @memcpy(i8* %249, i8* %250, i64 %251)
%253 = load i8*, i8** %26
%254 = load i64, i64* %18
%255 = getelementptr inbounds i8, i8* %253, i64 %254
store i8 47, i8* %255
%256 = load i8*, i8** %26
%257 = load i64, i64* %18
%258 = getelementptr inbounds i8, i8* %256, i64 %257
%259 = getelementptr inbounds i8, i8* %258, i64 1
%260 = load %struct.dirent*, %struct.dirent** %14
%261 = getelementptr inbounds %struct.dirent, %struct.dirent* %260, i32 0, i32 1
%262 = load i8*, i8** %261
%263 = call i32 @strcpy(i8* %259, i8* %262)
br label %268
264: ; preds = %244
%265 = load %struct.dirent*, %struct.dirent** %14
%266 = getelementptr inbounds %struct.dirent, %struct.dirent* %265, i32 0, i32 1
%267 = load i8*, i8** %266
store i8* %267, i8** %26
br label %268
268: ; preds = %264, %248
%269 = load i8*, i8** %17
%270 = icmp ne i8* %269, null
br i1 %270, label %271, label %284
271: ; preds = %268
%272 = load i8*, i8** %26
%273 = load i8*, i8** %17
%274 = load i32, i32* %9
%275 = load i32 (i8*, i32)*, i32 (i8*, i32)** %10
%276 = load %struct.match**, %struct.match*** %11
%277 = call i32 @match_in_dir(i8* %272, i8* %273, i32 %274, i32 (i8*, i32)* %275, %struct.match** %276)
store i32 %277, i32* %21
%278 = icmp ne i32 %277, 0
br i1 %278, label %279, label %283
279: ; preds = %271
%280 = load i32*, i32** %12
%281 = call i32 @closedir(i32* %280)
%282 = load i32, i32* %21
store i32 %282, i32* %6
store i32 1, i32* %22
br label %332
283: ; preds = %271
br label %331
284: ; preds = %268
store i32 0, i32* %27
%285 = load i32, i32* %9
%286 = load i32, i32* @GLOB_MARK
%287 = and i32 %285, %286
%288 = icmp ne i32 %287, 0
br i1 %288, label %289, label %314
289: ; preds = %284
%290 = load %struct.dirent*, %struct.dirent** %14
%291 = getelementptr inbounds %struct.dirent, %struct.dirent* %290, i32 0, i32 2
%292 = load i32, i32* %291
%293 = icmp ne i32 %292, 0
br i1 %293, label %294, label %307
294: ; preds = %289
%295 = load %struct.dirent*, %struct.dirent** %14
%296 = getelementptr inbounds %struct.dirent, %struct.dirent* %295, i32 0, i32 2
%297 = load i32, i32* %296
%298 = shl i32 %297, 12
%299 = call i32 @S_ISLNK(i32 %298)
%300 = icmp ne i32 %299, 0
br i1 %300, label %307, label %301
301: ; preds = %294
%302 = load %struct.dirent*, %struct.dirent** %14
%303 = getelementptr inbounds %struct.dirent, %struct.dirent* %302, i32 0, i32 2
%304 = load i32, i32* %303
%305 = shl i32 %304, 12
%306 = call i32 @S_ISDIR(i32 %305)
store i32 %306, i32* %27
br label %313
307: ; preds = %294, %289
%308 = load i8*, i8** %26
%309 = call i32 @stat(i8* %308, %struct.stat* %28)
%310 = getelementptr inbounds %struct.stat, %struct.stat* %28, i32 0, i32 0
%311 = load i32, i32* %310
%312 = call i32 @S_ISDIR(i32 %311)
store i32 %312, i32* %27
br label %313
313: ; preds = %307, %301
br label %314
314: ; preds = %313, %284
%315 = load %struct.match**, %struct.match*** %11
%316 = load i8*, i8** %26
%317 = load i64, i64* %18
%318 = load %struct.dirent*, %struct.dirent** %14
%319 = getelementptr inbounds %struct.dirent, %struct.dirent* %318, i32 0, i32 0
%320 = load i64, i64* %319
%321 = add i64 %317, %320
%322 = add i64 %321, 1
%323 = load i32, i32* %27
%324 = call i64 @append(%struct.match** %315, i8* %316, i64 %322, i32 %323)
%325 = icmp ne i64 %324, 0
br i1 %325, label %326, label %330
326: ; preds = %314
%327 = load i32*, i32** %12
%328 = call i32 @closedir(i32* %327)
%329 = load i32, i32* @GLOB_NOSPACE
store i32 %329, i32* %6
store i32 1, i32* %22
br label %332
330: ; preds = %314
br label %331
331: ; preds = %330, %283
store i32 0, i32* %22
br label %332
332: ; preds = %331, %326, %279, %243, %220, %209
%333 = load i8*, i8** %24
%334 = load i32, i32* %22
switch i32 %334, label %355 [
i32 0, label %335
i32 5, label %181
]
335: ; preds = %332
br label %181
336: ; preds = %188
%337 = load i32*, i32** %12
%338 = call i32 @closedir(i32* %337)
%339 = load i32, i32* %21
%340 = icmp ne i32 %339, 0
br i1 %340, label %341, label %354
341: ; preds = %336
%342 = load i32 (i8*, i32)*, i32 (i8*, i32)** %10
%343 = load i8*, i8** %7
%344 = load i32, i32* %21
%345 = call i32 %342(i8* %343, i32 %344)
%346 = icmp ne i32 %345, 0
br i1 %346, label %352, label %347
347: ; preds = %341
%348 = load i32, i32* %9
%349 = load i32, i32* @GLOB_ERR
%350 = and i32 %348, %349
%351 = icmp ne i32 %350, 0
br i1 %351, label %352, label %354
352: ; preds = %347, %341
%353 = load i32, i32* @GLOB_ABORTED
store i32 %353, i32* %6
store i32 1, i32* %22
br label %355
354: ; preds = %347, %336
store i32 0, i32* %6
store i32 1, i32* %22
br label %355
355: ; preds = %354, %352, %332, %175, %159, %157, %144, %142, %116
%356 = load i8*, i8** %15
%357 = load i32, i32* %6
ret i32 %357
}

LLVM IR (-O2):
%struct.match = type { i32 }
%struct.dirent = type { i64, i8*, i32 }
%struct.stat = type { i32 }
@GLOB_NOESCAPE = global i32 0
@FNM_NOESCAPE = global i32 0
@GLOB_PERIOD = global i32 0
@FNM_PERIOD = global i32 0
@.str = [2 x i8] c".\00"
@errno = global i32 0
@ENOTDIR = global i32 0
@EACCES = global i32 0
@GLOB_NOSPACE = global i32 0
@GLOB_ERR = global i32 0
@GLOB_ABORTED = global i32 0
@GLOB_MARK = global i32 0
define i32 @match_in_dir(i8* %0, i8* %1, i32 %2, i32 (i8*, i32)* nocapture %3, %struct.match** %4) {
%6 = alloca %struct.dirent
%7 = alloca %struct.dirent*
%8 = alloca %struct.stat
%9 = alloca %struct.stat
%10 = bitcast %struct.dirent* %6 to i8*
%11 = bitcast %struct.dirent** %7 to i8*
%12 = tail call i32 @strlen(i8* %1)
%13 = add nsw i32 %12, 1
%14 = zext i32 %13 to i64
%15 = tail call i8* @llvm.stacksave()
%16 = alloca i8, i64 %14
%17 = tail call i32 @strlen(i8* %0)
%18 = sext i32 %17 to i64
%19 = load i32, i32* @GLOB_NOESCAPE
%20 = and i32 %19, %2
%21 = icmp eq i32 %20, 0
%22 = load i32, i32* @FNM_NOESCAPE
%23 = select i1 %21, i32 0, i32 %22
%24 = load i32, i32* @GLOB_PERIOD
%25 = and i32 %24, %2
%26 = icmp eq i32 %25, 0
%27 = load i32, i32* @FNM_PERIOD
%28 = select i1 %26, i32 %27, i32 0
%29 = or i32 %28, %23
%30 = tail call i8* @strchr(i8* dereferenceable(1) %1, i8 signext 47)
%31 = icmp eq i8* %30, null
br i1 %31, label %46, label %32
32: ; preds = %5
%33 = call i32 @strcpy(i8* %16, i8* %1)
%34 = ptrtoint i8* %30 to i64
%35 = ptrtoint i8* %1 to i64
%36 = sub i64 %34, %35
%37 = getelementptr inbounds i8, i8* %16, i64 %36
store i8 0, i8* %37
br label %38
38: ; preds = %38, %32
%39 = phi i8* [ %30, %32 ], [ %42, %38 ]
%40 = load i8, i8* %39
%41 = icmp eq i8 %40, 47
%42 = getelementptr inbounds i8, i8* %39, i64 1
br i1 %41, label %38, label %43
43: ; preds = %38
%44 = load i32, i32* @GLOB_NOESCAPE
%45 = and i32 %44, %2
br label %46
46: ; preds = %43, %5
%47 = phi i32 [ %45, %43 ], [ %20, %5 ]
%48 = phi i8* [ %39, %43 ], [ null, %5 ]
%49 = phi i8* [ %16, %43 ], [ %1, %5 ]
%50 = icmp eq i32 %47, 0
%51 = zext i1 %50 to i32
%52 = call i32 @is_literal(i8* %49, i32 %51)
%53 = load i8, i8* %0
%54 = icmp eq i8 %53, 47
br i1 %54, label %55, label %60
55: ; preds = %46
%56 = getelementptr inbounds i8, i8* %0, i64 1
%57 = load i8, i8* %56
%58 = icmp eq i8 %57, 0
%59 = select i1 %58, i64 0, i64 %18
br label %60
60: ; preds = %55, %46
%61 = phi i64 [ %18, %46 ], [ %59, %55 ]
%62 = icmp eq i8 %53, 0
%63 = select i1 %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8* %0
%64 = call i32* @opendir(i8* %63)
%65 = load i32, i32* @errno
%66 = icmp eq i32* %64, null
br i1 %66, label %67, label %101
67: ; preds = %60
%68 = load i32, i32* @ENOTDIR
%69 = icmp eq i32 %65, %68
br i1 %69, label %234, label %70
70: ; preds = %67
%71 = load i32, i32* @EACCES
%72 = icmp eq i32 %65, %71
br i1 %72, label %73, label %92
73: ; preds = %70
%74 = load i8, i8* %49
%75 = icmp eq i8 %74, 0
br i1 %75, label %76, label %92
76: ; preds = %73
%77 = bitcast %struct.stat* %8 to i8*
%78 = call i32 @stat(i8* %0, %struct.stat* %8)
%79 = icmp eq i32 %78, 0
br i1 %79, label %80, label %85
80: ; preds = %76
%81 = getelementptr inbounds %struct.stat, %struct.stat* %8, i64 0, i32 0
%82 = load i32, i32* %81
%83 = call i32 @S_ISDIR(i32 %82)
%84 = icmp eq i32 %83, 0
br i1 %84, label %85, label %86
85: ; preds = %80, %76
br label %92
86: ; preds = %80
%87 = trunc i64 %61 to i32
%88 = call i64 @append(%struct.match** %4, i8* %0, i64 %61, i32 %87)
%89 = icmp eq i64 %88, 0
%90 = load i32, i32* @GLOB_NOSPACE
%91 = select i1 %89, i32 0, i32 %90
br label %234
92: ; preds = %85, %73, %70
%93 = call i32 %3(i8* %0, i32 %65)
%94 = icmp eq i32 %93, 0
br i1 %94, label %95, label %99
95: ; preds = %92
%96 = load i32, i32* @GLOB_ERR
%97 = and i32 %96, %2
%98 = icmp eq i32 %97, 0
br i1 %98, label %234, label %99
99: ; preds = %95, %92
%100 = load i32, i32* @GLOB_ABORTED
br label %234
101: ; preds = %60
%102 = load i8, i8* %49
%103 = icmp eq i8 %102, 0
br i1 %103, label %117, label %104
104: ; preds = %101
%105 = call i32 @readdir_r(i32* %64, %struct.dirent* %6, %struct.dirent** %7)
%106 = icmp eq i32 %105, 0
%107 = load %struct.dirent*, %struct.dirent** %7
%108 = icmp ne %struct.dirent* %107, null
%109 = select i1 %106, i1 %108, i1 false
br i1 %109, label %110, label %221
110: ; preds = %104
%111 = add nsw i64 %61, 2
%112 = icmp eq i32 %52, 0
%113 = icmp eq i8* %48, null
%114 = bitcast %struct.stat* %9 to i8*
%115 = getelementptr inbounds %struct.stat, %struct.stat* %9, i64 0, i32 0
%116 = add nsw i64 %61, 1
br label %124
117: ; preds = %101
%118 = trunc i64 %61 to i32
%119 = call i64 @append(%struct.match** %4, i8* %0, i64 %61, i32 %118)
%120 = icmp eq i64 %119, 0
%121 = load i32, i32* @GLOB_NOSPACE
%122 = select i1 %120, i32 0, i32 %121
%123 = call i32 @closedir(i32* %64)
br label %234
124: ; preds = %110, %215
%125 = phi %struct.dirent* [ %107, %110 ], [ %218, %215 ]
%126 = getelementptr inbounds %struct.dirent, %struct.dirent* %125, i64 0, i32 0
%127 = load i64, i64* %126
%128 = add i64 %111, %127
%129 = call i8* @llvm.stacksave()
%130 = alloca i8, i64 %128
%131 = load %struct.dirent*, %struct.dirent** %7
%132 = getelementptr inbounds %struct.dirent, %struct.dirent* %131, i64 0, i32 1
%133 = load i8*, i8** %132
br i1 %112, label %134, label %137
134: ; preds = %124
%135 = call i64 @fnmatch(i8* %49, i8* %133, i32 %29)
%136 = icmp eq i64 %135, 0
br i1 %136, label %140, label %215
137: ; preds = %124
%138 = call i64 @strcmp(i8* %49, i8* %133)
%139 = icmp eq i64 %138, 0
br i1 %139, label %140, label %215
140: ; preds = %134, %137
br i1 %113, label %157, label %141
141: ; preds = %140
%142 = load %struct.dirent*, %struct.dirent** %7
%143 = getelementptr inbounds %struct.dirent, %struct.dirent* %142, i64 0, i32 2
%144 = load i32, i32* %143
%145 = icmp eq i32 %144, 0
br i1 %145, label %157, label %146
146: ; preds = %141
%147 = shl i32 %144, 12
%148 = call i32 @S_ISDIR(i32 %147)
%149 = icmp eq i32 %148, 0
br i1 %149, label %150, label %157
150: ; preds = %146
%151 = load %struct.dirent*, %struct.dirent** %7
%152 = getelementptr inbounds %struct.dirent, %struct.dirent* %151, i64 0, i32 2
%153 = load i32, i32* %152
%154 = shl i32 %153, 12
%155 = call i32 @S_ISLNK(i32 %154)
%156 = icmp eq i32 %155, 0
br i1 %156, label %215, label %157
157: ; preds = %150, %146, %141, %140
%158 = load i8, i8* %0
%159 = icmp eq i8 %158, 0
br i1 %159, label %168, label %160
160: ; preds = %157
%161 = call i32 @memcpy(i8* %130, i8* %0, i64 %61)
%162 = getelementptr inbounds i8, i8* %130, i64 %61
store i8 47, i8* %162
%163 = getelementptr inbounds i8, i8* %162, i64 1
%164 = load %struct.dirent*, %struct.dirent** %7
%165 = getelementptr inbounds %struct.dirent, %struct.dirent* %164, i64 0, i32 1
%166 = load i8*, i8** %165
%167 = call i32 @strcpy(i8* %163, i8* %166)
br label %172
168: ; preds = %157
%169 = load %struct.dirent*, %struct.dirent** %7
%170 = getelementptr inbounds %struct.dirent, %struct.dirent* %169, i64 0, i32 1
%171 = load i8*, i8** %170
br label %172
172: ; preds = %168, %160
%173 = phi i8* [ %130, %160 ], [ %171, %168 ]
br i1 %113, label %179, label %174
174: ; preds = %172
%175 = call i32 @match_in_dir(i8* %173, i8* %48, i32 %2, i32 (i8*, i32)* %3, %struct.match** %4)
%176 = icmp eq i32 %175, 0
br i1 %176, label %215, label %177
177: ; preds = %174
%178 = call i32 @closedir(i32* %64)
br label %213
179: ; preds = %172
%180 = load i32, i32* @GLOB_MARK
%181 = and i32 %180, %2
%182 = icmp eq i32 %181, 0
br i1 %182, label %202, label %183
183: ; preds = %179
%184 = load %struct.dirent*, %struct.dirent** %7
%185 = getelementptr inbounds %struct.dirent, %struct.dirent* %184, i64 0, i32 2
%186 = load i32, i32* %185
%187 = icmp eq i32 %186, 0
br i1 %187, label %198, label %188
188: ; preds = %183
%189 = shl i32 %186, 12
%190 = call i32 @S_ISLNK(i32 %189)
%191 = icmp eq i32 %190, 0
br i1 %191, label %192, label %198
192: ; preds = %188
%193 = load %struct.dirent*, %struct.dirent** %7
%194 = getelementptr inbounds %struct.dirent, %struct.dirent* %193, i64 0, i32 2
%195 = load i32, i32* %194
%196 = shl i32 %195, 12
%197 = call i32 @S_ISDIR(i32 %196)
br label %202
198: ; preds = %188, %183
%199 = call i32 @stat(i8* %173, %struct.stat* %9)
%200 = load i32, i32* %115
%201 = call i32 @S_ISDIR(i32 %200)
br label %202
202: ; preds = %192, %198, %179
%203 = phi i32 [ %201, %198 ], [ %197, %192 ], [ 0, %179 ]
%204 = load %struct.dirent*, %struct.dirent** %7
%205 = getelementptr inbounds %struct.dirent, %struct.dirent* %204, i64 0, i32 0
%206 = load i64, i64* %205
%207 = add i64 %116, %206
%208 = call i64 @append(%struct.match** %4, i8* %173, i64 %207, i32 %203)
%209 = icmp eq i64 %208, 0
br i1 %209, label %215, label %210
210: ; preds = %202
%211 = call i32 @closedir(i32* %64)
%212 = load i32, i32* @GLOB_NOSPACE
br label %213
213: ; preds = %177, %210
%214 = phi i32 [ %212, %210 ], [ %175, %177 ]
br label %234
215: ; preds = %202, %174, %150, %137, %134
%216 = call i32 @readdir_r(i32* %64, %struct.dirent* %6, %struct.dirent** %7)
%217 = icmp eq i32 %216, 0
%218 = load %struct.dirent*, %struct.dirent** %7
%219 = icmp ne %struct.dirent* %218, null
%220 = select i1 %217, i1 %219, i1 false
br i1 %220, label %124, label %221
221: ; preds = %215, %104
%222 = phi i32 [ %105, %104 ], [ %216, %215 ]
%223 = phi i1 [ %106, %104 ], [ %217, %215 ]
%224 = call i32 @closedir(i32* %64)
br i1 %223, label %234, label %225
225: ; preds = %221
%226 = call i32 %3(i8* %0, i32 %222)
%227 = icmp eq i32 %226, 0
br i1 %227, label %228, label %232
228: ; preds = %225
%229 = load i32, i32* @GLOB_ERR
%230 = and i32 %229, %2
%231 = icmp eq i32 %230, 0
br i1 %231, label %234, label %232
232: ; preds = %228, %225
%233 = load i32, i32* @GLOB_ABORTED
br label %234
234: ; preds = %213, %86, %221, %228, %95, %67, %232, %117, %99
%235 = phi i32 [ %233, %232 ], [ %122, %117 ], [ %100, %99 ], [ %91, %86 ], [ 0, %67 ], [ 0, %95 ], [ 0, %228 ], [ 0, %221 ], [ %214, %213 ]
ret i32 %235
}