// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movq %r9, 0x10(%rsp)
movq %r8, 0x38(%rsp)
movl %ecx, 0xc(%rsp)
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, 0x18(%rsp)
movl 0xd0(%rsp), %r14d
movslq %r14d, %r15
movq 0x1b3cf(%rip), %rax     # 0x29aa0
cmpq %r15, %rax
jae 0xe70a
testq %rax, %rax
je 0xe6e7
movq 0x1b3c6(%rip), %rdi     # 0x29aa8
callq 0x2260
movq %r15, 0x1b3b2(%rip)     # 0x29aa0
shlq $0x2, %r15
movq %r15, %rdi
callq 0x22a0
movq %rax, 0x1b3a7(%rip)     # 0x29aa8
testq %rax, %rax
je 0xea9f
movl 0xc8(%rsp), %esi
movq 0x88(%rsp), %rbp
movq %rbp, %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xded4
xorl %r13d, %r13d
testl %eax, %eax
cmovgl %eax, %r13d
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
movl 0xc(%rsp), %r15d
movl %r15d, %ecx
movq 0x38(%rsp), %r8
movq 0x80(%rsp), %r9
pushq %r14
movl 0xd0(%rsp), %eax
pushq %rax
pushq 0xa0(%rsp)
pushq %rbp
movq %r8, %rbp
callq *0xb8(%rsp)
addq $0x20, %rsp
movq 0xa0(%rsp), %rax
testq %rax, %rax
je 0xe818
movq %rax, %r10
movl 0xb0(%rsp), %ecx
movl 0xa8(%rsp), %edx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
movl %edx, %ecx
negl %ecx
cmovsl %edx, %ecx
movl (%rbp), %r8d
cmpl %r14d, %r8d
jge 0xe818
cmpl %r15d, %ecx
jg 0xe818
cmpl %r15d, %eax
jl 0xe818
movl 0xc0(%rsp), %eax
subq $0x8, %rsp
movq 0x20(%rsp), %rdi
movq %r12, %rsi
movq %rbx, %rdx
movl %r15d, %ecx
movl %r13d, %r9d
pushq %r14
movl 0xd8(%rsp), %r11d
movq %r11, %r13
pushq %r11
pushq %rax
movl 0xd8(%rsp), %eax
pushq %rax
pushq 0xa8(%rsp)
callq *%r10
addq $0x30, %rsp
movslq %r13d, %rax
movq 0x88(%rsp), %rcx
leaq (%rcx,%rax,4), %rax
addq $-0x4, %rax
cmpq %rcx, %rax
jb 0xe828
movl $0x0, (%rax)
addq $-0x4, %rax
jmp 0xe807
movq 0x10(%rsp), %rax
movl $0x0, (%rax)
jmp 0xea90
testl %r14d, %r14d
jle 0xea85
movq 0x1b270(%rip), %rax     # 0x29aa8
movl %r14d, %ecx
incq %rcx
movq 0x80(%rsp), %rsi
movslq -0x8(%r12,%rcx,4), %rdx
movl (%rsi,%rdx,4), %edx
movl %edx, -0x8(%rax,%rcx,4)
decq %rcx
cmpq $0x1, %rcx
ja 0xe846
testl %r14d, %r14d
jle 0xea85
movl (%rbp), %eax
movl %eax, 0x2c(%rsp)
xorl %r8d, %r8d
movq 0x1b233(%rip), %rdx     # 0x29aa8
xorl %r10d, %r10d
movq %rbx, 0x30(%rsp)
movslq %r10d, %rcx
cmpl %r15d, (%rbx,%rcx,4)
jle 0xe8d6
leaq (%rdx,%rcx,4), %rax
movl (%rax), %edi
leaq (%rbx,%rcx,4), %rbx
movq %rcx, 0x40(%rsp)
incl %ecx
movl $0x1, %esi
movl $0x1, %r14d
movq %r10, 0x20(%rsp)
movq %r14, %r9
cmpl %edi, (%rax,%r14,4)
movl %ecx, %r11d
cmovnel %r8d, %esi
incl %r10d
incq %r14
leal 0x1(%r11), %ecx
cmpl %r15d, (%rbx,%r9,4)
jg 0xe8a7
testl %esi, %esi
je 0xe8e9
movl 0xd0(%rsp), %r14d
movq 0x30(%rsp), %rbx
incl %r10d
movl %r10d, %r13d
movl %r13d, %r10d
cmpl %r14d, %r13d
jl 0xe87d
jmp 0xea0e
movslq %r14d, %rax
imulq $0x55555556, %rax, %rcx # imm = 0x55555556
movq %rcx, %rax
shrq $0x3f, %rax
shrq $0x20, %rcx
addl %eax, %ecx
movl $0x1, %eax
leal (%rax,%rax,2), %eax
incl %eax
cmpl %ecx, %eax
jl 0xe905
leal 0x1(%r10), %r13d
movq 0x20(%rsp), %rcx
leal (%rax,%rcx), %edi
cmpl %r10d, %edi
jg 0xe975
movslq %eax, %r15
addq 0x40(%rsp), %r15
movq 0x20(%rsp), %rcx
movl %ecx, %ebx
movl (%r12,%r15,4), %r14d
movl (%rdx,%r15,4), %esi
movl %ebx, %ecx
leal (%rax,%rcx), %r8d
movslq %ecx, %rbp
movl (%rdx,%rbp,4), %r9d
movslq %r8d, %rcx
cmpl %esi, %r9d
jle 0xe961
movl %r9d, (%rdx,%rcx,4)
movl (%r12,%rbp,4), %r8d
movl %r8d, (%r12,%rcx,4)
movl %ebp, %ecx
subl %eax, %ecx
cmpl %edi, %ebp
jge 0xe938
jmp 0xe964
movq %rcx, %rbp
movl %esi, (%rdx,%rbp,4)
movl %r14d, (%r12,%rbp,4)
incq %r15
incl %ebx
cmpl %r15d, %r13d
jne 0xe92e
movl %eax, %ecx
movl $0xaaaaaaab, %esi       # imm = 0xAAAAAAAB
imulq %rsi, %rcx
shrq $0x21, %rcx
cmpl $0x2, %eax
movl %ecx, %eax
jg 0xe912
cmpl %r10d, 0x20(%rsp)
movq 0x38(%rsp), %rbp
movl 0xc(%rsp), %r15d
movl 0xd0(%rsp), %r14d
movq 0x30(%rsp), %rbx
movl $0x0, %r8d
jge 0xe8dc
movq 0x40(%rsp), %r10
incq %r10
movslq %r11d, %rax
negq %rax
movq 0x88(%rsp), %rdi
leaq 0x3620(%rip), %r9       # 0x11ff0
movl (%rdx,%r10,4), %ecx
cmpl -0x4(%rdx,%r10,4), %ecx
je 0xe9f9
movl %r15d, -0x4(%rbx,%r10,4)
incl (%rbp)
movl %r10d, %ecx
andl $0x1f, %ecx
movl (%r9,%rcx,4), %ecx
movl %r10d, %esi
sarl $0x5, %esi
movslq %esi, %rsi
orl %ecx, (%rdi,%rsi,4)
leaq (%rax,%r10), %rcx
incq %rcx
incq %r10
cmpq $0x1, %rcx
jne 0xe9d0
jmp 0xe8dc
movl 0x2c(%rsp), %eax
cmpl %eax, (%rbp)
movq 0x88(%rsp), %r10
jle 0xea85
movq 0x10(%rsp), %rax
movl $0x2, (%rax)
movq %rbx, %rdx
movl $0x6b1d, %ebx           # imm = 0x6B1D
movq 0x90(%rsp), %r13
xorl (%r13), %ebx
movq 0x18(%rsp), %rdi
movq %r12, %rsi
movl %r15d, %ecx
movq %rbp, %r8
movq 0x80(%rsp), %r9
pushq %r14
movl 0xd0(%rsp), %eax
pushq %rax
pushq %r13
pushq %r10
callq *0xb8(%rsp)
addq $0x20, %rsp
addl (%r13), %ebx
movl $0x7fff, %eax           # imm = 0x7FFF
andl %eax, %ebx
xorl %ecx, %ecx
cmpl %eax, %ebx
cmovnel %ebx, %ecx
movl %ecx, (%r13)
jmp 0xea90
movq 0x10(%rsp), %rax
movl $0x1, (%rax)
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x260d