// File: /workspace/github_cpp_makefile_star2_O3/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 $0x58, %rsp
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movslq %esi, %rsi
leaq 0x30(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x5010
leaq 0x10(%rsp), %rsi
movq %r14, %rdi
callq 0x2b10
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
shrq $0x2, %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x4158
movq 0x10(%rsp), %r15
cmpq 0x18(%rsp), %r15
je 0x4b73
movl %ebp, %eax
movq %rax, 0x50(%rsp)
leaq (,%rax,4), %rax
movq %rax, 0x48(%rsp)
movl %ebp, 0x2c(%rsp)
testl %ebp, %ebp
jle 0x4ac7
movq 0x30(%rsp), %rdi
xorl %esi, %esi
movq 0x48(%rsp), %rdx
callq 0x2100
movl (%r15), %esi
movq %r14, %rdi
callq 0x2af0
movq (%rax), %r12
movl (%r15), %esi
movq %r14, %rdi
callq 0x2af0
cmpq 0x8(%rax), %r12
je 0x4b06
movl (%r12), %esi
movq %rbx, %rdi
callq 0x41b4
testl %eax, %eax
js 0x4b00
movl %eax, %eax
movq 0x30(%rsp), %rcx
incl (%rcx,%rax,4)
addq $0x4, %r12
jmp 0x4ad5
testl %ebp, %ebp
jle 0x4b4c
movq 0x18(%rsp), %rbp
subq 0x10(%rsp), %rbp
shrq $0x2, %rbp
incl %ebp
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movq %rbx, %rdi
movl %r13d, %esi
callq 0x41c0
movq 0x30(%rsp), %rcx
subl (%rcx,%r13,4), %eax
cmpl %ebp, %eax
cmovll %r13d, %r12d
cmovll %eax, %ebp
incq %r13
cmpq %r13, 0x50(%rsp)
jne 0x4b23
jmp 0x4b52
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl (%r15), %esi
movq %rbx, %rdi
movl %r12d, %edx
callq 0x419e
addq $0x4, %r15
cmpq 0x18(%rsp), %r15
movl 0x2c(%rsp), %ebp
jne 0x4ab2
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x4b8a
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x4ba1
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x4bd9
jmp 0x4bbf
jmp 0x4bbf
jmp 0x4bbf
jmp 0x4bbf
jmp 0x4bbf
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x4bd9
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x4bf0
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x2280