// File: /workspace/github_c_makefile_star2_O3/jondurbin[P]dre2/src/dre2_parse.c
// Function: dre2_strip_groups
void dre2_strip_groups( struct dre2 *graph, struct dre2 *new_graph, struct dre2_node **new_nodes, int *minimal, int **new_minimal, int *new_minimal_count, int **minimal_id )
{
  int i, j, k;
  struct dre2_node *nodes, *node;
  int node_count;
  int removed, offset;
  int *reachable, *visited, *temp_minimal;
  int *min_reachable, *min_visited;

  // Allocate some memory.
  reachable = ( int * )malloc( sizeof( int ) * graph->count );
  visited = ( int * )malloc( sizeof( int ) * graph->count );
  temp_minimal = ( int * )malloc( sizeof( int ) );
  min_reachable = ( int * )malloc( sizeof( int ) * graph->count );
  min_visited = ( int * )malloc( sizeof( int ) * graph->count );

  for ( i = 0; i < graph->count; i++ )
    ( *new_minimal )[i] = false;

  node_count = 0;
  *new_minimal_count = 0;
  for ( i = 0; i < graph->count; i++ )
  {
    // Initialize reachable nodes to all false.
    for ( j = 0; j < graph->count; j++ )
    {
      reachable[j] = false;
      visited[j] = false;
      min_reachable[j] = false;
      min_visited[j] = false;
    }
    dre2_reachable( graph, &reachable, &visited, i );
    dre2_min_reachable( graph, &min_reachable, &min_visited, i );

    if ( ( graph->v[i].c != DRE2_GROUP_OPEN && graph->v[i].c != DRE2_GROUP_CLOSE ) || ( i == 0 || i == graph->count - 1 ) )
    {
      // Add node to our min tree.
      dre2_add_node( new_nodes, &node_count, graph->v[i].c, &temp_minimal, true );

      ( *new_nodes )[node_count - 1].min_n_count = 0;
      ( *new_nodes )[node_count - 1].min_n = NULL;
      if ( minimal[i] )
      {
        ( *new_minimal )[node_count - 1] = true;
        *new_minimal_count = *new_minimal_count + 1;
        ( *minimal_id )[*new_minimal_count - 1] = node_count - 1;
      }
      graph->v[i].min_id = node_count - 1;
      if ( graph->v[i].c == DRE2_CHAR_CLASS )
      {
        for ( j = 0; j < RANGE; j++ )
          ( *new_nodes )[node_count - 1].possible[j] = graph->v[i].possible[j];
      }

      // Find the reachable nodes.
      for ( j = 0; j < graph->count; j++ )
      {
        if ( reachable[j] )
          dre2_add_neighbor( new_nodes, node_count - 1, j );
        if ( min_reachable[j] && minimal[j] )
        {
          ( *new_nodes )[node_count - 1].min_n_count++;
          if ( ( *new_nodes )[node_count - 1].min_n == NULL )
            ( *new_nodes )[node_count - 1].min_n = ( int * )malloc( sizeof( int ) * graph->count );
          ( *new_nodes )[node_count - 1].min_n[( *new_nodes )[node_count - 1].min_n_count - 1] = j;
        }
      }
    }
  }

  // Update the node IDs.
  for ( i = 0; i < node_count; i++ )
  {
    for ( j = 0; j < ( *new_nodes )[i].n_count; j++ )
      ( *new_nodes )[i].n[j] = graph->v[( *new_nodes )[i].n[j]].min_id;
  }

  for ( i = 0; i < *new_minimal_count; i++ )
  {
    for ( j = 0; j < ( *new_nodes )[( *minimal_id )[i]].min_n_count; j++ )
      ( *new_nodes )[( *minimal_id )[i]].min_n[j] = graph->v[( *new_nodes )[( *minimal_id )[i]].min_n[j]].min_id;
  }

  // Setup the minimized graph.
  new_graph->count = node_count;

  // Free the temp reachable nodes array.
  free( reachable );
  free( visited );
  free( temp_minimal );
  free( min_reachable );
  free( min_visited );

  // Set them all to null.
  reachable = NULL;
  visited = NULL;
  temp_minimal = NULL;
  min_reachable = NULL;
  min_visited = NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, 0x10(%rsp)
movq %r8, 0x28(%rsp)
movq %rcx, 0x50(%rsp)
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %r12
movq 0xc0(%rsp), %rax
movq %rax, 0x20(%rsp)
movslq 0x8(%rdi), %r14
leaq (,%r14,4), %rbx
movq %rbx, %rdi
callq 0x22a0
movq %rax, 0x48(%rsp)
movq %rax, 0x80(%rsp)
movq %rbx, %rdi
callq 0x22a0
movq %rax, 0x38(%rsp)
movq %rax, 0x78(%rsp)
movl $0x4, %edi
callq 0x22a0
movq %rax, 0x58(%rsp)
movq %rbx, %rdi
callq 0x22a0
movq %rax, 0x18(%rsp)
movq %rax, 0x70(%rsp)
movq %rbx, %rdi
callq 0x22a0
movq %rax, 0x30(%rsp)
movq %rax, 0x68(%rsp)
testq %r14, %r14
jle 0x3eff
movq 0x28(%rsp), %rax
movq (%rax), %rax
xorl %ecx, %ecx
movl $0x0, (%rax,%rcx,4)
incq %rcx
movslq 0x8(%r12), %rdx
cmpq %rdx, %rcx
jl 0x3eeb
xorl %ecx, %ecx
movl %ecx, 0xc(%rsp)
movq 0x10(%rsp), %rax
movl %ecx, (%rax)
movl 0x8(%r12), %eax
testl %eax, %eax
movq 0x48(%rsp), %r14
jle 0x4204
movq %r15, 0x60(%rsp)
movq $0x0, (%rsp)
xorl %ebp, %ebp
testl %eax, %eax
jle 0x3f71
movl %eax, %ebx
shlq $0x2, %rbx
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x2180
movq 0x38(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x2180
movq 0x18(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x2180
movq 0x30(%rsp), %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x2180
movq %r12, %rdi
leaq 0x80(%rsp), %rsi
leaq 0x78(%rsp), %rdx
movl %ebp, %ecx
callq 0x21c0
movq %r12, %rdi
leaq 0x70(%rsp), %rsi
leaq 0x68(%rsp), %rdx
movl %ebp, %ecx
callq 0x2060
movq (%r12), %rax
movq %rbp, %r15
shlq $0x6, %r15
movl (%rax,%r15), %edx
cmpl $-0x1, %edx
je 0x3fc2
cmpl $-0x2, %edx
setne %al
testq %rbp, %rbp
sete %cl
orb %al, %cl
je 0x3fc7
jmp 0x3fd8
testq %rbp, %rbp
je 0x3fd8
movl 0x8(%r12), %eax
leal -0x1(%rax), %ecx
cmpq %rcx, %rbp
jne 0x4125
movq %r13, %rdi
leaq 0xc(%rsp), %rsi
leaq 0x58(%rsp), %rcx
movl $0x1, %r8d
callq 0x20b0
movq (%r13), %rax
movl 0xc(%rsp), %ecx
movq %rbp, %rdx
movslq %ecx, %rbp
movq %rbp, %rbx
shlq $0x6, %rbx
movl $0x0, -0x8(%rax,%rbx)
movq $0x0, -0x10(%rax,%rbx)
movq 0x50(%rsp), %rax
movq %rdx, 0x40(%rsp)
cmpl $0x0, (%rax,%rdx,4)
movq %rcx, (%rsp)
je 0x4056
movq 0x28(%rsp), %rax
movq (%rax), %rax
movl $0x1, -0x4(%rax,%rbp,4)
movq 0x10(%rsp), %rdx
movslq (%rdx), %rax
leal 0x1(%rax), %ecx
movl %ecx, (%rdx)
decl %ebp
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
movl %ebp, (%rcx,%rax,4)
jmp 0x4059
leal -0x1(%rcx), %ebp
movq (%r12), %rax
movl %ebp, 0x24(%rax,%r15)
cmpl $-0x3, (%rax,%r15)
jne 0x408b
movq 0x28(%rax,%r15), %rax
movq (%r13), %rcx
movq -0x18(%rcx,%rbx), %rcx
xorl %edx, %edx
movl (%rax,%rdx,4), %esi
movl %esi, (%rcx,%rdx,4)
incq %rdx
cmpq $0x100, %rdx            # imm = 0x100
jne 0x4079
movl 0x8(%r12), %eax
testl %eax, %eax
jle 0x4120
xorl %r15d, %r15d
cmpl $0x0, (%r14,%r15,4)
je 0x40af
movq %r13, %rdi
movl %ebp, %esi
movl %r15d, %edx
callq 0x21d0
movq 0x18(%rsp), %rax
cmpl $0x0, (%rax,%r15,4)
je 0x410f
movq 0x50(%rsp), %rax
cmpl $0x0, (%rax,%r15,4)
je 0x410f
movq (%r13), %r14
movl -0x8(%r14,%rbx), %eax
incl %eax
movl %eax, -0x8(%r14,%rbx)
movq -0x10(%r14,%rbx), %rcx
testq %rcx, %rcx
jne 0x4103
addq %rbx, %r14
movslq 0x8(%r12), %rdi
shlq $0x2, %rdi
callq 0x22a0
movq %rax, -0x10(%r14)
movq (%r13), %rax
movq -0x10(%rax,%rbx), %rcx
movl -0x8(%rax,%rbx), %eax
cltq
movl %r15d, -0x4(%rcx,%rax,4)
movq 0x48(%rsp), %r14
incq %r15
movslq 0x8(%r12), %rax
cmpq %rax, %r15
jl 0x409b
movq 0x40(%rsp), %rbp
incq %rbp
movslq %eax, %rcx
cmpq %rcx, %rbp
jl 0x3f2d
cmpl $0x0, (%rsp)
movq 0x60(%rsp), %r15
jle 0x4189
movq (%r13), %rax
movl (%rsp), %ecx
xorl %edx, %edx
movq %rdx, %rsi
shlq $0x6, %rsi
cmpl $0x0, 0x10(%rax,%rsi)
jle 0x4181
addq %rax, %rsi
movq (%r12), %rdi
movq 0x8(%rsi), %r8
xorl %r9d, %r9d
movslq (%r8,%r9,4), %r10
shlq $0x6, %r10
movl 0x24(%rdi,%r10), %r10d
movl %r10d, (%r8,%r9,4)
incq %r9
movslq 0x10(%rsi), %r10
cmpq %r10, %r9
jl 0x4164
incq %rdx
cmpq %rcx, %rdx
jne 0x4148
movq 0x10(%rsp), %rax
movl (%rax), %esi
testl %esi, %esi
jle 0x4200
movq (%r13), %rax
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
xorl %edx, %edx
movslq (%rcx,%rdx,4), %rdi
movq %rdi, %r8
shlq $0x6, %r8
cmpl $0x0, 0x38(%rax,%r8)
jle 0x41f5
movq (%r12), %rsi
xorl %r8d, %r8d
shlq $0x6, %rdi
movq 0x30(%rax,%rdi), %rdi
movslq (%rdi,%r8,4), %r9
shlq $0x6, %r9
movl 0x24(%rsi,%r9), %r9d
movl %r9d, (%rdi,%r8,4)
incq %r8
movslq (%rcx,%rdx,4), %rdi
movq %rdi, %r9
shlq $0x6, %r9
movslq 0x38(%rax,%r9), %r9
cmpq %r9, %r8
jl 0x41bc
movq 0x10(%rsp), %rsi
movl (%rsi), %esi
incq %rdx
movslq %esi, %rdi
cmpq %rdi, %rdx
jl 0x41a2
movq (%rsp), %rcx
movl %ecx, 0x8(%r15)
movq %r14, %rdi
callq 0x2070
movq 0x38(%rsp), %rdi
callq 0x2070
movq 0x58(%rsp), %rdi
callq 0x2070
movq 0x18(%rsp), %rdi
callq 0x2070
movq 0x30(%rsp), %rdi
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2070