// File: /workspace/github_c_makefile_star2_O0/jondurbin[P]dre2/src/dre2_match.c
// Function: dre2_matcher
struct dre2_single_match dre2_matcher( struct dre2 *graph, unsigned char *begin_ptr, unsigned char *input, int start, int direction, int length, int *r_temp, int *reachable, int *state )
{
  int i, j, k;
  int *swapper, *next_nodes, *previous_nodes;
  int iter, l_iter;
  int matched, single_match;
  int r;
  int count, previous_count;
  int found, complete, assertion, assertion_match;
  struct dre2_node *node;
  struct dre2_single_match ret;

  ret.match = NULL;
  ret.skip_to = DRE2_INFINITE;
  ret.assertion_match = false;

  i = 0;
  next_nodes = direction == DRE2_LEFT ? graph->v[start].p : graph->v[start].n;
  count = direction == DRE2_LEFT ? graph->v[start].p_count : graph->v[start].n_count;

  if ( start == 0 || start == graph->count - 1 )
  {
    for ( i = 0; i < count; i++ )
      reachable[i] = next_nodes[i];
    l_iter = i;
  } else
  {
    reachable[0] = start;
    l_iter = 1;
  }

  assertion_match = false;
  while ( true )
  {
    // Check for valid states.
    i = 0;
    iter = 0;
    matched = false;
    complete = false;
    for ( i = 0; i < l_iter; i++ )
    {
      r = reachable[i];
      node = &graph->v[r];

      // Check if the character matches the node.
      single_match = false;
      switch ( node->c )
      {
        case DRE2_BOL:
        case DRE2_EOF:
        case DRE2_EOL:
          assertion = true;
          break;
        default:
          assertion = false;
          break;
      }

      if ( node->c == DRE2_BOL )
      {
        if ( ( direction == DRE2_LEFT && input - begin_ptr == -1 ) || ( direction == DRE2_RIGHT && input - begin_ptr == 0 ) )
          single_match = true;
      } else if ( node->c == DRE2_EOL && ( *input == '\n' || *input == '\0' ) )
      {
        single_match = true;
      } else if ( node->c == DRE2_EOF && *input == '\0' )
      {
        single_match = true;
      } else if ( node->c == DRE2_EOF && *input == '\n' && input - begin_ptr + 1 == length )
      {
        single_match = true;
      } else if ( node->c == DRE2_EOF && *input == ' ' && input - begin_ptr + 1 == length - 1 )
      {
        single_match = true;
      } else if ( dre2_char_matches( graph, node, *input ) )
      {
        single_match = true;
      }

      if ( assertion && single_match )
        assertion_match = true;

      // Set the next possible nodes.
      if ( single_match == true )
      {
        matched = true;

        // Set the next state to include this node's neighbors/parents.
        next_nodes = direction == DRE2_LEFT ? node->p : node->n;
        count = direction == DRE2_LEFT ? node->p_count : node->n_count;
        for ( j = 0; j < count; j++ )
        {
          if ( !state[next_nodes[j]] )
          {
            state[next_nodes[j]] = true;
            r_temp[iter++] = next_nodes[j];
            if ( ( direction == DRE2_RIGHT && next_nodes[j] == graph->count - 1 ) || ( direction == DRE2_LEFT && next_nodes[j] == 0 ) )
              complete = true;
          }
        }
      } else if ( graph->impossible[*input] )
      {
        ret.skip_to = input - begin_ptr;
      }
    }

    if ( !matched && graph->impossible[*input] )
    {
      for ( i = 0; i < graph->v[0].n_count; i++ )
      {
        if ( direction == DRE2_LEFT && graph->v[graph->v[0].n[i]].c == DRE2_BOL )
        {
          ret.skip_to = length;
          break;
        }
      }
    }

    if ( complete )
    {
      ret.match = input;
      ret.assertion_match = assertion_match;
      if ( !( graph->options & DRE2_GREEDY ) )
      {
        for ( i = 0; i < iter; i++ )
          state[r_temp[i]] = false;
        return ret;
      }
    }

    // Reset the state lookup table.
    for ( i = 0; i < iter; i++ )
      state[r_temp[i]] = false;

    l_iter = iter;

    swapper = reachable;
    reachable = r_temp;
    r_temp = swapper;

    // Increment/Decrement input.
    if ( !assertion_match )
    {
      if ( direction == DRE2_LEFT )
        *input--;
      else
        *input++;
    }

    // If none of the active states matched, the regex failed to match.
    if ( matched == false )
      return ret;
  }
  return ret;
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0x28(%rsp)
movq %rdi, %rax
movq %rax, 0x30(%rsp)
movq 0xd8(%rsp), %rax
movq 0xd0(%rsp), %rax
movq 0xc8(%rsp), %rax
movl 0xc0(%rsp), %eax
movq %rsi, 0xb0(%rsp)
movq %rdx, 0xa8(%rsp)
movq %rcx, 0xa0(%rsp)
movl %r8d, 0x9c(%rsp)
movl %r9d, 0x98(%rsp)
movq $0x0, 0x10(%rdi)
movl $0xffffffff, 0x8(%rdi)  # imm = 0xFFFFFFFF
movl $0x0, (%rdi)
movl $0x0, 0x94(%rsp)
cmpl $0x0, 0x98(%rsp)
jne 0x982a
movq 0xb0(%rsp), %rax
movq (%rax), %rax
movslq 0x9c(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x984d
movq 0xb0(%rsp), %rax
movq (%rax), %rax
movslq 0x9c(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x78(%rsp)
cmpl $0x0, 0x98(%rsp)
jne 0x9884
movq 0xb0(%rsp), %rax
movq (%rax), %rax
movslq 0x9c(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
movl %eax, 0x1c(%rsp)
jmp 0x98a5
movq 0xb0(%rsp), %rax
movq (%rax), %rax
movslq 0x9c(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x58(%rsp)
cmpl $0x0, 0x9c(%rsp)
je 0x98d0
movl 0x9c(%rsp), %eax
movq 0xb0(%rsp), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x992b
movl $0x0, 0x94(%rsp)
movl 0x94(%rsp), %eax
cmpl 0x58(%rsp), %eax
jge 0x991e
movq 0x78(%rsp), %rax
movslq 0x94(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0xd0(%rsp), %rax
movslq 0x94(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x98db
movl 0x94(%rsp), %eax
movl %eax, 0x68(%rsp)
jmp 0x9944
movl 0x9c(%rsp), %ecx
movq 0xd0(%rsp), %rax
movl %ecx, (%rax)
movl $0x1, 0x68(%rsp)
movl $0x0, 0x44(%rsp)
movl $0x0, 0x94(%rsp)
movl $0x0, 0x6c(%rsp)
movl $0x0, 0x64(%rsp)
movl $0x0, 0x4c(%rsp)
movl $0x0, 0x94(%rsp)
movl 0x94(%rsp), %eax
cmpl 0x68(%rsp), %eax
jge 0x9d4c
movq 0xd0(%rsp), %rax
movslq 0x94(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x5c(%rsp)
movq 0xb0(%rsp), %rax
movq (%rax), %rax
movslq 0x5c(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, 0x38(%rsp)
movl $0x0, 0x60(%rsp)
movq 0x38(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x18(%rsp)
addl $0x12, %eax
subl $0x2, %eax
jb 0x99e6
jmp 0x99db
movl 0x18(%rsp), %eax
subl $-0x4, %eax
jne 0x99f0
jmp 0x99e6
movl $0x1, 0x48(%rsp)
jmp 0x99f8
movl $0x0, 0x48(%rsp)
movq 0x38(%rsp), %rax
cmpl $-0x12, (%rax)
jne 0x9a55
cmpl $0x0, 0x98(%rsp)
jne 0x9a25
movq 0xa0(%rsp), %rax
movq 0xa8(%rsp), %rcx
subq %rcx, %rax
cmpq $-0x1, %rax
je 0x9a48
cmpl $0x1, 0x98(%rsp)
jne 0x9a50
movq 0xa0(%rsp), %rax
movq 0xa8(%rsp), %rcx
subq %rcx, %rax
cmpq $0x0, %rax
jne 0x9a50
movl $0x1, 0x60(%rsp)
jmp 0x9b7c
movq 0x38(%rsp), %rax
cmpl $-0x11, (%rax)
jne 0x9a8c
movq 0xa0(%rsp), %rax
movzbl (%rax), %eax
cmpl $0xa, %eax
je 0x9a7f
movq 0xa0(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x9a8c
movl $0x1, 0x60(%rsp)
jmp 0x9b7a
movq 0x38(%rsp), %rax
cmpl $-0x4, (%rax)
jne 0x9ab3
movq 0xa0(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0x9ab3
movl $0x1, 0x60(%rsp)
jmp 0x9b78
movq 0x38(%rsp), %rax
cmpl $-0x4, (%rax)
jne 0x9afb
movq 0xa0(%rsp), %rax
movzbl (%rax), %eax
cmpl $0xa, %eax
jne 0x9afb
movq 0xa0(%rsp), %rax
movq 0xa8(%rsp), %rcx
subq %rcx, %rax
addq $0x1, %rax
movslq 0xc0(%rsp), %rcx
cmpq %rcx, %rax
jne 0x9afb
movl $0x1, 0x60(%rsp)
jmp 0x9b76
movq 0x38(%rsp), %rax
cmpl $-0x4, (%rax)
jne 0x9b48
movq 0xa0(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x20, %eax
jne 0x9b48
movq 0xa0(%rsp), %rax
movq 0xa8(%rsp), %rcx
subq %rcx, %rax
addq $0x1, %rax
movl 0xc0(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jne 0x9b48
movl $0x1, 0x60(%rsp)
jmp 0x9b74
movq 0xb0(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0xa0(%rsp), %rax
movzbl (%rax), %edx
callq 0x20e0
cmpl $0x0, %eax
je 0x9b72
movl $0x1, 0x60(%rsp)
jmp 0x9b74
jmp 0x9b76
jmp 0x9b78
jmp 0x9b7a
jmp 0x9b7c
cmpl $0x0, 0x48(%rsp)
je 0x9b92
cmpl $0x0, 0x60(%rsp)
je 0x9b92
movl $0x1, 0x44(%rsp)
cmpl $0x1, 0x60(%rsp)
jne 0x9cfa
movl $0x1, 0x64(%rsp)
cmpl $0x0, 0x98(%rsp)
jne 0x9bbf
movq 0x38(%rsp), %rax
movq 0x18(%rax), %rax
movq %rax, 0x10(%rsp)
jmp 0x9bcd
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x78(%rsp)
cmpl $0x0, 0x98(%rsp)
jne 0x9bef
movq 0x38(%rsp), %rax
movl 0x20(%rax), %eax
movl %eax, 0xc(%rsp)
jmp 0x9bfb
movq 0x38(%rsp), %rax
movl 0x10(%rax), %eax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x58(%rsp)
movl $0x0, 0x90(%rsp)
movl 0x90(%rsp), %eax
cmpl 0x58(%rsp), %eax
jge 0x9cf8
movq 0xd8(%rsp), %rax
movq 0x78(%rsp), %rcx
movslq 0x90(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x9ce0
movq 0xd8(%rsp), %rax
movq 0x78(%rsp), %rcx
movslq 0x90(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
movl $0x1, (%rax,%rcx,4)
movq 0x78(%rsp), %rax
movslq 0x90(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0xc8(%rsp), %rax
movl 0x6c(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x6c(%rsp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
cmpl $0x1, 0x98(%rsp)
jne 0x9cb9
movq 0x78(%rsp), %rax
movslq 0x90(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movq 0xb0(%rsp), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x9cd6
cmpl $0x0, 0x98(%rsp)
jne 0x9cde
movq 0x78(%rsp), %rax
movslq 0x90(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x9cde
movl $0x1, 0x4c(%rsp)
jmp 0x9ce0
jmp 0x9ce2
movl 0x90(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x90(%rsp)
jmp 0x9c0e
jmp 0x9d34
movq 0xb0(%rsp), %rax
movq 0xa0(%rsp), %rcx
movzbl (%rcx), %ecx
cmpl $0x0, 0x464(%rax,%rcx,4)
je 0x9d32
movq 0x28(%rsp), %rax
movq 0xa0(%rsp), %rcx
movq 0xa8(%rsp), %rdx
subq %rdx, %rcx
movl %ecx, 0x8(%rax)
jmp 0x9d34
jmp 0x9d36
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x997a
cmpl $0x0, 0x64(%rsp)
jne 0x9dfe
movq 0xb0(%rsp), %rax
movq 0xa0(%rsp), %rcx
movzbl (%rcx), %ecx
cmpl $0x0, 0x464(%rax,%rcx,4)
je 0x9dfe
movl $0x0, 0x94(%rsp)
movl 0x94(%rsp), %eax
movq 0xb0(%rsp), %rcx
movq (%rcx), %rcx
cmpl 0x10(%rcx), %eax
jge 0x9dfc
cmpl $0x0, 0x98(%rsp)
jne 0x9de7
movq 0xb0(%rsp), %rax
movq (%rax), %rax
movq 0xb0(%rsp), %rcx
movq (%rcx), %rcx
movq 0x8(%rcx), %rcx
movslq 0x94(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $-0x12, (%rax)
jne 0x9de7
movq 0x28(%rsp), %rax
movl 0xc0(%rsp), %ecx
movl %ecx, 0x8(%rax)
jmp 0x9dfc
jmp 0x9de9
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x9d83
jmp 0x9dfe
cmpl $0x0, 0x4c(%rsp)
je 0x9e8b
movq 0x28(%rsp), %rax
movq 0xa0(%rsp), %rcx
movq %rcx, 0x10(%rax)
movl 0x44(%rsp), %ecx
movl %ecx, (%rax)
movq 0xb0(%rsp), %rax
movl 0x43c(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x9e89
movl $0x0, 0x94(%rsp)
movl 0x94(%rsp), %eax
cmpl 0x6c(%rsp), %eax
jge 0x9e84
movq 0xd8(%rsp), %rax
movq 0xc8(%rsp), %rcx
movslq 0x94(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
movl $0x0, (%rax,%rcx,4)
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x9e41
jmp 0x9f5c
jmp 0x9e8b
movl $0x0, 0x94(%rsp)
movl 0x94(%rsp), %eax
cmpl 0x6c(%rsp), %eax
jge 0x9ed9
movq 0xd8(%rsp), %rax
movq 0xc8(%rsp), %rcx
movslq 0x94(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
movl $0x0, (%rax,%rcx,4)
movl 0x94(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x94(%rsp)
jmp 0x9e96
movl 0x6c(%rsp), %eax
movl %eax, 0x68(%rsp)
movq 0xd0(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, 0xd0(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0xc8(%rsp)
cmpl $0x0, 0x44(%rsp)
jne 0x9f4e
cmpl $0x0, 0x98(%rsp)
jne 0x9f38
movq 0xa0(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0xa0(%rsp)
jmp 0x9f4c
movq 0xa0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xa0(%rsp)
jmp 0x9f4e
cmpl $0x0, 0x64(%rsp)
jne 0x9f57
jmp 0x9f5c
jmp 0x994c
movq 0x30(%rsp), %rax
addq $0xb8, %rsp
retq
nopl (%rax)