// File: /workspace/github_c_makefile_star2_O0/jondurbin[P]dre2/src/dre2_backtracking.c
// Function: dre2_backtrack_recursive
int dre2_backtrack_recursive( struct dre2 *graph, unsigned char *input, int pos, int id, int **state, int **group_open, int **group_close )
{
  int i, j;
  int offset;
  int g_open, g_close;
  unsigned char *tp;
  int *last_state;
  int assertion, single_match;
  struct dre2_node *node;
  int length = strlen( input );

  tp = input + pos;

  // If we are at the regex close node, then we've matched as much as possible, return.
  if ( id == graph->count - 1 )
    return true;

  // If we are past the end of input, we can't match, return false.
  if ( *tp == '\0' && ( graph->v[id].c != DRE2_GROUP_OPEN && graph->v[id].c != DRE2_GROUP_CLOSE ) &&
         ( graph->v[id].c != DRE2_EOF && graph->v[id].c != DRE2_EOL && graph->v[id].c != DRE2_BOL ) )
    return false;

  // Make sure we haven't already tried this node.
  if ( ( *state )[id] )
    return false;

  last_state = ( int * )malloc( sizeof( int ) * graph->count );
  for ( i = 0; i < graph->count; i++ )
    last_state[i] = ( *state )[i];

  ( *state )[id] = true;

  // Match the input character if it's not a group.
  if ( graph->v[id].c != DRE2_GROUP_OPEN && graph->v[id].c != DRE2_GROUP_CLOSE )
  {
    single_match = false;
    node = &graph->v[id];
    switch ( node->c )
    {
      case DRE2_BOL:
      case DRE2_EOF:
      case DRE2_EOL:
        assertion = true;
        break;
      default:
        assertion = false;
        break;
    }

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

    if ( single_match )
    {
      if ( !assertion )
      {
        offset = 1;
        pos++;
      }
      for ( i = 0; i < graph->count; i++ )
        ( *state )[i] = false;
    } else
    {
      free( last_state );
      last_state = NULL;
      return false;
    }
  } else
  {
    offset = 0;
  }

  // Set the group open and close positions, but also track where it was so we can revert later if needed.
  if ( graph->v[id].c == DRE2_GROUP_OPEN && graph->v[id].group_id > 0 )
  {
    g_open = ( *group_open )[graph->v[id].group_id - 1];
    ( *group_open )[graph->v[id].group_id - 1] = pos;
  } else if ( graph->v[id].c == DRE2_GROUP_CLOSE && graph->v[id].group_id > 0 )
  {
    g_close = ( *group_close )[graph->v[id].group_id - 1];
    ( *group_close )[graph->v[id].group_id - 1] = pos;
  }

  // Check each of this nodes neighbors.
  for ( i = 0; i < graph->v[id].n_count; i++ )
  {
    // If the recursive function returns true, the regex matched.
    if ( dre2_backtrack_recursive( graph, input, pos, graph->v[id].n[i], state, group_open, group_close ) )
    {
      free( last_state );
      last_state = NULL;
      return true;
    }
  }

  // Revert state table on failure as well.
  for ( i = 0; i < graph->count; i++ )
    ( *state )[i] = last_state[i]; //false;

  // Revert group open/close on failure.
  if ( graph->v[id].c == DRE2_GROUP_OPEN && graph->v[id].group_id > 0 )
  {
    ( *group_open )[graph->v[id].group_id - 1] = g_open;
  } else if ( graph->v[id].c == DRE2_GROUP_CLOSE && graph->v[id].group_id > 0 )
  {
    ( *group_close )[graph->v[id].group_id - 1] = g_close;
  }
  free( last_state );
  last_state = NULL;
  return false;
}

