// File: /workspace/github_c_makefile_star2_O3/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 $0x88, %rsp
movq %r9, %r14
movq %r8, 0x28(%rsp)
movl %ecx, %ebp
movq %rdx, 0x20(%rsp)
movq %rsi, %r12
movq %rdi, 0x50(%rsp)
movl 0xd8(%rsp), %eax
movslq %eax, %rbx
movq 0x1a193(%rip), %rax     # 0x29ab0
cmpq %rbx, %rax
jae 0xf95e
testq %rax, %rax
je 0xf933
movq 0x1a18a(%rip), %rdi     # 0x29ab8
callq 0x2260
movq %rbx, 0x1a176(%rip)     # 0x29ab0
shlq $0x2, %rbx
movq %rbx, %rdi
callq 0x22a0
movq %rax, 0x1a16b(%rip)     # 0x29ab8
testq %rax, %rax
jne 0xf95e
leaq 0x3043(%rip), %rdi      # 0x1299c
callq 0xe47c
movl 0xd8(%rsp), %eax
addl $0x2, %eax
movslq %eax, %rbx
movq 0x1a15e(%rip), %rax     # 0x29ad0
cmpq %rbx, %rax
jae 0xf9b3
testq %rax, %rax
je 0xf988
movq 0x1a155(%rip), %rdi     # 0x29ad8
callq 0x2260
movq %rbx, 0x1a141(%rip)     # 0x29ad0
shlq $0x2, %rbx
movq %rbx, %rdi
callq 0x22a0
movq %rax, 0x1a136(%rip)     # 0x29ad8
testq %rax, %rax
jne 0xf9b3
leaq 0x2fee(%rip), %rdi      # 0x1299c
callq 0xe47c
movq 0x28(%rsp), %rax
movl (%rax), %eax
movslq %eax, %r15
movl 0xd8(%rsp), %ecx
cmpl %ecx, %r15d
jge 0x1000f
movq $0x0, 0x10(%rsp)
leaq 0x2b23(%rip), %rcx      # 0x12500
movl %ebp, 0x8(%rsp)
movq 0x20(%rsp), %rbx
movq %r12, 0x80(%rsp)
movq %r14, 0x40(%rsp)
movq 0x10(%rsp), %rdx
movslq %edx, %rax
movq %rcx, %r8
movl (%rcx,%rax,4), %ecx
movl %edx, %eax
movq 0xc0(%rsp), %rdi
testl %ecx, (%rdi)
jne 0xfa4e
movl $0x1, %esi
movq 0x10(%rsp), %rdx
movq %rdi, %r13
callq 0xded4
movq %r13, %rdi
testl %eax, %eax
jns 0xfa47
movl $0x1, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xded4
testl %eax, %eax
js 0x10046
movq 0xc0(%rsp), %rdi
leaq 0x2ab2(%rip), %r8       # 0x12500
movslq %eax, %rsi
movl (%r8,%rsi,4), %ecx
notl %ecx
andl %ecx, (%rdi)
leaq (,%rsi,4), %rdx
leaq (%rbx,%rsi,4), %r8
xorl %ecx, %ecx
movl %ecx, %edi
leal -0x1(%rdi), %ecx
leaq 0x4(%r8), %r9
cmpl %ebp, (%r8)
movq %r9, %r8
jg 0xfa67
movl %ecx, %r8d
notl %r8d
movq %r15, %r9
xorq $0x6b1d, %r9            # imm = 0x6B1D
leal (%r8,%rax,2), %r15d
addq %r9, %r15
cmpl $-0x1, %ecx
je 0xfe75
addl %eax, %r8d
xorl %r10d, %r10d
cmpl %r8d, %eax
leaq 0x2a58(%rip), %r8       # 0x12500
jg 0xfac6
addq %r12, %rdx
movl $0x1, %eax
subl %edi, %eax
xorl %r10d, %r10d
movslq (%rdx), %rsi
orl (%r8,%rsi,4), %r10d
addq $0x4, %rdx
decl %eax
jne 0xfab7
xorl $0x6b1d, %r15d          # imm = 0x6B1D
subl %ecx, %r15d
andl $0x7fff, %r15d          # imm = 0x7FFF
movq %r15, 0x18(%rsp)
movl 0xd8(%rsp), %eax
testl %eax, %eax
jle 0xffed
movq 0x19fe6(%rip), %r11     # 0x29ad8
movq 0x19fbf(%rip), %rcx     # 0x29ab8
leaq -0x4(%r11), %rax
movq %rax, 0x70(%rsp)
leaq 0x4(%r11), %rax
movq %rax, 0x68(%rsp)
xorl %edx, %edx
movl %r10d, 0x34(%rsp)
movq %r11, 0x60(%rsp)
movq %rcx, 0x58(%rsp)
movl %edx, 0x4(%rsp)
movslq %edx, %r9
movl %r9d, %r15d
negl %r15d
leaq (%rbx,%r9,4), %rax
xorl %ecx, %ecx
movq %rcx, %r13
decl %r15d
incq %rcx
cmpl %ebp, (%rax,%r13,4)
jg 0xfb2f
cmpl $0x1, %ecx
je 0xfcfa
movslq (%r12,%r9,4), %rax
movq 0x50(%rsp), %rcx
movl (%rcx,%rax,4), %eax
andl %r10d, %eax
je 0xfb8b
movl %eax, %ecx
shrl $0x18, %ecx
movl %eax, %edx
shrl $0xe, %edx
andl $0x3fc, %edx            # imm = 0x3FC
leaq 0x2a11(%rip), %rsi      # 0x12580
movl (%rdx,%rsi), %edi
addl (%rsi,%rcx,4), %edi
movl %eax, %ecx
shrl $0x8, %ecx
movl $0xff, %edx
andl %edx, %ecx
addl (%rsi,%rcx,4), %edi
andl %edx, %eax
addl (%rsi,%rax,4), %edi
jmp 0xfb8d
xorl %edi, %edi
movl %r15d, %r8d
notl %r8d
movl %edi, (%r14,%r9,4)
movslq %edi, %rax
movl $0x1, (%r11,%rax,4)
cmpl %r8d, %r9d
jge 0xfcdf
movslq %r8d, %rax
movq %rax, 0x38(%rsp)
movq %r9, %rbx
movl %edi, %edx
movq %r9, 0x48(%rsp)
movl %r8d, 0xc(%rsp)
movslq 0x4(%r12,%rbx,4), %rax
movq 0x50(%rsp), %rcx
movl (%rcx,%rax,4), %eax
andl %r10d, %eax
je 0xfc0d
movl %eax, %ecx
shrl $0x18, %ecx
movl %edx, %r12d
movl %eax, %edx
shrl $0xe, %edx
andl $0x3fc, %edx            # imm = 0x3FC
leaq 0x2992(%rip), %rsi      # 0x12580
movl (%rdx,%rsi), %ebp
addl (%rsi,%rcx,4), %ebp
movl %eax, %ecx
shrl $0x8, %ecx
movl $0xff, %edx
andl %edx, %ecx
addl (%rsi,%rcx,4), %ebp
andl %edx, %eax
movl %r12d, %edx
addl (%rsi,%rax,4), %ebp
jmp 0xfc0f
xorl %ebp, %ebp
movslq %ebp, %r12
cmpl %ebp, %edx
jle 0xfc6b
movq %rdi, 0x78(%rsp)
movslq %edx, %r14
movl %ebp, %eax
notl %eax
addl %edx, %eax
movq %r14, %rcx
subq %rax, %rcx
movq 0x70(%rsp), %rdx
leaq (%rdx,%rcx,4), %rdi
leaq 0x4(,%rax,4), %rdx
xorl %esi, %esi
callq 0x2120
decq %r14
cmpq %r12, %r14
jg 0xfc42
movl %r14d, %edx
movq 0x40(%rsp), %r14
movl 0x34(%rsp), %r10d
movq 0x60(%rsp), %r11
movq 0x48(%rsp), %r9
movl 0xc(%rsp), %r8d
movq 0x78(%rsp), %rdi
cmpl %ebp, %edi
jge 0xfcb2
movslq %edi, %rax
movq 0x68(%rsp), %rcx
movl %edx, %r14d
movq %rdi, %rdx
leaq (%rcx,%rax,4), %rdi
notl %edx
addl %ebp, %edx
leaq 0x4(,%rdx,4), %rdx
xorl %esi, %esi
callq 0x2120
movl %r14d, %edx
movq 0x40(%rsp), %r14
movl 0xc(%rsp), %r8d
movq 0x48(%rsp), %r9
movq 0x60(%rsp), %r11
movl 0x34(%rsp), %r10d
movl %ebp, %edi
incl (%r11,%r12,4)
incq %rbx
movl %ebp, (%r14,%rbx,4)
cmpq 0x38(%rsp), %rbx
movq 0x80(%rsp), %r12
jne 0xfbc2
cmpl %edi, %edx
movq 0x20(%rsp), %rbx
jne 0xfd15
movl %edx, %edi
movl 0x8(%rsp), %ebp
movq 0x18(%rsp), %rax
xorl $0x6b1d, %eax           # imm = 0x6B1D
addl 0x4(%rsp), %edi
addl %eax, %edi
andl $0x7fff, %edi           # imm = 0x7FFF
movq %rdi, 0x18(%rsp)
negl %r15d
movl %r15d, %edx
movl 0xd8(%rsp), %eax
cmpl %eax, %r15d
jl 0xfb1c
jmp 0xffed
movl 0x8(%rsp), %ebp
jg 0xfdde
movslq %edx, %rax
incl %edi
leaq (%r11,%rax,4), %rax
movl $0xffffffff, 0x38(%rsp) # imm = 0xFFFFFFFF
movl 0x4(%rsp), %esi
movl %edx, %ecx
movl (%rax), %edx
testl %edx, %edx
je 0xfdca
movq %rdi, %r14
movl 0x38(%rsp), %edi
cmpl %edi, %edx
cmovgl %edx, %edi
movl %edi, 0x38(%rsp)
movl %esi, (%rax)
movl 0x30(%rsp), %edi
cmovgl %esi, %edi
movl %edi, 0x30(%rsp)
cmpl 0x4(%rsp), %esi
je 0xfd98
movslq %esi, %rdi
leaq 0x2793(%rip), %r8       # 0x12500
movl (%r8,%rdi,4), %edi
movq 0xc0(%rsp), %r8
orl %edi, (%r8)
movl 0xc(%rsp), %r8d
cmpl $0x1, %edx
movq 0x10(%rsp), %rdi
cmovel %esi, %edi
movq %rdi, 0x10(%rsp)
movq 0x28(%rsp), %rdi
incl (%rdi)
addl %esi, %edx
movq 0x18(%rsp), %rdi
xorl $0x6b1d, %edi           # imm = 0x6B1D
addl %ecx, %esi
addl %edi, %esi
andl $0x7fff, %esi           # imm = 0x7FFF
movq %rsi, 0x18(%rsp)
cmpl %r8d, %edx
jg 0xfdc0
movslq %edx, %rsi
movl %ebp, -0x4(%rbx,%rsi,4)
movq %r14, %rdi
movq 0x40(%rsp), %r14
jmp 0xfdcc
movl %esi, %edx
incl %ecx
addq $0x4, %rax
movl %edx, %esi
movl %ecx, %edx
cmpl %ecx, %edi
jne 0xfd34
cmpl %r8d, 0x4(%rsp)
jg 0xfe43
leaq (%r12,%r9,4), %rax
leaq (%r14,%r9,4), %rcx
incq %r13
xorl %edx, %edx
movq 0x58(%rsp), %rbx
movl (%rax,%rdx,4), %esi
movslq (%rcx,%rdx,4), %rdi
movslq (%r11,%rdi,4), %r8
leal 0x1(%r8), %r9d
movl %r9d, (%r11,%rdi,4)
movl %esi, (%rbx,%r8,4)
incq %rdx
cmpl %edx, %r13d
jne 0xfdf7
movl 0xc(%rsp), %ecx
cmpl %ecx, 0x4(%rsp)
movq 0x20(%rsp), %rbx
movq 0x48(%rsp), %r9
jg 0xfe43
movq 0x58(%rsp), %rcx
leaq (%rcx,%r9,4), %rcx
xorl %edx, %edx
movl (%rcx,%rdx,4), %esi
movl %esi, (%rax,%rdx,4)
incq %rdx
cmpl %edx, %r13d
jne 0xfe35
movq 0xc0(%rsp), %rdx
movl (%rdx), %ecx
leaq 0x26ac(%rip), %rsi      # 0x12500
movl (%rsi,%r9,4), %eax
testl %ecx, %eax
jne 0xfcfa
orl %ecx, %eax
movslq 0x30(%rsp), %rcx
movl (%rsi,%rcx,4), %ecx
notl %ecx
andl %eax, %ecx
movl %ecx, (%rdx)
jmp 0xfcfa
andl $0x7fff, %r15d          # imm = 0x7FFF
movl 0xd8(%rsp), %eax
testl %eax, %eax
jle 0xffe8
movslq (%r12,%rsi,4), %rax
xorl %ecx, %ecx
movl %ecx, %esi
movslq %ecx, %rdi
leaq (%rbx,%rdi,4), %r8
xorl %edx, %edx
movq %rdx, %r9
incq %rdx
cmpl %ebp, (%r8,%r9,4)
jg 0xfe9c
cmpl $0x1, %edx
je 0xffd7
movq %r15, %r13
leal -0x1(%rcx), %r10d
addq %rdx, %r10
cmpl %r10d, %ecx
jle 0xfec8
movl %r10d, %r9d
movl %ecx, %r8d
jmp 0xff07
movl %esi, %r8d
movl %r10d, %r9d
movslq %r8d, %r11
movslq (%r12,%r11,4), %rbx
leaq 0x2624(%rip), %r15      # 0x12500
movl (%r15,%rbx,4), %ebp
movq 0x50(%rsp), %r15
testl %ebp, (%r15,%rax,4)
je 0xfef0
incl %r8d
jmp 0xff02
movslq %r9d, %r9
movl (%r12,%r9,4), %ebp
movl %ebp, (%r12,%r11,4)
movl %ebx, (%r12,%r9,4)
decl %r9d
cmpl %r9d, %r8d
jle 0xfece
movl %r9d, %r11d
subl %ecx, %r11d
jl 0xffcb
cmpl %r10d, %r8d
movl 0x8(%rsp), %ebp
movq 0x20(%rsp), %rbx
movq %r13, %r15
jg 0xffd7
movslq %r9d, %r10
movl %ebp, (%rbx,%r10,4)
xorl $0x6b1d, %r15d          # imm = 0x6B1D
addl %r9d, %r15d
movq 0x28(%rsp), %r10
incl (%r10)
andl $0x7fff, %r15d          # imm = 0x7FFF
movq 0xc0(%rsp), %r13
movl (%r13), %r10d
leaq 0x25a5(%rip), %r13      # 0x12500
movl (%r13,%rdi,4), %edi
testl %r10d, %edi
jne 0xff92
movl %ecx, %ebx
subl %r8d, %ebx
addl %edx, %ebx
decl %ebx
cmpl %ebx, %r11d
movq 0x20(%rsp), %rbx
jge 0xff92
orl %r10d, %edi
movq 0xc0(%rsp), %rsi
movl %edi, (%rsi)
cmpl %ecx, %r9d
movq 0x10(%rsp), %rsi
cmovel %ecx, %esi
jmp 0xffc4
movl %r8d, %edi
negl %edi
addq %rdi, %rsi
addq %rdx, %rsi
decq %rsi
movslq %r8d, %rdi
leaq 0x2556(%rip), %r9       # 0x12500
orl (%r9,%rdi,4), %r10d
movq 0xc0(%rsp), %rdi
movl %r10d, (%rdi)
testl %esi, %esi
movq 0x10(%rsp), %rsi
cmovel %r8d, %esi
movq %rsi, 0x10(%rsp)
jmp 0xffd7
movl 0x8(%rsp), %ebp
movq 0x20(%rsp), %rbx
movq %r13, %r15
addl %edx, %ecx
movl 0xd8(%rsp), %edx
cmpl %edx, %ecx
jl 0xfe91
movq %r15, 0x18(%rsp)
movq 0x28(%rsp), %rax
movl (%rax), %eax
movl 0xd8(%rsp), %ecx
cmpl %ecx, %eax
movq 0x18(%rsp), %r15
leaq 0x24f7(%rip), %rcx      # 0x12500
jl 0xf9f3
xorl $0x6b1d, %r15d          # imm = 0x6B1D
addl %eax, %r15d
movl $0x7fff, %eax           # imm = 0x7FFF
andl %eax, %r15d
xorl %ecx, %ecx
cmpl %eax, %r15d
cmovnel %r15d, %ecx
movq 0xc8(%rsp), %rax
movl %ecx, (%rax)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x28(%rsp), %rax
movl (%rax), %eax
jmp 0x1000f