// File: /workspace/github_c_makefile_star2_O0/jondurbin[P]dre2/src/dre2_parse.c
// Function: dre2_parse
struct dre2 *dre2_parse( unsigned char *re, int options )
{
  int i, j;
  struct dre2_node *v, *min_v;
  int node_count, group_count;
  int length;
  int all_minimal;
  int *minimal, *new_minimal, minimal_count, *minimal_id;
  struct dre2_parse_return ret;
  struct dre2 *min_graph, *graph;
  int bol, eol, eof;

  // Setup the return graph and temp, initial graph.
  graph = ( struct dre2 * )malloc( sizeof( struct dre2 ) );
  min_graph = ( struct dre2 * )malloc( sizeof( struct dre2 ) );

  // Make sure options are set correctly.
  if ( options & DRE2_FULL_MATCH || options & DRE2_SUBMATCH )
    options = options | DRE2_GREEDY;

  // Call the recursive parse function.
  graph->options = options;
  graph->starting_points = NULL;
  graph->starting_chars = NULL;
  graph->original = NULL;
  graph->r_temp = NULL;
  graph->reachable = NULL;
  graph->state = NULL;

  v = NULL;

  minimal = ( int * )malloc( sizeof( int ) );
  node_count = 0;
  length = strlen( re );
  group_count = 0;
  ret = dre2_parse_recursive( &v, &node_count, re, length, 0, &minimal, &group_count );
  graph->group_count = group_count;
  if ( ret.pos == -1 )
  {
    cleanup_nodes( &v, node_count );
    free( minimal );
    free( v );
    minimal = NULL;
    v = NULL;
    graph->v = v;
    free( graph );
    graph = NULL;
    return graph;
  }

  graph->v = v;
  graph->count = node_count;

  dre2_add_parents( graph );

  min_graph->options = options;
  min_graph->starting_points = NULL;
  min_graph->starting_chars = ( int * )calloc( RANGE, sizeof( int ) );

  new_minimal = ( int * )calloc( graph->count, sizeof( int ) );
  minimal_id = ( int * )malloc( sizeof( int ) * graph->count );
  minimal_count = 0;

  // Strip out the group nodes and make it an epsilon-free graph.
  min_v = ( struct dre2_node * )malloc( sizeof( struct dre2 ) * graph->count );
  dre2_strip_groups( graph, min_graph, &min_v, minimal, &new_minimal, &minimal_count, &minimal_id );
  min_graph->v = min_v;

  // Setup the reverse graph.
  dre2_add_parents( min_graph );

  // Setup the skip table and find impossible chars.
  dre2_skip_table( min_graph );
  dre2_impossible_chars( min_graph );

  // Clean up the original graph's memory if we don't need it.
  if ( !( options & DRE2_SUBMATCH ) )
  {
    cleanup_dre2( graph );
    min_graph->original = NULL;
  } else
  {
    min_graph->original = graph;
  }

  // Find the best starting point and chars.
  min_graph->starting_point = dre2_starting_point( min_graph, new_minimal, minimal_id, minimal_count );
  dre2_starting_chars( min_graph, new_minimal );

  if ( min_graph->single )
  {
    for ( i = 0; i < RANGE; i++ )
    {
      if ( min_graph->starting_chars[i] )
        min_graph->c = i;
    }
  }

  if ( min_graph->starting_point == -1 )
  {
    min_graph->match_method = DRE2_MN;
  } else if ( min_graph->starting_point == 0 || min_graph->starting_point != min_graph->count - 1 )
  {
    if ( min_graph->single )
      min_graph->match_method = DRE2_SN_SC;
    else
      min_graph->match_method = DRE2_SN_MC;
  } else
  {
    if ( min_graph->single )
      min_graph->match_method = DRE2_SN_SC_H;
    else
      min_graph->match_method = DRE2_SN_MC_H;
  }

  // Make it case-insensitive.
  if ( options & DRE2_NO_CASE )
  {
    for ( i = 0; i < min_graph->count; i++ )
    {
      if ( min_graph->v[i].c == DRE2_CHAR_CLASS )
      {
        for ( j = 'a'; j <= 'z'; j++ )
        {
          if ( min_graph->v[i].possible[j] )
            min_graph->v[i].possible[j - ('a' - 'A')] = true;
        }
        for ( j = 'A'; j <= 'Z'; j++ )
        {
          if ( min_graph->v[i].possible[j] )
            min_graph->v[i].possible[j + ('a' - 'A')] = true;
        }
      }
    }
  }

  if ( options & DRE2_THREAD_SAFE )
  {
    min_graph->r_temp = NULL;
    min_graph->reachable = NULL;
    min_graph->state = NULL;
  } else
  {
    min_graph->r_temp = ( int * )malloc( sizeof( int ) * min_graph->count );
    min_graph->reachable = ( int * )malloc( sizeof( int ) * min_graph->count );
    min_graph->state = ( int * )calloc( min_graph->count, sizeof( int ) );
  }

  if ( min_graph->starting_point > 0 && min_graph->starting_point < graph->count - 1 )
  {
    if ( min_graph->match_method == DRE2_SN_SC || min_graph->match_method == DRE2_SN_MC )
      min_graph->initial_skip = dre2_initial_skip( min_graph );
  }

  min_graph->has_loop = false;
  for ( i = 0; i < min_graph->count; i++ )
  {
    for ( j = 0; j < min_graph->v[i].n_count; j++ )
    {
      if ( min_graph->v[i].n[j] <= i )
      {
        min_graph->has_loop = true;
        i = min_graph->count;
        break;
      }
    }
  }

  // Cleanup.
  free( new_minimal );
  free( minimal_id );
  free( minimal );
  new_minimal = NULL;
  minimal_id = NULL;
  minimal = NULL;

  return min_graph;
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xa8(%rsp)
movl %esi, 0xa4(%rsp)
movl $0x870, %edi            # imm = 0x870
callq 0x2280
movq %rax, 0x38(%rsp)
movl $0x870, %edi            # imm = 0x870
callq 0x2280
movq %rax, 0x40(%rsp)
movl 0xa4(%rsp), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x85c2
movl 0xa4(%rsp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x85d3
movl 0xa4(%rsp), %eax
orl $0x1, %eax
movl %eax, 0xa4(%rsp)
movl 0xa4(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0x43c(%rax)
movq 0x38(%rsp), %rax
movq $0x0, 0x430(%rax)
movq 0x38(%rsp), %rax
movq $0x0, 0x418(%rax)
movq 0x38(%rsp), %rax
movq $0x0, 0x458(%rax)
movq 0x38(%rsp), %rax
movq $0x0, 0x440(%rax)
movq 0x38(%rsp), %rax
movq $0x0, 0x448(%rax)
movq 0x38(%rsp), %rax
movq $0x0, 0x450(%rax)
movq $0x0, 0x90(%rsp)
movl $0x4, %edi
callq 0x2280
movq %rax, 0x70(%rsp)
movl $0x0, 0x84(%rsp)
movq 0xa8(%rsp), %rdi
callq 0x2100
movl %eax, 0x7c(%rsp)
movl $0x0, 0x80(%rsp)
movq 0xa8(%rsp), %rdx
movl 0x7c(%rsp), %ecx
movq %rsp, %rax
leaq 0x80(%rsp), %rsi
movq %rsi, (%rax)
leaq 0x90(%rsp), %rdi
leaq 0x84(%rsp), %rsi
xorl %r8d, %r8d
leaq 0x70(%rsp), %r9
callq 0x2290
movl %edx, 0x18(%rsp)
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x20(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x28(%rsp)
movq 0x20(%rsp), %rax
movq %rax, 0x4c(%rsp)
movl 0x28(%rsp), %eax
movl %eax, 0x54(%rsp)
movl 0x80(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0x460(%rax)
cmpl $-0x1, 0x54(%rsp)
jne 0x8779
movl 0x84(%rsp), %esi
leaq 0x90(%rsp), %rdi
callq 0x2160
movq 0x70(%rsp), %rdi
callq 0x2070
movq 0x90(%rsp), %rdi
callq 0x2070
movq $0x0, 0x70(%rsp)
movq $0x0, 0x90(%rsp)
movq 0x90(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, (%rax)
movq 0x38(%rsp), %rdi
callq 0x2070
movq $0x0, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0xb0(%rsp)
jmp 0x8db1
movq 0x90(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, (%rax)
movl 0x84(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0x8(%rax)
movq 0x38(%rsp), %rdi
callq 0x2220
movl 0xa4(%rsp), %ecx
movq 0x40(%rsp), %rax
movl %ecx, 0x43c(%rax)
movq 0x40(%rsp), %rax
movq $0x0, 0x430(%rax)
movl $0x100, %edi            # imm = 0x100
movl $0x4, %esi
callq 0x21d0
movq %rax, %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x418(%rax)
movq 0x38(%rsp), %rax
movslq 0x8(%rax), %rdi
movl $0x4, %esi
callq 0x21d0
movq %rax, 0x68(%rsp)
movq 0x38(%rsp), %rax
movslq 0x8(%rax), %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, 0x58(%rsp)
movl $0x0, 0x64(%rsp)
movq 0x38(%rsp), %rax
movslq 0x8(%rax), %rax
imulq $0x870, %rax, %rdi      # imm = 0x870
callq 0x2280
movq %rax, 0x88(%rsp)
movq 0x38(%rsp), %rdi
movq 0x40(%rsp), %rsi
movq 0x70(%rsp), %rcx
leaq 0x88(%rsp), %rdx
leaq 0x68(%rsp), %r8
leaq 0x64(%rsp), %r9
leaq 0x58(%rsp), %rax
movq %rax, (%rsp)
callq 0x2330
movq 0x88(%rsp), %rcx
movq 0x40(%rsp), %rax
movq %rcx, (%rax)
movq 0x40(%rsp), %rdi
callq 0x2220
movq 0x40(%rsp), %rdi
callq 0x20b0
movq 0x40(%rsp), %rdi
callq 0x2150
movl 0xa4(%rsp), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0x88be
movq 0x38(%rsp), %rdi
callq 0x22c0
movq 0x40(%rsp), %rax
movq $0x0, 0x458(%rax)
jmp 0x88cf
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x458(%rax)
movq 0x40(%rsp), %rdi
movq 0x68(%rsp), %rsi
movq 0x58(%rsp), %rdx
movl 0x64(%rsp), %ecx
callq 0x21c0
movl %eax, %ecx
movq 0x40(%rsp), %rax
movl %ecx, 0x410(%rax)
movq 0x40(%rsp), %rdi
movq 0x68(%rsp), %rsi
callq 0x20f0
movq 0x40(%rsp), %rax
cmpl $0x0, 0x420(%rax)
je 0x896e
movl $0x0, 0xa0(%rsp)
cmpl $0x100, 0xa0(%rsp) # imm = 0x100
jge 0x896c
movq 0x40(%rsp), %rax
movq 0x418(%rax), %rax
movslq 0xa0(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x8957
movl 0xa0(%rsp), %eax
movb %al, %cl
movq 0x40(%rsp), %rax
movb %cl, 0x428(%rax)
jmp 0x8959
movl 0xa0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa0(%rsp)
jmp 0x891c
jmp 0x896e
movq 0x40(%rsp), %rax
cmpl $-0x1, 0x410(%rax)
jne 0x8990
movq 0x40(%rsp), %rax
movl $0x4, 0x424(%rax)
jmp 0x8a1a
movq 0x40(%rsp), %rax
cmpl $0x0, 0x410(%rax)
je 0x89b8
movq 0x40(%rsp), %rax
movl 0x410(%rax), %eax
movq 0x40(%rsp), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
je 0x89e8
movq 0x40(%rsp), %rax
cmpl $0x0, 0x420(%rax)
je 0x89d7
movq 0x40(%rsp), %rax
movl $0x0, 0x424(%rax)
jmp 0x89e6
movq 0x40(%rsp), %rax
movl $0x1, 0x424(%rax)
jmp 0x8a18
movq 0x40(%rsp), %rax
cmpl $0x0, 0x420(%rax)
je 0x8a07
movq 0x40(%rsp), %rax
movl $0x2, 0x424(%rax)
jmp 0x8a16
movq 0x40(%rsp), %rax
movl $0x3, 0x424(%rax)
jmp 0x8a18
jmp 0x8a1a
movl 0xa4(%rsp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x8b8d
movl $0x0, 0xa0(%rsp)
movl 0xa0(%rsp), %eax
movq 0x40(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x8b8b
movq 0x40(%rsp), %rax
movq (%rax), %rax
movslq 0xa0(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $-0x3, (%rax)
jne 0x8b73
movl $0x61, 0x9c(%rsp)
cmpl $0x7a, 0x9c(%rsp)
jg 0x8aef
movq 0x40(%rsp), %rax
movq (%rax), %rax
movslq 0xa0(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq 0x28(%rax), %rax
movslq 0x9c(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x8ada
movq 0x40(%rsp), %rax
movq (%rax), %rax
movslq 0xa0(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq 0x28(%rax), %rax
movl 0x9c(%rsp), %ecx
subl $0x20, %ecx
movslq %ecx, %rcx
movl $0x1, (%rax,%rcx,4)
jmp 0x8adc
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x8a78
movl $0x41, 0x9c(%rsp)
cmpl $0x5a, 0x9c(%rsp)
jg 0x8b71
movq 0x40(%rsp), %rax
movq (%rax), %rax
movslq 0xa0(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq 0x28(%rax), %rax
movslq 0x9c(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x8b5c
movq 0x40(%rsp), %rax
movq (%rax), %rax
movslq 0xa0(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq 0x28(%rax), %rax
movl 0x9c(%rsp), %ecx
addl $0x20, %ecx
movslq %ecx, %rcx
movl $0x1, (%rax,%rcx,4)
jmp 0x8b5e
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x8afa
jmp 0x8b73
jmp 0x8b75
movl 0xa0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa0(%rsp)
jmp 0x8a38
jmp 0x8b8d
movl 0xa4(%rsp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x8bce
movq 0x40(%rsp), %rax
movq $0x0, 0x440(%rax)
movq 0x40(%rsp), %rax
movq $0x0, 0x448(%rax)
movq 0x40(%rsp), %rax
movq $0x0, 0x450(%rax)
jmp 0x8c32
movq 0x40(%rsp), %rax
movslq 0x8(%rax), %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x440(%rax)
movq 0x40(%rsp), %rax
movslq 0x8(%rax), %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x448(%rax)
movq 0x40(%rsp), %rax
movslq 0x8(%rax), %rdi
movl $0x4, %esi
callq 0x21d0
movq %rax, %rcx
movq 0x40(%rsp), %rax
movq %rcx, 0x450(%rax)
movq 0x40(%rsp), %rax
cmpl $0x0, 0x410(%rax)
jle 0x8c8f
movq 0x40(%rsp), %rax
movl 0x410(%rax), %eax
movq 0x38(%rsp), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x8c8f
movq 0x40(%rsp), %rax
cmpl $0x0, 0x424(%rax)
je 0x8c76
movq 0x40(%rsp), %rax
cmpl $0x1, 0x424(%rax)
jne 0x8c8d
movq 0x40(%rsp), %rdi
callq 0x20d0
movl %eax, %ecx
movq 0x40(%rsp), %rax
movl %ecx, 0x864(%rax)
jmp 0x8c8f
movq 0x40(%rsp), %rax
movl $0x0, 0x868(%rax)
movl $0x0, 0xa0(%rsp)
movl 0xa0(%rsp), %eax
movq 0x40(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jge 0x8d6b
movl $0x0, 0x9c(%rsp)
movl 0x9c(%rsp), %eax
movq 0x40(%rsp), %rcx
movq (%rcx), %rcx
movslq 0xa0(%rsp), %rdx
shlq $0x6, %rdx
addq %rdx, %rcx
cmpl 0x10(%rcx), %eax
jge 0x8d53
movq 0x40(%rsp), %rax
movq (%rax), %rax
movslq 0xa0(%rsp), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movslq 0x9c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
cmpl 0xa0(%rsp), %eax
jg 0x8d3b
movq 0x40(%rsp), %rax
movl $0x1, 0x868(%rax)
movq 0x40(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, 0xa0(%rsp)
jmp 0x8d53
jmp 0x8d3d
movl 0x9c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x9c(%rsp)
jmp 0x8cc9
jmp 0x8d55
movl 0xa0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xa0(%rsp)
jmp 0x8ca9
movq 0x68(%rsp), %rdi
callq 0x2070
movq 0x58(%rsp), %rdi
callq 0x2070
movq 0x70(%rsp), %rdi
callq 0x2070
movq $0x0, 0x68(%rsp)
movq $0x0, 0x58(%rsp)
movq $0x0, 0x70(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
addq $0xb8, %rsp
retq
nopw %cs:(%rax,%rax)