// File: /workspace/github_cpp_makefile_star2_O3/jgeumlek[P]moltengamepadctl/source/oscpkt/oscpkt.hh
// Function: oscpkt::internalPatternMatch(char const*, char const*)
inline const char *internalPatternMatch(const char *pattern, const char *path) {
  while (*pattern) {
    const char *p = pattern;
    if (*p == '?' && *path) { ++p; ++path; }
    else if (*p == '[' && *path) { // bracketted range, e.g. [a-zABC]
      ++p;
      bool reverse = false;
      if (*p == '!') { reverse = true; ++p; }
      bool match = reverse;
      for (; *p && *p != ']'; ++p) {
        char c0 = *p, c1 = c0;
        if (p[1] == '-' && p[2] && p[2] != ']') { p += 2; c1 = *p; }
        if (*path >= c0 && *path <= c1) { match = !reverse; }
      }
      if (!match || *p != ']') return pattern;
      ++p; ++path;
    } else if (*p == '*') { // wildcard '*'
      while (*p == '*') ++p; 
      const char *best = 0;
      while (true) {
        const char *ret = internalPatternMatch(p, path);
        if (ret && ret > best) best = ret;
        if (*path == 0 || *path == '/') break;
        else ++path;
      }
      return best;
    } else if (*p == '/' && *(p+1) == '/') { // the super-wildcard '//'
      while (*(p+1)=='/') ++p;
      const char *best = 0;
      while (true) {
        const char *ret = internalPatternMatch(p, path);
        if (ret && ret > best) best = ret;
        if (*path == 0) break;
        if (*path == 0 || (path = strchr(path+1, '/')) == 0) break;
      }      
      return best;
    } else if (*p == '{') { // braced list {foo,bar,baz}
      const char *end = strchr(p, '}'), *q;
      if (!end) return 0; // syntax error in brace list..
      bool match = false;
      do {
        ++p;
        q = strchr(p, ',');
        if (q == 0 || q > end) q = end;
        if (strncmp(p, path, q-p)==0) {
          path += (q-p); p = end+1; match = true;
        } else p=q;
      } while (q != end && !match);
      if (!match) return pattern;
    } else if (*p == *path) { ++p; ++path; } // any other character
    else break;
    pattern = p;
  }
  return (*path == 0 ? pattern : 0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbp
movq %rdi, %r15
movq %r15, %r13
movb (%r15), %cl
movzbl %cl, %eax
cmpl $0x3e, %eax
jg 0x4e27
cmpl $0x2f, %eax
jne 0x4eca
cmpb $0x2f, 0x1(%r13)
jne 0x4f44
jmp 0x4fd0
cmpl $0x3f, %eax
je 0x4edc
cmpl $0x5b, %eax
je 0x4ee4
cmpl $0x7b, %eax
jne 0x4f44
movq %r13, %rdi
movl $0x7d, %esi
callq 0x20b0
testq %rax, %rax
je 0x5027
movq %rax, %r12
leaq 0x1(%rax), %r15
movq %r13, (%rsp)
movq %rbp, %rbx
incq %r13
movq %r13, %rdi
movl $0x2c, %esi
callq 0x20b0
cmpq %r12, %rax
movq %rax, %r14
cmovaq %r12, %r14
testq %rax, %rax
cmoveq %r12, %r14
movq %r14, %rbp
subq %r13, %rbp
movq %r13, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x2100
testl %eax, %eax
movq %r14, %r13
cmoveq %r15, %r13
movl $0x0, %ecx
cmovneq %rcx, %rbp
addq %rbx, %rbp
cmpq %r12, %r14
je 0x4eb9
testl %eax, %eax
jne 0x4e63
testl %eax, %eax
movq (%rsp), %r13
je 0x4e00
jmp 0x4f7f
testl %eax, %eax
je 0x4f74
cmpl $0x2a, %eax
jne 0x4f44
jmp 0x4f91
cmpb $0x0, (%rbp)
jne 0x4f4b
jmp 0x4f44
movb (%rbp), %al
testb %al, %al
je 0x4f44
leaq 0x1(%r13), %r15
leaq 0x2(%r13), %rsi
xorl %edx, %edx
cmpb $0x21, 0x1(%r13)
sete %cl
setne %dl
cmoveq %rsi, %r15
movzbl (%r15), %esi
testl %esi, %esi
je 0x4f59
cmpl $0x5d, %esi
je 0x4f59
cmpb $0x2d, 0x1(%r15)
jne 0x4f26
movzbl 0x2(%r15), %edi
testl %edi, %edi
je 0x4f26
cmpl $0x5d, %edi
jne 0x4f3e
movl %esi, %edi
cmpb %dil, %al
movzbl %cl, %edi
movl %edx, %ecx
cmovgl %edi, %ecx
cmpb %sil, %al
cmovll %edi, %ecx
incq %r15
jmp 0x4f04
addq $0x2, %r15
jmp 0x4f28
movb (%rbp), %al
cmpb %al, %cl
jne 0x4f77
incq %r13
incq %rbp
movq %r13, %r15
jmp 0x4e00
cmpb $0x5d, %sil
setne %al
notb %cl
orb %al, %cl
testb $0x1, %cl
jne 0x4f7f
incq %r15
incq %rbp
jmp 0x4e00
movb (%rbp), %al
xorl %ecx, %ecx
testb %al, %al
cmovneq %rcx, %r13
movq %r13, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %r15
cmpb $0x2a, 0x1(%r15)
leaq 0x1(%r15), %r15
je 0x4f94
xorl %r13d, %r13d
movq %r13, %r12
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4def
cmpq %r13, %rax
cmovaq %rax, %r13
testq %rax, %rax
cmoveq %r12, %r13
movzbl (%rbp), %eax
testl %eax, %eax
je 0x4f7f
cmpl $0x2f, %eax
je 0x4f7f
incq %rbp
jmp 0x4fa2
decq %r13
movq %r13, %r15
cmpb $0x2f, 0x2(%r15)
leaq 0x1(%r15), %r15
je 0x4fd6
xorl %r13d, %r13d
movq %r13, %r12
movq %r15, %rdi
movq %rbp, %rsi
callq 0x4def
cmpq %r13, %rax
cmovaq %rax, %r13
testq %rax, %rax
cmoveq %r12, %r13
cmpb $0x0, (%rbp)
je 0x4f7f
incq %rbp
movq %rbp, %rdi
movl $0x2f, %esi
callq 0x20b0
movq %rax, %rbp
testq %rax, %rax
jne 0x4fe4
jmp 0x4f7f
xorl %r13d, %r13d
jmp 0x4f7f
nop