// File: /workspace/github_c_makefile_star2_O0/jondurbin[P]dre2/src/dre2_parse.c
// Function: dre2_best_choice
int dre2_best_choice( struct dre2 *graph, int *required, int count )
{
  int i, j;
  int temp;
  int *ids, *cost;
  int best;
  int literal;

  ids = ( int * )malloc( sizeof( int ) * count );
  cost = ( int * )malloc( sizeof( int ) * count );

  literal = false;
  for ( i = 0; i < count; i++ )
  {
    ids[i] = required[i];
    cost[i] = required[i] == 0 || required[i] == graph->count - 1 ? 100000 : dre2_node_cost( graph, required[i] );
    if ( graph->v[required[i]].c >= 0 )
      literal = true;
  }

  for ( i = 0; i < count - 1; i++ )
  {
    for ( j = i + 1; j < count; j++ )
    {
      if ( cost[i] > cost[j] || ( cost[i] == cost[j] && ids[i] < ids[j] ) )
      {
        temp = cost[i];
        cost[i] = cost[j];
        cost[j] = temp;
        temp = ids[i];
        ids[i] = ids[j];
        ids[j] = temp;
      }
    }
  }
  best = ids[0];

  if ( graph->options & DRE2_GREEDY && !literal && dre2_contains_int( required, count, graph->count - 2 ) )
    best = graph->count - 2;

  free( cost );
  free( ids );
  cost = NULL;
  ids = NULL;

  return best;
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movl %edx, 0x34(%rsp)
movslq 0x34(%rsp), %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, 0x20(%rsp)
movslq 0x34(%rsp), %rdi
shlq $0x2, %rdi
callq 0x2280
movq %rax, 0x18(%rsp)
movl $0x0, 0x10(%rsp)
movl $0x0, 0x30(%rsp)
movl 0x30(%rsp), %eax
cmpl 0x34(%rsp), %eax
jge 0x39af
movq 0x38(%rsp), %rax
movslq 0x30(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x20(%rsp), %rax
movslq 0x30(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x38(%rsp), %rax
movslq 0x30(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x393c
movq 0x38(%rsp), %rax
movslq 0x30(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movq 0x40(%rsp), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x3947
movl $0x186a0, %eax          # imm = 0x186A0
movl %eax, 0xc(%rsp)
jmp 0x3962
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rax
movslq 0x30(%rsp), %rcx
movl (%rax,%rcx,4), %esi
callq 0x2030
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %edx
movq 0x18(%rsp), %rax
movslq 0x30(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x40(%rsp), %rax
movq (%rax), %rax
movq 0x38(%rsp), %rcx
movslq 0x30(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
shlq $0x6, %rcx
addq %rcx, %rax
cmpl $0x0, (%rax)
jl 0x399d
movl $0x1, 0x10(%rsp)
jmp 0x399f
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x38e8
movl $0x0, 0x30(%rsp)
movl 0x30(%rsp), %eax
movl 0x34(%rsp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0x3ad7
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x34(%rsp), %eax
jge 0x3ac5
movq 0x18(%rsp), %rax
movslq 0x30(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movq 0x18(%rsp), %rcx
movslq 0x2c(%rsp), %rdx
cmpl (%rcx,%rdx,4), %eax
jg 0x3a3b
movq 0x18(%rsp), %rax
movslq 0x30(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movq 0x18(%rsp), %rcx
movslq 0x2c(%rsp), %rdx
cmpl (%rcx,%rdx,4), %eax
jne 0x3ab3
movq 0x20(%rsp), %rax
movslq 0x30(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movq 0x20(%rsp), %rcx
movslq 0x2c(%rsp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x3ab3
movq 0x18(%rsp), %rax
movslq 0x30(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x28(%rsp)
movq 0x18(%rsp), %rax
movslq 0x2c(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x18(%rsp), %rax
movslq 0x30(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x28(%rsp), %edx
movq 0x18(%rsp), %rax
movslq 0x2c(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x20(%rsp), %rax
movslq 0x30(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x28(%rsp)
movq 0x20(%rsp), %rax
movslq 0x2c(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x20(%rsp), %rax
movslq 0x30(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x28(%rsp), %edx
movq 0x20(%rsp), %rax
movslq 0x2c(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x3ab5
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
jmp 0x39d5
jmp 0x3ac7
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x39b7
movq 0x20(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x14(%rsp)
movq 0x40(%rsp), %rax
movl 0x43c(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x3b29
cmpl $0x0, 0x10(%rsp)
jne 0x3b29
movq 0x38(%rsp), %rdi
movl 0x34(%rsp), %esi
movq 0x40(%rsp), %rax
movl 0x8(%rax), %edx
subl $0x2, %edx
callq 0x2310
cmpl $0x0, %eax
je 0x3b29
movq 0x40(%rsp), %rax
movl 0x8(%rax), %eax
subl $0x2, %eax
movl %eax, 0x14(%rsp)
movq 0x18(%rsp), %rdi
callq 0x2070
movq 0x20(%rsp), %rdi
callq 0x2070
movq $0x0, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movl 0x14(%rsp), %eax
addq $0x48, %rsp
retq
nopl (%rax,%rax)