// File: /workspace/github_cpp_makefile_star2_O1/riyadparvez[P]louvain-method/community.cpp
// Function: Community::one_level()
bool
Community::one_level() {
  bool improvement=false ;
  int nb_moves;
  int nb_pass_done = 0;
  double new_mod   = modularity();
  double cur_mod   = new_mod;

  vector<int> random_order(size);
  for (int i=0 ; i<size ; i++)
    random_order[i]=i;
  for (int i=0 ; i<size-1 ; i++) {
    int rand_pos = rand()%(size-i)+i;
    int tmp      = random_order[i];
    random_order[i] = random_order[rand_pos];
    random_order[rand_pos] = tmp;
  }

  // repeat while 
  //   there is an improvement of modularity
  //   or there is an improvement of modularity greater than a given epsilon 
  //   or a predefined number of pass have been done
  do {
    cur_mod = new_mod;
    nb_moves = 0;
    nb_pass_done++;

    // for each node: remove the node from its community and insert it in the best community
    for (int node_tmp=0 ; node_tmp<size ; node_tmp++) {
//      int node = node_tmp;
      int node = random_order[node_tmp];
      int node_comm     = n2c[node];
      double w_degree = g.weighted_degree(node);

      // computation of all neighboring communities of current node
      neigh_comm(node);
      // remove node from its current community
      remove(node, node_comm, neigh_weight[node_comm]);

      // compute the nearest community for node
      // default choice for future insertion is the former community
      int best_comm        = node_comm;
      double best_nblinks  = 0.;
      double best_increase = 0.;
      for (unsigned int i=0 ; i<neigh_last ; i++) {
        double increase = modularity_gain(node, neigh_pos[i], neigh_weight[neigh_pos[i]], w_degree);
        if (increase>best_increase) {
          best_comm     = neigh_pos[i];
          best_nblinks  = neigh_weight[neigh_pos[i]];
          best_increase = increase;
        }
      }

      // insert node in the nearest community
      insert(node, best_comm, best_nblinks);
     
      if (best_comm!=node_comm)
        nb_moves++;
    }

    double total_tot=0;
    double total_in=0;
    for (unsigned int i=0 ; i<tot.size() ;i++) {
      total_tot+=tot[i];
      total_in+=in[i];
    }

    new_mod = modularity();
    if (nb_moves>0)
      improvement=true;
    
  } while (nb_moves>0 && new_mod-cur_mod>min_modularity);

  return improvement;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
callq 0x478a
movsd %xmm0, 0x8(%rsp)
movslq 0xb0(%rbx), %rsi
leaq 0x18(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x59dc
cmpl $0x0, 0xb0(%rbx)
jle 0x51ba
movq 0x18(%rsp), %rax
xorl %ecx, %ecx
movl %ecx, (%rax,%rcx,4)
incq %rcx
movslq 0xb0(%rbx), %rdx
cmpq %rdx, %rcx
jl 0x51a8
cmpl $0x2, 0xb0(%rbx)
jl 0x5208
xorl %r14d, %r14d
xorl %r15d, %r15d
callq 0x2080
movl 0xb0(%rbx), %ecx
addl %r14d, %ecx
cltd
idivl %ecx
movq 0x18(%rsp), %rax
movl (%rax,%r15,4), %ecx
movslq %edx, %rdx
addq %r15, %rdx
movl (%rax,%rdx,4), %esi
movl %esi, (%rax,%r15,4)
movl %ecx, (%rax,%rdx,4)
incq %r15
movslq 0xb0(%rbx), %rax
decq %rax
decl %r14d
cmpq %rax, %r15
jl 0x51c9
xorl %r14d, %r14d
xorl %ebp, %ebp
cmpl $0x0, 0xb0(%rbx)
jle 0x53ce
movq %r14, 0x30(%rsp)
xorl %r14d, %r14d
movq 0x18(%rsp), %rax
movl (%rax,%r14,4), %r15d
cmpl %r15d, 0x38(%rbx)
jbe 0x5433
movq 0x98(%rbx), %rax
cmpq %rax, 0xa0(%rbx)
je 0x5299
testq %r15, %r15
je 0x525a
leal -0x1(%r15), %ecx
movq 0x50(%rbx), %rdx
movq (%rdx,%rcx,8), %rcx
leaq (%rax,%rcx,4), %rax
movq 0x50(%rbx), %rcx
leal -0x1(%r15), %edx
xorpd %xmm1, %xmm1
xorl %esi, %esi
testq %r15, %r15
je 0x5277
movq (%rcx,%r15,8), %rdi
subq (%rcx,%rdx,8), %rdi
jmp 0x5279
movl (%rcx), %edi
movl %edi, %edi
cmpq %rdi, %rsi
jae 0x5291
xorps %xmm0, %xmm0
cvtss2sd (%rax,%rsi,4), %xmm0
addsd %xmm0, %xmm1
incq %rsi
jmp 0x5268
movsd %xmm1, 0x10(%rsp)
jmp 0x52c7
testq %r15, %r15
je 0x52b0
movq 0x50(%rbx), %rcx
movq (%rcx,%r15,8), %rax
leal -0x1(%r15), %edx
subq (%rcx,%rdx,8), %rax
jmp 0x52b7
movq 0x50(%rbx), %rax
movq (%rax), %rax
movl %eax, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movsd %xmm0, 0x10(%rsp)
movslq %r15d, %rax
movq 0xb8(%rbx), %rcx
movl (%rcx,%rax,4), %r13d
movslq %r13d, %r12
movq %rbx, %rdi
movl %r15d, %esi
callq 0x4500
movq (%rbx), %rax
movsd (%rax,%r12,8), %xmm0
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x557e
movl 0x30(%rbx), %eax
testq %rax, %rax
je 0x538c
testl %r15d, %r15d
js 0x5452
cmpl %r15d, 0xb0(%rbx)
jle 0x5452
movq %rbp, %r12
movq (%rbx), %rcx
movq 0x18(%rbx), %rdx
movq 0xe8(%rbx), %rsi
movsd 0x48(%rbx), %xmm1
xorpd %xmm2, %xmm2
xorl %edi, %edi
xorpd %xmm3, %xmm3
movl %r13d, %ebp
movsd 0x10(%rsp), %xmm6
movslq (%rdx,%rdi,4), %r8
movl %r8d, %r9d
movsd (%rcx,%r9,8), %xmm0
movsd (%rsi,%r8,8), %xmm5
mulsd %xmm6, %xmm5
divsd %xmm1, %xmm5
movapd %xmm0, %xmm4
subsd %xmm5, %xmm4
ucomisd %xmm2, %xmm4
cmoval %r8d, %ebp
ja 0x5376
movapd %xmm3, %xmm0
maxsd %xmm2, %xmm4
incq %rdi
movapd %xmm4, %xmm2
movapd %xmm0, %xmm3
cmpq %rdi, %rax
jne 0x5345
jmp 0x5396
movq %rbp, %r12
xorpd %xmm0, %xmm0
movl %r13d, %ebp
movq %rbx, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0x5730
xorl %eax, %eax
cmpl %r13d, %ebp
setne %al
movq %r12, %rbp
addl %eax, %ebp
incq %r14
movslq 0xb0(%rbx), %rax
cmpq %rax, %r14
jl 0x5222
testl %ebp, %ebp
setne %bpl
movq 0x30(%rsp), %r14
movzbl %r14b, %r14d
testb %bpl, %bpl
movl $0x1, %eax
cmovnel %eax, %r14d
je 0x5406
movq %rbx, %rdi
callq 0x478a
movapd %xmm0, %xmm1
subsd 0x8(%rsp), %xmm1
ucomisd 0x108(%rbx), %xmm1
movsd %xmm0, 0x8(%rsp)
ja 0x520b
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x541d
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x2200
andb $0x1, %r14b
movl %r14d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2c41(%rip), %rdi      # 0x807b
leaq 0x2c53(%rip), %rsi      # 0x8094
leaq 0x2d42(%rip), %rcx      # 0x818a
movl $0x74, %edx
callq 0x2130
leaq 0x2d86(%rip), %rdi      # 0x81df
leaq 0x2d94(%rip), %rsi      # 0x81f4
leaq 0x2ded(%rip), %rcx      # 0x8254
movl $0x7a, %edx
callq 0x2130
jmp 0x5473
movq %rax, %rbx
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x548d
movq 0x28(%rsp), %rsi
subq %rdi, %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2370
nop