// File: /workspace/github_cpp_makefile_star2_O1/pollo[P]graph-partitioning/partitioners.cpp
// Function: linear_deterministic_greedy(Graph const&, int, Partition*)
void linear_deterministic_greedy(const Graph& graph,
                                 int partitions_number,
                                 Partition* partition)
{
  vector<int> nodes;
  vector<double> 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 partitions score
    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]++;
      }
    }

    //weight partitions score
    for (int i=0; i<partitions_number; i++)
    {
      double C = ((double)nodes.size())/partitions_number;
      partition_score[i] *= 1 - partition->get_partition_size(i)/C;
    }

    //select best partition
    int selected_partition = -1;
    double score = 0;
    for (int i=0; i<partitions_number; i++)
    {
      if (partition_score[i] > score)
      {
        selected_partition = i;
        score = partition_score[i];
      }
      else if (partition_score[i] == score)
      {
        if (selected_partition == -1 ||
            partition->get_partition_size(i) <=
            partition->get_partition_size(selected_partition))
        {
          selected_partition = i;
        }
      }
    }

    //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 $0x68, %rsp
movq %rdx, %rbx
movq %rdi, %r12
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movl %esi, 0x8(%rsp)
movslq %esi, %rsi
leaq 0x38(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x4f82
leaq 0x10(%rsp), %rsi
movq %r12, %rdi
callq 0x2b1a
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
shrq $0x2, %rsi
movq %rbx, %rdi
movl 0x8(%rsp), %edx
callq 0x4150
movq 0x10(%rsp), %rbp
cmpq 0x18(%rsp), %rbp
je 0x4991
movl 0x8(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x60(%rsp)
movl %eax, %r14d
leaq (,%r14,8), %rax
movq %rax, 0x50(%rsp)
movq %r12, 0x58(%rsp)
cmpl $0x0, 0x8(%rsp)
jle 0x4832
movq 0x38(%rsp), %rdi
xorl %esi, %esi
movq 0x50(%rsp), %rdx
callq 0x2100
movl (%rbp), %esi
movq %r12, %rdi
callq 0x2afa
movq (%rax), %r15
movl (%rbp), %esi
movq %r12, %rdi
callq 0x2afa
cmpq 0x8(%rax), %r15
je 0x487f
movl (%r15), %esi
movq %rbx, %rdi
callq 0x41ac
testl %eax, %eax
js 0x4879
movl %eax, %eax
movq 0x38(%rsp), %rcx
movsd (%rcx,%rax,8), %xmm0
addsd 0x1b14(%rip), %xmm0     # 0x6388
movsd %xmm0, (%rcx,%rax,8)
addq $0x4, %r15
jmp 0x4840
cmpl $0x0, 0x8(%rsp)
jle 0x48fc
xorl %r12d, %r12d
movq 0x10(%rsp), %r13
movq 0x18(%rsp), %r15
movq %rbx, %rdi
movl %r12d, %esi
callq 0x41b8
subq %r13, %r15
sarq $0x2, %r15
movq %r15, %xmm0
punpckldq 0x1aee(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x1af6(%rip), %xmm0     # 0x63b0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
divsd 0x60(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd %xmm1, %xmm0
movsd 0x1aa9(%rip), %xmm1     # 0x6388
subsd %xmm0, %xmm1
movq 0x38(%rsp), %rax
mulsd (%rax,%r12,8), %xmm1
movsd %xmm1, (%rax,%r12,8)
incq %r12
cmpq %r12, %r14
jne 0x4889
cmpl $0x0, 0x8(%rsp)
jle 0x4969
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorpd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
xorl %r13d, %r13d
movq 0x38(%rsp), %rax
movsd (%rax,%r13,8), %xmm0
ucomisd 0x30(%rsp), %xmm0
jbe 0x4934
movl %r13d, %r12d
movsd %xmm0, 0x30(%rsp)
jmp 0x495f
jne 0x495f
jp 0x495f
cmpl $-0x1, %r12d
je 0x495c
movq %rbx, %rdi
movl %r13d, %esi
callq 0x41b8
movl %eax, %r15d
movq %rbx, %rdi
movl %r12d, %esi
callq 0x41b8
cmpl %eax, %r15d
jg 0x495f
movl %r13d, %r12d
incq %r13
cmpq %r13, %r14
jne 0x4916
jmp 0x496f
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
movl (%rbp), %esi
movq %rbx, %rdi
movl %r12d, %edx
callq 0x4196
addq $0x4, %rbp
cmpq 0x18(%rsp), %rbp
movq 0x58(%rsp), %r12
jne 0x481a
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x49a8
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x49bf
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x49f9
jmp 0x49df
jmp 0x49df
jmp 0x49df
jmp 0x49df
jmp 0x49df
jmp 0x49df
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x49f9
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x4a10
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21c0
movq %rbx, %rdi
callq 0x2280