// File: 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
movq %rsp, %rbp
subq $0x4c0, %rsp            # imm = 0x4C0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x478(%rbp)
addq $0x18, %rdi
movq %rdi, -0x490(%rbp)
callq 0x32d0
movq -0x478(%rbp), %rdi
addq $0x30, %rdi
movq %rdi, -0x488(%rbp)
callq 0x32f0
movq -0x478(%rbp), %rdi
addq $0x48, %rdi
movq %rdi, -0x480(%rbp)
callq 0x3310
movq -0x478(%rbp), %rdi
addq $0x60, %rdi
movq %rdi, -0x470(%rbp)
callq 0x3330
leaq -0x228(%rbp), %rdi
callq 0x21e0
jmp 0x25f8
movq -0x10(%rbp), %rax
movq %rax, -0x4a0(%rbp)
movl $0x8, %edi
movl $0x4, %esi
callq 0x3350
movl %eax, -0x494(%rbp)
jmp 0x261a
movl -0x494(%rbp), %edx
movq -0x4a0(%rbp), %rsi
leaq -0x228(%rbp), %rdi
callq 0x2100
jmp 0x2635
movq -0x478(%rbp), %rsi
leaq -0x228(%rbp), %rdi
movl $0x4, %edx
callq 0x2230
jmp 0x264f
movq -0x228(%rbp), %rax
movq -0x18(%rax), %rax
leaq -0x228(%rbp,%rax), %rdi
callq 0x2150
movl %eax, -0x4a4(%rbp)
jmp 0x266f
movl -0x4a4(%rbp), %eax
cmpl $0x0, %eax
jne 0x267c
jmp 0x26c9
leaq 0x12981(%rip), %rdi     # 0x15004
leaq 0x1299b(%rip), %rsi     # 0x15025
movl $0x22, %edx
leaq 0x129a0(%rip), %rcx     # 0x15036
callq 0x2110
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x29a8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
jmp 0x299c
movq -0x478(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movl (%rax), %eax
movl %eax, %esi
callq 0x3370
jmp 0x26e2
movq -0x478(%rbp), %rdi
addq $0x18, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3400
movq %rax, %rsi
movq -0x478(%rbp), %rax
movl (%rax), %eax
shll $0x3, %eax
movl %eax, %edx
leaq -0x228(%rbp), %rdi
callq 0x2230
jmp 0x2715
movq -0x478(%rbp), %rax
movq %rax, %rdi
addq $0x18, %rdi
movl (%rax), %eax
decl %eax
movl %eax, %esi
callq 0x3400
movq %rax, %rcx
movq -0x478(%rbp), %rax
movq (%rcx), %rcx
movq %rcx, 0x8(%rax)
movq %rax, %rdi
addq $0x48, %rdi
movq 0x8(%rax), %rsi
callq 0x3420
jmp 0x2751
movq -0x478(%rbp), %rdi
addq $0x48, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x34b0
movq %rax, %rsi
movq -0x478(%rbp), %rax
movq 0x8(%rax), %rdx
shlq $0x3, %rdx
leaq -0x228(%rbp), %rdi
callq 0x2230
jmp 0x2785
movq -0x478(%rbp), %rdi
addq $0x60, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x34d0
jmp 0x279b
movq -0x478(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x10(%rax)
cmpl $0x0, -0x1c(%rbp)
jne 0x287d
leaq -0x440(%rbp), %rdi
callq 0x21e0
jmp 0x27c2
movq -0x18(%rbp), %rax
movq %rax, -0x4b0(%rbp)
movl $0x8, %edi
movl $0x4, %esi
callq 0x3350
movl %eax, -0x4a8(%rbp)
jmp 0x27e4
movl -0x4a8(%rbp), %edx
movq -0x4b0(%rbp), %rsi
leaq -0x440(%rbp), %rdi
callq 0x2100
jmp 0x27ff
movq -0x478(%rbp), %rax
movq %rax, %rdi
addq $0x60, %rdi
movq 0x8(%rax), %rsi
callq 0x34d0
jmp 0x2818
movq -0x478(%rbp), %rdi
addq $0x60, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3560
movq %rax, %rsi
movq -0x478(%rbp), %rax
movq 0x8(%rax), %rdx
shlq $0x2, %rdx
leaq -0x440(%rbp), %rdi
callq 0x2230
jmp 0x284c
leaq -0x440(%rbp), %rdi
callq 0x2080
jmp 0x287d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x440(%rbp), %rdi
callq 0x2080
jmp 0x299c
movl $0x0, -0x444(%rbp)
movq -0x478(%rbp), %rcx
movl -0x444(%rbp), %eax
cmpl (%rcx), %eax
jae 0x2926
leaq -0x460(%rbp), %rdi
movq %rdi, -0x4b8(%rbp)
callq 0x3580
movq -0x4b8(%rbp), %rdi
movl -0x444(%rbp), %eax
movl %eax, -0x464(%rbp)
leaq -0x464(%rbp), %rsi
callq 0x35a0
jmp 0x28d0
movq -0x478(%rbp), %rdi
addq $0x30, %rdi
leaq -0x460(%rbp), %rsi
callq 0x35d0
jmp 0x28e9
leaq -0x460(%rbp), %rdi
callq 0x3640
movl -0x444(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x444(%rbp)
jmp 0x2887
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x230(%rbp)
movl %eax, -0x234(%rbp)
leaq -0x460(%rbp), %rdi
callq 0x3640
jmp 0x299c
movl $0x0, -0x468(%rbp)
movq -0x478(%rbp), %rcx
movl -0x468(%rbp), %eax
cmpl (%rcx), %eax
jae 0x2987
movq -0x478(%rbp), %rdi
movl -0x468(%rbp), %esi
callq 0x36a0
movsd %xmm0, -0x4c0(%rbp)
jmp 0x295d
movq -0x478(%rbp), %rax
movsd -0x4c0(%rbp), %xmm0
addsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rax)
movl -0x468(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x468(%rbp)
jmp 0x2930
leaq -0x228(%rbp), %rdi
callq 0x2080
addq $0x4c0, %rsp            # imm = 0x4C0
popq %rbp
retq
leaq -0x228(%rbp), %rdi
callq 0x2080
movq -0x470(%rbp), %rdi
callq 0x37c0
movq -0x480(%rbp), %rdi
callq 0x3820
movq -0x488(%rbp), %rdi
callq 0x3880
movq -0x490(%rbp), %rdi
callq 0x38e0
movq -0x230(%rbp), %rdi
callq 0x2300
nopw %cs:(%rax,%rax)