// File: /workspace/github_cpp_makefile_star2_O2/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 $0xe8, %rsp
movq %rsi, %r14
movq %rdi, (%rsp)
movslq 0xb0(%rsi), %rsi
leaq 0x30(%rsp), %rdx
orl $-0x1, (%rdx)
leaq 0x80(%rsp), %rbx
leaq 0x18(%rsp), %rcx
movq %rbx, %rdi
callq 0x4c36
movq 0xb8(%r14), %rcx
xorl %edx, %edx
movq (%rbx), %rsi
movslq 0xb0(%r14), %rax
cmpq %rax, %rdx
jge 0x42ae
movslq (%rcx,%rdx,4), %rax
incl (%rsi,%rax,4)
incq %rdx
jmp 0x4296
xorl %ecx, %ecx
movq 0x80(%rsp), %rdx
xorl %esi, %esi
movslq %eax, %rdi
cmpq %rdi, %rcx
jge 0x42d9
cmpl $-0x1, (%rdx,%rcx,4)
je 0x42d4
movl %esi, (%rdx,%rcx,4)
incl %esi
movl 0xb0(%r14), %eax
incq %rcx
jmp 0x42ba
movslq %esi, %rbx
leaq 0x18(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movq %rbx, %rsi
callq 0x4c8c
leaq 0xd0(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movq %rbx, %rsi
callq 0x4c8c
xorl %eax, %eax
leaq 0x30(%rsp), %rbx
movl %eax, 0x30(%rsp)
cmpl 0xb0(%r14), %eax
jge 0x4393
cltq
movq 0x68(%r14), %rcx
movq 0xb8(%r14), %rdx
movslq (%rdx,%rax,4), %rdx
movq 0x80(%rsp), %rsi
movslq (%rsi,%rdx,4), %rdx
movq 0xd0(%rsp), %rsi
imulq $0x18, %rdx, %rdx
leaq (%rsi,%rdx), %rdi
movq 0x8(%rsi,%rdx), %rsi
imulq $0x18, %rax, %rax
movq (%rcx,%rax), %rdx
movq 0x8(%rcx,%rax), %rcx
callq 0x4cde
movslq 0x30(%rsp), %rax
movq 0xb8(%r14), %rcx
movslq (%rcx,%rax,4), %rax
movq 0x80(%rsp), %rcx
movslq (%rcx,%rax,4), %rax
imulq $0x18, %rax, %rdi
addq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0x4cfe
movl 0x30(%rsp), %eax
incl %eax
jmp 0x430a
leaq 0xd0(%rsp), %rsi
movq (%rsp), %r15
movq %r15, %rdi
callq 0x2728
movq 0x20(%rsp), %rax
subq 0x18(%rsp), %rax
pushq $0x18
popq %rbx
cqto
idivq %rbx
movl %eax, (%r15)
leaq 0x18(%r15), %rdi
movq %rdi, 0x60(%rsp)
movq %rax, %rsi
callq 0x2bfe
movq 0x20(%rsp), %rax
subq 0x18(%rsp), %rax
cqto
idivq %rbx
leaq 0x38(%r14), %r13
leaq 0x48(%r15), %rcx
movq %rcx, 0xa8(%rsp)
leaq 0x60(%r15), %rcx
movq %rcx, 0xa0(%rsp)
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
movq %rax, 0x98(%rsp)
leaq 0x30(%rsp), %r12
xorl %eax, %eax
movq %r13, 0xb0(%rsp)
cmpq 0x98(%rsp), %rax
je 0x4646
andl $0x0, 0x38(%rsp)
andq $0x0, 0x40(%rsp)
movq %rax, %rcx
leaq 0x38(%rsp), %rax
movq %rax, 0x48(%rsp)
movq %rax, 0x50(%rsp)
andq $0x0, 0x58(%rsp)
movq 0x18(%rsp), %rax
movq %rcx, 0x68(%rsp)
imulq $0x18, %rcx, %rbx
movq 0x8(%rax,%rbx), %rcx
subq (%rax,%rbx), %rcx
shrq $0x2, %rcx
testl %ecx, %ecx
movl $0x0, %eax
cmovlel %eax, %ecx
movq %rcx, 0xc0(%rsp)
xorl %ebp, %ebp
movq %rbx, 0xb8(%rsp)
cmpq 0xc0(%rsp), %rbp
je 0x459c
movq 0x18(%rsp), %rax
movq (%rax,%rbx), %rax
movl (%rax,%rbp,4), %esi
movq %r13, %rdi
callq 0x2e22
movq %rax, %r15
movq %r13, %rdi
movq %rdx, %r13
movq 0x18(%rsp), %rax
movq (%rax,%rbx), %rax
movq %rbp, 0xc8(%rsp)
movl (%rax,%rbp,4), %esi
callq 0x2e7c
movl %eax, %ebx
testl %eax, %eax
movl $0x0, %eax
cmovlel %eax, %ebx
xorl %ebp, %ebp
cmpq %rbp, %rbx
je 0x457c
movslq (%r15,%rbp,4), %rax
movq 0xb8(%r14), %rcx
movslq (%rcx,%rax,4), %rax
movq 0x80(%rsp), %rcx
movl (%rcx,%rax,4), %eax
movl %eax, 0xc(%rsp)
movq 0xa0(%r14), %rax
movsd 0x2ca2(%rip), %xmm0     # 0x71a8
movsd %xmm0, 0x10(%rsp)
cmpq 0x98(%r14), %rax
je 0x4522
cvtss2sd (%r13,%rbp,4), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r12, %rdi
leaq 0xc(%rsp), %rsi
callq 0x5e5c
leaq 0x38(%rsp), %rcx
cmpq %rcx, %rax
je 0x4553
cvtss2sd 0x24(%rax), %xmm0
movsd 0x10(%rsp), %xmm1
addsd %xmm0, %xmm1
cvtsd2ss %xmm1, %xmm0
movss %xmm0, 0x24(%rax)
jmp 0x4574
movl 0xc(%rsp), %eax
movl %eax, 0x70(%rsp)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x78(%rsp)
movq %r12, %rdi
leaq 0x70(%rsp), %rsi
callq 0x5eae
incq %rbp
jmp 0x44d0
movq 0xc8(%rsp), %rbp
incq %rbp
movq 0xb0(%rsp), %r13
movq 0xb8(%rsp), %rbx
jmp 0x447e
movq 0x68(%rsp), %rdx
testq %rdx, %rdx
je 0x45ba
movq 0x60(%rsp), %rax
movq (%rax), %rax
movq 0x58(%rsp), %rcx
addq -0x8(%rax,%rdx,8), %rcx
jmp 0x45c7
movq 0x58(%rsp), %rcx
movq 0x60(%rsp), %rax
movq (%rax), %rax
movq %rcx, (%rax,%rdx,8)
movq 0x58(%rsp), %rax
movq (%rsp), %rcx
addq %rax, 0x8(%rcx)
movq 0x48(%rsp), %rbx
leaq 0x38(%rsp), %rax
cmpq %rax, %rbx
je 0x4631
cvtss2sd 0x24(%rbx), %xmm0
movq (%rsp), %rax
addsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rax)
movl 0x20(%rbx), %eax
movl %eax, 0x70(%rsp)
movq 0xa8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x6034
leaq 0x24(%rbx), %rsi
movq 0xa0(%rsp), %rdi
callq 0x4d1c
movq %rbx, %rdi
callq 0x2110
movq %rax, %rbx
jmp 0x45dd
movq %r12, %rdi
callq 0x55e4
movq 0x68(%rsp), %rax
incq %rax
jmp 0x4416
leaq 0xd0(%rsp), %rdi
callq 0x2d5e
leaq 0x18(%rsp), %rdi
callq 0x2d5e
leaq 0x80(%rsp), %rdi
callq 0x34f2
movq (%rsp), %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x46ad
jmp 0x4693
movq %rax, %rbx
jmp 0x46c3
movq %rax, %rbx
jmp 0x46cd
jmp 0x4693
movq %rax, %rbx
jmp 0x46b6
jmp 0x46a0
jmp 0x46a0
jmp 0x46a0
jmp 0x46a0
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x55e4
movq (%rsp), %rdi
callq 0x4944
leaq 0xd0(%rsp), %rdi
callq 0x2d5e
leaq 0x18(%rsp), %rdi
callq 0x2d5e
leaq 0x80(%rsp), %rdi
callq 0x34f2
movq %rbx, %rdi
callq 0x22f0