// File: /workspace/github_c_makefile_star2_O3/mishun[P]plantri/plantri.c
// Function: bip_P_legal
static void
bip_P_legal(EDGE *ref, EDGE *good_or[], int *ngood_or, int *ngood_ref,
          EDGE *good_mir[], int *ngood_mir, int *ngood_mir_ref, EDGE *hint)

/* The P-operation with reference edge *ref has just been performed.
   Make a list in good_or[0..*ngood_or-1] of the reference edges of
   legal P-reductions (oriented editions) that might be canonical,
   with the first *ngood_ref of those being ref.
   Make a list in good_mir[0..*ngood_mir-1] of the
   reference edges of legal P-reductions (mirror-image editions) that
   might be canonical, with the first *ngood_mir_ref of those being ref.
   *ngood_ref and *ngood_mir_ref might each be 0 or 1.  If they are
   both 0, nothing else need be correct.
   All the edges in good_or[] and good_mir[] must start with the same
   vertex degree and end with the same vertex degree (actually, colour
   as passed to canon_edge_oriented).
   The "type" used in this procedure needs to match the requirements of
   find_extensions_bip(), so changing it is dangerous.
   If hint!=NULL, it is an edge of the graph that has some chance of
   being a better P-reduction than the one just performed.
*/
{
    int i,j,w,z,ok;
    long degend,deg0,deg1,deg2,deg3,deg4,deg5;
    long thistype,besttype;
    EDGE *e,*e1,*ew,*ewlast;

    degend = degree[ref->end];
    deg0 = degend << 21;
    deg1 = nv-degree[ref->next->next->invers->next->next->end];
    deg2 = degree[ref->next->end];
    deg3 = degree[ref->prev->end];
    deg4 = degree[ref->invers->prev->prev->end];
    deg5 = degree[ref->invers->next->next->end];

    besttype = deg0 + (deg1<<11) + (deg2<<2) + (deg3<<1) + deg4-deg5;
    thistype = deg0 + (deg1<<11) + (deg3<<2) + (deg2<<1) + deg5-deg4;
    if (besttype > thistype)
    {
        good_or[0] = ref;
        *ngood_or = *ngood_ref = 1;
        *ngood_mir = *ngood_mir_ref = 0;
    }
    else if (besttype == thistype)
    {
        good_or[0] = good_mir[0] = ref;
        *ngood_or = *ngood_ref = 1;
        *ngood_mir = *ngood_mir_ref = 1;
    }
    else
    {
        good_mir[0] = ref;
        *ngood_or = *ngood_ref = 0;
        *ngood_mir = *ngood_mir_ref = 1;
        besttype = thistype;
    }

    if (hint)
    {
	e = hint;
	w = e->end;
	e1 = e->next->next;
	if (degree[w] >= degend && degree[e->start] == 4
 	          && degree[e->next->end] != 4 && degree[e->prev->end] != 4
		  && degree[e1->end] == 4 && e != ref)
	{
            z = e1->invers->next->next->end;
	    ok = (degree[z] == 4);
	    if (!ok)
	    {
		ew = e->invers;
		ewlast = ew->prev;
		for (ew = ew->next->next; ew != ewlast; ew = ew->next)
		    if (ew->end == z) break;
		ok = (ew == ewlast);
	    }

	    if (ok)
	    {
		deg0 = ((long)degree[w] << 21) + ((long)(nv-degree[z]) << 11);
                deg2 = degree[e->next->end];
                deg3 = degree[e->prev->end];
                deg4 = degree[e->invers->prev->prev->end];
                deg5 = degree[e->invers->next->next->end];

                thistype = deg0 + (deg2<<2) + (deg3<<1) + deg4-deg5;
                if (thistype > besttype)
                {
                    *ngood_ref = *ngood_mir_ref = 0;
                    return;
                }

                thistype = deg0 + (deg3<<2) + (deg2<<1) + deg5-deg4;
                if (thistype > besttype)
                {
                    *ngood_ref = *ngood_mir_ref = 0;
                    return;
                }
	    }
	}
    }

    for (i = 0; i < nv; ++i)
    if (degree[i] == 4)
    {
	e = firstedge[i];
	j = 0;
	if (degree[e->end] == 4) {e1 = e; ++j;} e=e->next;
	if (degree[e->end] == 4) {e1 = e; ++j;} e=e->next;
	if (degree[e->end] == 4) {e1 = e; ++j;} e=e->next;
	if (degree[e->end] == 4) {e1 = e; ++j;}
	if (j != 1) continue;

	e = e1->next->next;
        
	w = e->end;
        if (degree[w] < degend) continue;
	if (e == ref) continue;
	z = e1->invers->next->next->end;
        
	if (degree[z] != 4)
	{
            ew = e->invers;
            ewlast = ew->prev;
            for (ew = ew->next->next; ew != ewlast; ew = ew->next)
                if (ew->end == z) break;
            if (ew != ewlast) continue;
	}

        deg0 = ((long)degree[w] << 21) + ((long)(nv-degree[z]) << 11);
	deg2 = degree[e->next->end];
	deg3 = degree[e->prev->end];
        deg4 = degree[e->invers->prev->prev->end];
        deg5 = degree[e->invers->next->next->end];

	thistype = deg0 + (deg2<<2) + (deg3<<1) + deg4-deg5;
	if (thistype > besttype)
        {
	    *ngood_ref = *ngood_mir_ref = 0;
	    return;
	}
	else if (thistype == besttype)
	    good_or[(*ngood_or)++] = e;

        thistype = deg0 + (deg3<<2) + (deg2<<1) + deg5-deg4;
        if (thistype > besttype)
        {
            *ngood_ref = *ngood_mir_ref = 0;
            return;
        }
        else if (thistype == besttype)
            good_mir[(*ngood_mir)++] = e;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %r8, -0x38(%rsp)
movq %rcx, %r10
movq %rsi, -0x30(%rsp)
movq 0x40(%rsp), %r12
movslq 0x4(%rdi), %rcx
leaq 0xa6af(%rip), %rax      # 0x27bf0
movslq (%rax,%rcx,4), %rcx
movq %rcx, -0x28(%rsp)
shlq $0x15, %rcx
movslq 0x2270bb(%rip), %r11    # 0x244610
movq 0x18(%rdi), %rsi
movq 0x18(%rsi), %r8
movq 0x20(%r8), %r8
movq 0x18(%r8), %r8
movq 0x18(%r8), %r8
movslq 0x4(%r8), %r8
movslq (%rax,%r8,4), %r8
movq %r11, %rbx
subq %r8, %rbx
movq 0x10(%rdi), %r8
movslq 0x4(%rsi), %rsi
movslq (%rax,%rsi,4), %rsi
movslq 0x4(%r8), %r8
movslq (%rax,%r8,4), %r8
shlq $0xb, %rbx
addq %rcx, %rbx
leaq (%rbx,%rsi,4), %rcx
leaq (%rbx,%rsi,2), %rsi
movq 0x20(%rdi), %rbx
leaq (%rcx,%r8,2), %r15
leaq (%rsi,%r8,4), %r14
movq 0x10(%rbx), %rcx
movq 0x10(%rcx), %rcx
movslq 0x4(%rcx), %rcx
movslq (%rax,%rcx,4), %rcx
addq %rcx, %r15
subq %rcx, %r14
movq 0x38(%rsp), %r8
movq 0x18(%rbx), %rcx
movq 0x18(%rcx), %rcx
movslq 0x4(%rcx), %rcx
movslq (%rax,%rcx,4), %rcx
subq %rcx, %r15
addq %rcx, %r14
xorl %ecx, %ecx
cmpq %r14, %r15
jg 0x1d5f2
xorl %esi, %esi
movq -0x38(%rsp), %rcx
movq %rdi, (%rcx)
movl $0x1, %ecx
cmpq %r14, %r15
jne 0x1d602
movq -0x30(%rsp), %rsi
movq %rdi, (%rsi)
movl $0x1, %esi
movq %r15, %r14
movl %esi, (%r10)
movl %esi, (%rdx)
movl %ecx, (%r8)
movl %ecx, (%r9)
testq %r12, %r12
movq %r10, -0x20(%rsp)
movq %r9, -0x10(%rsp)
movq %rdx, -0x8(%rsp)
je 0x1d730
movslq 0x4(%r12), %rsi
movq 0x18(%r12), %rcx
movq 0x18(%rcx), %r15
movslq (%rax,%rsi,4), %rbp
cmpl -0x28(%rsp), %ebp
jl 0x1d730
movslq (%r12), %rsi
cmpl $0x4, (%rax,%rsi,4)
jne 0x1d730
movslq 0x4(%rcx), %rcx
movslq (%rax,%rcx,4), %r13
cmpq $0x4, %r13
je 0x1d730
movq 0x10(%r12), %rcx
movslq 0x4(%rcx), %rcx
movslq (%rax,%rcx,4), %rdx
cmpq $0x4, %rdx
je 0x1d730
cmpq %rdi, %r12
je 0x1d730
movslq 0x4(%r15), %rcx
cmpl $0x4, (%rax,%rcx,4)
jne 0x1d730
movq 0x20(%r15), %rcx
movq 0x18(%rcx), %rcx
movq 0x18(%rcx), %rcx
movslq 0x4(%rcx), %r8
movl (%rax,%r8,4), %esi
movq 0x20(%r12), %rcx
movq 0x10(%rcx), %r10
movq 0x18(%rcx), %rcx
cmpl $0x4, %esi
jne 0x1d8f1
shlq $0x15, %rbp
movl %r11d, %r8d
subl %esi, %r8d
movslq %r8d, %rsi
shlq $0xb, %rsi
addq %rbp, %rsi
movq 0x10(%r10), %r8
movslq 0x4(%r8), %r8
movslq (%rax,%r8,4), %r8
movq 0x18(%rcx), %rcx
movslq 0x4(%rcx), %rcx
movslq (%rax,%rcx,4), %rcx
leaq (,%r13,4), %r9
leaq (%r9,%rdx,2), %r9
addq %rsi, %r9
addq %r8, %r9
subq %rcx, %r9
cmpq %r14, %r9
jg 0x1d71b
addq %r13, %r13
leaq (,%rdx,4), %r9
addq %r13, %r9
addq %rsi, %r9
subq %r8, %r9
addq %rcx, %r9
cmpq %r14, %r9
jle 0x1d730
xorl %eax, %eax
movq 0x38(%rsp), %rcx
movl %eax, (%rcx)
movq -0x20(%rsp), %rcx
movl %eax, (%rcx)
jmp 0x1d8e6
testl %r11d, %r11d
jle 0x1d8e6
xorl %r12d, %r12d
leaq 0xa2ad(%rip), %r13      # 0x279f0
movq %rdi, -0x18(%rsp)
cmpl $0x4, (%rax,%r12,4)
jne 0x1d8da
movq (%r13,%r12,8), %rcx
movslq 0x4(%rcx), %rsi
xorl %r8d, %r8d
cmpl $0x4, (%rax,%rsi,4)
sete %r8b
cmoveq %rcx, %r15
movq 0x18(%rcx), %rcx
movslq 0x4(%rcx), %rsi
leal 0x1(%r8), %r9d
cmpl $0x4, (%rax,%rsi,4)
cmovnel %r8d, %r9d
cmoveq %rcx, %r15
movq 0x18(%rcx), %rcx
movslq 0x4(%rcx), %rsi
xorl %r8d, %r8d
cmpl $0x4, (%rax,%rsi,4)
cmoveq %rcx, %r15
sete %r8b
addl %r9d, %r8d
movq 0x18(%rcx), %rcx
movslq 0x4(%rcx), %rsi
xorl %r9d, %r9d
cmpl $0x4, (%rax,%rsi,4)
sete %r9b
cmoveq %rcx, %r15
addl %r8d, %r9d
cmpl $0x1, %r9d
jne 0x1d8da
movq 0x18(%r15), %rcx
movq 0x18(%rcx), %rbp
cmpq %rdi, %rbp
je 0x1d8da
movslq 0x4(%rbp), %rcx
movl (%rax,%rcx,4), %r10d
cmpl -0x28(%rsp), %r10d
jl 0x1d8da
movq 0x20(%r15), %rcx
movq 0x18(%rcx), %rcx
movq 0x18(%rcx), %rcx
movslq 0x4(%rcx), %r8
movl (%rax,%r8,4), %esi
movq 0x20(%rbp), %r9
movq 0x10(%r9), %rcx
movq 0x18(%r9), %r9
cmpl $0x4, %esi
jne 0x1d8c4
movslq %r10d, %r8
shlq $0x15, %r8
movl %r11d, %r10d
subl %esi, %r10d
movslq %r10d, %r10
shlq $0xb, %r10
addq %r8, %r10
movq 0x10(%rbp), %rsi
movq 0x18(%rbp), %r8
movslq 0x4(%r8), %r8
movslq (%rax,%r8,4), %r8
movslq 0x4(%rsi), %rsi
movslq (%rax,%rsi,4), %rsi
movq 0x10(%rcx), %rcx
movslq 0x4(%rcx), %rcx
movslq (%rax,%rcx,4), %rcx
movq 0x18(%r9), %r9
movslq 0x4(%r9), %r9
movslq (%rax,%r9,4), %rbx
leaq (%r10,%r8,4), %r9
leaq (%r9,%rsi,2), %r9
addq %rcx, %r9
subq %rbx, %r9
cmpq %r14, %r9
jg 0x1d71b
jne 0x1d893
movq %r13, %rdi
movq -0x8(%rsp), %r13
movslq (%r13), %r9
leal 0x1(%r9), %edx
movl %edx, (%r13)
movq %rdi, %r13
movq -0x18(%rsp), %rdi
movq -0x30(%rsp), %rdx
movq %rbp, (%rdx,%r9,8)
leaq (%r10,%r8,2), %rdx
leaq (%rdx,%rsi,4), %rdx
subq %rcx, %rdx
addq %rbx, %rdx
cmpq %r14, %rdx
jg 0x1d71b
jne 0x1d8da
movq -0x10(%rsp), %rsi
movslq (%rsi), %rcx
leal 0x1(%rcx), %edx
movl %edx, (%rsi)
movq -0x38(%rsp), %rdx
movq %rbp, (%rdx,%rcx,8)
jmp 0x1d8da
movq %r9, %rbx
movq 0x18(%rbx), %rbx
cmpq %rcx, %rbx
je 0x1d80e
cmpl %r8d, 0x4(%rbx)
jne 0x1d8c7
incq %r12
cmpq %r11, %r12
jne 0x1d748
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, %rbx
movq 0x18(%rbx), %rbx
cmpq %r10, %rbx
je 0x1d6b9
cmpl %r8d, 0x4(%rbx)
jne 0x1d8f4
jmp 0x1d730