// File: /workspace/github_c_makefile_star2_O2/ComplexNetworks-DCC-FCUP[P]gtrieScanner/nauty/naugraph.c
// Function: refine1
void
refine1(graph *g, int *lab, int *ptn, int level, int *numcells,
       permutation *count, set *active, int *code, int m, int n)
{
	int i,c1,c2,labc1;
	setword x;
	int split1,split2,cell1,cell2;
	int cnt,bmin,bmax;
	long longcode;
	set *gptr,workset0;
        int maxcell,maxpos,hint;

#if !MAXN 
	DYNALLOC1(permutation,workperm,workperm_sz,n,"refine1"); 
	DYNALLOC1(int,bucket,bucket_sz,n+2,"refine1"); 
#endif

	longcode = *numcells;
	split1 = -1;

        hint = 0;
        while (*numcells < n && ((split1 = hint, ISELEMENT1(active,split1))
                             || (split1 = nextelement(active,1,split1)) >= 0
                             || (split1 = nextelement(active,1,-1)) >= 0))
	{
	    DELELEMENT1(active,split1);
	    for (split2 = split1; ptn[split2] > level; ++split2) {}
	    longcode = MASH(longcode,split1+split2);
	    if (split1 == split2)       /* trivial splitting cell */
	    {
	        gptr = GRAPHROW(g,lab[split1],1);
	        for (cell1 = 0; cell1 < n; cell1 = cell2 + 1)
	        {
	            for (cell2 = cell1; ptn[cell2] > level; ++cell2) {}
	            if (cell1 == cell2) continue;
	            c1 = cell1;
	            c2 = cell2;
	            while (c1 <= c2)
	            {
	                labc1 = lab[c1];
	                if (ISELEMENT1(gptr,labc1))
	                    ++c1;
	                else
	                {
	                    lab[c1] = lab[c2];
	                    lab[c2] = labc1;
	                    --c2;
	                }
	            }
	            if (c2 >= cell1 && c1 <= cell2)
	            {
	                ptn[c2] = level;
	                longcode = MASH(longcode,c2);
	                ++*numcells;
                        if (ISELEMENT1(active,cell1) || c2-cell1 >= cell2-c1)
			{
                            ADDELEMENT1(active,c1);
			    if (c1 == cell2) hint = c1;
			}
                        else
			{
                            ADDELEMENT1(active,cell1);
			    if (c2 == cell1) hint = cell1;
			}
	            }
	        }
	    }

	    else        /* nontrivial splitting cell */
	    {
	        workset0 = 0;
	        for (i = split1; i <= split2; ++i)
	            ADDELEMENT1(&workset0,lab[i]);
	        longcode = MASH(longcode,split2-split1+1);

	        for (cell1 = 0; cell1 < n; cell1 = cell2 + 1)
	        {
	            for (cell2 = cell1; ptn[cell2] > level; ++cell2) {}
	            if (cell1 == cell2) continue;
	            i = cell1;
	            if ((x = workset0 & g[lab[i]]) != 0)
	                cnt = POPCOUNT(x);
	            else
	                cnt = 0;
	            count[i] = bmin = bmax = cnt;
	            bucket[cnt] = 1;
	            while (++i <= cell2)
	            {
	                if ((x = workset0 & g[lab[i]]) != 0)
	                    cnt = POPCOUNT(x);
	                else
	                    cnt = 0;
	                while (bmin > cnt) bucket[--bmin] = 0;
	                while (bmax < cnt) bucket[++bmax] = 0;
	                ++bucket[cnt];
	                count[i] = cnt;
	            }
	            if (bmin == bmax)
	            {
	                longcode = MASH(longcode,bmin+cell1);
	                continue;
	            }
	            c1 = cell1;
                    maxcell = -1;
	            for (i = bmin; i <= bmax; ++i)
	                if (bucket[i])
	                {
	                    c2 = c1 + bucket[i];
	                    bucket[i] = c1;
	                    longcode = MASH(longcode,i+c1);
                            if (c2-c1 > maxcell)
                            {
                                maxcell = c2-c1;
                                maxpos = c1;
                            }
	                    if (c1 != cell1)
	                    {
	                        ADDELEMENT1(active,c1);
                                if (c2-c1 == 1) hint = c1;
	                        ++*numcells;
	                    }
	                    if (c2 <= cell2) ptn[c2-1] = level;
	                    c1 = c2;
	                }
	            for (i = cell1; i <= cell2; ++i)
	                workperm[bucket[count[i]]++] = lab[i];
	            for (i = cell1; i <= cell2; ++i) lab[i] = workperm[i];
                    if (!ISELEMENT1(active,cell1))
                    {
                        ADDELEMENT1(active,cell1);
                        DELELEMENT1(active,maxpos);
                    }
	        }
	    }
	}

	longcode = MASH(longcode,*numcells);
	*code = CLEANUP(longcode);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x40(%rsp)
movq %r8, 0x28(%rsp)
movl %ecx, %ebp
movq %rdx, 0x30(%rsp)
movq %rsi, %r12
movq %rdi, %r13
movl 0xa8(%rsp), %eax
movslq %eax, %rbx
movq 0x1ad44(%rip), %rax     # 0x29ad0
cmpq %rbx, %rax
jae 0xedcd
testq %rax, %rax
je 0xeda2
movq 0x1ad3b(%rip), %rdi     # 0x29ad8
callq 0x2280
movq %rbx, 0x1ad27(%rip)     # 0x29ad0
shlq $0x2, %rbx
movq %rbx, %rdi
callq 0x22d0
movq %rax, 0x1ad1c(%rip)     # 0x29ad8
testq %rax, %rax
jne 0xedcd
leaq 0x2ba4(%rip), %rdi      # 0x1196c
callq 0xda1f
movl 0xa8(%rsp), %eax
addl $0x2, %eax
movslq %eax, %rbx
movq 0x1ad0f(%rip), %rax     # 0x29af0
cmpq %rbx, %rax
jae 0xee22
testq %rax, %rax
je 0xedf7
movq 0x1ad06(%rip), %rdi     # 0x29af8
callq 0x2280
movq %rbx, 0x1acf2(%rip)     # 0x29af0
shlq $0x2, %rbx
movq %rbx, %rdi
callq 0x22d0
movq %rax, 0x1ace7(%rip)     # 0x29af8
testq %rax, %rax
jne 0xee22
leaq 0x2b4f(%rip), %rdi      # 0x1196c
callq 0xda1f
movq 0x90(%rsp), %rdi
movabsq $0x100000000, %r15      # imm = 0x100000000
movq 0x28(%rsp), %rax
movl (%rax), %eax
movslq %eax, %rbx
movq $0x0, 0x8(%rsp)
movl 0xa8(%rsp), %ecx
cmpl %ecx, %eax
jge 0xf3cb
movq 0x8(%rsp), %rdx
movslq %edx, %rax
leaq 0x266b(%rip), %rsi      # 0x114d0
movl (%rsi,%rax,4), %ecx
movl %edx, %eax
testl %ecx, (%rdi)
jne 0xeead
pushq $0x1
popq %r14
movl %r14d, %esi
movq 0x8(%rsp), %rdx
callq 0xd54c
testl %eax, %eax
jns 0xee9e
movq 0x90(%rsp), %rdi
movl %r14d, %esi
pushq $-0x1
popq %rdx
callq 0xd54c
testl %eax, %eax
js 0xf3c4
movq 0x90(%rsp), %rdi
leaq 0x2623(%rip), %rsi      # 0x114d0
movslq %eax, %rcx
movl (%rsi,%rcx,4), %edx
notl %edx
andl %edx, (%rdi)
movq %rcx, %rsi
shlq $0x20, %rsi
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
addq %rdx, %rsi
movq 0x30(%rsp), %rdx
leaq (%rdx,%rcx,4), %rdi
xorl %edx, %edx
movq %rdx, %r8
addq %r15, %rsi
incq %rdx
cmpl %ebp, (%rdi,%r8,4)
jg 0xeed6
xorq $0x6b1d, %rbx           # imm = 0x6B1D
leal (%rdx,%rax,2), %edi
decl %edi
addq %rbx, %rdi
cmpl $0x1, %edx
jne 0xf07a
andl $0x7fff, %edi           # imm = 0x7FFF
movslq (%r12,%rcx,4), %rax
xorl %r14d, %r14d
movq %rdi, %rbx
movl 0xa8(%rsp), %ecx
cmpl %ecx, %r14d
jge 0xf3b0
movslq %r14d, %rsi
leal -0x1(%r14), %edx
movq 0x30(%rsp), %rcx
movq %rsi, 0x18(%rsp)
leaq (%rcx,%rsi,4), %r8
movl %r14d, %r10d
xorl %r9d, %r9d
movq %r9, %r11
movl %r10d, %esi
incl %edx
incq %r9
leal 0x1(%rsi), %r10d
cmpl %ebp, (%r8,%r11,4)
jg 0xef38
cmpl $0x1, %r9d
je 0xf070
movl %edx, %r9d
movq %r14, 0x10(%rsp)
movl %r14d, %r11d
leaq 0x2567(%rip), %rcx      # 0x114d0
movl %r11d, %r10d
movslq %r11d, %r8
leaq (%r12,%r8,4), %r11
xorl %r8d, %r8d
leal (%r10,%r8), %r15d
movslq %r9d, %r14
cmpl %r9d, %r15d
jg 0xefb4
movslq (%r11,%r8,4), %r15
movl (%rcx,%r15,4), %edi
testl %edi, (%r13,%rax,4)
je 0xef96
incq %r8
jmp 0xef76
movslq %r10d, %r11
leaq (%r12,%r11,4), %rdi
movl (%r12,%r14,4), %r9d
movl %r9d, (%rdi,%r8,4)
movl %r15d, (%r12,%r14,4)
decl %r14d
addl %r8d, %r11d
movl %r14d, %r9d
jmp 0xef69
movl %r9d, %r15d
subl 0x10(%rsp), %r15d
jl 0xf066
leaq (%r10,%r8), %r11
cmpl %edx, %r11d
jg 0xf066
movq %rcx, %rdi
movq 0x30(%rsp), %rcx
movl %ebp, (%rcx,%r14,4)
xorl $0x6b1d, %ebx           # imm = 0x6B1D
addl %r9d, %ebx
movq 0x28(%rsp), %rcx
incl (%rcx)
andl $0x7fff, %ebx           # imm = 0x7FFF
movq 0x90(%rsp), %rcx
movl (%rcx), %r14d
movq 0x18(%rsp), %rcx
movl (%rdi,%rcx,4), %edi
testl %r14d, %edi
jne 0xf035
movl %edx, %ecx
subl %r10d, %ecx
subl %r8d, %ecx
cmpl %ecx, %r15d
jge 0xf035
orl %r14d, %edi
movq 0x90(%rsp), %rcx
movl %edi, (%rcx)
movq 0x10(%rsp), %rsi
cmpl %esi, %r9d
movq 0x8(%rsp), %rcx
cmovel %esi, %ecx
jmp 0xf061
subl %r10d, %esi
movslq %r10d, %rcx
leaq 0x248e(%rip), %rdi      # 0x114d0
leaq (%rdi,%rcx,4), %rcx
orl (%rcx,%r8,4), %r14d
movq 0x90(%rsp), %rcx
movl %r14d, (%rcx)
cmpl %r8d, %esi
movq 0x8(%rsp), %rcx
cmovel %r11d, %ecx
movq %rcx, 0x8(%rsp)
movabsq $0x100000000, %r15      # imm = 0x100000000
incl %edx
movl %edx, %r14d
jmp 0xef0d
sarq $0x20, %rsi
movl $0x0, 0x18(%rsp)
cmpq %rsi, %rcx
jg 0xf0a7
movslq (%r12,%rcx,4), %r8
leaq 0x243a(%rip), %r9       # 0x114d0
movl 0x18(%rsp), %eax
orl (%r9,%r8,4), %eax
movl %eax, 0x18(%rsp)
incq %rcx
jmp 0xf086
xorl $0x6b1d, %edi           # imm = 0x6B1D
addl %edi, %edx
andl $0x7fff, %edx           # imm = 0x7FFF
movq 0x1aa3c(%rip), %rcx     # 0x29af8
xorl %r11d, %r11d
movq 0x1aa12(%rip), %rax     # 0x29ad8
movq %rax, 0x50(%rsp)
movq %rdx, %rbx
leaq 0x247b(%rip), %rsi      # 0x11550
movl 0xa8(%rsp), %edx
cmpl %edx, %r11d
jge 0xf3b0
movslq %r11d, %rax
movq %rax, %r9
shlq $0x20, %r9
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
addq %rdx, %r9
movq 0x30(%rsp), %rdx
movq %rax, 0x20(%rsp)
leaq (%rdx,%rax,4), %rdx
xorl %edi, %edi
addq %r15, %r9
decl %edi
leaq 0x4(%rdx), %r8
cmpl %ebp, (%rdx)
movq %r8, %rdx
jg 0xf10c
cmpl $-0x1, %edi
je 0xf3a8
movq 0x20(%rsp), %rax
movslq (%r12,%rax,4), %rdx
movl (%r13,%rdx,4), %edx
andl 0x18(%rsp), %edx
je 0xf173
movl %edx, %r8d
shrl $0x18, %r8d
movl %edx, %r10d
shrl $0xe, %r10d
andl $0x3fc, %r10d           # imm = 0x3FC
movl (%r10,%rsi), %r15d
addl (%rsi,%r8,4), %r15d
movl %edx, %r8d
shrl $0x8, %r8d
movl $0xff, %r10d
andl %r10d, %r8d
addl (%rsi,%r8,4), %r15d
andl %r10d, %edx
addl (%rsi,%rdx,4), %r15d
jmp 0xf176
xorl %r15d, %r15d
movl %edi, %eax
notl %eax
movl %r11d, 0x10(%rsp)
addl %r11d, %eax
movl %eax, 0x4c(%rsp)
movq 0x40(%rsp), %rdx
movq 0x20(%rsp), %r8
movl %r15d, (%rdx,%r8,4)
movslq %r15d, %rdx
movl $0x1, (%rcx,%rdx,4)
sarq $0x20, %r9
movl %r15d, %edx
movslq %edx, %r11
cmpq %r9, %r8
jge 0xf236
incq %r8
movslq (%r12,%r8,4), %rdx
movl (%r13,%rdx,4), %edx
andl 0x18(%rsp), %edx
je 0xf1fb
movl %edx, %r10d
shrl $0x18, %r10d
movl %edx, %r14d
shrl $0xe, %r14d
andl $0x3fc, %r14d           # imm = 0x3FC
movl (%r14,%rsi), %r14d
addl (%rsi,%r10,4), %r14d
movl %edx, %r10d
shrl $0x8, %r10d
movl $0xff, %eax
andl %eax, %r10d
addl (%rsi,%r10,4), %r14d
andl %eax, %edx
addl (%rsi,%rdx,4), %r14d
jmp 0xf1fe
xorl %r14d, %r14d
movslq %r15d, %r15
movslq %r14d, %rdx
cmpq %rdx, %r15
jle 0xf21d
andl $0x0, -0x4(%rcx,%r15,4)
decq %r15
jmp 0xf204
andl $0x0, 0x4(%rcx,%r11,4)
incq %r11
cmpq %rdx, %r11
jl 0xf214
incl (%rcx,%rdx,4)
movq 0x40(%rsp), %r10
movl %edx, (%r10,%r8,4)
movl %r11d, %edx
jmp 0xf1a5
cmpl %edx, %r15d
jne 0xf265
xorl $0x6b1d, %ebx           # imm = 0x6B1D
movl 0x10(%rsp), %r11d
addl %r11d, %r15d
addl %ebx, %r15d
andl $0x7fff, %r15d          # imm = 0x7FFF
movq %r15, %rbx
movabsq $0x100000000, %r15      # imm = 0x100000000
jmp 0xf3a8
movslq %r15d, %r15
movl 0x10(%rsp), %edx
pushq $-0x1
popq %r8
movl 0x3c(%rsp), %eax
movq 0x50(%rsp), %rsi
cmpq %r11, %r15
jg 0xf317
movl (%rcx,%r15,4), %r14d
testl %r14d, %r14d
je 0xf309
cmpl %r8d, %r14d
cmovgl %r14d, %r8d
movl %edx, (%rcx,%r15,4)
cmovgl %edx, %eax
cmpl 0x10(%rsp), %edx
je 0xf2dd
movslq %edx, %r10
leaq 0x2227(%rip), %rsi      # 0x114d0
movl (%rsi,%r10,4), %r10d
movq %r13, %rsi
movq 0x90(%rsp), %r13
orl %r10d, (%r13)
movq %rsi, %r13
cmpl $0x1, %r14d
movq 0x8(%rsp), %rsi
cmovel %edx, %esi
movq %rsi, 0x8(%rsp)
movq 0x50(%rsp), %rsi
movq 0x28(%rsp), %r10
incl (%r10)
addl %edx, %r14d
xorl $0x6b1d, %ebx           # imm = 0x6B1D
addl %r15d, %edx
addl %ebx, %edx
movl %edx, %ebx
andl $0x7fff, %ebx           # imm = 0x7FFF
cmpl 0x4c(%rsp), %r14d
jg 0xf30c
movslq %r14d, %rdx
movq 0x30(%rsp), %r10
movl %ebp, -0x4(%r10,%rdx,4)
jmp 0xf30c
movl %edx, %r14d
incq %r15
movl %r14d, %edx
jmp 0xf279
movq 0x20(%rsp), %rdx
movabsq $0x100000000, %r15      # imm = 0x100000000
cmpq %r9, %rdx
jg 0xf34d
movl (%r12,%rdx,4), %r8d
movq 0x40(%rsp), %r10
movslq (%r10,%rdx,4), %r10
movslq (%rcx,%r10,4), %r11
leal 0x1(%r11), %r14d
movl %r14d, (%rcx,%r10,4)
movl %r8d, (%rsi,%r11,4)
incq %rdx
jmp 0xf326
movq 0x20(%rsp), %rdx
movl 0x10(%rsp), %r11d
cmpq %r9, %rdx
jg 0xf369
movl (%rsi,%rdx,4), %r8d
movl %r8d, (%r12,%rdx,4)
incq %rdx
jmp 0xf357
movl %eax, 0x3c(%rsp)
movq 0x90(%rsp), %r9
movl (%r9), %r8d
leaq 0x2151(%rip), %rsi      # 0x114d0
movq 0x20(%rsp), %rax
movl (%rsi,%rax,4), %edx
testl %r8d, %edx
jne 0xf3a1
orl %r8d, %edx
movslq 0x3c(%rsp), %r8
movl (%rsi,%r8,4), %r8d
notl %r8d
andl %edx, %r8d
movl %r8d, (%r9)
leaq 0x21a8(%rip), %rsi      # 0x11550
subl %edi, %r11d
jmp 0xf0d5
movq 0x28(%rsp), %rax
movl (%rax), %eax
movq 0x90(%rsp), %rdi
jmp 0xee47
movq 0x28(%rsp), %rax
movl (%rax), %eax
xorl $0x6b1d, %ebx           # imm = 0x6B1D
addl %eax, %ebx
movl $0x7fff, %eax           # imm = 0x7FFF
andl %eax, %ebx
xorl %ecx, %ecx
cmpl %eax, %ebx
cmovnel %ebx, %ecx
movq 0x98(%rsp), %rax
movl %ecx, (%rax)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq