// File: /workspace/github_c_makefile_star2_O2/ComplexNetworks-DCC-FCUP[P]gtrieScanner/Isomorphism.cpp
// Function: Isomorphism::canonicalBasedNautyReverse(char const*, char*, int)
void Isomorphism::canonicalBasedNautyReverse(const char *in, char *best, int size) {

  int n, i, j, max_i, conn, max_conn;
  bool used[size], flag;
  int v[size];
  int degree_levels = size;
  int degree[degree_levels][size];
  bool adj[size][size];

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

  for (n=0; n<size; n++) {
    max_i = max_conn = INT_MAX;
    for (i=0;i<size;i++) {
      if (used[i]) continue;
      conn = 0;

      for (j=0;j<n;j++)
	if (adj[i][v[j]]) conn++;
      
      flag = false;

      if (max_conn==INT_MAX) flag=true;
      else if (conn>0 && conn < max_conn) flag = true;
      else if (max_conn==0 && conn>0) flag = true;
      else if (conn == max_conn) {
	for (j=0; j<degree_levels; j++)
	    if (degree[j][i] != degree[j][max_i]) {
	      if (degree[j][i] < degree[j][max_i]) flag=true;
	      break;
	    }
	if (j==degree_levels) {
	  for (j=0; j<n; j++)	  
	    if (adj[i][v[j]] != adj[max_i][v[j]]) {
	      if (!adj[i][v[j]]) flag = true;
	      break;
	    }
	}
      }

      if (flag) {
	max_i      = i;
	max_conn   = conn;
      }
    }
    used[max_i]=true;
    v[n] = max_i;
  }

  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 $0x48, %rsp
movq %rsi, -0x60(%rbp)
movq %rdi, %r11
movl %edx, %ecx
movq %rsp, %rsi
leaq 0xf(%rcx), %rax
andq $-0x10, %rax
subq %rax, %rsi
movq %rsi, -0x38(%rbp)
movq %rsi, %rsp
movq %rsp, %rax
leaq 0xf(,%rcx,4), %rsi
andq $-0x10, %rsi
subq %rsi, %rax
movq %rax, %rsp
movq %rcx, %rdi
imulq %rcx, %rdi
movq %rsp, %r8
leaq 0xf(,%rdi,4), %rsi
andq $-0x10, %rsi
subq %rsi, %r8
movq %r8, -0x30(%rbp)
movq %r8, %rsp
movq %rsp, %r9
addq $0xf, %rdi
andq $-0x10, %rdi
subq %rdi, %r9
movq %r9, %rsp
movslq %edx, %r10
xorl %r8d, %r8d
testl %r10d, %r10d
movl $0x0, %r12d
movq %rdx, -0x50(%rbp)
cmovgl %edx, %r12d
movq %r11, %rdi
movq %r9, -0x40(%rbp)
movq %r11, -0x58(%rbp)
cmpq %r12, %r8
je 0x7a83
movq -0x30(%rbp), %rdx
andl $0x0, (%rdx,%r8,4)
movq -0x38(%rbp), %rdx
movb $0x0, (%rdx,%r8)
xorl %esi, %esi
movq %rdi, %rbx
xorl %r14d, %r14d
cmpq %r14, %rcx
je 0x7a75
cmpb $0x31, (%r11,%r14)
je 0x7a57
cmpb $0x31, (%rbx)
jne 0x7a68
movb $0x1, (%r9,%r14)
incl %esi
movq -0x30(%rbp), %rdx
movl %esi, (%rdx,%r8,4)
jmp 0x7a6d
movb $0x0, (%r9,%r14)
incq %r14
addq %r10, %rbx
jmp 0x7a46
incq %r8
addq %r10, %r11
addq %rcx, %r9
incq %rdi
jmp 0x7a27
leaq (,%rcx,4), %rdx
movq %rdx, -0x48(%rbp)
pushq $0x1
popq %rdx
movq -0x30(%rbp), %rdi
movq -0x30(%rbp), %r8
cmpq %r10, %rdx
jge 0x7aea
movq %rdx, %rsi
imulq %rcx, %rsi
leaq (%r8,%rsi,4), %rsi
movq -0x40(%rbp), %r9
xorl %r11d, %r11d
cmpq %rcx, %r11
je 0x7ae1
andl $0x0, (%rsi,%r11,4)
xorl %ebx, %ebx
xorl %r15d, %r15d
cmpq %r15, %rcx
je 0x7ad9
cmpb $0x1, (%r9,%r15)
jne 0x7ad4
addl (%rdi,%r15,4), %ebx
movl %ebx, (%rsi,%r11,4)
incq %r15
jmp 0x7ac0
incq %r11
addq %rcx, %r9
jmp 0x7ab1
incq %rdx
addq -0x48(%rbp), %rdi
jmp 0x7a9a
xorl %r15d, %r15d
movq %r10, -0x70(%rbp)
movq %r12, -0x68(%rbp)
cmpq %r12, %r15
je 0x7c0c
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
xorl %r12d, %r12d
xorl %r9d, %r9d
movl $0x7fffffff, %ebx       # imm = 0x7FFFFFFF
movq -0x38(%rbp), %r10
movslq %ebx, %rdi
cmpq %rcx, %r9
je 0x7bf3
cmpb $0x0, (%r10,%r9)
je 0x7b2b
movl %r11d, %edx
jmp 0x7b74
movq %r9, %r13
imulq %rcx, %r13
addq -0x40(%rbp), %r13
xorl %esi, %esi
xorl %edx, %edx
cmpq %rsi, %r15
je 0x7b51
movslq (%rax,%rsi,4), %r8
movzbl (%r13,%r8), %r8d
addl %r8d, %edx
incq %rsi
jmp 0x7b3a
cmpl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
je 0x7b71
cmpl %r11d, %edx
setl %sil
testl %r11d, %r11d
sete %r8b
testl %edx, %edx
je 0x7b80
orb %sil, %r8b
je 0x7b80
movl %r9d, %ebx
incq %r9
addq $0x4, %r12
movl %edx, %r11d
jmp 0x7b13
cmpl %r11d, %edx
jne 0x7b26
movq -0x30(%rbp), %rsi
movq %rcx, %r10
movq %rcx, %r8
subq $0x1, %r8
jb 0x7ba8
movl (%rsi,%rdi,4), %r14d
cmpl %r14d, (%rsi,%r12)
jne 0x7bac
addq -0x48(%rbp), %rsi
movq %r8, %r10
jmp 0x7b8f
xorl %esi, %esi
jmp 0x7bb5
setl %sil
testl %r10d, %r10d
jne 0x7bde
imulq %rcx, %rdi
addq -0x40(%rbp), %rdi
xorl %r8d, %r8d
cmpq %r8, %r15
je 0x7bde
movslq (%rax,%r8,4), %r14
movb (%r13,%r14), %r10b
incq %r8
cmpb (%rdi,%r14), %r10b
je 0x7bc0
xorb $0x1, %r10b
orb %r10b, %sil
testb $0x1, %sil
jne 0x7be7
movl %r11d, %edx
testb $0x1, %sil
movq -0x38(%rbp), %r10
jne 0x7b71
jmp 0x7b74
movb $0x1, (%r10,%rdi)
movl %edi, (%rax,%r15,4)
incq %r15
movq -0x70(%rbp), %r10
movq -0x68(%rbp), %r12
jmp 0x7af5
movq -0x50(%rbp), %rcx
imull %ecx, %ecx
movq -0x60(%rbp), %r8
movb $0x0, (%r8,%rcx)
xorl %ecx, %ecx
movq -0x58(%rbp), %r9
cmpq %r12, %rcx
je 0x7c52
movslq (%rax,%rcx,4), %rdx
imulq %r10, %rdx
xorl %esi, %esi
cmpq %rsi, %r12
je 0x7c4a
movslq (%rax,%rsi,4), %rdi
addq %rdx, %rdi
movb (%r9,%rdi), %dil
movb %dil, (%r8,%rsi)
incq %rsi
jmp 0x7c31
incq %rcx
addq %r10, %r8
jmp 0x7c22
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)