// File: /workspace/github_cpp_makefile_star2_O1/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
subq $0x18, %rsp
movq %rsi, %rbp
movq %rdi, %r14
movzbl (%r14), %eax
cmpl $0x3e, %eax
jle 0x4f00
cmpl $0x7b, %eax
je 0x50a8
cmpl $0x5b, %eax
je 0x4fad
cmpl $0x3f, %eax
jne 0x4f83
cmpb $0x0, (%rbp)
jne 0x4f91
cmpl $0x5a, %eax
jg 0x4f9f
cmpl $0x2a, %eax
je 0x5056
cmpl $0x2f, %eax
je 0x4f0e
jmp 0x4f83
cmpl $0x2a, %eax
je 0x5056
cmpl $0x2f, %eax
jne 0x4f7b
cmpb $0x2f, 0x1(%r14)
jne 0x4f71
leaq -0x1(%r14), %r12
cmpb $0x2f, 0x2(%r12)
leaq 0x1(%r12), %r12
je 0x4f19
xorl %r15d, %r15d
movq %r15, %rbx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x4ea2
cmpq %r15, %rax
cmovaq %rax, %r15
testq %rax, %rax
cmoveq %rbx, %r15
cmpb $0x0, (%rbp)
je 0x4f66
incq %rbp
movq %rbp, %rdi
movl $0x2f, %esi
callq 0x20b0
movq %rax, %rbp
testq %rax, %rax
setne %al
jmp 0x4f68
xorl %eax, %eax
testb %al, %al
jne 0x4f29
jmp 0x509e
cmpl $0x7b, %eax
jne 0x4f83
jmp 0x50a8
testl %eax, %eax
je 0x5171
movl $0x3, %ecx
cmpb (%rbp), %al
jne 0x5164
incq %r14
incq %rbp
movq %r14, %r12
jmp 0x515f
cmpl $0x7b, %eax
je 0x50a8
cmpl $0x5b, %eax
jne 0x4f83
movb (%rbp), %cl
testb %cl, %cl
je 0x503f
leaq 0x1(%r14), %r12
leaq 0x2(%r14), %rsi
cmpb $0x21, 0x1(%r14)
sete %al
setne %dl
cmoveq %rsi, %r12
movzbl (%r12), %esi
testl %esi, %esi
je 0x5017
cmpl $0x5d, %esi
je 0x5017
cmpb $0x2d, 0x1(%r12)
jne 0x4ff4
movzbl 0x2(%r12), %edi
testl %edi, %edi
je 0x4ff4
cmpl $0x5d, %edi
jne 0x5011
movl %esi, %edi
cmpb %dil, %cl
movzbl %al, %edi
movl $0x0, %eax
movb %dl, %al
cmovgl %edi, %eax
cmpb %sil, %cl
cmovll %edi, %eax
incq %r12
jmp 0x4fcf
addq $0x2, %r12
jmp 0x4ff6
cmpb $0x5d, %sil
sete %cl
andb %al, %cl
movzbl %cl, %eax
addq %rax, %rbp
movl $0x1, %ecx
testb %al, %al
cmoveq %r14, %r15
je 0x5164
addq %rax, %r12
jmp 0x515f
cmpl $0x7b, %eax
je 0x50a8
cmpl $0x2f, %eax
je 0x4f0e
cmpl $0x2a, %eax
jne 0x4f83
leaq -0x1(%r14), %r12
cmpb $0x2a, 0x1(%r12)
leaq 0x1(%r12), %r12
je 0x505a
xorl %r15d, %r15d
movq %r15, %rbx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x4ea2
cmpq %r15, %rax
cmovaq %rax, %r15
testq %rax, %rax
cmoveq %rbx, %r15
movzbl (%rbp), %ecx
xorl %eax, %eax
testl %ecx, %ecx
je 0x509a
cmpl $0x2f, %ecx
je 0x509a
incq %rbp
movb $0x1, %al
testb %al, %al
jne 0x506a
movl $0x1, %ecx
jmp 0x5164
movq %r14, %rdi
movl $0x7d, %esi
callq 0x20b0
testq %rax, %rax
je 0x514d
movq %rax, %r13
movq %r15, (%rsp)
incq %rax
movq %rax, 0x10(%rsp)
xorl %ebx, %ebx
movq %r14, 0x8(%rsp)
movq %r14, %r12
movq %rbp, %r15
incq %r12
movq %r12, %rdi
movl $0x2c, %esi
callq 0x20b0
cmpq %r13, %rax
movq %rax, %r14
cmovaq %r13, %r14
testq %rax, %rax
cmoveq %r13, %r14
movq %r14, %rbp
subq %r12, %rbp
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0x2100
testl %eax, %eax
movq %r14, %r12
cmoveq 0x10(%rsp), %r12
movl $0x0, %eax
cmovneq %rax, %rbp
movzbl %bl, %ebx
movl $0x1, %eax
cmovel %eax, %ebx
addq %r15, %rbp
cmpq %r13, %r14
je 0x513b
testb $0x1, %bl
je 0x50d7
testb $0x1, %bl
movq 0x8(%rsp), %r14
movq (%rsp), %r15
cmoveq %r14, %r15
jmp 0x5155
xorl %ebx, %ebx
movq %r14, %r12
xorl %r15d, %r15d
movl $0x1, %ecx
testb $0x1, %bl
je 0x5164
xorl %ecx, %ecx
movq %r12, %r14
testl %ecx, %ecx
je 0x4eb6
cmpl $0x1, %ecx
je 0x517c
xorl %r15d, %r15d
cmpb $0x0, (%rbp)
cmoveq %r14, %r15
movq %r15, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq