// File: /workspace/github_c_makefile_star2_O0/jondurbin[P]dre2/src/dre2_parse.c
// Function: dre2_starting_point
int dre2_starting_point( struct dre2 *graph, int *minimal, int *minimal_id, int minimal_count )
{
  int i, j, k, l, m;
  int min_iter, iter;
  int id, all, found, temp;
  int *required;
  int required_count;
  int best;
  int **found_in, *found_in_count, *found_in_id;
  int *swapper;
  int *remaining;
  int largest, last_largest;
  struct dre2_path *paths;
  int path_count;
  struct dre2_fl_cost cost;

  // First, check if the first or last node is acceptable.
  cost = dre2_first_or_last_cost( graph, minimal );

  // Initialize paths.
  path_count = 1;
  paths = ( struct dre2_path * )malloc( sizeof( struct dre2_path ) );
  paths[0].nodes = ( int * )malloc( sizeof( int ) * graph->count );
  paths[0].count = 1;
  paths[0].nodes[0] = 0;

  graph->starting_points = ( int * )malloc( sizeof( int ) * graph->count );
  graph->starting_count = 0;

  // Recursively find paths through the minimal graph.
  dre2_find_paths_recursive( graph, 0, &path_count, &paths );
  required = NULL;
  for ( i = 0; i < path_count; i++ )
  {
    best = dre2_best_choice( graph, paths[i].nodes, paths[i].count );
    if ( !dre2_contains_int( graph->starting_points, graph->starting_count, best ) )
      graph->starting_points[graph->starting_count++] = best;
  }

  // Allocate some memory.
  found_in = ( int ** )malloc( sizeof( int * ) * ( minimal_count - 2 ) );
  found_in_count = ( int * )malloc( sizeof( int ) * ( minimal_count - 2 ) );
  found_in_id = ( int * )malloc( sizeof( int ) * ( minimal_count - 2 ) );
  remaining = ( int * )malloc( sizeof( int ) * ( minimal_count - 2 ) );

  for ( i = 0; i < minimal_count - 2; i++ )
  {
    found_in_count[i] = 0;
    found_in[i] = ( int * )malloc( sizeof( int ) * path_count );
    found_in_id[i] = minimal_id[i + 1];
  }

  best = -1;
  if ( path_count == 1 && paths[0].count > 2 )
  {
    required_count = 0;
    required = ( int * )malloc( sizeof( int ) * graph->count );
    for ( i = 1; i < paths[0].count -1; i++ )
    {
      switch ( graph->v[paths[0].nodes[i]].c )
      {
        case DRE2_BOL:
        case DRE2_EOL:
        case DRE2_EOF:
          break;
        default:
          required[required_count++] = paths[0].nodes[i];
          break;
      }
    }
    if ( required_count > 0 )
      best = dre2_best_choice( graph, required, required_count );
    goto INITIAL_CLEANUP;
  } else if ( path_count > 1 )
  {
    required_count = 0;
    required = ( int * )malloc( sizeof( int ) * graph->count );
    for ( i = 1; i < minimal_count - 1; i++ )
    {
      all = true;
      id = minimal_id[i];
      switch ( graph->v[id].c )
      {
        case DRE2_BOL:
        case DRE2_EOL:
        case DRE2_EOF:
          break;
        default:
          for ( j = 0; j < path_count; j++ )
          {
            if ( !dre2_binsearch( paths[j].nodes, 0, paths[j].count - 1, id ) )
            {
              all = false;
            } else
            {
              found_in_count[i - 1]++;
              found_in[i - 1][found_in_count[i - 1] - 1] = j;
            }
          }
          if ( all )
            required[required_count++] = id;
          break;
      }
    }
    if ( required_count > 0 )
    {
      best = dre2_best_choice( graph, required, required_count );
      goto INITIAL_CLEANUP;
    }
  }

  best = dre2_first_or_last( graph, &cost );

  INITIAL_CLEANUP:
  if ( path_count > 1 && dre2_use_paths( graph, best, &cost ) )
    best = -1;

  if ( required != NULL )
  {
    free( required ); required = NULL;
  }

  for ( i = 0; i < path_count; i++ )
  {
    free( paths[i].nodes );
    paths[i].nodes = NULL;
  }
  for ( i = 0; i < minimal_count - 2; i++ )
  {
    free( found_in[i] ); found_in[i] = NULL;
  }
  free( found_in ); found_in = NULL;
  free( found_in_count ); found_in_count = NULL;
  free( found_in_id ); found_in_id = NULL;
  free( remaining ); remaining = NULL;
  free( paths ); paths = NULL;

  return best;
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xd0(%rsp)
movq %rsi, 0xc8(%rsp)
movq %rdx, 0xc0(%rsp)
movl %ecx, 0xbc(%rsp)
movq 0xd0(%rsp), %rsi
movq 0xc8(%rsp), %rdx
leaq 0x14(%rsp), %rdi
callq 0x22f0
movq 0x14(%rsp), %rax
movq %rax, 0x2c(%rsp)
movq 0x1c(%rsp), %rax
movq %rax, 0x34(%rsp)
movq 0x24(%rsp), %rax
movq %rax, 0x3c(%rsp)
movl $0x1, 0x44(%rsp)
movl $0x10, %edi
callq 0x2280
movq %rax, 0x48(%rsp)
movq 0xd0(%rsp), %rax
movslq 0x8(%rax), %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, %rcx
movq 0x48(%rsp), %rax
movq %rcx, (%rax)
movq 0x48(%rsp), %rax
movl $0x1, 0x8(%rax)
movq 0x48(%rsp), %rax
movq (%rax), %rax
movl $0x0, (%rax)
movq 0xd0(%rsp), %rax
movslq 0x8(%rax), %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, %rcx
movq 0xd0(%rsp), %rax
movq %rcx, 0x430(%rax)
movq 0xd0(%rsp), %rax
movl $0x0, 0x438(%rax)
movq 0xd0(%rsp), %rdi
xorl %esi, %esi
leaq 0x44(%rsp), %rdx
leaq 0x48(%rsp), %rcx
callq 0x22a0
movq $0x0, 0x88(%rsp)
movl $0x0, 0xb8(%rsp)
movl 0xb8(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x43e6
movq 0xd0(%rsp), %rdi
movq 0x48(%rsp), %rax
movslq 0xb8(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
movq 0x48(%rsp), %rax
movslq 0xb8(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
callq 0x2180
movl %eax, 0x80(%rsp)
movq 0xd0(%rsp), %rax
movq 0x430(%rax), %rdi
movq 0xd0(%rsp), %rax
movl 0x438(%rax), %esi
movl 0x80(%rsp), %edx
callq 0x2310
cmpl $0x0, %eax
jne 0x43ce
movl 0x80(%rsp), %edx
movq 0xd0(%rsp), %rax
movq 0x430(%rax), %rax
movq 0xd0(%rsp), %rsi
movl 0x438(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x438(%rsi)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x43d0
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x4318
movl 0xbc(%rsp), %eax
subl $0x2, %eax
movslq %eax, %rdi
shlq $0x3, %rdi
callq 0x2280
movq %rax, 0x78(%rsp)
movl 0xbc(%rsp), %eax
subl $0x2, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, 0x70(%rsp)
movl 0xbc(%rsp), %eax
subl $0x2, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, 0x68(%rsp)
movl 0xbc(%rsp), %eax
subl $0x2, %eax
movslq %eax, %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, 0x58(%rsp)
movl $0x0, 0xb8(%rsp)
movl 0xb8(%rsp), %eax
movl 0xbc(%rsp), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jge 0x44e6
movq 0x70(%rsp), %rax
movslq 0xb8(%rsp), %rcx
movl $0x0, (%rax,%rcx,4)
movslq 0x44(%rsp), %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, %rdx
movq 0x78(%rsp), %rax
movslq 0xb8(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0xc0(%rsp), %rax
movl 0xb8(%rsp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq 0x68(%rsp), %rax
movslq 0xb8(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x445d
movl $0xffffffff, 0x80(%rsp) # imm = 0xFFFFFFFF
cmpl $0x1, 0x44(%rsp)
jne 0x4617
movq 0x48(%rsp), %rax
cmpl $0x2, 0x8(%rax)
jle 0x4617
movl $0x0, 0x84(%rsp)
movq 0xd0(%rsp), %rax
movslq 0x8(%rax), %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, 0x88(%rsp)
movl $0x1, 0xb8(%rsp)
movl 0xb8(%rsp), %eax
movq 0x48(%rsp), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x45e5
movq 0xd0(%rsp), %rax
movq (%rax), %rax
movq 0x48(%rsp), %rcx
movq (%rcx), %rcx
movslq 0xb8(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
shlq $0x6, %rcx
movl (%rax,%rcx), %eax
movl %eax, 0x10(%rsp)
addl $0x12, %eax
subl $0x2, %eax
jb 0x4597
jmp 0x458c
movl 0x10(%rsp), %eax
subl $-0x4, %eax
jne 0x4599
jmp 0x4597
jmp 0x45cd
movq 0x48(%rsp), %rax
movq (%rax), %rax
movslq 0xb8(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x88(%rsp), %rax
movl 0x84(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x84(%rsp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x45cf
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x453e
cmpl $0x0, 0x84(%rsp)
jle 0x4612
movq 0xd0(%rsp), %rdi
movq 0x88(%rsp), %rsi
movl 0x84(%rsp), %edx
callq 0x2180
movl %eax, 0x80(%rsp)
jmp 0x483e
cmpl $0x1, 0x44(%rsp)
jle 0x4823
movl $0x0, 0x84(%rsp)
movq 0xd0(%rsp), %rax
movslq 0x8(%rax), %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, 0x88(%rsp)
movl $0x1, 0xb8(%rsp)
movl 0xb8(%rsp), %eax
movl 0xbc(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x47f2
movl $0x1, 0x98(%rsp)
movq 0xc0(%rsp), %rax
movslq 0xb8(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x9c(%rsp)
movq 0xd0(%rsp), %rax
movq (%rax), %rax
movslq 0x9c(%rsp), %rcx
shlq $0x6, %rcx
movl (%rax,%rcx), %eax
movl %eax, 0xc(%rsp)
addl $0x12, %eax
subl $0x2, %eax
jb 0x46c6
jmp 0x46bb
movl 0xc(%rsp), %eax
subl $-0x4, %eax
jne 0x46cb
jmp 0x46c6
jmp 0x47da
movl $0x0, 0xb4(%rsp)
movl 0xb4(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x47a6
movq 0x48(%rsp), %rax
movslq 0xb4(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
movq 0x48(%rsp), %rax
movslq 0xb4(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
subl $0x1, %edx
movl 0x9c(%rsp), %ecx
xorl %esi, %esi
callq 0x22d0
cmpl $0x0, %eax
jne 0x4738
movl $0x0, 0x98(%rsp)
jmp 0x478e
movq 0x70(%rsp), %rax
movl 0xb8(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl 0xb4(%rsp), %edx
movq 0x78(%rsp), %rax
movl 0xb8(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq 0x70(%rsp), %rcx
movl 0xb8(%rsp), %esi
subl $0x1, %esi
movslq %esi, %rsi
movl (%rcx,%rsi,4), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x4790
movl 0xb4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb4(%rsp)
jmp 0x46d6
cmpl $0x0, 0x98(%rsp)
je 0x47d8
movl 0x9c(%rsp), %edx
movq 0x88(%rsp), %rax
movl 0x84(%rsp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x84(%rsp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x47da
jmp 0x47dc
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x4655
cmpl $0x0, 0x84(%rsp)
jle 0x4821
movq 0xd0(%rsp), %rdi
movq 0x88(%rsp), %rsi
movl 0x84(%rsp), %edx
callq 0x2180
movl %eax, 0x80(%rsp)
jmp 0x483e
jmp 0x4823
jmp 0x4825
movq 0xd0(%rsp), %rdi
leaq 0x2c(%rsp), %rsi
callq 0x2360
movl %eax, 0x80(%rsp)
cmpl $0x1, 0x44(%rsp)
jle 0x486e
movq 0xd0(%rsp), %rdi
movl 0x80(%rsp), %esi
leaq 0x2c(%rsp), %rdx
callq 0x2110
cmpl $0x0, %eax
je 0x486e
movl $0xffffffff, 0x80(%rsp) # imm = 0xFFFFFFFF
cmpq $0x0, 0x88(%rsp)
je 0x4892
movq 0x88(%rsp), %rdi
callq 0x2070
movq $0x0, 0x88(%rsp)
movl $0x0, 0xb8(%rsp)
movl 0xb8(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x48f4
movq 0x48(%rsp), %rax
movslq 0xb8(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x2070
movq 0x48(%rsp), %rax
movslq 0xb8(%rsp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq $0x0, (%rax)
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x489d
movl $0x0, 0xb8(%rsp)
movl 0xb8(%rsp), %eax
movl 0xbc(%rsp), %ecx
subl $0x2, %ecx
cmpl %ecx, %eax
jge 0x4952
movq 0x78(%rsp), %rax
movslq 0xb8(%rsp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x2070
movq 0x78(%rsp), %rax
movslq 0xb8(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
movl 0xb8(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xb8(%rsp)
jmp 0x48ff
movq 0x78(%rsp), %rdi
callq 0x2070
movq $0x0, 0x78(%rsp)
movq 0x70(%rsp), %rdi
callq 0x2070
movq $0x0, 0x70(%rsp)
movq 0x68(%rsp), %rdi
callq 0x2070
movq $0x0, 0x68(%rsp)
movq 0x58(%rsp), %rdi
callq 0x2070
movq $0x0, 0x58(%rsp)
movq 0x48(%rsp), %rdi
callq 0x2070
movq $0x0, 0x48(%rsp)
movl 0x80(%rsp), %eax
addq $0xd8, %rsp
retq