// File: /workspace/github_cpp_makefile_star2_O3/riyadparvez[P]louvain-method/graph_binary.cpp
// Function: Graph::Graph(char*, char*, int)
Graph::Graph(char *filename, char *filename_w, int type) {
  ifstream finput;
  finput.open(filename,fstream::in | fstream::binary);

  // Read number of nodes on 4 bytes
  finput.read((char *)&nb_nodes, 4);
  assert(finput.rdstate() == ios::goodbit);

  // Read cumulative degree sequence: 8 bytes for each node
  // cum_degree[0]=degree(0); cum_degree[1]=degree(0)+degree(1), etc.
  degrees.resize(nb_nodes);
  finput.read((char *)&degrees[0], nb_nodes*8);

  // Read links: 4 bytes for each link (each link is counted twice)
  nb_links=degrees[nb_nodes-1];
  links.resize(nb_links);
  finput.read((char *)(&links[0]), (long)nb_links*8);  

  // IF WEIGHTED : read weights: 4 bytes for each link (each link is counted twice)
  weights.resize(0);
  total_weight=0;
  if (type==WEIGHTED) {
    ifstream finput_w;
    finput_w.open(filename_w,fstream::in | fstream::binary);
    weights.resize(nb_links);
    finput_w.read((char *)&weights[0], (long)nb_links*4);  
  }    

  //initilize first graph without contraction
  for (unsigned int i=0 ; i<nb_nodes ; i++) {
    vector<int> n;
    n.push_back(i);
    nodes.push_back(n);
  }
  
  // Compute total weight
  for (unsigned int i=0 ; i<nb_nodes ; i++) {
    total_weight += (double)weighted_degree(i);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
movl %ecx, %r14d
movq %rdx, %rbp
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x18(%rdi), %rax
movq %rax, 0x18(%rsp)
leaq 0x30(%rdi), %r15
leaq 0x48(%rdi), %rax
movq %rax, 0x10(%rsp)
leaq 0x60(%rdi), %r13
xorpd %xmm0, %xmm0
movupd %xmm0, 0x68(%rdi)
movupd %xmm0, 0x58(%rdi)
movupd %xmm0, 0x48(%rdi)
movupd %xmm0, 0x38(%rdi)
movupd %xmm0, 0x28(%rdi)
movupd %xmm0, 0x18(%rdi)
leaq 0x230(%rsp), %rdi
callq 0x2220
leaq 0x230(%rsp), %rdi
movq %r12, %rsi
movl $0xc, %edx
callq 0x2120
leaq 0x230(%rsp), %rdi
movl $0x4, %edx
movq %rbx, %rsi
callq 0x2280
movq 0x230(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x250(%rsp,%rax)
jne 0x28e6
movl (%rbx), %esi
movq 0x18(%rsp), %rdi
callq 0x315e
movq 0x18(%rbx), %rsi
movl (%rbx), %edx
shll $0x3, %edx
leaq 0x230(%rsp), %rdi
callq 0x2280
movl (%rbx), %eax
decl %eax
movq 0x18(%rbx), %rcx
movq (%rcx,%rax,8), %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rsp), %rdi
callq 0x3190
movq 0x8(%rbx), %rdx
movq 0x48(%rbx), %rsi
shlq $0x3, %rdx
leaq 0x230(%rsp), %rdi
callq 0x2280
movq %r13, %rdi
xorl %esi, %esi
callq 0x31c2
movq $0x0, 0x10(%rbx)
testl %r14d, %r14d
jne 0x27c0
leaq 0x20(%rsp), %rdi
callq 0x2220
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
movl $0xc, %edx
callq 0x2120
movq 0x8(%rbx), %rsi
movq %r13, %rdi
callq 0x31c2
movq 0x8(%rbx), %rdx
movq 0x60(%rbx), %rsi
shlq $0x2, %rdx
leaq 0x20(%rsp), %rdi
callq 0x2280
leaq 0x20(%rsp), %rdi
callq 0x2070
cmpl $0x0, (%rbx)
je 0x28c7
xorl %r12d, %r12d
leaq 0x20(%rsp), %r14
leaq 0xc(%rsp), %rbp
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movl %r12d, 0xc(%rsp)
movq %r14, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x37a8
movq %r15, %rdi
movq %r14, %rsi
callq 0x31f4
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x281d
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2200
incl %r12d
movl (%rbx), %eax
cmpl %eax, %r12d
jb 0x27d6
testq %rax, %rax
je 0x28c7
movsd 0x10(%rbx), %xmm0
movq 0x68(%rbx), %rcx
movq 0x60(%rbx), %rdx
movq 0x18(%rbx), %rsi
xorl %edi, %edi
cmpq %rdx, %rcx
je 0x285c
testq %rdi, %rdi
je 0x286c
leaq -0x1(%rdi), %r8
movq -0x8(%rsi,%rdi,8), %r9
leaq (%rdx,%r9,4), %r9
jmp 0x2875
testq %rdi, %rdi
je 0x28a8
movq (%rsi,%rdi,8), %r8
subq -0x8(%rsi,%rdi,8), %r8
jmp 0x28ab
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movq %rdx, %r9
xorpd %xmm1, %xmm1
xorl %r10d, %r10d
testq %rdi, %rdi
je 0x288b
movq (%rsi,%rdi,8), %r11
subq (%rsi,%r8,8), %r11
jmp 0x288e
movl (%rsi), %r11d
movl %r11d, %r11d
cmpq %r11, %r10
jae 0x28b6
xorps %xmm2, %xmm2
cvtss2sd (%r9,%r10,4), %xmm2
addsd %xmm2, %xmm1
incq %r10
jmp 0x287c
movq (%rsi), %r8
movl %r8d, %r8d
xorps %xmm1, %xmm1
cvtsi2sd %r8, %xmm1
addsd %xmm1, %xmm0
incq %rdi
cmpq %rax, %rdi
jne 0x2843
movsd %xmm0, 0x10(%rbx)
leaq 0x230(%rsp), %rdi
callq 0x2070
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5733(%rip), %rdi      # 0x8020
leaq 0x574d(%rip), %rsi      # 0x8041
leaq 0x5757(%rip), %rcx      # 0x8052
movl $0x22, %edx
callq 0x2130
jmp 0x291b
movq %rax, %r14
jmp 0x2949
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x2070
jmp 0x293c
movq %rax, %r14
jmp 0x293c
jmp 0x2922
movq %rax, %r14
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x293c
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2200
leaq 0x230(%rsp), %rdi
callq 0x2070
movq (%r13), %rdi
testq %rdi, %rdi
je 0x295e
movq 0x70(%rbx), %rsi
subq %rdi, %rsi
callq 0x2200
movq 0x10(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2977
movq 0x58(%rbx), %rsi
subq %rdi, %rsi
callq 0x2200
movq %r15, %rdi
callq 0x3220
movq 0x18(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2998
movq 0x28(%rbx), %rsi
subq %rdi, %rsi
callq 0x2200
movq %r14, %rdi
callq 0x2370