// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %rbx
movl %esi, %r14d
movq %rdi, %r12
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movslq %esi, %rsi
leaq 0x30(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x4892
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x2a1c
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
shrq $0x2, %rsi
movq %rbx, %rdi
movl %r14d, %edx
callq 0x3f38
movq 0x10(%rsp), %r13
xorl %eax, %eax
testl %r14d, %r14d
cmovlel %eax, %r14d
movq %r12, 0x28(%rsp)
cmpq 0x18(%rsp), %r13
je 0x4508
movq 0x30(%rsp), %rax
xorl %ecx, %ecx
cmpq %rcx, %r14
je 0x446c
andl $0x0, (%rax,%rcx,4)
incq %rcx
jmp 0x445e
movl (%r13), %esi
movq %r12, %rdi
callq 0x2a00
movq (%rax), %r15
movl (%r13), %esi
movq %r12, %rdi
callq 0x2a00
cmpq 0x8(%rax), %r15
je 0x44ac
movl (%r15), %esi
movq %rbx, %rdi
callq 0x3f8e
testl %eax, %eax
js 0x44a6
movl %eax, %eax
movq 0x30(%rsp), %rcx
incl (%rcx,%rax,4)
addq $0x4, %r15
jmp 0x447b
movq 0x18(%rsp), %r15
subq 0x10(%rsp), %r15
shrq $0x2, %r15
incl %r15d
xorl %r12d, %r12d
pushq $-0x1
popq %rbp
cmpq %r12, %r14
je 0x44ec
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3f9a
movq 0x30(%rsp), %rcx
subl (%rcx,%r12,4), %eax
cmpl %r15d, %eax
cmovll %r12d, %ebp
cmovll %eax, %r15d
incq %r12
jmp 0x44c3
movl (%r13), %esi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x3f78
addq $0x4, %r13
movq 0x28(%rsp), %r12
jmp 0x444c
leaq 0x30(%rsp), %rdi
callq 0x27d4
leaq 0x10(%rsp), %rdi
callq 0x27d4
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x4547
jmp 0x453a
jmp 0x453a
jmp 0x453a
jmp 0x453a
jmp 0x453a
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x27d4
leaq 0x10(%rsp), %rdi
callq 0x27d4
movq %rbx, %rdi
callq 0x2280