// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpb $0x0, (%rax)
je 0xb271
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x3f, %eax
jne 0xaeb7
movq -0x18(%rbp), %rax
cmpb $0x0, (%rax)
je 0xaeb7
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0xb264
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5b, %eax
jne 0xaff1
movq -0x18(%rbp), %rax
cmpb $0x0, (%rax)
je 0xaff1
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movb $0x0, -0x21(%rbp)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x21, %eax
jne 0xaf00
movb $0x1, -0x21(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movb -0x21(%rbp), %al
andb $0x1, %al
movb %al, -0x22(%rbp)
movq -0x20(%rbp), %rcx
xorl %eax, %eax
cmpb $0x0, (%rcx)
movb %al, -0x5a(%rbp)
je 0xaf26
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5d, %eax
setne %al
movb %al, -0x5a(%rbp)
movb -0x5a(%rbp), %al
testb $0x1, %al
jne 0xaf32
jmp 0xafb5
movq -0x20(%rbp), %rax
movb (%rax), %al
movb %al, -0x23(%rbp)
movb -0x23(%rbp), %al
movb %al, -0x24(%rbp)
movq -0x20(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2d, %eax
jne 0xaf7a
movq -0x20(%rbp), %rax
cmpb $0x0, 0x2(%rax)
je 0xaf7a
movq -0x20(%rbp), %rax
movsbl 0x2(%rax), %eax
cmpl $0x5d, %eax
je 0xaf7a
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movb (%rax), %al
movb %al, -0x24(%rbp)
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
movsbl -0x23(%rbp), %ecx
cmpl %ecx, %eax
jl 0xafa2
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
movsbl -0x24(%rbp), %ecx
cmpl %ecx, %eax
jg 0xafa2
movb -0x21(%rbp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x22(%rbp)
jmp 0xafa4
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0xaf08
testb $0x1, -0x22(%rbp)
je 0xafc7
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5d, %eax
je 0xafd4
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xb297
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0xb262
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2a, %eax
jne 0xb084
jmp 0xb003
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2a, %eax
jne 0xb01d
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0xb003
movq $0x0, -0x30(%rbp)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xae60
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0xb04f
movq -0x38(%rbp), %rax
cmpq -0x30(%rbp), %rax
jbe 0xb04f
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xb067
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0xb069
jmp 0xb077
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0xb025
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xb297
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2f, %eax
jne 0xb13b
movq -0x20(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2f, %eax
jne 0xb13b
jmp 0xb0a7
movq -0x20(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x2f, %eax
jne 0xb0c2
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0xb0a7
movq $0x0, -0x40(%rbp)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xae60
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0xb0f4
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
jbe 0xb0f4
movq -0x48(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xb102
jmp 0xb12e
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0xb12a
movq -0x18(%rbp), %rdi
addq $0x1, %rdi
movl $0x2f, %esi
callq 0x30d0
movq %rax, -0x18(%rbp)
cmpq $0x0, %rax
jne 0xb12c
jmp 0xb12e
jmp 0xb0ca
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xb297
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7b, %eax
jne 0xb22c
movq -0x20(%rbp), %rdi
movl $0x7d, %esi
callq 0x30d0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0xb171
movq $0x0, -0x8(%rbp)
jmp 0xb297
movb $0x0, -0x59(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movl $0x2c, %esi
callq 0x30d0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0xb1a4
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jbe 0xb1ac
movq -0x50(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x58(%rbp), %rdx
movq -0x20(%rbp), %rax
subq %rax, %rdx
callq 0x3140
cmpl $0x0, %eax
jne 0xb1ee
movq -0x58(%rbp), %rax
movq -0x20(%rbp), %rcx
subq %rcx, %rax
addq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movb $0x1, -0x59(%rbp)
jmp 0xb1f6
movq -0x58(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0xb1f8
movq -0x58(%rbp), %rcx
xorl %eax, %eax
cmpq -0x50(%rbp), %rcx
movb %al, -0x5b(%rbp)
je 0xb20f
movb -0x59(%rbp), %al
xorb $-0x1, %al
movb %al, -0x5b(%rbp)
movb -0x5b(%rbp), %al
testb $0x1, %al
jne 0xb175
testb $0x1, -0x59(%rbp)
jne 0xb22a
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xb297
jmp 0xb25c
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
movq -0x18(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0xb258
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0xb25a
jmp 0xb271
jmp 0xb25c
jmp 0xb25e
jmp 0xb260
jmp 0xb262
jmp 0xb264
movq -0x20(%rbp), %rax
movq %rax, -0x10(%rbp)
jmp 0xae70
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
jne 0xb287
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
jmp 0xb28f
xorl %eax, %eax
movq %rax, -0x68(%rbp)
jmp 0xb28f
movq -0x68(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax,%rax)