// File: /workspace/github_c_makefile_star2_O3/ComplexNetworks-DCC-FCUP[P]gtrieScanner/Isomorphism.cpp
// Function: Isomorphism::canonicalRandom(char const*, char*, int)
void Isomorphism::canonicalRandom(const char *in, char *best, int size) {
  int n, i, j, aux;
  bool used[size];
  int v[size];
  int ncand, cand[size];
  bool adj[size][size];

  for (i=0; i<size; i++) {
    used[i]      = false;
    for (j=0; j<size; j++)
      if (in[i*size+j]=='1' || in[j*size+i]=='1') adj[i][j]=true;
      else adj[i][j]=false;
  }


  for (n=0; n<size; n++) {
    
    ncand = 0;
    for (i=0; i<size; i++) {
      if (used[i]) continue;
      for (j=0;j<n;j++)
	if (adj[i][v[j]]) break;
      if (j<n) cand[ncand++]=i;
    }

    if (ncand==0)
      for (i=0; i<size; i++)
	if (!used[i]) cand[ncand++]=i;

    aux = random()%ncand;

    v[n]=cand[aux];
    used[cand[aux]]=true;
  }
  

  best[size*size]=0;
  for (i=0; i<n; i++)
    for (j=0; j<n; j++)
      best[i*size+j] = in[v[i]*size+v[j]];
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %r12d
movq %rsp, %r15
leaq 0xf(%r12), %rax
andq $-0x10, %rax
subq %rax, %r15
movq %r15, %rsp
movq %rsp, %r13
leaq 0xf(,%r12,4), %rax
andq $-0x10, %rax
subq %rax, %r13
movq %r13, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, %rsp
movq %r12, %rax
imulq %r12, %rax
movq %rsp, %r10
addq $0xf, %rax
andq $-0x10, %rax
subq %rax, %r10
movq %r10, %rsp
testl %edx, %edx
jle 0x7f33
movq %rcx, -0x38(%rbp)
xorl %eax, %eax
movq %rdi, %rcx
movq %rdi, %rbx
movq %r10, -0x30(%rbp)
movb $0x0, (%r15,%rax)
movq %rcx, %r11
xorl %r8d, %r8d
movb $0x1, %r9b
cmpb $0x31, (%rbx,%r8)
je 0x7e19
cmpb $0x31, (%r11)
sete %r9b
movb %r9b, (%r10,%r8)
incq %r8
addq %r12, %r11
cmpq %r8, %r12
jne 0x7e07
incq %rax
addq %r12, %r10
addq %r12, %rbx
incq %rcx
cmpq %r12, %rax
jne 0x7dfc
testl %edx, %edx
movq -0x38(%rbp), %r8
movq -0x30(%rbp), %r9
jle 0x7f33
movq %rdx, -0x40(%rbp)
movq %rdi, -0x48(%rbp)
movq %rsi, -0x50(%rbp)
xorl %r14d, %r14d
xorl %eax, %eax
xorl %ebx, %ebx
testq %r14, %r14
je 0x7e92
cmpb $0x0, (%r15,%rax)
jne 0x7e92
movq %rax, %rcx
imulq %r12, %rcx
addq %r9, %rcx
xorl %edx, %edx
movslq (%r13,%rdx,4), %rsi
cmpb $0x1, (%rcx,%rsi)
je 0x7e89
incq %rdx
cmpq %rdx, %r14
jne 0x7e74
jmp 0x7e92
movslq %ebx, %rcx
incl %ebx
movl %eax, (%r8,%rcx,4)
incq %rax
cmpq %r12, %rax
jne 0x7e5c
testl %ebx, %ebx
jne 0x7eba
xorl %eax, %eax
xorl %ebx, %ebx
cmpb $0x0, (%r15,%rax)
jne 0x7eb2
movslq %ebx, %rcx
incl %ebx
movl %eax, (%r8,%rcx,4)
incq %rax
cmpq %rax, %r12
jne 0x7ea2
callq 0x2100
movq -0x38(%rbp), %r8
movslq %ebx, %rcx
cqto
idivq %rcx
movslq (%r8,%rdx,4), %rax
movl %eax, (%r13,%r14,4)
movb $0x1, (%r15,%rax)
incq %r14
cmpq %r12, %r14
movq -0x30(%rbp), %r9
jne 0x7e58
movq %r12, %rax
imulq %r12, %rax
movq -0x50(%rbp), %r8
movb $0x0, (%r8,%rax)
xorl %eax, %eax
movslq -0x40(%rbp), %rcx
movq -0x48(%rbp), %r9
movslq (%r13,%rax,4), %rdx
imulq %rcx, %rdx
xorl %esi, %esi
movslq (%r13,%rsi,4), %rdi
addq %rdx, %rdi
movb (%r9,%rdi), %dil
movb %dil, (%r8,%rsi)
incq %rsi
cmpq %rsi, %r12
jne 0x7f0e
incq %rax
addq %r12, %r8
cmpq %r12, %rax
jne 0x7f03
jmp 0x7f3a
imull %edx, %edx
movb $0x0, (%rsi,%rdx)
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop