// File: /workspace/github_c_makefile_star2_O1/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 $0x98, %rsp
movq %r9, 0x58(%rsp)
movq %r8, %r14
movl %ecx, %r15d
movq %rdx, %r12
movq %rsi, 0x18(%rsp)
movq %rdi, 0x60(%rsp)
movl 0xe8(%rsp), %ebp
movslq %ebp, %rbx
movq 0x1a367(%rip), %rax     # 0x29ab0
cmpq %rbx, %rax
jae 0xf78a
testq %rax, %rax
je 0xf75f
movq 0x1a35e(%rip), %rdi     # 0x29ab8
callq 0x2260
movq %rbx, 0x1a34a(%rip)     # 0x29ab0
shlq $0x2, %rbx
movq %rbx, %rdi
callq 0x22a0
movq %rax, 0x1a33f(%rip)     # 0x29ab8
testq %rax, %rax
jne 0xf78a
leaq 0x3207(%rip), %rdi      # 0x1298c
callq 0xe265
leal 0x2(%rbp), %eax
movslq %eax, %rbx
movq 0x1a339(%rip), %rax     # 0x29ad0
cmpq %rbx, %rax
jae 0xf7d8
testq %rax, %rax
je 0xf7ad
movq 0x1a330(%rip), %rdi     # 0x29ad8
callq 0x2260
movq %rbx, 0x1a31c(%rip)     # 0x29ad0
shlq $0x2, %rbx
movq %rbx, %rdi
callq 0x22a0
movq %rax, 0x1a311(%rip)     # 0x29ad8
testq %rax, %rax
jne 0xf7d8
leaq 0x31b9(%rip), %rdi      # 0x1298c
callq 0xe265
movl (%r14), %eax
movq %rax, (%rsp)
cmpl %ebp, %eax
jge 0xfe1e
movq 0xd0(%rsp), %rbx
movq $0x0, 0x10(%rsp)
movq %r12, 0x38(%rsp)
movq %r14, 0x50(%rsp)
movl %r15d, 0x28(%rsp)
movq 0x10(%rsp), %rdx
movslq %edx, %rax
leaq 0x2cda(%rip), %rdi      # 0x124f0
movl (%rdi,%rax,4), %ecx
movl %edx, %eax
testl %ecx, (%rbx)
jne 0xf856
movq %rbx, %rdi
movl $0x1, %esi
movq 0x10(%rsp), %rdx
callq 0xdcbc
testl %eax, %eax
jns 0xf84f
movq %rbx, %rdi
movl $0x1, %esi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
callq 0xdcbc
testl %eax, %eax
js 0xfe1e
leaq 0x2c9a(%rip), %rdi      # 0x124f0
movslq %eax, %rsi
movl (%rdi,%rsi,4), %ecx
notl %ecx
andl %ecx, (%rbx)
leaq (,%rsi,4), %rdx
leaq (%r12,%rsi,4), %r8
xorl %ecx, %ecx
movl %ecx, %edi
leal -0x1(%rdi), %ecx
leaq 0x4(%r8), %r9
cmpl %r15d, (%r8)
movq %r9, %r8
jg 0xf86e
movl %ecx, %r8d
notl %r8d
movq (%rsp), %r9
xorq $0x6b1d, %r9            # imm = 0x6B1D
leal (%r8,%rax,2), %r10d
addq %r9, %r10
movq %r10, (%rsp)
cmpl $-0x1, %ecx
je 0xfcb8
addl %eax, %r8d
xorl %r11d, %r11d
cmpl %r8d, %eax
leaq 0x2c3c(%rip), %r8       # 0x124f0
jg 0xf8d4
addq 0x18(%rsp), %rdx
movl $0x1, %eax
subl %edi, %eax
xorl %r11d, %r11d
movslq (%rdx), %rsi
orl (%r8,%rsi,4), %r11d
addq $0x4, %rdx
decl %eax
jne 0xf8c5
movq (%rsp), %rax
xorq $0x6b1d, %rax           # imm = 0x6B1D
negl %ecx
addq %rax, %rcx
movq %rcx, (%rsp)
testl %ebp, %ebp
jle 0xfe0d
movq 0x1a1e2(%rip), %r10     # 0x29ad8
movq 0x1a1bb(%rip), %rdx     # 0x29ab8
leaq -0x4(%r10), %rax
movq %rax, 0x80(%rsp)
leaq 0x4(%r10), %rax
movq %rax, 0x78(%rsp)
xorl %eax, %eax
movl %r11d, 0x30(%rsp)
movq %r10, 0x40(%rsp)
movq %rdx, 0x68(%rsp)
movl %eax, 0xc(%rsp)
movslq %eax, %rsi
movl %esi, %ebx
negl %ebx
leaq (%r12,%rsi,4), %rax
xorl %ecx, %ecx
movq %rcx, %r13
decl %ebx
incq %rcx
cmpl %r15d, (%rax,%r13,4)
jg 0xf934
cmpl $0x1, %ecx
je 0xfca7
movq %rsi, 0x48(%rsp)
movl 0xc(%rsp), %r8d
movslq %r8d, %r9
movq 0x18(%rsp), %rsi
movslq (%rsi,%r9,4), %rax
movq 0x60(%rsp), %rcx
movl (%rcx,%rax,4), %eax
andl %r11d, %eax
je 0xf9a1
movl %eax, %ecx
shrl $0x18, %ecx
movl %eax, %edx
shrl $0xe, %edx
andl $0x3fc, %edx            # imm = 0x3FC
leaq 0x2beb(%rip), %rdi      # 0x12570
movl (%rdx,%rdi), %ebp
addl (%rdi,%rcx,4), %ebp
movl %eax, %ecx
shrl $0x8, %ecx
movl $0xff, %edx
andl %edx, %ecx
addl (%rdi,%rcx,4), %ebp
andl %edx, %eax
addl (%rdi,%rax,4), %ebp
jmp 0xf9a3
xorl %ebp, %ebp
movl %ebx, %ecx
notl %ecx
movq 0x58(%rsp), %rax
movq %r9, 0x70(%rsp)
movl %ebp, (%rax,%r9,4)
movslq %ebp, %rax
movl $0x1, (%r10,%rax,4)
cmpl %ecx, %r8d
movl %ecx, 0x24(%rsp)
jge 0xfaf6
movslq %ecx, %rax
movq %rax, 0x90(%rsp)
movq 0x48(%rsp), %r15
movl %ebp, %r14d
movl %ebp, %r8d
movslq 0x4(%rsi,%r15,4), %rax
movq 0x60(%rsp), %rcx
movl (%rcx,%rax,4), %eax
andl %r11d, %eax
je 0xfa28
movl %eax, %ecx
shrl $0x18, %ecx
movl %eax, %edx
shrl $0xe, %edx
andl $0x3fc, %edx            # imm = 0x3FC
leaq 0x2b64(%rip), %rsi      # 0x12570
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
addl (%rsi,%rax,4), %ebp
jmp 0xfa2a
xorl %ebp, %ebp
movslq %ebp, %r12
cmpl %ebp, %r14d
movl %r8d, 0x34(%rsp)
jle 0xfa7b
movq %r14, %rcx
movslq %ecx, %r14
movl %ebp, %eax
notl %eax
addl %ecx, %eax
movq %r14, %rcx
subq %rax, %rcx
movq 0x80(%rsp), %rdx
leaq (%rdx,%rcx,4), %rdi
leaq 0x4(,%rax,4), %rdx
xorl %esi, %esi
callq 0x2120
decq %r14
cmpq %r12, %r14
jg 0xfa64
movl 0x30(%rsp), %r11d
movq 0x40(%rsp), %r10
movl 0x34(%rsp), %r8d
cmpl %ebp, %r8d
jge 0xfad1
movq %r14, 0x88(%rsp)
movslq %r8d, %r14
movq 0x78(%rsp), %rax
leaq (%rax,%r14,4), %rdi
movl %r8d, %eax
notl %eax
addl %ebp, %eax
leaq 0x4(,%rax,4), %rdx
xorl %esi, %esi
callq 0x2120
subq %r12, %r14
xorl %eax, %eax
decq %rax
cmpq %rax, %r14
jne 0xfaaf
movl 0x34(%rsp), %r8d
subl %eax, %r8d
movl 0x30(%rsp), %r11d
movq 0x40(%rsp), %r10
movq 0x88(%rsp), %r14
incl (%r10,%r12,4)
incq %r15
movq 0x58(%rsp), %rax
movl %ebp, (%rax,%r15,4)
cmpq 0x90(%rsp), %r15
movq 0x18(%rsp), %rsi
jne 0xf9e3
jmp 0xfafc
movl %ebp, %r14d
movl %ebp, %r8d
cmpl %r8d, %r14d
jne 0xfb2b
movq (%rsp), %rax
xorq $0x6b1d, %rax           # imm = 0x6B1D
addl 0xc(%rsp), %r14d
addq %r14, %rax
movq %rax, (%rsp)
movq 0x50(%rsp), %r14
movl 0x28(%rsp), %r15d
movq 0x38(%rsp), %r12
jmp 0xfca0
movl 0x28(%rsp), %r15d
movq 0x38(%rsp), %r12
movl 0xc(%rsp), %ebp
jg 0xfbe9
movslq %r14d, %rax
incl %r8d
leaq (%r10,%rax,4), %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ebp, %esi
movl (%rax), %edx
testl %edx, %edx
je 0xfbd5
cmpl %ecx, %edx
cmovgl %edx, %ecx
movl %esi, (%rax)
movl 0x2c(%rsp), %edi
cmovgl %esi, %edi
movl %edi, 0x2c(%rsp)
cmpl %ebp, %esi
je 0xfbae
movslq %esi, %rdi
movq %r12, %r9
movq %r14, %r12
movl %r8d, %r14d
leaq 0x2971(%rip), %r8       # 0x124f0
movl (%r8,%rdi,4), %edi
movq 0xd0(%rsp), %r8
orl %edi, (%r8)
movl %r14d, %r8d
movq %r12, %r14
movq %r9, %r12
cmpl $0x1, %edx
movq 0x10(%rsp), %rdi
cmovel %esi, %edi
movq %rdi, 0x10(%rsp)
movq 0x50(%rsp), %rdi
incl (%rdi)
addl %esi, %edx
movq (%rsp), %rdi
xorq $0x6b1d, %rdi           # imm = 0x6B1D
addl %r14d, %esi
addq %rdi, %rsi
movq %rsi, (%rsp)
cmpl 0x24(%rsp), %edx
jg 0xfbd7
movslq %edx, %rsi
movl %r15d, -0x4(%r12,%rsi,4)
jmp 0xfbd7
movl %esi, %edx
incl %r14d
addq $0x4, %rax
movl %edx, %esi
cmpl %r14d, %r8d
jne 0xfb50
cmpl 0x24(%rsp), %ebp
movq 0x68(%rsp), %rbp
jg 0xfc3a
movq 0x18(%rsp), %rax
movq 0x48(%rsp), %rdx
leaq (%rax,%rdx,4), %rax
movq 0x58(%rsp), %rcx
leaq (%rcx,%rdx,4), %rcx
leaq 0x1(%r13), %rdx
xorl %esi, %esi
movl (%rax,%rsi,4), %edi
movslq (%rcx,%rsi,4), %r8
movslq (%r10,%r8,4), %r9
leal 0x1(%r9), %r10d
movq 0x40(%rsp), %r14
movl %r10d, (%r14,%r8,4)
movq 0x40(%rsp), %r10
movl %edi, (%rbp,%r9,4)
incq %rsi
cmpl %esi, %edx
jne 0xfc11
movl 0x24(%rsp), %eax
cmpl %eax, 0xc(%rsp)
jg 0xfc6e
movq 0x68(%rsp), %rax
movq 0x48(%rsp), %rdx
leaq (%rax,%rdx,4), %rax
movq 0x18(%rsp), %rcx
leaq (%rcx,%rdx,4), %rcx
incq %r13
xorl %edx, %edx
movl (%rax,%rdx,4), %esi
movl %esi, (%rcx,%rdx,4)
incq %rdx
cmpl %edx, %r13d
jne 0xfc60
movq 0xd0(%rsp), %rdx
movl (%rdx), %ecx
leaq 0x2871(%rip), %rsi      # 0x124f0
movq 0x70(%rsp), %rax
movl (%rsi,%rax,4), %eax
testl %ecx, %eax
movq 0x50(%rsp), %r14
jne 0xfca0
orl %ecx, %eax
movslq 0x2c(%rsp), %rcx
movl (%rsi,%rcx,4), %ecx
notl %ecx
andl %eax, %ecx
movl %ecx, (%rdx)
movl 0xe8(%rsp), %ebp
negl %ebx
movl %ebx, %eax
cmpl %ebp, %ebx
jl 0xf923
jmp 0xfe0d
testl %ebp, %ebp
jle 0xfe0d
movq 0x18(%rsp), %rax
movslq (%rax,%rsi,4), %rax
xorl %ecx, %ecx
movl %ecx, %esi
movslq %ecx, %rdi
leaq (%r12,%rdi,4), %r8
xorl %edx, %edx
movq %rdx, %r9
incq %rdx
cmpl %r15d, (%r8,%r9,4)
jg 0xfcd6
cmpl $0x1, %edx
je 0xfe03
leal -0x1(%rcx), %r10d
addq %rdx, %r10
cmpl %r10d, %ecx
jle 0xfcff
movl %r10d, %r9d
movl %ecx, %r8d
jmp 0xfd45
movl %esi, %r8d
movl %r10d, %r9d
movq 0x18(%rsp), %r12
movslq %r8d, %r11
movslq (%r12,%r11,4), %rbx
leaq 0x27d8(%rip), %r13      # 0x124f0
movl (%r13,%rbx,4), %ebp
movq 0x60(%rsp), %r13
testl %ebp, (%r13,%rax,4)
je 0xfd2e
incl %r8d
jmp 0xfd40
movslq %r9d, %r9
movl (%r12,%r9,4), %ebp
movl %ebp, (%r12,%r11,4)
movl %ebx, (%r12,%r9,4)
decl %r9d
cmpl %r9d, %r8d
jle 0xfd0a
movl %r9d, %r11d
subl %ecx, %r11d
jl 0xfdf7
cmpl %r10d, %r8d
movq 0x38(%rsp), %r12
movl 0xe8(%rsp), %ebp
jg 0xfe03
movslq %r9d, %r10
movl %r15d, (%r12,%r10,4)
movq (%rsp), %rbx
xorq $0x6b1d, %rbx           # imm = 0x6B1D
incl (%r14)
addq %r10, %rbx
movq %rbx, (%rsp)
movq 0xd0(%rsp), %rbx
movl (%rbx), %r10d
leaq 0x275c(%rip), %r13      # 0x124f0
movl (%r13,%rdi,4), %edi
testl %r10d, %edi
jne 0xfdc6
movl %ecx, %ebx
subl %r8d, %ebx
addl %edx, %ebx
decl %ebx
cmpl %ebx, %r11d
movq 0xd0(%rsp), %rbx
jge 0xfdc6
orl %r10d, %edi
movl %edi, (%rbx)
cmpl %ecx, %r9d
movq 0x10(%rsp), %rsi
cmovel %ecx, %esi
jmp 0xfdf0
movl %r8d, %edi
negl %edi
addq %rdi, %rsi
addq %rdx, %rsi
decq %rsi
movslq %r8d, %rdi
leaq 0x2712(%rip), %r9       # 0x124f0
orl (%r9,%rdi,4), %r10d
movl %r10d, (%rbx)
testl %esi, %esi
movq 0x10(%rsp), %rsi
cmovel %r8d, %esi
movq %rsi, 0x10(%rsp)
jmp 0xfe03
movq 0x38(%rsp), %r12
movl 0xe8(%rsp), %ebp
addl %edx, %ecx
cmpl %ebp, %ecx
jl 0xfccb
cmpl %ebp, (%r14)
movq 0xd0(%rsp), %rbx
jl 0xf807
movq (%rsp), %rsi
xorl $0x6b1d, %esi           # imm = 0x6B1D
addl (%r14), %esi
andl $0x7fff, %esi           # imm = 0x7FFF
movabsq $0x2000400080011, %rcx  # imm = 0x2000400080011
movq %rsi, %rax
mulq %rcx
movl %edx, %eax
shll $0xf, %eax
subl %eax, %edx
addl %esi, %edx
movq 0xd8(%rsp), %rax
movl %edx, (%rax)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq