// File: /workspace/github_cpp_makefile_star2_O1/riyadparvez[P]louvain-method/graph.cpp
// Function: Graph::display_binary(char*, char*, int)
void
Graph::display_binary(char *filename, char *filename_w, int type) {
  ofstream foutput;
  foutput.open(filename, fstream::out | fstream::binary);

  unsigned int s = links.size();

  // outputs number of nodes
  foutput.write((char *)(&s),4);

  // outputs cumulative degree sequence
  long tot=0;
  for (unsigned int i=0 ; i<s ; i++) {
    tot+=(long)links[i].size();
    foutput.write((char *)(&tot),8);
  }

  // outputs links
  for (unsigned int i=0 ; i<s ; i++) {
    for (unsigned int j=0 ; j<links[i].size() ; j++) {
      int dest = links[i][j].first;
      foutput.write((char *)(&dest),4);
    }
  }
  foutput.close();

  // outputs weights in a separate file
  if (type==WEIGHTED) {
    ofstream foutput_w;
    foutput_w.open(filename_w,fstream::out | fstream::binary);
    for (unsigned int i=0 ; i<s ; i++) {
      for (unsigned int j=0 ; j<links[i].size() ; j++) {
	float weight = links[i][j].second;
	foutput_w.write((char *)(&weight),4);
      }
    }
    foutput_w.close();
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x428, %rsp            # imm = 0x428
movl %ecx, %ebp
movq %rdx, 0x20(%rsp)
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x228(%rsp), %r12
movq %r12, %rdi
callq 0x2280
movq %r12, %rdi
movq %r15, %rsi
movl $0x14, %edx
callq 0x2040
movq 0x8(%rbx), %rax
subq (%rbx), %rax
shrq $0x3, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
leaq 0xc(%rsp), %rsi
movl %eax, (%rsi)
leaq 0x228(%rsp), %rdi
movl $0x4, %edx
callq 0x2200
movq $0x0, 0x18(%rsp)
cmpl $0x0, 0xc(%rsp)
je 0x2ddf
movl $0x8, %r14d
xorl %r13d, %r13d
leaq 0x228(%rsp), %r15
leaq 0x18(%rsp), %r12
movq (%rbx), %rax
movq (%rax,%r14), %rcx
subq -0x8(%rax,%r14), %rcx
sarq $0x3, %rcx
addq %rcx, 0x18(%rsp)
movl $0x8, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2200
incq %r13
movl 0xc(%rsp), %eax
addq $0x18, %r14
cmpq %rax, %r13
jb 0x2daa
movl %ebp, 0x10(%rsp)
cmpl $0x0, 0xc(%rsp)
je 0x2e59
xorl %r13d, %r13d
leaq 0x228(%rsp), %r15
leaq 0x28(%rsp), %r12
movq (%rbx), %rcx
leaq (,%r13,2), %r14
addq %r13, %r14
movq (%rcx,%r14,8), %rax
cmpq %rax, 0x8(%rcx,%r14,8)
je 0x2e4d
movl $0x1, %ebp
xorl %ecx, %ecx
movl (%rax,%rcx,8), %eax
movl %eax, 0x28(%rsp)
movl $0x4, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x2200
movl %ebp, %ecx
movq (%rbx), %rdx
movq (%rdx,%r14,8), %rax
movq 0x8(%rdx,%r14,8), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
incl %ebp
cmpq %rcx, %rdx
ja 0x2e1a
incq %r13
movl 0xc(%rsp), %eax
cmpq %rax, %r13
jb 0x2dfa
leaq 0x228(%rsp), %rdi
callq 0x2210
cmpl $0x0, 0x10(%rsp)
jne 0x2f3c
leaq 0x28(%rsp), %rdi
callq 0x2280
leaq 0x28(%rsp), %rdi
movq 0x20(%rsp), %rsi
movl $0x14, %edx
callq 0x2040
cmpl $0x0, 0xc(%rsp)
je 0x2f00
xorl %r12d, %r12d
leaq 0x28(%rsp), %r14
leaq 0x14(%rsp), %r15
movq (%rbx), %rcx
leaq (%r12,%r12,2), %r13
movq (%rcx,%r13,8), %rax
cmpq %rax, 0x8(%rcx,%r13,8)
je 0x2ef4
movl $0x1, %ebp
xorl %ecx, %ecx
movss 0x4(%rax,%rcx,8), %xmm0
movss %xmm0, 0x14(%rsp)
movl $0x4, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2200
movl %ebp, %ecx
movq (%rbx), %rdx
movq (%rdx,%r13,8), %rax
movq 0x8(%rdx,%r13,8), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
incl %ebp
cmpq %rcx, %rdx
ja 0x2ebc
incq %r12
movl 0xc(%rsp), %eax
cmpq %rax, %r12
jb 0x2ea3
leaq 0x28(%rsp), %rdi
callq 0x2210
movq 0x50b7(%rip), %rax      # 0x7fc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x30(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x28(%rsp,%rcx)
callq 0x2150
leaq 0x120(%rsp), %rdi
callq 0x2090
movq 0x5085(%rip), %rax      # 0x7fc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x230(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x228(%rsp,%rcx)
callq 0x2150
leaq 0x320(%rsp), %rdi
callq 0x2090
addq $0x428, %rsp            # imm = 0x428
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2fa1
jmp 0x2f92
jmp 0x2fa1
jmp 0x2fa1
jmp 0x2fa1
jmp 0x2fa1
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x2230
jmp 0x2fa4
movq %rax, %rbx
leaq 0x228(%rsp), %rdi
callq 0x2230
movq %rbx, %rdi
callq 0x22b0
nop