// File: /workspace/github_cpp_makefile_star2_O1/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 $0xd8, %rsp
movq %rsi, %r14
movq %rdi, %rbp
movslq 0xb0(%rsi), %rsi
leaq 0x18(%rsp), %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
leaq 0x60(%rsp), %rdi
leaq 0x48(%rsp), %rcx
callq 0x58d6
cmpl $0x0, 0xb0(%r14)
jle 0x4bcc
movq 0xb8(%r14), %rax
movq 0x60(%rsp), %rcx
xorl %edx, %edx
movslq (%rax,%rdx,4), %rsi
incl (%rcx,%rsi,4)
incq %rdx
movslq 0xb0(%r14), %rsi
cmpq %rsi, %rdx
jl 0x4bb6
xorl %r15d, %r15d
cmpl $0x0, 0xb0(%r14)
jle 0x4bff
movq 0x60(%rsp), %rax
xorl %ecx, %ecx
cmpl $-0x1, (%rax,%rcx,4)
je 0x4bed
movl %r15d, (%rax,%rcx,4)
incl %r15d
incq %rcx
movslq 0xb0(%r14), %rdx
cmpq %rdx, %rcx
jl 0x4be0
movslq %r15d, %r15
leaq 0x48(%rsp), %rdi
leaq 0x18(%rsp), %rdx
movq %r15, %rsi
callq 0x5954
leaq 0xc0(%rsp), %rdi
leaq 0x18(%rsp), %rdx
movq %r15, %rsi
callq 0x5954
movl $0x0, 0x18(%rsp)
cmpl $0x0, 0xb0(%r14)
jle 0x4cde
xorl %eax, %eax
leaq 0x18(%rsp), %r15
cltq
movq 0x68(%r14), %rcx
movq 0xb8(%r14), %rdx
movslq (%rdx,%rax,4), %rdx
movq 0x60(%rsp), %rsi
movslq (%rsi,%rdx,4), %rdx
movq 0xc0(%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 0x663c
movslq 0x18(%rsp), %rax
movq 0xb8(%r14), %rcx
movslq (%rcx,%rax,4), %rcx
movq 0x60(%rsp), %rdx
movslq (%rdx,%rcx,4), %rcx
movq 0x48(%rsp), %rdx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdx,%rcx,8), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x4cbf
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rdi)
jmp 0x4cc7
movq %r15, %rdx
callq 0x6830
movl 0x18(%rsp), %eax
incl %eax
movl %eax, 0x18(%rsp)
cmpl 0xb0(%r14), %eax
jl 0x4c43
leaq 0xc0(%rsp), %rsi
movq %rbp, %rdi
callq 0x29a8
movq 0x50(%rsp), %rsi
subq 0x48(%rsp), %rsi
sarq $0x3, %rsi
movabsq $-0x5555555555555555, %rbx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rbx, %rsi
movl %esi, (%rbp)
leaq 0x18(%rbp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x318e
movq 0x50(%rsp), %rax
subq 0x48(%rsp), %rax
sarq $0x3, %rax
imulq %rbx, %rax
movq %rax, 0x8(%rsp)
testl %eax, %eax
jle 0x504b
leaq 0x20(%rsp), %r13
leaq 0x48(%rbp), %rax
movq %rax, 0xa8(%rsp)
leaq 0x60(%rbp), %rax
movq %rax, 0xa0(%rsp)
movq 0x8(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x8(%rsp)
xorl %eax, %eax
movq %rbp, 0x80(%rsp)
movl $0x0, 0x20(%rsp)
movq %rax, %rcx
xorl %eax, %eax
movq %rax, 0x28(%rsp)
movq %r13, 0x30(%rsp)
movq %r13, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rax
movq %rcx, 0x78(%rsp)
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rax,%rcx,8), %rdx
movq %rcx, 0xb0(%rsp)
subq (%rax,%rcx,8), %rdx
shrq $0x2, %rdx
movq %rdx, 0x10(%rsp)
testl %edx, %edx
jle 0x4f5c
movq 0x10(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x10(%rsp)
xorl %edx, %edx
movq 0x48(%rsp), %rax
movq 0xb0(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl (%rax,%rdx,4), %eax
cmpl %eax, 0x38(%r14)
jbe 0x508e
movq %rdx, 0xb8(%rsp)
testq %rax, %rax
je 0x4e30
movq 0x98(%r14), %rbx
leal -0x1(%rax), %ecx
cmpq %rbx, 0xa0(%r14)
je 0x4e40
movq 0x50(%r14), %rdx
movq (%rdx,%rcx,8), %rcx
leaq (,%rcx,4), %rbp
addq 0x80(%r14), %rbp
leaq (%rbx,%rcx,4), %rbx
jmp 0x4e53
movq 0x80(%r14), %rbp
movq 0x98(%r14), %rbx
jmp 0x4e53
movq 0x50(%r14), %rdx
movq (%rdx,%rcx,8), %rbp
shlq $0x2, %rbp
addq 0x80(%r14), %rbp
testq %rax, %rax
je 0x4e68
movq 0x50(%r14), %rcx
movq (%rcx,%rax,8), %r15
decl %eax
subq (%rcx,%rax,8), %r15
jmp 0x4e6f
movq 0x50(%r14), %rax
movq (%rax), %r15
testl %r15d, %r15d
jle 0x4f3e
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
xorl %r12d, %r12d
movq 0xa0(%r14), %rax
movsd 0x32e7(%rip), %xmm0     # 0x8178
cmpq 0x98(%r14), %rax
je 0x4ea3
xorps %xmm0, %xmm0
cvtss2sd (%rbx,%r12,4), %xmm0
movslq (%rbp,%r12,4), %rax
movq 0xb8(%r14), %rcx
movslq (%rcx,%rax,4), %rax
movq 0x60(%rsp), %rcx
movl (%rcx,%rax,4), %eax
movq 0x28(%rsp), %rdx
movq %r13, %rcx
testq %rdx, %rdx
je 0x4ee2
movq %r13, %rcx
xorl %esi, %esi
cmpl %eax, 0x20(%rdx)
setl %sil
cmovgeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0x4ecb
movq %r13, %rdx
cmpq %r13, %rcx
je 0x4ef4
cmpl 0x20(%rcx), %eax
cmovlq %r13, %rcx
movq %rcx, %rdx
cmpq %r13, %rdx
je 0x4f10
xorps %xmm1, %xmm1
cvtss2sd 0x24(%rdx), %xmm1
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x24(%rdx)
jmp 0x4f32
movl %eax, 0x88(%rsp)
movsd %xmm0, 0x90(%rsp)
leaq 0x18(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x690c
incq %r12
cmpq %r15, %r12
jne 0x4e82
movq 0xb8(%rsp), %rdx
incq %rdx
cmpq 0x10(%rsp), %rdx
movq 0x80(%rsp), %rbp
jne 0x4dd5
movq 0x78(%rsp), %rdx
testq %rdx, %rdx
je 0x4f7d
movq 0x98(%rsp), %rax
movq (%rax), %rcx
movq 0x40(%rsp), %rax
addq -0x8(%rcx,%rdx,8), %rax
jmp 0x4f82
movq 0x40(%rsp), %rax
movq 0x18(%rbp), %rcx
movq %rax, (%rcx,%rdx,8)
movq 0x40(%rsp), %rax
addq %rax, 0x8(%rbp)
movq 0x30(%rsp), %r12
cmpq %r13, %r12
je 0x502e
xorps %xmm0, %xmm0
cvtss2sd 0x24(%r12), %xmm0
addsd 0x10(%rbp), %xmm0
movsd %xmm0, 0x10(%rbp)
movl 0x20(%r12), %eax
movl %eax, 0x88(%rsp)
movq 0x50(%rbp), %rsi
cmpq 0x58(%rbp), %rsi
je 0x4fd7
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x50(%rbp)
jmp 0x4fec
movq 0xa8(%rsp), %rdi
leaq 0x88(%rsp), %rdx
callq 0x6a56
leaq 0x24(%r12), %rdx
movq 0x68(%rbp), %rsi
cmpq 0x70(%rbp), %rsi
je 0x500d
movss (%rdx), %xmm0
movss %xmm0, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x68(%rbp)
jmp 0x501a
movq 0xa0(%rsp), %rdi
callq 0x6b32
movq %r12, %rdi
callq 0x2160
movq %rax, %r12
cmpq %r13, %rax
jne 0x4fa1
leaq 0x18(%rsp), %rdi
callq 0x6196
movq 0x78(%rsp), %rax
incq %rax
cmpq 0x8(%rsp), %rax
jne 0x4d73
leaq 0xc0(%rsp), %rdi
callq 0x3250
leaq 0x48(%rsp), %rdi
callq 0x3250
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x5079
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2200
movq %rbp, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2fe6(%rip), %rdi      # 0x807b
leaq 0x2ff8(%rip), %rsi      # 0x8094
leaq 0x3002(%rip), %rcx      # 0x80a5
movl $0x84, %edx
callq 0x2130
movq %rax, %r14
jmp 0x50e7
jmp 0x50c6
movq %rax, %r14
jmp 0x513c
movq %rax, %r14
jmp 0x5146
jmp 0x50c6
movq %rax, %r14
jmp 0x512f
jmp 0x50cd
movq %rax, %r14
jmp 0x50dd
movq %rax, %r14
movq 0x80(%rsp), %rbp
leaq 0x18(%rsp), %rdi
callq 0x6196
movq 0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x50fc
movq 0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x2200
movq 0x48(%rbp), %rdi
testq %rdi, %rdi
je 0x5111
movq 0x58(%rbp), %rsi
subq %rdi, %rsi
callq 0x2200
leaq 0x30(%rbp), %rdi
callq 0x3250
movq 0x18(%rbp), %rdi
testq %rdi, %rdi
je 0x512f
movq 0x28(%rbp), %rsi
subq %rdi, %rsi
callq 0x2200
leaq 0xc0(%rsp), %rdi
callq 0x3250
leaq 0x48(%rsp), %rdi
callq 0x3250
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x515d
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x2200
movq %r14, %rdi
callq 0x2370
nop