// Assembly:
subq $0x78, %rsp
movq 0x80(%rsp), %rax
movq %rdi, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movl %edx, 0x5c(%rsp)
movl %ecx, 0x58(%rsp)
movq %r8, 0x50(%rsp)
movq %r9, 0x48(%rsp)
movq 0x60(%rsp), %rdi
callq 0x2100
movl %eax, 0xc(%rsp)
movq 0x60(%rsp), %rax
movslq 0x5c(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x28(%rsp)
movl 0x58(%rsp), %eax
movq 0x68(%rsp), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0xba98
movl $0x1, 0x74(%rsp)
jmp 0xc0d9
movq 0x28(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0xbb33
movq 0x68(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $-0x1, (%rax)
je 0xbb33
movq 0x68(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $-0x2, (%rax)
je 0xbb33
movq 0x68(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $-0x4, (%rax)
je 0xbb33
movq 0x68(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $-0x11, (%rax)
je 0xbb33
movq 0x68(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $-0x12, (%rax)
je 0xbb33
movl $0x0, 0x74(%rsp)
jmp 0xc0d9
movq 0x50(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0xbb53
movl $0x0, 0x74(%rsp)
jmp 0xc0d9
movq 0x68(%rsp), %rax
movslq 0x8(%rax), %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, 0x20(%rsp)
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
movq 0x68(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jge 0xbbaa
movq 0x50(%rsp), %rax
movq (%rax), %rax
movslq 0x44(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x20(%rsp), %rax
movslq 0x44(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0xbb72
movq 0x50(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
movl $0x1, (%rax,%rcx,4)
movq 0x68(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $-0x1, (%rax)
je 0xbde5
movq 0x68(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $-0x2, (%rax)
je 0xbde5
movl $0x0, 0x18(%rsp)
movq 0x68(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x8(%rsp)
addl $0x12, %eax
subl $0x2, %eax
jb 0xbc39
jmp 0xbc2e
movl 0x8(%rsp), %eax
subl $-0x4, %eax
jne 0xbc43
jmp 0xbc39
movl $0x1, 0x1c(%rsp)
jmp 0xbc4b
movl $0x0, 0x1c(%rsp)
movq 0x10(%rsp), %rax
cmpl $-0x12, (%rax)
jne 0xbc69
cmpl $0x0, 0x5c(%rsp)
jne 0xbc69
movl $0x1, 0x18(%rsp)
jmp 0xbd69
movq 0x10(%rsp), %rax
cmpl $-0x11, (%rax)
jne 0xbc9a
movq 0x28(%rsp), %rax
movzbl (%rax), %eax
cmpl $0xa, %eax
je 0xbc8d
movq 0x28(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0xbc9a
movl $0x1, 0x18(%rsp)
jmp 0xbd67
movq 0x10(%rsp), %rax
cmpl $-0x4, (%rax)
jne 0xbcbe
movq 0x28(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x0, %eax
jne 0xbcbe
movl $0x1, 0x18(%rsp)
jmp 0xbd65
movq 0x10(%rsp), %rax
cmpl $-0x4, (%rax)
jne 0xbcfa
movq 0x28(%rsp), %rax
movzbl (%rax), %eax
cmpl $0xa, %eax
jne 0xbcfa
movq 0x28(%rsp), %rax
movq 0x60(%rsp), %rcx
subq %rcx, %rax
addq $0x1, %rax
movslq 0xc(%rsp), %rcx
cmpq %rcx, %rax
jne 0xbcfa
movl $0x1, 0x18(%rsp)
jmp 0xbd63
movq 0x10(%rsp), %rax
cmpl $-0x4, (%rax)
jne 0xbd3b
movq 0x28(%rsp), %rax
movzbl (%rax), %eax
cmpl $0x20, %eax
jne 0xbd3b
movq 0x28(%rsp), %rax
movq 0x60(%rsp), %rcx
subq %rcx, %rax
addq $0x1, %rax
movl 0xc(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jne 0xbd3b
movl $0x1, 0x18(%rsp)
jmp 0xbd61
movq 0x68(%rsp), %rdi
movq 0x10(%rsp), %rsi
movq 0x28(%rsp), %rax
movzbl (%rax), %edx
callq 0x20e0
cmpl $0x0, %eax
je 0xbd5f
movl $0x1, 0x18(%rsp)
jmp 0xbd61
jmp 0xbd63
jmp 0xbd65
jmp 0xbd67
jmp 0xbd69
cmpl $0x0, 0x18(%rsp)
je 0xbdc3
cmpl $0x0, 0x1c(%rsp)
jne 0xbd8a
movl $0x1, 0x3c(%rsp)
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
movq 0x68(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jge 0xbdc1
movq 0x50(%rsp), %rax
movq (%rax), %rax
movslq 0x44(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0xbd92
jmp 0xbde3
movq 0x20(%rsp), %rdi
callq 0x2070
movq $0x0, 0x20(%rsp)
movl $0x0, 0x74(%rsp)
jmp 0xc0d9
jmp 0xbded
movl $0x0, 0x3c(%rsp)
movq 0x68(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $-0x1, (%rax)
jne 0xbe7d
movq 0x68(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $0x0, 0x3c(%rax)
jle 0xbe7d
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq 0x68(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x58(%rsp), %rdx
shlq $0x6, %rdx
addq %rdx, %rcx
movl 0x3c(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x38(%rsp)
movl 0x5c(%rsp), %edx
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq 0x68(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x58(%rsp), %rsi
shlq $0x6, %rsi
addq %rsi, %rcx
movl 0x3c(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xbf10
movq 0x68(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $-0x2, (%rax)
jne 0xbf0e
movq 0x68(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $0x0, 0x3c(%rax)
jle 0xbf0e
movq 0x80(%rsp), %rax
movq (%rax), %rax
movq 0x68(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x58(%rsp), %rdx
shlq $0x6, %rdx
addq %rdx, %rcx
movl 0x3c(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x34(%rsp)
movl 0x5c(%rsp), %edx
movq 0x80(%rsp), %rax
movq (%rax), %rax
movq 0x68(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x58(%rsp), %rsi
shlq $0x6, %rsi
addq %rsi, %rcx
movl 0x3c(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xbf10
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
movq 0x68(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x58(%rsp), %rdx
shlq $0x6, %rdx
addq %rdx, %rcx
cmpl 0x10(%rcx), %eax
jge 0xbfb9
movq 0x68(%rsp), %rdi
movq 0x60(%rsp), %rsi
movl 0x5c(%rsp), %edx
movq 0x68(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movslq 0x44(%rsp), %rcx
movl (%rax,%rcx,4), %ecx
movq 0x50(%rsp), %r8
movq 0x48(%rsp), %r9
movq 0x80(%rsp), %rax
movq %rax, (%rsp)
callq 0x2080
cmpl $0x0, %eax
je 0xbfa7
movq 0x20(%rsp), %rdi
callq 0x2070
movq $0x0, 0x20(%rsp)
movl $0x1, 0x74(%rsp)
jmp 0xc0d9
jmp 0xbfa9
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0xbf18
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
movq 0x68(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jge 0xbff9
movq 0x20(%rsp), %rax
movslq 0x44(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x50(%rsp), %rax
movq (%rax), %rax
movslq 0x44(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0xbfc1
movq 0x68(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $-0x1, (%rax)
jne 0xc05a
movq 0x68(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $0x0, 0x3c(%rax)
jle 0xc05a
movl 0x38(%rsp), %edx
movq 0x48(%rsp), %rax
movq (%rax), %rax
movq 0x68(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x58(%rsp), %rsi
shlq $0x6, %rsi
addq %rsi, %rcx
movl 0x3c(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xc0be
movq 0x68(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $-0x2, (%rax)
jne 0xc0bc
movq 0x68(%rsp), %rax
movq (%rax), %rax
movslq 0x58(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $0x0, 0x3c(%rax)
jle 0xc0bc
movl 0x34(%rsp), %edx
movq 0x80(%rsp), %rax
movq (%rax), %rax
movq 0x68(%rsp), %rcx
movq (%rcx), %rcx
movslq 0x58(%rsp), %rsi
shlq $0x6, %rsi
addq %rsi, %rcx
movl 0x3c(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xc0be
movq 0x20(%rsp), %rdi
callq 0x2070
movq $0x0, 0x20(%rsp)
movl $0x0, 0x74(%rsp)
movl 0x74(%rsp), %eax
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)