// File: /workspace/github_c_makefile_star2_O0/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
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x30(%rbp)
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x88(%rbp)
movq %rcx, %rsp
movq %rax, -0x38(%rbp)
movl -0x14(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x80(%rbp)
movq %rcx, %rsp
movq %rax, -0x40(%rbp)
movl -0x14(%rbp), %eax
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x78(%rbp)
movq %rcx, %rsp
movq %rax, -0x50(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %ecx
movq %rcx, %rax
movq %rax, -0x70(%rbp)
movq %rcx, %rsi
imulq %rsi, %rsi
addq $0xf, %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0x68(%rbp)
movq %rdx, %rsp
movq %rcx, -0x58(%rbp)
movq %rax, -0x60(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xf3ac
movq -0x88(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xf39c
movq -0x8(%rbp), %rax
movl -0x1c(%rbp), %ecx
imull -0x14(%rbp), %ecx
addl -0x20(%rbp), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x31, %eax
je 0xf354
movq -0x8(%rbp), %rax
movl -0x20(%rbp), %ecx
imull -0x14(%rbp), %ecx
addl -0x1c(%rbp), %ecx
movslq %ecx, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x31, %eax
jne 0xf371
movq -0x68(%rbp), %rax
movq -0x70(%rbp), %rdx
movslq -0x1c(%rbp), %rcx
imulq %rdx, %rcx
addq %rcx, %rax
movslq -0x20(%rbp), %rcx
movb $0x1, (%rax,%rcx)
jmp 0xf38c
movq -0x68(%rbp), %rax
movq -0x70(%rbp), %rdx
movslq -0x1c(%rbp), %rcx
imulq %rdx, %rcx
addq %rcx, %rax
movslq -0x20(%rbp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0xf38e
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xf318
jmp 0xf39e
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xf2f6
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xf4f7
movl $0x0, -0x44(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xf45f
movq -0x88(%rbp), %rax
movslq -0x1c(%rbp), %rcx
testb $0x1, (%rax,%rcx)
je 0xf3ec
jmp 0xf451
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xf42f
movq -0x80(%rbp), %rcx
movq -0x68(%rbp), %rax
movq -0x70(%rbp), %rsi
movslq -0x1c(%rbp), %rdx
imulq %rsi, %rdx
addq %rdx, %rax
movslq -0x20(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
testb $0x1, (%rax,%rcx)
je 0xf422
jmp 0xf42f
jmp 0xf424
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xf3f3
movl -0x20(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xf44f
movq -0x78(%rbp), %rax
movl -0x1c(%rbp), %edx
movl -0x44(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x44(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xf451
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xf3cd
cmpl $0x0, -0x44(%rbp)
jne 0xf4ac
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xf4aa
movq -0x88(%rbp), %rax
movslq -0x1c(%rbp), %rcx
testb $0x1, (%rax,%rcx)
jne 0xf49d
movq -0x78(%rbp), %rax
movl -0x1c(%rbp), %edx
movl -0x44(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x44(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0xf49f
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xf46c
jmp 0xf4ac
callq 0x3130
movq -0x78(%rbp), %rcx
movslq -0x44(%rbp), %rsi
cqto
idivq %rsi
movq -0x88(%rbp), %rax
movq %rdx, %rsi
movq -0x80(%rbp), %rdx
movl %esi, -0x24(%rbp)
movslq -0x24(%rbp), %rsi
movl (%rcx,%rsi,4), %edi
movslq -0x18(%rbp), %rsi
movl %edi, (%rdx,%rsi,4)
movslq -0x24(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movb $0x1, (%rax,%rcx)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xf3b3
movq -0x10(%rbp), %rax
movl -0x14(%rbp), %ecx
imull -0x14(%rbp), %ecx
movslq %ecx, %rcx
movb $0x0, (%rax,%rcx)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xf573
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xf566
movq -0x80(%rbp), %rdx
movq -0x8(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rdx,%rcx,4), %ecx
imull -0x14(%rbp), %ecx
movslq -0x20(%rbp), %rsi
addl (%rdx,%rsi,4), %ecx
movslq %ecx, %rcx
movb (%rax,%rcx), %dl
movq -0x10(%rbp), %rax
movl -0x1c(%rbp), %ecx
imull -0x14(%rbp), %ecx
addl -0x20(%rbp), %ecx
movslq %ecx, %rcx
movb %dl, (%rax,%rcx)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xf51f
jmp 0xf568
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xf510
movq -0x30(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nop