// File: attractivechaos[P]udb2/stb/./stb.h
// Function: stb__reg_parse
static char *stb__reg_parse(stb_matcher *matcher, int start, char *regex, stb_uint16 *end)
{
   int n;
   int last_start = -1;
   stb_uint16 last_end = start;

   while (*regex) {
      switch (*regex) {
         case '(':
            last_start = last_end;
            regex = stb__reg_parse_alt(matcher, last_end, regex+1, &last_end);
            if (regex == NULL || *regex != ')')
               return NULL;
            ++regex;
            break;

         case '|':
         case ')':
            *end = last_end;
            return regex;

         case '?':
            if (last_start < 0) return NULL;
            stb__add_epsilon(matcher, last_start, last_end);
            ++regex;
            break;

         case '*':
            if (last_start < 0) return NULL;
            stb__add_epsilon(matcher, last_start, last_end);

            // fall through

         case '+':
            if (last_start < 0) return NULL;
            stb__add_epsilon(matcher, last_end, last_start);
            // prevent links back to last_end from chaining to last_start
            n = stb__add_node(matcher);
            stb__add_epsilon(matcher, last_end, n);
            last_end = n;
            ++regex;
            break;

         case '{':   // not supported!
            // @TODO: given {n,m}, clone last_start to last_end m times,
            // and include epsilons from start to first m-n blocks
            return NULL; 

         case '\\':
            ++regex;
            if (!*regex) return NULL;

            // fallthrough
         default: // match exactly this character
            n = stb__add_node(matcher);
            stb__add_edge(matcher, last_end, n, *regex);
            last_start = last_end;
            last_end = n;
            ++regex;
            break;

         case '$':
            n = stb__add_node(matcher);
            stb__add_edge(matcher, last_end, n, '\n');
            last_start = last_end;
            last_end = n;
            ++regex;
            break;

         case '.':
            n = stb__add_node(matcher);
            stb__add_edge(matcher, last_end, n, -1);
            last_start = last_end;
            last_end = n;
            ++regex;
            break;

         case '[': {
            stb_uint8 flags[256];
            int invert = 0,z;
            ++regex;
            if (matcher->num_charset == 0) {
               matcher->charset = (stb_uint *) stb_malloc(matcher, sizeof(*matcher->charset) * 256);
               memset(matcher->charset, 0, sizeof(*matcher->charset) * 256);
            }

            memset(flags,0,sizeof(flags));

            // leading ^ is special
            if (*regex == '^')
               ++regex, invert = 1;

            // leading ] is special
            if (*regex == ']') {
               flags[']'] = 1;
               ++regex;
            }
            while (*regex != ']') {
               stb_uint a;
               if (!*regex) return NULL;
               a = *regex++;
               if (regex[0] == '-' && regex[1] != ']') {
                  stb_uint i,b = regex[1];
                  regex += 2;
                  if (b == 0) return NULL;
                  if (a > b) return NULL;
                  for (i=a; i <= b; ++i)
                     flags[i] = 1;
               } else
                  flags[a] = 1;
            }
            ++regex;
            if (invert) {
               int i;
               for (i=0; i < 256; ++i)
                  flags[i] = 1-flags[i];
            }

            // now check if any existing charset matches
            for (z=0; z < matcher->num_charset; ++z) {
               int i, k[2] = { 0, 1 << z};
               for (i=0; i < 256; ++i) {
                  unsigned int f = k[flags[i]];
                  if ((matcher->charset[i] & k[1]) != f)
                     break;
               }
               if (i == 256) break;
            }

            if (z == matcher->num_charset) {
               int i;
               ++matcher->num_charset;
               if (matcher->num_charset > 32) {
                  assert(0); /* NOTREACHED */
                  return NULL; // too many charsets, oops
               }
               for (i=0; i < 256; ++i)
                  if (flags[i])
                     matcher->charset[i] |= (1 << z);
            }

            n = stb__add_node(matcher);
            stb__add_edge(matcher, last_end, n, -2 - z);
            last_start = last_end;
            last_end = n;
            break;
         }
      }
   }
   *end = last_end;
   return regex;
}

// Assembly:
subq $0x178, %rsp            # imm = 0x178
movq %rdi, 0x168(%rsp)
movl %esi, 0x164(%rsp)
movq %rdx, 0x158(%rsp)
movq %rcx, 0x150(%rsp)
movl $0xffffffff, 0x148(%rsp) # imm = 0xFFFFFFFF
movl 0x164(%rsp), %eax
movw %ax, 0x146(%rsp)
movq 0x158(%rsp), %rax
cmpb $0x0, (%rax)
je 0x1e449
movq 0x158(%rsp), %rax
movsbl (%rax), %eax
addl $-0x24, %eax
movl %eax, %ecx
movq %rcx, 0x8(%rsp)
subl $0x58, %eax
ja 0x1df2c
movq 0x8(%rsp), %rax
leaq 0x1459(%rip), %rcx      # 0x1f174
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movzwl 0x146(%rsp), %eax
movl %eax, 0x148(%rsp)
movq 0x168(%rsp), %rdi
movzwl 0x146(%rsp), %esi
movq 0x158(%rsp), %rdx
addq $0x1, %rdx
leaq 0x146(%rsp), %rcx
callq 0x17180
movq %rax, 0x158(%rsp)
cmpq $0x0, 0x158(%rsp)
je 0x1dd7f
movq 0x158(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x29, %eax
je 0x1dd90
movq $0x0, 0x170(%rsp)
jmp 0x1e46c
movq 0x158(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x158(%rsp)
jmp 0x1e444
movw 0x146(%rsp), %cx
movq 0x150(%rsp), %rax
movw %cx, (%rax)
movq 0x158(%rsp), %rax
movq %rax, 0x170(%rsp)
jmp 0x1e46c
cmpl $0x0, 0x148(%rsp)
jge 0x1ddec
movq $0x0, 0x170(%rsp)
jmp 0x1e46c
movq 0x168(%rsp), %rdi
movl 0x148(%rsp), %esi
movzwl 0x146(%rsp), %edx
callq 0x1daa0
movq 0x158(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x158(%rsp)
jmp 0x1e444
cmpl $0x0, 0x148(%rsp)
jge 0x1de3c
movq $0x0, 0x170(%rsp)
jmp 0x1e46c
movq 0x168(%rsp), %rdi
movl 0x148(%rsp), %esi
movzwl 0x146(%rsp), %edx
callq 0x1daa0
cmpl $0x0, 0x148(%rsp)
jge 0x1de73
movq $0x0, 0x170(%rsp)
jmp 0x1e46c
movq 0x168(%rsp), %rdi
movzwl 0x146(%rsp), %esi
movl 0x148(%rsp), %edx
callq 0x1daa0
movq 0x168(%rsp), %rdi
callq 0x1d950
movl %eax, 0x14c(%rsp)
movq 0x168(%rsp), %rdi
movzwl 0x146(%rsp), %esi
movl 0x14c(%rsp), %edx
callq 0x1daa0
movl 0x14c(%rsp), %eax
movw %ax, 0x146(%rsp)
movq 0x158(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x158(%rsp)
jmp 0x1e444
movq $0x0, 0x170(%rsp)
jmp 0x1e46c
movq 0x158(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x158(%rsp)
movq 0x158(%rsp), %rax
cmpb $0x0, (%rax)
jne 0x1df2a
movq $0x0, 0x170(%rsp)
jmp 0x1e46c
jmp 0x1df2c
movq 0x168(%rsp), %rdi
callq 0x1d950
movl %eax, 0x14c(%rsp)
movq 0x168(%rsp), %rdi
movzwl 0x146(%rsp), %esi
movl 0x14c(%rsp), %edx
movq 0x158(%rsp), %rax
movsbl (%rax), %ecx
callq 0x1e480
movzwl 0x146(%rsp), %eax
movl %eax, 0x148(%rsp)
movl 0x14c(%rsp), %eax
movw %ax, 0x146(%rsp)
movq 0x158(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x158(%rsp)
jmp 0x1e444
movq 0x168(%rsp), %rdi
callq 0x1d950
movl %eax, 0x14c(%rsp)
movq 0x168(%rsp), %rdi
movzwl 0x146(%rsp), %esi
movl 0x14c(%rsp), %edx
movl $0xa, %ecx
callq 0x1e480
movzwl 0x146(%rsp), %eax
movl %eax, 0x148(%rsp)
movl 0x14c(%rsp), %eax
movw %ax, 0x146(%rsp)
movq 0x158(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x158(%rsp)
jmp 0x1e444
movq 0x168(%rsp), %rdi
callq 0x1d950
movl %eax, 0x14c(%rsp)
movq 0x168(%rsp), %rdi
movzwl 0x146(%rsp), %esi
movl 0x14c(%rsp), %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
callq 0x1e480
movzwl 0x146(%rsp), %eax
movl %eax, 0x148(%rsp)
movl 0x14c(%rsp), %eax
movw %ax, 0x146(%rsp)
movq 0x158(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x158(%rsp)
jmp 0x1e444
movl $0x0, 0x3c(%rsp)
movq 0x158(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x158(%rsp)
movq 0x168(%rsp), %rax
cmpl $0x0, 0x10(%rax)
jne 0x1e0d9
movq 0x168(%rsp), %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x75b0
movq %rax, %rcx
movq 0x168(%rsp), %rax
movq %rcx, 0x8(%rax)
movq 0x168(%rsp), %rax
movq 0x8(%rax), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x2160
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
movl $0x100, %edx            # imm = 0x100
callq 0x2160
movq 0x158(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x5e, %eax
jne 0x1e116
movq 0x158(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x158(%rsp)
movl $0x1, 0x3c(%rsp)
movq 0x158(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x5d, %eax
jne 0x1e142
movb $0x1, 0x9d(%rsp)
movq 0x158(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x158(%rsp)
jmp 0x1e144
movq 0x158(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x5d, %eax
je 0x1e24c
movq 0x158(%rsp), %rax
cmpb $0x0, (%rax)
jne 0x1e176
movq $0x0, 0x170(%rsp)
jmp 0x1e46c
movq 0x158(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x158(%rsp)
movsbl (%rax), %eax
movl %eax, 0x34(%rsp)
movq 0x158(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x1e23e
movq 0x158(%rsp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x5d, %eax
je 0x1e23e
movq 0x158(%rsp), %rax
movsbl 0x1(%rax), %eax
movl %eax, 0x2c(%rsp)
movq 0x158(%rsp), %rax
addq $0x2, %rax
movq %rax, 0x158(%rsp)
cmpl $0x0, 0x2c(%rsp)
jne 0x1e1f9
movq $0x0, 0x170(%rsp)
jmp 0x1e46c
movl 0x34(%rsp), %eax
cmpl 0x2c(%rsp), %eax
jbe 0x1e214
movq $0x0, 0x170(%rsp)
jmp 0x1e46c
movl 0x34(%rsp), %eax
movl %eax, 0x30(%rsp)
movl 0x30(%rsp), %eax
cmpl 0x2c(%rsp), %eax
ja 0x1e23c
movl 0x30(%rsp), %eax
movb $0x1, 0x40(%rsp,%rax)
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x1e21c
jmp 0x1e247
movl 0x34(%rsp), %eax
movb $0x1, 0x40(%rsp,%rax)
jmp 0x1e144
movq 0x158(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x158(%rsp)
cmpl $0x0, 0x3c(%rsp)
je 0x1e2a4
movl $0x0, 0x28(%rsp)
cmpl $0x100, 0x28(%rsp)      # imm = 0x100
jge 0x1e2a2
movslq 0x28(%rsp), %rax
movzbl 0x40(%rsp,%rax), %ecx
movl $0x1, %eax
subl %ecx, %eax
movb %al, %cl
movslq 0x28(%rsp), %rax
movb %cl, 0x40(%rsp,%rax)
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x1e26f
jmp 0x1e2a4
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
movq 0x168(%rsp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x1e349
movl $0x0, 0x1c(%rsp)
movl 0x38(%rsp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, 0x20(%rsp)
movl $0x0, 0x24(%rsp)
cmpl $0x100, 0x24(%rsp)      # imm = 0x100
jge 0x1e32b
movslq 0x24(%rsp), %rax
movzbl 0x40(%rsp,%rax), %eax
movl 0x1c(%rsp,%rax,4), %eax
movl %eax, 0x18(%rsp)
movq 0x168(%rsp), %rax
movq 0x8(%rax), %rax
movslq 0x24(%rsp), %rcx
movl (%rax,%rcx,4), %eax
andl 0x20(%rsp), %eax
cmpl 0x18(%rsp), %eax
je 0x1e31c
jmp 0x1e32b
jmp 0x1e31e
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x1e2e0
cmpl $0x100, 0x24(%rsp)      # imm = 0x100
jne 0x1e337
jmp 0x1e349
jmp 0x1e339
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x1e2ac
movl 0x38(%rsp), %eax
movq 0x168(%rsp), %rcx
cmpl 0x10(%rcx), %eax
jne 0x1e3ed
movq 0x168(%rsp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
movq 0x168(%rsp), %rax
cmpl $0x20, 0x10(%rax)
jle 0x1e39c
leaq 0x132a(%rip), %rdi      # 0x1f6ae
leaq 0xffe(%rip), %rsi       # 0x1f389
movl $0x242d, %edx           # imm = 0x242D
leaq 0x1db0(%rip), %rcx      # 0x20147
callq 0x2140
movl $0x0, 0x14(%rsp)
cmpl $0x100, 0x14(%rsp)      # imm = 0x100
jge 0x1e3eb
movslq 0x14(%rsp), %rax
cmpb $0x0, 0x40(%rsp,%rax)
je 0x1e3dc
movl 0x38(%rsp), %ecx
movl $0x1, %edx
shll %cl, %edx
movq 0x168(%rsp), %rax
movq 0x8(%rax), %rax
movslq 0x14(%rsp), %rcx
orl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
jmp 0x1e3de
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0x1e3a4
jmp 0x1e3ed
movq 0x168(%rsp), %rdi
callq 0x1d950
movl %eax, 0x14c(%rsp)
movq 0x168(%rsp), %rdi
movzwl 0x146(%rsp), %esi
movl 0x14c(%rsp), %edx
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
subl 0x38(%rsp), %ecx
callq 0x1e480
movzwl 0x146(%rsp), %eax
movl %eax, 0x148(%rsp)
movl 0x14c(%rsp), %eax
movw %ax, 0x146(%rsp)
jmp 0x1dce0
movw 0x146(%rsp), %cx
movq 0x150(%rsp), %rax
movw %cx, (%rax)
movq 0x158(%rsp), %rax
movq %rax, 0x170(%rsp)
movq 0x170(%rsp), %rax
addq $0x178, %rsp            # imm = 0x178
retq
nopl (%rax)