// File: /workspace/github_cpp_makefile_star2_O1/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 0x28d2
movl (%rbx), %esi
movq 0x18(%rsp), %rdi
callq 0x318e
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 0x31c0
movq 0x8(%rbx), %rdx
movq 0x48(%rbx), %rsi
shlq $0x3, %rdx
leaq 0x230(%rsp), %rdi
callq 0x2280
movq %r13, %rdi
xorl %esi, %esi
callq 0x31f2
movq $0x0, 0x10(%rbx)
testl %r14d, %r14d
jne 0x27a0
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 0x31f2
movq 0x8(%rbx), %rdx
movq 0x60(%rbx), %rsi
shlq $0x2, %rdx
leaq 0x20(%rsp), %rdi
callq 0x2280
leaq 0x20(%rsp), %rdi
callq 0x2070
movl (%rbx), %esi
testl %esi, %esi
je 0x281a
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 0x28(%rsp), %rsi
testq %rsi, %rsi
je 0x27e3
movl %r12d, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x27ee
movq %r14, %rdi
movq %rbp, %rdx
callq 0x37c8
movq %r15, %rdi
movq %r14, %rsi
callq 0x3224
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2810
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2200
incl %r12d
movl (%rbx), %esi
cmpl %esi, %r12d
jb 0x27b3
testl %esi, %esi
je 0x28b3
movsd 0x10(%rbx), %xmm0
movq 0x68(%rbx), %rax
movq 0x60(%rbx), %rcx
movq 0x18(%rbx), %rdx
movl %esi, %esi
xorl %edi, %edi
cmpq %rcx, %rax
je 0x2884
movq %rcx, %r8
testq %rdi, %rdi
je 0x284d
movq -0x8(%rdx,%rdi,8), %r8
leaq (%rcx,%r8,4), %r8
leal -0x1(%rdi), %r9d
xorpd %xmm1, %xmm1
xorl %r10d, %r10d
testq %rdi, %rdi
je 0x2867
movq (%rdx,%rdi,8), %r11
subq (%rdx,%r9,8), %r11
jmp 0x286a
movl (%rdx), %r11d
movl %r11d, %r11d
cmpq %r11, %r10
jae 0x28a2
xorps %xmm2, %xmm2
cvtss2sd (%r8,%r10,4), %xmm2
addsd %xmm2, %xmm1
incq %r10
jmp 0x2858
testq %rdi, %rdi
je 0x2894
movq (%rdx,%rdi,8), %r8
subq -0x8(%rdx,%rdi,8), %r8
jmp 0x2897
movq (%rdx), %r8
movl %r8d, %r8d
xorps %xmm1, %xmm1
cvtsi2sd %r8, %xmm1
addsd %xmm1, %xmm0
incq %rdi
cmpq %rsi, %rdi
jne 0x2837
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 0x5747(%rip), %rdi      # 0x8020
leaq 0x5761(%rip), %rsi      # 0x8041
leaq 0x576b(%rip), %rcx      # 0x8052
movl $0x22, %edx
callq 0x2130
jmp 0x2907
movq %rax, %r14
jmp 0x2935
movq %rax, %r14
leaq 0x20(%rsp), %rdi
callq 0x2070
jmp 0x2928
movq %rax, %r14
jmp 0x2928
jmp 0x290e
movq %rax, %r14
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2928
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x2200
leaq 0x230(%rsp), %rdi
callq 0x2070
movq (%r13), %rdi
testq %rdi, %rdi
je 0x294a
movq 0x70(%rbx), %rsi
subq %rdi, %rsi
callq 0x2200
movq 0x10(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2963
movq 0x58(%rbx), %rsi
subq %rdi, %rsi
callq 0x2200
movq %r15, %rdi
callq 0x3250
movq 0x18(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x2984
movq 0x28(%rbx), %rsi
subq %rdi, %rsi
callq 0x2200
movq %r14, %rdi
callq 0x2370