// File: /workspace/github_c_makefile_star2_O3/ComplexNetworks-DCC-FCUP[P]gtrieScanner/Isomorphism.cpp
// Function: Isomorphism::_goCan2(int, char const*, int*, bool*, char*, int, char*)
void Isomorphism::_goCan2(int pos, const char *in, int *perm, bool *used, char *best, int size, char *current) {
  int i, j;

  if (strcmp(current,best)<0) return;

  if (pos==size) {
    strcpy(best, current);
    return;
  }
  
  // At the beggining everyone is a possible candidate
  bool candidate[size];
  for (i=0; i<size; i++)
    if (used[i]) candidate[i]=false;
    else         candidate[i]=true;


  for (i=0; i<pos; i++) {
    for (j=0; j<size ;j++)
      if (candidate[j] && in[perm[i]*size+j]=='1') break;
    if (j<size) // at least one neighbour
      for (j=0; j<size ;j++)
	if (candidate[j] && in[perm[i]*size+j]=='0') candidate[j]=false;
  }

  // Among those that are still candidates, select the
  // biggest neighborhood on those candidates
  int degree[size];
  int max=-1;
  for (i=0; i<size; i++) {
    degree[i]=0;
    if (candidate[i]) {
      for (j=0; j<size; j++)
	if (i!=j && candidate[j] && in[j*size+i]=='1')
	  degree[i]++;
      if (degree[i]>max) max=degree[i];
    }
  }

  for (i=0; i<size; i++)
    if (candidate[i] && degree[i]==max) {
      perm[pos]=i;
      used[i]=true;
      current[pos*size+pos] = in[i*size+i];
      for (j=0; j<pos; j++) {
	current[pos*size+j] = in[i*size+perm[j]]; 
	current[j*size+pos] = in[perm[j]*size+i]; 
      }

      _goCan2(pos+1, in, perm, used, best, size, current);

      current[pos*size+pos] = '2';
      for (j=0; j<pos; j++) {
	current[pos*size+j] = '2';
	current[j*size+pos] = '2';
      }
      used[i]=false;
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %r9d, %r14d
movq %r8, %rbx
movq %rcx, -0x68(%rbp)
movq %rdx, %r12
movq %rsi, -0x60(%rbp)
movl %edi, %r15d
movq 0x10(%rbp), %rdi
movq %rdi, -0x30(%rbp)
movq %r8, %rsi
callq 0x22c0
testl %eax, %eax
js 0x7c8f
cmpl %r14d, %r15d
jne 0x79e3
movq %rbx, %rdi
movq -0x30(%rbp), %rsi
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x21d0
movl %r14d, %r9d
movq %r15, %r11
movq %rsp, -0x78(%rbp)
movl %r14d, %r13d
movq %rsp, %r15
leaq 0xf(%r13), %rax
andq $-0x10, %rax
subq %rax, %r15
movq %r15, %rsp
testl %r14d, %r14d
movq -0x68(%rbp), %rcx
movq -0x30(%rbp), %r10
jle 0x7a22
xorl %eax, %eax
movb (%rcx,%rax), %dl
xorb $0x1, %dl
movb %dl, (%r15,%rax)
incq %rax
cmpq %rax, %r13
jne 0x7a10
movl %r11d, %r8d
movslq %r9d, %r14
testl %r11d, %r11d
movq -0x60(%rbp), %rsi
jle 0x7a80
xorl %eax, %eax
testl %r9d, %r9d
jle 0x7a78
xorl %edx, %edx
cmpb $0x1, (%r15,%rdx)
jne 0x7a52
movslq (%r12,%rax,4), %rdi
imulq %r14, %rdi
addq %rsi, %rdi
cmpb $0x31, (%rdx,%rdi)
je 0x7a5c
incq %rdx
cmpq %rdx, %r13
jne 0x7a3a
jmp 0x7a78
xorl %edx, %edx
cmpb $0x1, (%r15,%rdx)
jne 0x7a70
cmpb $0x30, (%rdi,%rdx)
jne 0x7a70
movb $0x0, (%r15,%rdx)
incq %rdx
cmpq %rdx, %r13
jne 0x7a5e
incq %rax
cmpq %r8, %rax
jne 0x7a33
movq %r14, -0x90(%rbp)
movq %rbx, -0x58(%rbp)
movq %rsp, %rbx
leaq 0xf(,%r13,4), %rax
andq $-0x10, %rax
subq %rax, %rbx
movq %rbx, %rsp
testl %r9d, %r9d
jle 0x7c8b
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %eax, %eax
movq %r8, -0x70(%rbp)
movl $0x0, (%rbx,%rax,4)
cmpb $0x1, (%r15,%rax)
jne 0x7af8
xorl %edi, %edi
movq %rsi, %rdx
xorl %r8d, %r8d
cmpq %r8, %rax
je 0x7ae2
cmpb $0x1, (%r15,%r8)
jne 0x7ae2
cmpb $0x31, (%rdx,%rax)
jne 0x7ae2
incl %edi
movl %edi, (%rbx,%rax,4)
incq %r8
addq %r13, %rdx
cmpq %r8, %r13
jne 0x7acb
cmpl %r14d, %edi
cmovgl %edi, %r14d
movq -0x70(%rbp), %r8
incq %rax
cmpq %r13, %rax
jne 0x7ab5
movl %r14d, -0x3c(%rbp)
testl %r9d, %r9d
jle 0x7c8b
movslq %r11d, %rax
movq %rax, -0x98(%rbp)
movl %r9d, %edx
imull %r11d, %edx
leal (%rdx,%r11), %eax
movslq %eax, %r14
leal 0x1(%r11), %eax
movl %eax, -0x34(%rbp)
addq %r10, %rdx
leaq (%r10,%r8), %rax
movq %rax, -0x50(%rbp)
xorl %r8d, %r8d
movl %r9d, -0x38(%rbp)
movq %r11, -0x48(%rbp)
movq %rbx, -0xa0(%rbp)
movq %rdx, -0x88(%rbp)
movq %r14, -0x80(%rbp)
cmpb $0x1, (%r15,%r8)
jne 0x7c7f
movl -0x3c(%rbp), %eax
cmpl %eax, (%rbx,%r8,4)
jne 0x7c7f
movl %r8d, %edx
imull %r9d, %edx
leaq (%rsi,%r8), %rax
movq -0x98(%rbp), %rdi
movl %r8d, (%r12,%rdi,4)
movb $0x1, (%rcx,%r8)
movslq %edx, %rdx
movb (%rdx,%rax), %dl
movb %dl, (%r10,%r14)
testl %r11d, %r11d
movq %r8, -0xa8(%rbp)
jle 0x7c3a
imulq %r13, %r8
addq %rsi, %r8
movq -0x50(%rbp), %rdx
xorl %r11d, %r11d
movq -0x70(%rbp), %rbx
movq -0x90(%rbp), %r10
movq -0x88(%rbp), %r14
movslq (%r12,%r11,4), %rdi
movb (%r8,%rdi), %dil
movb %dil, (%r14,%r11)
movslq (%r12,%r11,4), %rdi
imulq %r10, %rdi
movb (%rax,%rdi), %dil
movb %dil, (%rdx)
incq %r11
addq %r13, %rdx
cmpq %r11, %rbx
jne 0x7bc1
subq $0x8, %rsp
movl -0x34(%rbp), %edi
movq %r12, %rdx
movq -0x58(%rbp), %r8
pushq -0x30(%rbp)
callq 0x7984
movq -0x30(%rbp), %r10
addq $0x10, %rsp
movq -0x80(%rbp), %rax
movb $0x32, (%r10,%rax)
movq -0x48(%rbp), %r11
testl %r11d, %r11d
movq %r14, %rdx
movq %rax, %r14
movb $0x32, %sil
jle 0x7c60
movq -0x50(%rbp), %rax
xorl %ecx, %ecx
movb %sil, (%rdx,%rcx)
movb %sil, (%rax)
incq %rcx
addq %r13, %rax
cmpq %rcx, %rbx
jne 0x7c26
jmp 0x7c60
subq $0x8, %rsp
movl -0x34(%rbp), %edi
movq %r12, %rdx
movq -0x58(%rbp), %r8
pushq %r10
callq 0x7984
movq -0x30(%rbp), %r10
addq $0x10, %rsp
movb $0x32, (%r10,%r14)
movq -0x48(%rbp), %r11
movq -0x68(%rbp), %rcx
movq -0xa8(%rbp), %r8
movb $0x0, (%rcx,%r8)
movl -0x38(%rbp), %r9d
movq -0x60(%rbp), %rsi
movq -0xa0(%rbp), %rbx
incq %r8
cmpq %r13, %r8
jne 0x7b54
movq -0x78(%rbp), %rsp
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq