// File: /workspace/github_cpp_makefile_star2_O3/riyadparvez[P]louvain-method/community.cpp
// Function: Community::partition2graph_binary()
Graph
Community::partition2graph_binary() {
  // Renumber communities
  vector<int> renumber(size, -1);
  for (int node=0 ; node<size ; node++) {
    renumber[n2c[node]]++;
  }

  int final=0;
  for (int i=0 ; i<size ; i++)
    if (renumber[i]!=-1)
      renumber[i]=final++;

  // Compute communities
  vector<vector<int> > comm_nodes(final);
  vector<vector<int> > communities(final);
  //printf("%s %d \n", __FILE__, __LINE__);
  for (int node=0 ; node<size ; node++) {
    //TODO add node handling
    vector<int>& comm = communities[renumber[n2c[node]]];  
    comm.insert(comm.end(), g.nodes[node].begin(), g.nodes[node].end());
    comm_nodes[renumber[n2c[node]]].push_back(node);
  }
  /*
  for (size_t i=0; i<g.nodes.size(); i++) {
    for (size_t j=0; j<g.nodes[i].size(); j++) {
      printf("%d n ", g.nodes[i][j]);
    }
    printf("n \n");
  }
  */
  /*
  for (size_t i=0; i<communities.size(); i++) {
    for (size_t j=0; j<communities[i].size(); j++) {
      printf("%d c ", communities[i][j]);
    }
    printf("i: %d \n", i);
  }
  printf("%s %d \n", __FILE__, __LINE__);
  */
  Graph g2(communities);  
  
  g2.nb_nodes = comm_nodes.size();
  g2.degrees.resize(comm_nodes.size());

  int comm_deg = comm_nodes.size();
  for (int comm=0 ; comm<comm_deg ; comm++) {
    map<int,float> m;
    map<int,float>::iterator it;

    int comm_size = comm_nodes[comm].size();
    for (int node=0 ; node<comm_size ; node++) {
      pair<vector<unsigned int>::iterator, vector<float>::iterator> p = g.neighbors(comm_nodes[comm][node]);
      int deg = g.nb_neighbors(comm_nodes[comm][node]);
      for (int i=0 ; i<deg ; i++) {
    int neigh        = *(p.first+i);
    int neigh_comm   = renumber[n2c[neigh]];
    double neigh_weight = (g.weights.size()==0)?1.:*(p.second+i);

    it = m.find(neigh_comm);
    if (it==m.end())
      m.insert(make_pair(neigh_comm, neigh_weight));
    else
      it->second+=neigh_weight;
      }
    }
    g2.degrees[comm]=(comm==0)?m.size():g2.degrees[comm-1]+m.size();
    g2.nb_links+=m.size();

    
    for (it = m.begin() ; it!=m.end() ; it++) {
      g2.total_weight  += it->second;
      g2.links.push_back(it->first);
      g2.weights.push_back(it->second);
    }
  }

  return g2;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rsi, %r14
movq %rdi, %r13
movslq 0xb0(%rsi), %rsi
movq %rsp, %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
leaq 0x58(%rsp), %rdi
leaq 0x40(%rsp), %rcx
callq 0x58c8
cmpl $0x0, 0xb0(%r14)
jle 0x4c14
movq 0xb8(%r14), %rcx
movq 0x58(%rsp), %rdx
xorl %esi, %esi
movslq (%rcx,%rsi,4), %rax
incl (%rdx,%rax,4)
incq %rsi
movslq 0xb0(%r14), %rax
cmpq %rax, %rsi
jl 0x4bcc
xorl %r15d, %r15d
testl %eax, %eax
jle 0x4c17
movq 0x58(%rsp), %rcx
xorl %edx, %edx
cmpl $-0x1, (%rcx,%rdx,4)
je 0x4c04
movl %r15d, (%rcx,%rdx,4)
incl %r15d
movl 0xb0(%r14), %eax
incq %rdx
movslq %eax, %rsi
cmpq %rsi, %rdx
jl 0x4bf0
movslq %r15d, %r15
jmp 0x4c17
xorl %r15d, %r15d
leaq 0x40(%rsp), %rdi
movq %rsp, %rdx
movq %r15, %rsi
callq 0x5a44
leaq 0xb0(%rsp), %rdi
movq %rsp, %rdx
movq %r15, %rsi
callq 0x5a44
movl $0x0, (%rsp)
cmpl $0x0, 0xb0(%r14)
jle 0x4cec
xorl %eax, %eax
movq %rsp, %r15
cltq
movq 0x68(%r14), %rcx
movq 0xb8(%r14), %rdx
movslq (%rdx,%rax,4), %rdx
movq 0x58(%rsp), %rsi
movslq (%rsi,%rdx,4), %rdx
movq 0xb0(%rsp), %rsi
leaq (%rdx,%rdx,2), %rdx
leaq (%rsi,%rdx,8), %rdi
movq 0x8(%rdi), %rsi
leaq (%rax,%rax,2), %rax
movq (%rcx,%rax,8), %rdx
movq 0x8(%rcx,%rax,8), %rcx
callq 0x691c
movslq (%rsp), %rax
movq 0xb8(%r14), %rcx
movslq (%rcx,%rax,4), %rcx
movq 0x58(%rsp), %rdx
movslq (%rdx,%rcx,4), %rcx
movq 0x40(%rsp), %rdx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x4ccf
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x4cd7
movq %r15, %rdx
callq 0x6ad8
movl (%rsp), %eax
incl %eax
movl %eax, (%rsp)
cmpl 0xb0(%r14), %eax
jl 0x4c54
leaq 0xb0(%rsp), %rsi
movq %r13, %rdi
callq 0x29bc
movq 0x48(%rsp), %rsi
subq 0x40(%rsp), %rsi
sarq $0x3, %rsi
movabsq $-0x5555555555555555, %rbx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rbx, %rsi
movl %esi, (%r13)
leaq 0x18(%r13), %rdi
movq %rdi, 0x70(%rsp)
callq 0x315e
movq 0x48(%rsp), %rax
subq 0x40(%rsp), %rax
sarq $0x3, %rax
imulq %rbx, %rax
movq %rax, 0x30(%rsp)
testl %eax, %eax
jle 0x502f
leaq 0x48(%r13), %rax
movq %rax, 0xa0(%rsp)
leaq 0x60(%r13), %rax
movq %rax, 0x98(%rsp)
movq 0x30(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x30(%rsp)
xorl %edx, %edx
movq %r13, 0x80(%rsp)
movl $0x0, 0x8(%rsp)
xorl %ecx, %ecx
movq %rcx, 0x10(%rsp)
leaq 0x8(%rsp), %rax
movq %rax, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movq %rcx, 0x28(%rsp)
movq 0x40(%rsp), %rax
movq %rdx, 0x78(%rsp)
leaq (%rdx,%rdx,2), %rcx
movq 0x8(%rax,%rcx,8), %rdx
movq %rcx, 0xa8(%rsp)
subq (%rax,%rcx,8), %rdx
shrq $0x2, %rdx
movq %rdx, 0x38(%rsp)
testl %edx, %edx
jle 0x4f3e
movq 0x38(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x38(%rsp)
xorl %r12d, %r12d
movq 0x40(%rsp), %rax
movq 0xa8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax,%r12,4), %eax
cmpl %eax, 0x38(%r14)
jbe 0x5072
movq 0x98(%r14), %rbx
testq %rax, %rax
je 0x4e41
movq 0x50(%r14), %rcx
leal -0x1(%rax), %edx
movq (%rcx,%rdx,8), %rdx
leaq (,%rdx,4), %rbp
addq 0x80(%r14), %rbp
cmpq %rbx, 0xa0(%r14)
movl $0x0, %esi
cmovneq %rdx, %rsi
leaq (%rbx,%rsi,4), %rbx
movq (%rcx,%rax,8), %r15
subq %rdx, %r15
jmp 0x4e4f
movq 0x50(%r14), %rax
movq 0x80(%r14), %rbp
movq (%rax), %r15
testl %r15d, %r15d
jle 0x4f28
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %r13d, %r13d
movq 0xa0(%r14), %rax
movsd 0x3307(%rip), %xmm0     # 0x8178
cmpq 0x98(%r14), %rax
je 0x4e83
xorps %xmm0, %xmm0
cvtss2sd (%rbx,%r13,4), %xmm0
movslq (%rbp,%r13,4), %rax
movq 0xb8(%r14), %rcx
movslq (%rcx,%rax,4), %rax
movq 0x58(%rsp), %rcx
movl (%rcx,%rax,4), %eax
movq 0x10(%rsp), %r8
testq %r8, %r8
je 0x4ee3
leaq 0x8(%rsp), %rcx
movq %rcx, %rdx
movq %r8, %rsi
movl 0x20(%r8), %edi
xorl %r8d, %r8d
cmpl %eax, %edi
setl %r8b
movq %rsi, %rcx
cmovlq %rdx, %rcx
movq 0x10(%rsi,%r8,8), %r8
testq %r8, %r8
jne 0x4eaa
leaq 0x8(%rsp), %r8
cmpq %r8, %rcx
je 0x4ee3
cmpl %eax, %edi
cmovlq %rdx, %rsi
cmpl 0x20(%rsi), %eax
jge 0x4f11
movl %eax, 0x88(%rsp)
movsd %xmm0, 0x90(%rsp)
movq %rsp, %rdi
leaq 0x88(%rsp), %rsi
callq 0x6bb4
incq %r13
cmpq %r15, %r13
jne 0x4e62
jmp 0x4f28
xorps %xmm1, %xmm1
cvtss2sd 0x24(%rcx), %xmm1
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x24(%rcx)
jmp 0x4f03
incq %r12
cmpq 0x38(%rsp), %r12
movq 0x80(%rsp), %r13
jne 0x4ddf
movq 0x78(%rsp), %rdx
testq %rdx, %rdx
je 0x4f5c
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq 0x28(%rsp), %rcx
addq -0x8(%rax,%rdx,8), %rcx
jmp 0x4f69
movq 0x28(%rsp), %rcx
movq 0x70(%rsp), %rax
movq (%rax), %rax
movq %rcx, (%rax,%rdx,8)
movq 0x28(%rsp), %rax
addq %rax, 0x8(%r13)
movq 0x18(%rsp), %r12
leaq 0x8(%rsp), %rax
cmpq %rax, %r12
je 0x5014
xorps %xmm0, %xmm0
cvtss2sd 0x24(%r12), %xmm0
addsd 0x10(%r13), %xmm0
movsd %xmm0, 0x10(%r13)
movl 0x20(%r12), %eax
movl %eax, 0x88(%rsp)
movq 0x50(%r13), %rsi
cmpq 0x58(%r13), %rsi
je 0x4fc1
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x50(%r13)
jmp 0x4fd6
movq 0xa0(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x6cfc
leaq 0x24(%r12), %rdx
movq 0x68(%r13), %rsi
cmpq 0x70(%r13), %rsi
je 0x4ff7
movss (%rdx), %xmm0
movss %xmm0, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x68(%r13)
jmp 0x5004
movq 0x98(%rsp), %rdi
callq 0x6dd8
movq %r12, %rdi
callq 0x2160
movq %rax, %r12
jmp 0x4f7b
movq %rsp, %rdi
callq 0x621c
movq 0x78(%rsp), %rdx
incq %rdx
cmpq 0x30(%rsp), %rdx
jne 0x4d7a
leaq 0xb0(%rsp), %rdi
callq 0x3220
leaq 0x40(%rsp), %rdi
callq 0x3220
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x505d
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x2200
movq %r13, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x3002(%rip), %rdi      # 0x807b
leaq 0x3014(%rip), %rsi      # 0x8094
leaq 0x301e(%rip), %rcx      # 0x80a5
movl $0x84, %edx
callq 0x2130
movq %rax, %r14
jmp 0x50c6
jmp 0x50a7
movq %rax, %r14
jmp 0x511b
movq %rax, %r14
jmp 0x5125
jmp 0x50a7
movq %rax, %r14
jmp 0x510e
jmp 0x50ae
movq %rax, %r14
jmp 0x50be
movq %rax, %r14
movq 0x80(%rsp), %r13
movq %rsp, %rdi
callq 0x621c
movq 0x60(%r13), %rdi
testq %rdi, %rdi
je 0x50db
movq 0x70(%r13), %rsi
subq %rdi, %rsi
callq 0x2200
movq 0x48(%r13), %rdi
testq %rdi, %rdi
je 0x50f0
movq 0x58(%r13), %rsi
subq %rdi, %rsi
callq 0x2200
leaq 0x30(%r13), %rdi
callq 0x3220
movq 0x18(%r13), %rdi
testq %rdi, %rdi
je 0x510e
movq 0x28(%r13), %rsi
subq %rdi, %rsi
callq 0x2200
leaq 0xb0(%rsp), %rdi
callq 0x3220
leaq 0x40(%rsp), %rdi
callq 0x3220
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x513c
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x2200
movq %r14, %rdi
callq 0x2370