// File: /workspace/github_c_makefile_star2_O2/ComplexNetworks-DCC-FCUP[P]fase/DynamicGraph.cpp
// Function: DynamicGraph::prepareGraph()
void DynamicGraph::prepareGraph() {
  _deleteAux();
  ready = true;

  hybrid_ch = new int[_num_nodes];

  int i, j;
  long long int total = 0;
  for (i = 0; i < _num_nodes; i++) {
    sort(_adjOut[i].begin(), _adjOut[i].end());
    sort(_adjIn[i].begin(), _adjIn[i].end());

    total += _out[i];
  }

  int tmp_log = 2 * total / _num_nodes;
  _sqrt_nodes = 1;
  while (_sqrt_nodes < tmp_log)
    _sqrt_nodes *= 2;
  _sqrt_nodes--;

  _adjM = new bool*[_num_nodes];

  vector<pair<int, int> > vs;
  for (i = 0; i < _num_nodes; i++) {
    hybrid_ch[i] = 1;
    vs.push_back(pair<int, int>(_out[i], i));
  }

  sort(vs.begin(), vs.end());
  reverse(vs.begin(), vs.end());

  for (i = 0; i < min(5 * _sqrt_nodes / 2, _num_nodes); i++) {
    int cur_node = vs[i].second;
    hybrid_ch[cur_node] = 0;
    _adjM[cur_node] = new bool[_num_nodes];
    for (j = 0; j < _num_nodes; j++)
      _adjM[cur_node][j] = false;

    for (j = 0; j < _out[cur_node]; j++)
      _adjM[cur_node][_adjOut[cur_node][j]] = true;
  }

  _hashM = new l_list**[_num_nodes];

  for (i = 0; i < _num_nodes; i++) {
    if (!hybrid_ch[i])
      continue;

    int tmp_log = 5 * _out[i] / 2;
    _hash_out[i] = 1;
    while (_hash_out[i] < tmp_log)
      _hash_out[i] *= 2;
    _hash_out[i]--;

    _hashM[i] = new l_list*[_hash_out[i] + 1];

    for (j = 0; j <= _hash_out[i]; j++)
      _hashM[i][j] = NULL;
  }

  for (i = 0; i < _num_nodes; i++) {
    if (!hybrid_ch[i])
      continue;

    for (j = 0; j < _out[i]; j++) {
      l_list* n_node = new l_list();
      n_node->value = _adjOut[i][j];
      n_node->next = _hashM[i][_adjOut[i][j] & _hash_out[i]];
      _hashM[i][_adjOut[i][j] & _hash_out[i]] = n_node;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
callq 0x490e
movb $0x1, 0x78(%rbx)
movslq 0xc(%rbx), %r13
leaq (,%r13,4), %rdi
testq %r13, %r13
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
callq 0x2030
movq %rax, 0x40(%rbx)
pushq $0x2
popq %r15
xorl %r12d, %r12d
xorl %r14d, %r14d
movslq %r13d, %rcx
cmpq %rcx, %r12
jge 0x4c5f
movq 0x58(%rbx), %rax
movq -0x8(%rax,%r15,4), %rdi
movq (%rax,%r15,4), %rsi
callq 0x544f
movq 0x60(%rbx), %rax
movq -0x8(%rax,%r15,4), %rdi
movq (%rax,%r15,4), %rsi
callq 0x544f
movq 0x28(%rbx), %rax
movslq (%rax,%r12,4), %rax
addq %rax, %r14
incq %r12
movl 0xc(%rbx), %r13d
addq $0x6, %r15
jmp 0x4c1b
addq %r14, %r14
movq %r14, %rax
cqto
idivq %rcx
pushq $0x1
popq %rsi
movl %esi, %edx
leal (%rdx,%rdx), %esi
cmpl %eax, %edx
jl 0x4c6d
decl %edx
movl %edx, 0x14(%rbx)
leaq (,%rcx,8), %rdi
testl %ecx, %ecx
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
callq 0x2030
movq %rax, 0x48(%rbx)
leaq 0x10(%rsp), %r14
andq $0x0, 0x10(%r14)
xorps %xmm0, %xmm0
movaps %xmm0, (%r14)
xorl %r12d, %r12d
leaq 0x8(%rsp), %r15
movslq %r13d, %rax
cmpq %rax, %r12
jge 0x4ce7
movq 0x40(%rbx), %rax
movl $0x1, (%rax,%r12,4)
movq 0x28(%rbx), %rax
movl (%rax,%r12,4), %eax
movl %eax, 0x8(%rsp)
movl %r12d, 0xc(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x5884
incq %r12
movl 0xc(%rbx), %r13d
jmp 0x4cae
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x5a01
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x5f95
movl 0xc(%rbx), %r15d
xorl %r14d, %r14d
pushq $0x2
popq %rbp
xorl %r13d, %r13d
imull $0x5, 0x14(%rbx), %eax
cltd
idivl %ebp
cmpl %eax, %r15d
cmovll %r15d, %eax
cltq
cmpq %rax, %r13
jge 0x4db4
movq 0x10(%rsp), %rax
movslq 0x4(%rax,%r13,8), %r12
movq 0x40(%rbx), %rax
andl $0x0, (%rax,%r12,4)
movl 0xc(%rbx), %r15d
movslq %r15d, %rdi
callq 0x2030
movq 0x48(%rbx), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x48(%rbx), %rax
testl %r15d, %r15d
movl $0x0, %ecx
cmovgl %r15d, %ecx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x4d76
movq (%rax,%r12,8), %rsi
movb $0x0, (%rsi,%rdx)
incq %rdx
jmp 0x4d64
movq 0x28(%rbx), %rcx
movq 0x48(%rbx), %rax
movl (%rcx,%r12,4), %ecx
imulq $0x18, %r12, %rdx
addq 0x58(%rbx), %rdx
testl %ecx, %ecx
cmovlel %r14d, %ecx
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x4dac
movq (%rax,%r12,8), %rdi
movq (%rdx), %r8
movslq (%r8,%rsi,4), %r8
movb $0x1, (%rdi,%r8)
incq %rsi
jmp 0x4d92
incq %r13
jmp 0x4d12
movslq %r15d, %rdi
shlq $0x3, %rdi
testl %r15d, %r15d
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
callq 0x2030
movq %rax, 0x70(%rbx)
xorl %r14d, %r14d
pushq $0x1
popq %r13
movslq %r15d, %rax
cmpq %rax, %r14
jge 0x4e52
movq 0x40(%rbx), %rax
cmpl $0x0, (%rax,%r14,4)
je 0x4e4d
movq 0x28(%rbx), %rax
movq 0x30(%rbx), %rcx
imull $0x5, (%rax,%r14,4), %eax
cltd
idivl %ebp
movl %r13d, %esi
movl %esi, %edx
leal (%rdx,%rdx), %esi
cmpl %eax, %edx
jl 0x4dfb
leal -0x1(%rdx), %eax
movl %eax, (%rcx,%r14,4)
movslq %edx, %rdi
shlq $0x3, %rdi
testl %edx, %edx
pushq $-0x1
popq %rax
cmovsq %rax, %rdi
callq 0x2030
movq 0x70(%rbx), %rcx
movq %rax, (%rcx,%r14,8)
xorl %eax, %eax
movq 0x30(%rbx), %rcx
movslq (%rcx,%r14,4), %rcx
cmpq %rcx, %rax
jg 0x4e49
movq 0x70(%rbx), %rcx
movq (%rcx,%r14,8), %rcx
andq $0x0, (%rcx,%rax,8)
incq %rax
jmp 0x4e2a
movl 0xc(%rbx), %r15d
incq %r14
jmp 0x4dd5
xorl %r12d, %r12d
testl %r15d, %r15d
cmovlel %r12d, %r15d
pushq $0x10
popq %r14
cmpq %r15, %r12
je 0x4ecb
movq 0x40(%rbx), %rax
cmpl $0x0, (%rax,%r12,4)
je 0x4ec6
imulq $0x18, %r12, %r13
xorl %ebp, %ebp
movq 0x28(%rbx), %rax
movslq (%rax,%r12,4), %rax
cmpq %rax, %rbp
jge 0x4ec6
movq %r14, %rdi
callq 0x21a0
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
movq 0x58(%rbx), %rcx
movq (%rcx,%r13), %rcx
movl (%rcx,%rbp,4), %ecx
movl %ecx, (%rax)
movq 0x30(%rbx), %rdx
movq 0x70(%rbx), %rsi
movq (%rsi,%r12,8), %rdi
andl (%rdx,%r12,4), %ecx
movslq %ecx, %rcx
movq (%rdi,%rcx,8), %rdx
movq %rdx, 0x8(%rax)
movq (%rsi,%r12,8), %rdx
movq %rax, (%rdx,%rcx,8)
incq %rbp
jmp 0x4e76
incq %r12
jmp 0x4e60
leaq 0x10(%rsp), %rdi
callq 0x5850
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4eec
jmp 0x4eec
jmp 0x4eec
jmp 0x4eec
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x5850
movq %rbx, %rdi
callq 0x22f0
nop