// File: /workspace/github_cpp_makefile_star2_O2/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, %ebx
movq %rdx, %rbp
movq %rsi, %r15
movq %rdi, %r13
leaq 0x18(%rdi), %rax
movq %rax, 0x18(%rsp)
leaq 0x30(%rdi), %r14
leaq 0x48(%rdi), %rax
movq %rax, 0x10(%rsp)
leaq 0x60(%rdi), %r12
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 0x21c0
leaq 0x230(%rsp), %rdi
pushq $0xc
popq %rdx
movq %r15, %rsi
callq 0x20e0
leaq 0x230(%rsp), %rdi
pushq $0x4
popq %rdx
movq %r13, %rsi
callq 0x2210
movq 0x230(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0x250(%rsp,%rax)
jne 0x268a
movl (%r13), %esi
movq 0x18(%rsp), %rdi
callq 0x2bfe
movq 0x18(%r13), %rsi
movl (%r13), %edx
shll $0x3, %edx
leaq 0x230(%rsp), %rdi
callq 0x2210
movl (%r13), %eax
decl %eax
movq 0x18(%r13), %rcx
movq (%rcx,%rax,8), %rsi
movq %rsi, 0x8(%r13)
movq 0x10(%rsp), %rdi
callq 0x2c30
movq 0x8(%r13), %rdx
movq 0x48(%r13), %rsi
shlq $0x3, %rdx
leaq 0x230(%rsp), %rdi
callq 0x2210
movq %r12, %rdi
xorl %esi, %esi
callq 0x2c62
andq $0x0, 0x10(%r13)
testl %ebx, %ebx
jne 0x25f9
leaq 0x20(%rsp), %rdi
callq 0x21c0
leaq 0x20(%rsp), %rdi
pushq $0xc
popq %rdx
movq %rbp, %rsi
callq 0x20e0
movq 0x8(%r13), %rsi
movq %r12, %rdi
callq 0x2c62
movq 0x8(%r13), %rdx
movq 0x60(%r13), %rsi
shlq $0x2, %rdx
leaq 0x20(%rsp), %rdi
callq 0x2210
leaq 0x20(%rsp), %rdi
callq 0x2060
xorl %r15d, %r15d
leaq 0x20(%rsp), %rbx
leaq 0xc(%rsp), %rbp
movl (%r13), %eax
cmpl %eax, %r15d
jae 0x2647
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movl %r15d, 0xc(%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x3526
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2c94
movq %rbx, %rdi
callq 0x34f2
incl %r15d
jmp 0x2606
xorl %ebx, %ebx
cmpl %eax, %ebx
jae 0x266b
movq %r13, %rdi
movl %ebx, %esi
callq 0x2cc0
addsd 0x10(%r13), %xmm0
movsd %xmm0, 0x10(%r13)
incl %ebx
movl (%r13), %eax
jmp 0x2649
leaq 0x230(%rsp), %rdi
callq 0x2060
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x498f(%rip), %rdi      # 0x7020
leaq 0x49a9(%rip), %rsi      # 0x7041
leaq 0x49b3(%rip), %rcx      # 0x7052
pushq $0x22
popq %rdx
callq 0x20f0
jmp 0x26bf
movq %rax, %rbx
jmp 0x26e0
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2060
jmp 0x26d3
jmp 0x26bf
movq %rax, %rbx
jmp 0x26d3
jmp 0x26c6
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x34f2
leaq 0x230(%rsp), %rdi
callq 0x2060
movq %r12, %rdi
callq 0x2f90
movq 0x10(%rsp), %rdi
callq 0x2f5c
movq %r14, %rdi
callq 0x2d5e
movq 0x18(%rsp), %rdi
callq 0x2ec6
movq %rbx, %rdi
callq 0x22f0