// File: /workspace/github_c_makefile_star2_O0/ComplexNetworks-DCC-FCUP[P]gtrieScanner/GraphUtils.cpp
// Function: GraphUtils::orderGraph(Graph*, Graph*)
void GraphUtils::orderGraph(Graph *old, Graph *g) {
  int i, j, aux;
  int size= old->numNodes();
  int degree[size];
  int *ds[size];
  int neighbours[size];
  vector<int> *v;

  for (i=0; i<size; i++) {
    degree[i] = old->nodeOutEdges(i) + old->nodeOutEdges(i);
    neighbours[i] = old->numNeighbours(i);
    ds[i] = new int[neighbours[i]];        
    v = old->neighbours(i);
    for (j=0; j<neighbours[i]; j++)
      ds[i][j] = old->nodeOutEdges((*v)[j]) + old->nodeOutEdges((*v)[j]);
    qsort(ds[i], old->numNeighbours(i), sizeof(int), _compare_int);
  }
  
  _degree =  degree;
  _ds     = ds;
  _neighbours = neighbours;
  int n[size], r[size];
  for (i=0; i<size; i++) n[i]=i;
  qsort(n, size, sizeof(int), _compare_degree);
  for (i=0; i<size; i++) r[n[i]]=i;

  for (i=0; i<size; i++)
    delete[] ds[i];

  g->createGraph(size, old->type());
  for (i=0; i<size; i++) {
    v = old->outEdges(i);
    aux = v->size();
    for (j=0; j<aux; j++)
      g->addEdge(r[i], r[(*v)[j]]);
    v = old->inEdges(i);
    aux = v->size();
    for (j=0; j<aux; j++)
      g->addEdge(r[(*v)[j]], r[i]);
  }
  
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq (%rdi), %rax
movq 0x40(%rax), %rax
callq *%rax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x28(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x70(%rbp)
movq %rcx, %rsp
movq %rax, -0x30(%rbp)
movl -0x20(%rbp), %eax
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x68(%rbp)
movq %rcx, %rsp
movq %rax, -0x38(%rbp)
movl -0x20(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x60(%rbp)
movq %rcx, %rsp
movq %rax, -0x40(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0xb1c2
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movq (%rdi), %rax
callq *0x60(%rax)
movl %eax, -0x74(%rbp)
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movq (%rdi), %rax
callq *0x60(%rax)
movl -0x74(%rbp), %edx
movl %eax, %ecx
movq -0x70(%rbp), %rax
addl %ecx, %edx
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movq (%rdi), %rax
callq *0x70(%rax)
movl %eax, %edx
movq -0x60(%rbp), %rax
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movslq -0x14(%rbp), %rcx
movslq (%rax,%rcx,4), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x3030
movq %rax, %rdx
movq -0x68(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movq (%rdi), %rax
callq *0x98(%rax)
movq %rax, -0x48(%rbp)
movl $0x0, -0x18(%rbp)
movq -0x60(%rbp), %rcx
movl -0x18(%rbp), %eax
movslq -0x14(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0xb179
movq -0x8(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x48(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0x8720
movq -0x88(%rbp), %rdi
movl (%rax), %esi
movq (%rdi), %rax
callq *0x60(%rax)
movl %eax, -0x78(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x48(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0x8720
movq -0x80(%rbp), %rdi
movl (%rax), %esi
movq (%rdi), %rax
callq *0x60(%rax)
movl -0x78(%rbp), %edx
movl %eax, %ecx
movq -0x68(%rbp), %rax
addl %ecx, %edx
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x18(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xb0f9
movq -0x68(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x90(%rbp)
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movq (%rdi), %rax
callq *0x70(%rax)
movq -0x90(%rbp), %rdi
movslq %eax, %rsi
movl $0x4, %edx
leaq -0x2af(%rip), %rcx      # 0xaf00
callq 0x34b0
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xb051
movq -0x60(%rbp), %rax
movq -0x68(%rbp), %rcx
movq -0x70(%rbp), %rdx
movq %rdx, 0x2203b(%rip)     # 0x2d210
movq %rcx, 0x2203c(%rip)     # 0x2d218
movq %rax, 0x2203d(%rip)     # 0x2d220
movl -0x20(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xa0(%rbp)
movq %rcx, %rsp
movq %rax, -0x50(%rbp)
movl -0x20(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x98(%rbp)
movq %rcx, %rsp
movq %rax, -0x58(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0xb254
movq -0xa0(%rbp), %rax
movl -0x14(%rbp), %edx
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xb230
movq -0xa0(%rbp), %rdi
movslq -0x20(%rbp), %rsi
movl $0x4, %edx
leaq -0x32b(%rip), %rcx      # 0xaf40
callq 0x34b0
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0xb2a6
movq -0x98(%rbp), %rax
movq -0xa0(%rbp), %rcx
movl -0x14(%rbp), %edx
movslq -0x14(%rbp), %rsi
movslq (%rcx,%rsi,4), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xb277
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0xb2e7
movq -0x68(%rbp), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xa8(%rbp)
cmpq $0x0, %rax
je 0xb2da
movq -0xa8(%rbp), %rdi
callq 0x3360
jmp 0xb2dc
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xb2ad
movq -0x10(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0xac(%rbp)
movq -0x8(%rbp), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
movq -0xb8(%rbp), %rdi
movl -0xac(%rbp), %esi
movl %eax, %edx
movq (%rdi), %rax
callq *0x18(%rax)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0xb43c
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movq (%rdi), %rax
callq *0xb8(%rax)
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x8700
movl %eax, -0x1c(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xb3b6
movq -0x98(%rbp), %rax
movq -0x10(%rbp), %rcx
movq %rcx, -0xc8(%rbp)
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0xbc(%rbp)
movq -0x48(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0x8720
movq -0xc8(%rbp), %rdi
movl -0xbc(%rbp), %esi
movq %rax, %rcx
movq -0x98(%rbp), %rax
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %edx
movq (%rdi), %rax
callq *0x30(%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xb354
movq -0x8(%rbp), %rdi
movl -0x14(%rbp), %esi
movq (%rdi), %rax
callq *0xc0(%rax)
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x8700
movl %eax, -0x1c(%rbp)
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xb42c
movq -0x10(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x48(%rbp), %rdi
movslq -0x18(%rbp), %rsi
callq 0x8720
movq -0xd0(%rbp), %rdi
movq %rax, %rcx
movq -0x98(%rbp), %rax
movslq (%rcx), %rcx
movl (%rax,%rcx,4), %esi
movslq -0x14(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq (%rdi), %rax
callq *0x30(%rax)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xb3dd
jmp 0xb42e
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xb321
movq -0x28(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax,%rax)