// File: /workspace/github_c_makefile_star2_O2/ComplexNetworks-DCC-FCUP[P]gtrieScanner/nauty/nautil.c
// Function: doref
void
doref(graph *g, int *lab, int *ptn, int level, int *numcells,
     int *qinvar, permutation *invar, set *active, int *code,
     void (*refproc)(graph*,int*,int*,int,int*,permutation*,set*,int*,int,int),
     void (*invarproc)(graph*,int*,int*,int,int,int,permutation*,
                                                     int,boolean,int,int),
     int mininvarlev, int maxinvarlev, int invararg,
     boolean digraph, int m, int n)
{
	int j,h;
	permutation pw;
	int iw;
	int i,cell1,cell2,nc,tvpos,minlev,maxlev;
	long longcode;
	boolean same;

#if !MAXN 
	DYNALLOC1(permutation,workperm,workperm_sz,n,"doref"); 
#endif

	if ((tvpos = nextelement(active,M,-1)) < 0) tvpos = 0;

	(*refproc)(g,lab,ptn,level,numcells,invar,active,code,M,n);

	minlev = (mininvarlev < 0 ? -mininvarlev : mininvarlev);
	maxlev = (maxinvarlev < 0 ? -maxinvarlev : maxinvarlev);
	if (invarproc != NULL && *numcells < n
	                    && level >= minlev && level <= maxlev)
	{
	    (*invarproc)(g,lab,ptn,level,*numcells,tvpos,invar,invararg,
	                                                         digraph,M,n);
	    EMPTYSET(active,m);
	    for (i = n; --i >= 0;) workperm[i] = invar[lab[i]];
	    nc = *numcells;
	    for (cell1 = 0; cell1 < n; cell1 = cell2 + 1)
	    {
	        pw = workperm[cell1];
	        same = TRUE;
	        for (cell2 = cell1; ptn[cell2] > level; ++cell2)
	            if (workperm[cell2+1] != pw) same = FALSE;

	        if (same) continue;

	        j = (cell2 - cell1 + 1) / 3;
	        h = 1;
	        do
	            h = 3 * h + 1;
	        while (h < j);

	        do                      /* shell sort */
	        {
	            for (i = cell1 + h; i <= cell2; ++i)
	            {
	                iw = lab[i];
	                pw = workperm[i];
	                for (j = i; workperm[j-h] > pw; )
	                {
	                    workperm[j] = workperm[j-h];
	                    lab[j] = lab[j-h];
	                    if ((j -= h) < cell1 + h) break;
	                }
	                workperm[j] = pw;
	                lab[j] = iw;
	            }
	            h /= 3;
	        }
	        while (h > 0);

	        for (i = cell1 + 1; i <= cell2; ++i)
	            if (workperm[i] != workperm[i-1])
	            {
	                ptn[i-1] = level;
	                ++*numcells;
	                ADDELEMENT(active,i);
	            }
	    }

	    if (*numcells > nc)
	    {
	        *qinvar = 2;
	        longcode = *code;
	        (*refproc)(g,lab,ptn,level,numcells,invar,active,code,M,n);
	        longcode = MASH(longcode,*code);
	        *code = CLEANUP(longcode);
	    }
	    else
	        *qinvar = 1;
	}
	else
	    *qinvar = 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, 0x10(%rsp)
movq %r8, %rbx
movl %ecx, 0x4(%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, %r12
movq %rdi, 0x18(%rsp)
movl 0xc0(%rsp), %eax
movslq %eax, %r15
movq 0x1be59(%rip), %rax     # 0x29ac0
cmpq %r15, %rax
jae 0xdca0
testq %rax, %rax
je 0xdc7d
movq 0x1be50(%rip), %rdi     # 0x29ac8
callq 0x2280
movq %r15, 0x1be3c(%rip)     # 0x29ac0
shlq $0x2, %r15
movq %r15, %rdi
callq 0x22d0
movq %rax, 0x1be31(%rip)     # 0x29ac8
testq %rax, %rax
je 0xdfdb
movl 0xb8(%rsp), %r15d
movq 0x78(%rsp), %r14
pushq $-0x1
popq %rdx
movq %r14, %rdi
movl %r15d, %esi
callq 0xd54c
xorl %r13d, %r13d
testl %eax, %eax
cmovgl %eax, %r13d
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movq 0x8(%rsp), %rdx
movl 0x4(%rsp), %ebp
movl %ebp, %ecx
movq %rbx, %r8
movq 0x70(%rsp), %r9
movl 0xc0(%rsp), %eax
pushq %rax
pushq %r15
movq 0xa0(%rsp), %r15
pushq 0x90(%rsp)
pushq %r14
callq *0xa8(%rsp)
addq $0x20, %rsp
testq %r15, %r15
je 0xddae
movl 0xa0(%rsp), %ecx
movl 0x98(%rsp), %edx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
movl %edx, %ecx
negl %ecx
cmovsl %edx, %ecx
movl (%rbx), %r8d
movl 0xc0(%rsp), %edx
cmpl %edx, %r8d
jge 0xddae
cmpl %ebp, %ecx
jg 0xddae
cmpl %ebp, %eax
jl 0xddae
movl 0xb0(%rsp), %eax
movl 0xa8(%rsp), %r10d
subq $0x8, %rsp
movq 0x20(%rsp), %rdi
movq %r12, %rsi
movq 0x10(%rsp), %rdx
movl %ebp, %ecx
movl %r13d, %r9d
movl 0xc8(%rsp), %r11d
pushq %r11
movl 0xc8(%rsp), %r11d
movq %r11, %r14
pushq %r11
pushq %rax
pushq %r10
pushq 0x98(%rsp)
callq *%r15
addq $0x30, %rsp
movslq %r14d, %rax
movq 0x78(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
addq $-0x4, %rax
cmpq 0x78(%rsp), %rax
jb 0xddc5
andl $0x0, (%rax)
addq $-0x4, %rax
jmp 0xdd9e
movq 0x10(%rsp), %rax
andl $0x0, (%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1bcfc(%rip), %rdi     # 0x29ac8
movl 0xc0(%rsp), %eax
movl %eax, %eax
testl %eax, %eax
jle 0xddef
movslq -0x4(%r12,%rax,4), %rcx
movq 0x70(%rsp), %rdx
movl (%rdx,%rcx,4), %ecx
movl %ecx, -0x4(%rdi,%rax,4)
decq %rax
jmp 0xddd5
movl (%rbx), %eax
movl %eax, 0x2c(%rsp)
xorl %ecx, %ecx
movq %rbx, 0x30(%rsp)
movl 0xc0(%rsp), %eax
cmpl %eax, %ecx
jge 0xdf52
movq %rcx, 0x20(%rsp)
movslq %ecx, %r11
leaq (%rdi,%r11,4), %rax
movl (%rax), %edx
movq %r11, %r15
shlq $0x20, %r15
movq 0x8(%rsp), %rcx
leaq (%rcx,%r11,4), %rsi
pushq $0x1
popq %rcx
pushq $0x1
popq %r8
movl 0x4(%rsp), %r9d
cmpl %r9d, -0x4(%rsi,%rcx,4)
jle 0xde5b
cmpl %edx, (%rax,%rcx,4)
movl $0x0, %r9d
cmovnel %r9d, %r8d
movabsq $0x100000000, %r9       # imm = 0x100000000
addq %r9, %r15
incq %rcx
jmp 0xde30
testl %r8d, %r8d
je 0xde6c
movq 0x20(%rsp), %rax
addl %ecx, %eax
movq %rax, %rcx
jmp 0xddfc
movl %ecx, %eax
cltd
pushq $0x3
popq %rsi
idivl %esi
pushq $0x1
popq %rdx
movl %edx, %esi
leal (%rsi,%rsi,2), %esi
incl %esi
cmpl %eax, %esi
jl 0xde79
sarq $0x20, %r15
movq 0x20(%rsp), %r8
leal (%rsi,%r8), %eax
movslq %eax, %rdx
movl %r8d, %ebx
cmpq %r15, %rdx
jg 0xdee3
movl (%r12,%rdx,4), %r14d
movl (%rdi,%rdx,4), %r8d
movl %ebx, %r9d
leal (%rsi,%r9), %r10d
movslq %r9d, %r13
movl (%rdi,%r13,4), %ebp
movslq %r10d, %r9
cmpl %r8d, %ebp
jle 0xded1
movl %ebp, (%rdi,%r9,4)
movl (%r12,%r13,4), %r10d
movl %r10d, (%r12,%r9,4)
movl %r13d, %r9d
subl %esi, %r9d
cmpl %eax, %r13d
jge 0xdea5
jmp 0xded4
movq %r9, %r13
movl %r8d, (%rdi,%r13,4)
movl %r14d, (%r12,%r13,4)
incq %rdx
incl %ebx
jmp 0xde95
movl %esi, %eax
xorl %edx, %edx
pushq $0x3
popq %r8
divl %r8d
cmpl $0x2, %esi
movl %eax, %esi
jg 0xde86
movq 0x20(%rsp), %rax
incl %eax
movq 0x30(%rsp), %rbx
cmpq %r15, %r11
jge 0xde60
leaq 0x1(%r11), %rdx
movl 0x4(%rdi,%r11,4), %esi
cmpl (%rdi,%r11,4), %esi
je 0xdf4b
movl 0x4(%rsp), %esi
movq 0x8(%rsp), %r8
movl %esi, (%r8,%r11,4)
incl (%rbx)
movl %edx, %esi
andl $0x1f, %esi
leaq 0x308c(%rip), %r8       # 0x10fc0
movl (%r8,%rsi,4), %esi
movl %eax, %r8d
sarl $0x5, %r8d
movslq %r8d, %r8
movq 0x78(%rsp), %r9
orl %esi, (%r9,%r8,4)
incl %eax
movq %rdx, %r11
jmp 0xdf01
movl 0x2c(%rsp), %eax
cmpl %eax, (%rbx)
jle 0xdfcb
movq 0x10(%rsp), %rax
movl $0x2, (%rax)
movq %rbx, %r8
movl $0x6b1d, %ebx           # imm = 0x6B1D
movq 0x80(%rsp), %r14
xorl (%r14), %ebx
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movq 0x8(%rsp), %rdx
movl 0x4(%rsp), %ecx
movq 0x70(%rsp), %r9
movl 0xc0(%rsp), %eax
pushq %rax
movl 0xc0(%rsp), %eax
pushq %rax
pushq %r14
pushq 0x90(%rsp)
callq *0xa8(%rsp)
addq $0x20, %rsp
addl (%r14), %ebx
movl $0x7fff, %eax           # imm = 0x7FFF
andl %eax, %ebx
xorl %ecx, %ecx
cmpl %eax, %ebx
cmovnel %ebx, %ecx
movl %ecx, (%r14)
jmp 0xddb6
movq 0x10(%rsp), %rax
movl $0x1, (%rax)
jmp 0xddb6
leaq 0x3472(%rip), %rdi      # 0x11454
callq 0xda1f