// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rsi, %r14
movq (%rdi), %rax
movq %rdi, -0x48(%rbp)
callq *0x40(%rax)
movl %eax, %r12d
leaq 0xf(,%r12,4), %rsi
andq $-0x10, %rsi
movq %rsp, %r13
subq %rsi, %r13
movq %r13, %rsp
leaq 0xf(,%r12,8), %rcx
andq $-0x10, %rcx
movq %rsp, %rdx
subq %rcx, %rdx
movq %rdx, %rsp
movq %rsp, %rcx
subq %rsi, %rcx
movq %rcx, %rsp
testl %eax, %eax
movq %r14, -0x50(%rbp)
movq %r12, -0x60(%rbp)
jle 0x5d0b
movq %rcx, -0x38(%rbp)
movq %rsi, -0x68(%rbp)
movq %rdx, -0x58(%rbp)
xorl %r14d, %r14d
movq -0x48(%rbp), %rbx
movq %r13, -0x70(%rbp)
movq (%rbx), %rax
movq %rbx, %rdi
movl %r14d, %esi
callq *0x60(%rax)
movl %eax, %r15d
movq (%rbx), %rax
movq %rbx, %rdi
movl %r14d, %esi
callq *0x60(%rax)
addl %r15d, %eax
movl %eax, (%r13,%r14,4)
movq (%rbx), %rax
movq %rbx, %rdi
movl %r14d, %esi
callq *0x70(%rax)
movl %eax, %r12d
movq -0x38(%rbp), %rax
movl %r12d, (%rax,%r14,4)
movl %r12d, %eax
movq %rax, -0x40(%rbp)
leaq (,%rax,4), %rdi
testl %r12d, %r12d
movq $-0x1, %rax
cmovsq %rax, %rdi
callq 0x2030
movq %rax, %r13
movq -0x58(%rbp), %rax
movq %r13, (%rax,%r14,8)
movq (%rbx), %rax
movq %rbx, %rdi
movq %r14, -0x30(%rbp)
movl %r14d, %esi
callq *0x98(%rax)
testl %r12d, %r12d
jle 0x5bae
movq %rax, %r15
xorl %r14d, %r14d
movq (%r15), %rax
movl (%rax,%r14,4), %esi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x60(%rax)
movl %eax, %r12d
movq (%r15), %rax
movl (%rax,%r14,4), %esi
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x60(%rax)
addl %r12d, %eax
movl %eax, (%r13,%r14,4)
incq %r14
cmpq -0x40(%rbp), %r14
jb 0x5b7a
movq (%rbx), %rax
movq %rbx, %rdi
movq -0x30(%rbp), %r14
movl %r14d, %esi
callq *0x70(%rax)
movslq %eax, %rsi
movl $0x4, %edx
movq %r13, %rdi
leaq -0x184(%rip), %rcx      # 0x5a4c
callq 0x23c0
incq %r14
movq -0x60(%rbp), %r12
cmpq %r12, %r14
movq -0x70(%rbp), %r13
jne 0x5af5
movq %r13, 0x13b90(%rip)     # 0x19780
movq -0x58(%rbp), %r13
movq %r13, 0x13b8d(%rip)     # 0x19788
movq -0x38(%rbp), %rax
movq %rax, 0x13b8a(%rip)     # 0x19790
movq %rsp, %r15
movq -0x68(%rbp), %rax
subq %rax, %r15
movq %r15, %rsp
movq %rsp, %rbx
subq %rax, %rbx
movq %rbx, %rsp
testl %r12d, %r12d
movq %rbx, -0x38(%rbp)
jle 0x5d38
leal 0x1(%r12), %eax
andl $-0x2, %eax
leaq -0x1(%r12), %rcx
movq %rcx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqa 0xbf98(%rip), %xmm1     # 0x11be0
xorl %ecx, %ecx
movdqa 0xbf9e(%rip), %xmm2     # 0x11bf0
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0xbf9e(%rip), %xmm4     # 0x11c00
movq -0x50(%rbp), %r14
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %edx
notl %edx
testb $0x1, %dl
je 0x5c9b
movl %ecx, (%r15,%rcx,4)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %edx
testb $0x1, %dl
je 0x5cb1
leal 0x1(%rcx), %edx
movl %edx, 0x4(%r15,%rcx,4)
addq $0x2, %rcx
paddq %xmm4, %xmm1
cmpq %rcx, %rax
jne 0x5c66
leaq -0x26d(%rip), %rcx      # 0x5a58
movl $0x4, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x23c0
testl %r12d, %r12d
jle 0x5d53
xorl %eax, %eax
movslq (%r15,%rax,4), %rcx
movl %eax, (%rbx,%rcx,4)
incq %rax
cmpq %rax, %r12
jne 0x5cdc
testl %r12d, %r12d
jle 0x5d53
xorl %ebx, %ebx
movq (%r13,%rbx,8), %rdi
testq %rdi, %rdi
je 0x5d01
callq 0x2290
incq %rbx
cmpq %rbx, %r12
jne 0x5cf2
jmp 0x5d53
movq %r13, 0x13a6e(%rip)     # 0x19780
movq %rdx, 0x13a6f(%rip)     # 0x19788
movq %rcx, 0x13a70(%rip)     # 0x19790
movq %rsp, %r15
subq %rsi, %r15
movq %r15, %rsp
movq %rsp, %rax
subq %rsi, %rax
movq %rax, -0x38(%rbp)
movq %rax, %rsp
jmp 0x5d3c
movq -0x50(%rbp), %r14
movslq %r12d, %rsi
leaq -0x2ee(%rip), %rcx      # 0x5a58
movl $0x4, %edx
movq %r15, %rdi
callq 0x23c0
movq -0x48(%rbp), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
movq (%r14), %rcx
movq %r14, %rdi
movl %r12d, %esi
movl %eax, %edx
callq *0x18(%rcx)
testl %r12d, %r12d
jle 0x5e3f
xorl %esi, %esi
movq -0x50(%rbp), %r12
movq -0x38(%rbp), %r15
movq -0x48(%rbp), %rdi
movq (%rdi), %rax
movq %rsi, -0x30(%rbp)
callq *0xb8(%rax)
movq 0x8(%rax), %rbx
subq (%rax), %rbx
shrq $0x2, %rbx
testl %ebx, %ebx
jle 0x5dd6
movq %rax, %r13
movq -0x30(%rbp), %rax
movl (%r15,%rax,4), %eax
movl %eax, -0x40(%rbp)
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
xorl %r14d, %r14d
movq (%r13), %rax
movslq (%rax,%r14,4), %rax
movl (%r15,%rax,4), %edx
movq (%r12), %rax
movq %r12, %rdi
movl -0x40(%rbp), %esi
callq *0x30(%rax)
incq %r14
cmpq %r14, %rbx
jne 0x5db5
movq -0x48(%rbp), %rdi
movq (%rdi), %rax
movq -0x30(%rbp), %rsi
callq *0xc0(%rax)
movq 0x8(%rax), %rbx
subq (%rax), %rbx
shrq $0x2, %rbx
testl %ebx, %ebx
jle 0x5e2e
movq %rax, %r13
movq -0x30(%rbp), %rax
movl (%r15,%rax,4), %eax
movl %eax, -0x40(%rbp)
andl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
xorl %r14d, %r14d
movq (%r13), %rax
movslq (%rax,%r14,4), %rax
movl (%r15,%rax,4), %esi
movq (%r12), %rax
movq %r12, %rdi
movl -0x40(%rbp), %edx
callq *0x30(%rax)
incq %r14
cmpq %r14, %rbx
jne 0x5e0d
movq -0x30(%rbp), %rsi
incq %rsi
cmpq -0x60(%rbp), %rsi
jne 0x5d7e
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop