// File: /workspace/github_c_makefile_star2_O0/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
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x38(%rbp)
movq %rax, %rdx
addq $0xf, %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xa8(%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, -0xa0(%rbp)
movq %rcx, %rsp
movq %rax, -0x50(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
movl %eax, %ecx
movl -0x14(%rbp), %eax
movq %rax, -0x98(%rbp)
movq %rcx, %rdx
imulq %rax, %rdx
leaq 0xf(,%rdx,4), %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0x90(%rbp)
movq %rdx, %rsp
movq %rcx, -0x60(%rbp)
movq %rax, -0x68(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %ecx
movq %rcx, %rax
movq %rax, -0x88(%rbp)
movq %rcx, %rsi
imulq %rsi, %rsi
addq $0xf, %rsi
andq $-0x10, %rsi
movq %rsp, %rdx
subq %rsi, %rdx
movq %rdx, -0x80(%rbp)
movq %rdx, %rsp
movq %rcx, -0x70(%rbp)
movq %rax, -0x78(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xf766
movq -0x90(%rbp), %rax
movq -0x98(%rbp), %rcx
movq -0xa8(%rbp), %rdx
movslq -0x1c(%rbp), %rsi
movb $0x0, (%rdx,%rsi)
imulq $0x0, %rcx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xf756
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 0xf6e2
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 0xf728
movq -0x90(%rbp), %rax
movq -0x98(%rbp), %rcx
movq -0x80(%rbp), %rdx
movq -0x88(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
imulq %rdi, %rsi
addq %rsi, %rdx
movslq -0x20(%rbp), %rsi
movb $0x1, (%rdx,%rsi)
imulq $0x0, %rcx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0xf746
movq -0x80(%rbp), %rax
movq -0x88(%rbp), %rdx
movslq -0x1c(%rbp), %rcx
imulq %rdx, %rcx
addq %rcx, %rax
movslq -0x20(%rbp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0xf748
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xf6a2
jmp 0xf758
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xf65c
movl $0x1, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0xf855
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xf845
movq -0x90(%rbp), %rax
movq -0x98(%rbp), %rdx
movslq -0x20(%rbp), %rcx
imulq %rdx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xf835
movq -0x80(%rbp), %rax
movq -0x88(%rbp), %rdx
movslq -0x18(%rbp), %rcx
imulq %rdx, %rcx
addq %rcx, %rax
movslq -0x1c(%rbp), %rcx
testb $0x1, (%rax,%rcx)
je 0xf828
movq -0x90(%rbp), %rax
movq -0x98(%rbp), %rsi
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rdx
imulq %rsi, %rdx
shlq $0x2, %rdx
movq %rax, %rcx
addq %rdx, %rcx
movslq -0x1c(%rbp), %rdx
movl (%rcx,%rdx,4), %edx
movslq -0x20(%rbp), %rcx
imulq %rsi, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movslq -0x18(%rbp), %rcx
addl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
jmp 0xf82a
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xf7bb
jmp 0xf837
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xf780
jmp 0xf847
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xf76d
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xfaf5
movl $0x7fffffff, -0x2c(%rbp) # imm = 0x7FFFFFFF
movl $0x7fffffff, -0x24(%rbp) # imm = 0x7FFFFFFF
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0xfac7
movq -0xa8(%rbp), %rax
movslq -0x1c(%rbp), %rcx
testb $0x1, (%rax,%rcx)
je 0xf89f
jmp 0xfab9
movl $0x0, -0x28(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xf8f6
movq -0xa0(%rbp), %rcx
movq -0x80(%rbp), %rax
movq -0x88(%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 0xf8e9
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xf8eb
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xf8ad
movb $0x0, -0x41(%rbp)
cmpl $0x7fffffff, -0x2c(%rbp) # imm = 0x7FFFFFFF
jne 0xf90c
movb $0x1, -0x41(%rbp)
jmp 0xfaa5
cmpl $0x0, -0x28(%rbp)
jle 0xf923
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jge 0xf923
movb $0x1, -0x41(%rbp)
jmp 0xfaa3
cmpl $0x0, -0x2c(%rbp)
jne 0xf938
cmpl $0x0, -0x28(%rbp)
jle 0xf938
movb $0x1, -0x41(%rbp)
jmp 0xfaa1
movl -0x28(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0xfa9f
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x54(%rbp), %eax
jge 0xf9eb
movq -0x90(%rbp), %rcx
movq -0x98(%rbp), %rsi
movslq -0x20(%rbp), %rdx
imulq %rsi, %rdx
shlq $0x2, %rdx
movq %rcx, %rax
addq %rdx, %rax
movslq -0x1c(%rbp), %rdx
movl (%rax,%rdx,4), %eax
movslq -0x20(%rbp), %rdx
imulq %rsi, %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
movslq -0x24(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
je 0xf9db
movq -0x90(%rbp), %rcx
movq -0x98(%rbp), %rsi
movslq -0x20(%rbp), %rdx
imulq %rsi, %rdx
shlq $0x2, %rdx
movq %rcx, %rax
addq %rdx, %rax
movslq -0x1c(%rbp), %rdx
movl (%rax,%rdx,4), %eax
movslq -0x20(%rbp), %rdx
imulq %rsi, %rdx
shlq $0x2, %rdx
addq %rdx, %rcx
movslq -0x24(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0xf9d9
movb $0x1, -0x41(%rbp)
jmp 0xf9eb
jmp 0xf9dd
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xf94b
movl -0x20(%rbp), %eax
cmpl -0x54(%rbp), %eax
jne 0xfa9d
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xfa9b
movq -0xa0(%rbp), %rdx
movq -0x80(%rbp), %rcx
movq -0x88(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
imulq %rdi, %rsi
movq %rcx, %rax
addq %rsi, %rax
movslq -0x20(%rbp), %rsi
movslq (%rdx,%rsi,4), %rsi
movb (%rax,%rsi), %al
andb $0x1, %al
movzbl %al, %eax
movslq -0x24(%rbp), %rsi
imulq %rdi, %rsi
addq %rsi, %rcx
movslq -0x20(%rbp), %rsi
movslq (%rdx,%rsi,4), %rdx
movb (%rcx,%rdx), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0xfa8b
movq -0xa0(%rbp), %rcx
movq -0x80(%rbp), %rax
movq -0x88(%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)
jne 0xfa89
movb $0x1, -0x41(%rbp)
jmp 0xfa9b
jmp 0xfa8d
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xf9fe
jmp 0xfa9d
jmp 0xfa9f
jmp 0xfaa1
jmp 0xfaa3
jmp 0xfaa5
testb $0x1, -0x41(%rbp)
je 0xfab7
movl -0x1c(%rbp), %eax
movl %eax, -0x24(%rbp)
movl -0x28(%rbp), %eax
movl %eax, -0x2c(%rbp)
jmp 0xfab9
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xf87d
movq -0xa0(%rbp), %rax
movq -0xa8(%rbp), %rcx
movslq -0x24(%rbp), %rdx
movb $0x1, (%rcx,%rdx)
movl -0x24(%rbp), %edx
movslq -0x18(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xf85c
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 0xfb74
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0xfb67
movq -0xa0(%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 0xfb1d
jmp 0xfb69
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xfb0e
movq -0x38(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq