// File: pollo[P]graph-partitioning/partitioners.cpp
// Function: non_neighbors_greedy(Graph const&, int, Partition*)
void non_neighbors_greedy(const Graph& graph,
                          int partitions_number,
                          Partition* partition)
{
  vector<int> nodes;
  vector<int> partition_score(partitions_number);

  //get random sorted nodes
  graph.get_nodes_randomly(&nodes);

  //initialize partitions
  partition->set_size(nodes.size(), partitions_number);

  for (vector<int>::iterator node = nodes.begin();
       node != nodes.end();
       ++node) {

    //initialize partitions score
    for (int i=0; i<partitions_number; i++)
      partition_score[i] = 0;

    //compute number of neighbors
    for (vector<int>::const_iterator neighbor =
           graph.get_neighbors(*node).begin();
         neighbor != graph.get_neighbors(*node).end();
         ++neighbor)
    {
      int neighbor_partition = partition->get_node_partition(*neighbor);
      if (neighbor_partition >= 0) {
        partition_score[neighbor_partition]++;
      }
    }

    //select partition with minimum non neighbors
    int selected_partition = -1;
    int nn = nodes.size() + 1;
    for (int i=0; i<partitions_number; i++)
    {
      int partition_nn = partition->get_partition_size(i) - partition_score[i];
      if (partition_nn < nn)
      {
        selected_partition = i;
        nn = partition_nn;
      }
    }

    //assign node to partition
    partition->set_node_partition(*node, selected_partition);
  }
}

// Assembly:
subq $0xf8, %rsp
movq %rdi, 0xf0(%rsp)
movl %esi, 0xec(%rsp)
movq %rdx, 0xe0(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x2a30
movslq 0xec(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0xaf(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x2a80
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
leaq 0xb0(%rsp), %rdi
callq 0xa290
jmp 0x9633
leaq 0xaf(%rsp), %rdi
callq 0x2cb0
movq 0xf0(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x32d0
jmp 0x9657
movq 0xe0(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x4560
movq 0x40(%rsp), %rdi
movl %eax, %esi
movl 0xec(%rsp), %edx
callq 0x80d0
jmp 0x9686
leaq 0xc8(%rsp), %rdi
callq 0x3e80
movq %rax, 0x90(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x3eb0
movq %rax, 0x88(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x6420
testb $0x1, %al
jne 0x96ce
jmp 0x9921
movl $0x0, 0x84(%rsp)
movl 0x84(%rsp), %eax
cmpl 0xec(%rsp), %eax
jge 0x9763
movslq 0x84(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x4100
movl $0x0, (%rax)
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x96d9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa0(%rsp)
movl %eax, 0x9c(%rsp)
leaq 0xaf(%rsp), %rdi
callq 0x2cb0
jmp 0x9943
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa0(%rsp)
movl %eax, 0x9c(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x2ad0
jmp 0x9943
movq 0xf0(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x5840
movq 0x30(%rsp), %rdi
movl (%rax), %esi
callq 0x3280
movq %rax, 0x38(%rsp)
jmp 0x9790
movq 0x38(%rsp), %rdi
callq 0x3f50
movq %rax, 0x78(%rsp)
movq 0xf0(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x5840
movq 0x20(%rsp), %rdi
movl (%rax), %esi
callq 0x3280
movq %rax, 0x28(%rsp)
jmp 0x97cc
movq 0x28(%rsp), %rdi
callq 0x3fc0
movq %rax, 0x70(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x3f80
testb $0x1, %al
jne 0x97f0
jmp 0x9852
movq 0xe0(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x3ff0
movq 0x10(%rsp), %rdi
movl (%rax), %esi
callq 0x81a0
movl %eax, 0x1c(%rsp)
jmp 0x9819
movl 0x1c(%rsp), %eax
movl %eax, 0x6c(%rsp)
cmpl $0x0, 0x6c(%rsp)
jl 0x9841
movslq 0x6c(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x4100
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x9843
leaq 0x78(%rsp), %rdi
callq 0x4540
jmp 0x979f
movl $0xffffffff, 0x68(%rsp) # imm = 0xFFFFFFFF
leaq 0xc8(%rsp), %rdi
callq 0x4560
addq $0x1, %rax
movl %eax, 0x64(%rsp)
movl $0x0, 0x60(%rsp)
movl 0x60(%rsp), %eax
cmpl 0xec(%rsp), %eax
jge 0x98e3
movq 0xe0(%rsp), %rdi
movl 0x60(%rsp), %esi
callq 0x81d0
movl %eax, 0xc(%rsp)
jmp 0x989b
movslq 0x60(%rsp), %rsi
leaq 0xb0(%rsp), %rdi
callq 0x4100
movq %rax, %rcx
movl 0xc(%rsp), %eax
subl (%rcx), %eax
movl %eax, 0x5c(%rsp)
movl 0x5c(%rsp), %eax
cmpl 0x64(%rsp), %eax
jge 0x98d4
movl 0x60(%rsp), %eax
movl %eax, 0x68(%rsp)
movl 0x5c(%rsp), %eax
movl %eax, 0x64(%rsp)
jmp 0x98d6
movl 0x60(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
jmp 0x9877
movq 0xe0(%rsp), %rax
movq %rax, (%rsp)
leaq 0x90(%rsp), %rdi
callq 0x5840
movq (%rsp), %rdi
movl (%rax), %esi
movl 0x68(%rsp), %edx
callq 0x8140
jmp 0x990d
jmp 0x990f
leaq 0x90(%rsp), %rdi
callq 0x5810
jmp 0x969b
leaq 0xb0(%rsp), %rdi
callq 0x2ad0
leaq 0xc8(%rsp), %rdi
callq 0x2ad0
addq $0xf8, %rsp
retq
leaq 0xc8(%rsp), %rdi
callq 0x2ad0
movq 0xa0(%rsp), %rdi
callq 0x2270
nopl (%rax)