// File: /workspace/github_c_makefile_star2_O0/jondurbin[P]dre2/src/dre2_parse.c
// Function: dre2_skip_table
void dre2_skip_table( struct dre2 *graph )
{
  int i, j, r;
  int iter, l_iter;
  int matched, complete, total;
  int *swapper, *visited;
  int *reachable, *state, *r_temp;
  struct dre2_node *node;

  // Allocate some memory.
  state = ( int * )malloc( sizeof( int ) * graph->count );
  reachable = ( int * )malloc( sizeof( int ) * graph->count );
  r_temp = ( int * )malloc( sizeof( int ) * graph->count );

  // Initialize some variables.
  i = 0;
  iter = 0;
  total = 0;
  complete = false;

  // Initialize the reachable states to be neighbors of the first node.
  for ( i = 0; i < graph->v[graph->count - 1].p_count; i++ )
  {
    reachable[i] = graph->v[graph->count - 1].p[i];
    if ( reachable[i] == 0 )
    {
      for ( j = 0; j < RANGE; j++ )
        graph->skip_table[j] = 1;
      graph->min_length = 0;
      return;
    }
  }
  l_iter = i;

  visited = ( int * )malloc( sizeof( int ) * graph->count );
  for ( j = 0; j < RANGE; j++ )
    graph->skip_table[j] = 0;

  // Outer loop, runs until the initial node is reachable.
  while ( true )
  {
    if ( l_iter == 0 )
      break;

    total++;
    iter = 0;

    // Iterate through all of the reachable nodes.
    for ( j = 0; j < graph->count; j++ )
    {
      visited[j] = false;
      state[j] = false;
    }
    for ( i = 0; i < l_iter; i++ )
    {
      r = reachable[i];
      node = &graph->v[r];
      if ( total > 1 )
      {

        // Setup the skip table for the current node's chars.
        if ( node->c == DRE2_CHAR_CLASS )
        {
          for ( j = 0; j < RANGE; j++ )
          {
            if ( node->possible[j] && graph->skip_table[j] > total - 1 || graph->skip_table[j] == 0 )
              graph->skip_table[j] = total - 1;
          }
        } else if ( node->c >= 0 )
        {
          if ( graph->skip_table[node->c] > total - 1 || graph->skip_table[node->c] == 0 )
            graph->skip_table[node->c] = total - 1;
        }
      }
      if ( node->c == DRE2_BOL || node->c == DRE2_EOF || node->c == DRE2_EOL )
          total--;


      // Add the current node's parents to the next reachable nodes.
      for ( j = 0; j < node->p_count; j++ )
      {
        if ( !state[node->p[j]] && !visited[node->p[j]] )
          r_temp[iter++] = node->p[j];

        visited[node->p[j]] = true;
        state[node->p[j]] = true;
      }

      // Check if the initial state was reached.
      if ( state[0] == true )
      {
        complete = true;
      }
    }
    
    l_iter = iter;

    // Change the current reachable nodes to the next reachable nodes from above.
    swapper = reachable;
    reachable = r_temp;
    r_temp = swapper;
    if ( complete )
      break;
  }

  // Set remaining character's skip table value.
  for ( i = 0; i < RANGE; i++ )
  {
    if ( graph->skip_table[i] == 0 )
      graph->skip_table[i] = total;
  }

  // Set the min length of the regular expression.
  graph->min_length = total;

  free( reachable );
  free( r_temp );
  free( state );
  free( visited );
  reachable = NULL;
  r_temp = NULL;
  state = NULL;
  visited = NULL;
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq 0x50(%rsp), %rax
movslq 0x8(%rax), %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, 0x10(%rsp)
movq 0x50(%rsp), %rax
movslq 0x8(%rax), %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, 0x18(%rsp)
movq 0x50(%rsp), %rax
movslq 0x8(%rax), %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, 0x8(%rsp)
movl $0x0, 0x4c(%rsp)
movl $0x0, 0x40(%rsp)
movl $0x0, 0x30(%rsp)
movl $0x0, 0x34(%rsp)
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
movq 0x50(%rsp), %rcx
movq (%rcx), %rcx
movq 0x50(%rsp), %rdx
movl 0x8(%rdx), %edx
subl $0x1, %edx
movslq %edx, %rdx
shlq $0x6, %rdx
addq %rdx, %rcx
cmpl 0x20(%rcx), %eax
jge 0x68fd
movq 0x50(%rsp), %rax
movq (%rax), %rax
movq 0x50(%rsp), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq 0x18(%rax), %rax
movslq 0x4c(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x18(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x18(%rsp), %rax
movslq 0x4c(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x68eb
movl $0x0, 0x48(%rsp)
cmpl $0x100, 0x48(%rsp)      # imm = 0x100
jge 0x68d7
movq 0x50(%rsp), %rax
movslq 0x48(%rsp), %rcx
movl $0x1, 0xc(%rax,%rcx,4)
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0x68ae
movq 0x50(%rsp), %rax
movl $0x0, 0x40c(%rax)
jmp 0x6caf
jmp 0x68ed
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x6836
movl 0x4c(%rsp), %eax
movl %eax, 0x3c(%rsp)
movq 0x50(%rsp), %rax
movslq 0x8(%rax), %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, 0x20(%rsp)
movl $0x0, 0x48(%rsp)
cmpl $0x100, 0x48(%rsp)      # imm = 0x100
jge 0x694d
movq 0x50(%rsp), %rax
movslq 0x48(%rsp), %rcx
movl $0x0, 0xc(%rax,%rcx,4)
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0x6924
jmp 0x694f
cmpl $0x0, 0x3c(%rsp)
jne 0x695b
jmp 0x6c10
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
movl $0x0, 0x40(%rsp)
movl $0x0, 0x48(%rsp)
movl 0x48(%rsp), %eax
movq 0x50(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x69b3
movq 0x20(%rsp), %rax
movslq 0x48(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movq 0x10(%rsp), %rax
movslq 0x48(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0x6976
movl $0x0, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
cmpl 0x3c(%rsp), %eax
jge 0x6bdc
movq 0x18(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x44(%rsp)
movq 0x50(%rsp), %rax
movq (%rax), %rax
movslq 0x44(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq %rax, (%rsp)
cmpl $0x1, 0x30(%rsp)
jle 0x6acf
movq (%rsp), %rax
cmpl $-0x3, (%rax)
jne 0x6a7b
movl $0x0, 0x48(%rsp)
cmpl $0x100, 0x48(%rsp)      # imm = 0x100
jge 0x6a79
movq (%rsp), %rax
movq 0x28(%rax), %rax
movslq 0x48(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x6a44
movq 0x50(%rsp), %rax
movslq 0x48(%rsp), %rcx
movl 0xc(%rax,%rcx,4), %eax
movl 0x30(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jg 0x6a55
movq 0x50(%rsp), %rax
movslq 0x48(%rsp), %rcx
cmpl $0x0, 0xc(%rax,%rcx,4)
jne 0x6a6a
movl 0x30(%rsp), %edx
subl $0x1, %edx
movq 0x50(%rsp), %rax
movslq 0x48(%rsp), %rcx
movl %edx, 0xc(%rax,%rcx,4)
jmp 0x6a6c
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0x6a0e
jmp 0x6acd
movq (%rsp), %rax
cmpl $0x0, (%rax)
jl 0x6acb
movq 0x50(%rsp), %rax
movq (%rsp), %rcx
movslq (%rcx), %rcx
movl 0xc(%rax,%rcx,4), %eax
movl 0x30(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jg 0x6ab2
movq 0x50(%rsp), %rax
movq (%rsp), %rcx
movslq (%rcx), %rcx
cmpl $0x0, 0xc(%rax,%rcx,4)
jne 0x6ac9
movl 0x30(%rsp), %edx
subl $0x1, %edx
movq 0x50(%rsp), %rax
movq (%rsp), %rcx
movslq (%rcx), %rcx
movl %edx, 0xc(%rax,%rcx,4)
jmp 0x6acb
jmp 0x6acd
jmp 0x6acf
movq (%rsp), %rax
cmpl $-0x12, (%rax)
je 0x6aea
movq (%rsp), %rax
cmpl $-0x4, (%rax)
je 0x6aea
movq (%rsp), %rax
cmpl $-0x11, (%rax)
jne 0x6af5
movl 0x30(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x30(%rsp)
movl $0x0, 0x48(%rsp)
movl 0x48(%rsp), %eax
movq (%rsp), %rcx
cmpl 0x20(%rcx), %eax
jge 0x6bb8
movq 0x10(%rsp), %rax
movq (%rsp), %rcx
movq 0x18(%rcx), %rcx
movslq 0x48(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x6b6e
movq 0x20(%rsp), %rax
movq (%rsp), %rcx
movq 0x18(%rcx), %rcx
movslq 0x48(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x6b6e
movq (%rsp), %rax
movq 0x18(%rax), %rax
movslq 0x48(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x8(%rsp), %rax
movl 0x40(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x40(%rsp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq 0x20(%rsp), %rax
movq (%rsp), %rcx
movq 0x18(%rcx), %rcx
movslq 0x48(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
movl $0x1, (%rax,%rcx,4)
movq 0x10(%rsp), %rax
movq (%rsp), %rcx
movq 0x18(%rcx), %rcx
movslq 0x48(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
movl $0x1, (%rax,%rcx,4)
movl 0x48(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x48(%rsp)
jmp 0x6afd
movq 0x10(%rsp), %rax
cmpl $0x1, (%rax)
jne 0x6bca
movl $0x1, 0x34(%rsp)
jmp 0x6bcc
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x69bb
movl 0x40(%rsp), %eax
movl %eax, 0x3c(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpl $0x0, 0x34(%rsp)
je 0x6c0b
jmp 0x6c10
jmp 0x694f
movl $0x0, 0x4c(%rsp)
cmpl $0x100, 0x4c(%rsp)      # imm = 0x100
jge 0x6c54
movq 0x50(%rsp), %rax
movslq 0x4c(%rsp), %rcx
cmpl $0x0, 0xc(%rax,%rcx,4)
jne 0x6c45
movl 0x30(%rsp), %edx
movq 0x50(%rsp), %rax
movslq 0x4c(%rsp), %rcx
movl %edx, 0xc(%rax,%rcx,4)
jmp 0x6c47
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x6c18
movl 0x30(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, 0x40c(%rax)
movq 0x18(%rsp), %rdi
callq 0x2070
movq 0x8(%rsp), %rdi
callq 0x2070
movq 0x10(%rsp), %rdi
callq 0x2070
movq 0x20(%rsp), %rdi
callq 0x2070
movq $0x0, 0x18(%rsp)
movq $0x0, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)