// File: /workspace/github_c_makefile_star2_O2/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 %r9, -0x20(%rsp)
movq %r8, -0x30(%rsp)
movq %rdx, -0x18(%rsp)
movq %rsi, -0x28(%rsp)
movq 0x40(%rsp), %r12
movq 0x38(%rsp), %r11
movslq 0x4(%rdi), %rax
leaq 0xa0f4(%rip), %r10      # 0x25be0
movslq (%r10,%rax,4), %r9
movq %r9, %rax
shlq $0x15, %rax
movslq 0x226b02(%rip), %rsi    # 0x242600
movq 0x18(%rdi), %r8
movq 0x18(%r8), %rdx
movq 0x20(%rdx), %rdx
movq 0x18(%rdx), %rdx
movq 0x18(%rdx), %rdx
movslq 0x4(%rdx), %rdx
movslq (%r10,%rdx,4), %rdx
movq %rsi, -0x40(%rsp)
subq %rdx, %rsi
movq 0x10(%rdi), %rdx
movslq 0x4(%r8), %r8
movslq (%r10,%r8,4), %r8
movslq 0x4(%rdx), %rdx
movslq (%r10,%rdx,4), %rdx
shlq $0xb, %rsi
addq %rax, %rsi
leaq (%rsi,%r8,4), %rax
leaq (%rsi,%r8,2), %r8
movq 0x20(%rdi), %rsi
leaq (%rax,%rdx,2), %r14
leaq (%r8,%rdx,4), %rax
movq 0x10(%rsi), %r8
movq 0x18(%rsi), %rdx
movq 0x10(%r8), %rsi
movslq 0x4(%rsi), %rsi
movslq (%r10,%rsi,4), %rsi
movq 0x18(%rdx), %rdx
movslq 0x4(%rdx), %rdx
movslq (%r10,%rdx,4), %rdx
addq %rsi, %r14
subq %rdx, %r14
subq %rsi, %rax
addq %rdx, %rax
xorl %r8d, %r8d
movl $0x1, %edx
cmpq %rax, %r14
jg 0x1bb9c
xorl %esi, %esi
movq -0x30(%rsp), %r8
movq %rdi, (%r8)
movl %edx, %r8d
cmpq %rax, %r14
jne 0x1bbab
movq -0x28(%rsp), %rax
movq %rdi, (%rax)
movl %edx, %esi
movl %r8d, %edx
jmp 0x1bbae
movq %rax, %r14
movl %esi, (%rcx)
movq -0x18(%rsp), %rax
movl %esi, (%rax)
movl %edx, (%r11)
movq -0x20(%rsp), %rax
movl %edx, (%rax)
testq %r12, %r12
movq %r9, -0x48(%rsp)
movq %rcx, -0x10(%rsp)
movq %r14, -0x38(%rsp)
je 0x1bc23
movslq 0x4(%r12), %rcx
movq 0x18(%r12), %rax
movq 0x18(%rax), %r15
movslq (%r10,%rcx,4), %rbp
cmpl %r9d, %ebp
jl 0x1bc1c
movslq (%r12), %rcx
cmpl $0x4, (%r10,%rcx,4)
jne 0x1bc1c
movslq 0x4(%rax), %rax
movslq (%r10,%rax,4), %rax
cmpq $0x4, %rax
je 0x1bc1c
movq 0x10(%r12), %rcx
movslq 0x4(%rcx), %rcx
movslq (%r10,%rcx,4), %r13
cmpq $0x4, %r13
jne 0x1bde0
movq -0x48(%rsp), %r9
jmp 0x1bc23
xorl %r12d, %r12d
movq -0x40(%rsp), %rax
testl %eax, %eax
movl $0x0, %r13d
cmovgl %eax, %r13d
leaq 0x9da2(%rip), %rbp      # 0x259e0
movq %rdi, -0x8(%rsp)
cmpq %r13, %r12
je 0x1be9b
cmpl $0x4, (%r10,%r12,4)
jne 0x1bdd8
movq (%rbp,%r12,8), %rax
movslq 0x4(%rax), %rcx
xorl %edx, %edx
cmpl $0x4, (%r10,%rcx,4)
sete %dl
cmoveq %rax, %r15
movq 0x18(%rax), %rax
movslq 0x4(%rax), %rcx
leal 0x1(%rdx), %esi
cmpl $0x4, (%r10,%rcx,4)
cmovnel %edx, %esi
cmoveq %rax, %r15
movq 0x18(%rax), %rax
movslq 0x4(%rax), %rcx
xorl %edx, %edx
cmpl $0x4, (%r10,%rcx,4)
cmoveq %rax, %r15
sete %dl
addl %esi, %edx
movq 0x18(%rax), %rax
movslq 0x4(%rax), %rcx
xorl %esi, %esi
cmpl $0x4, (%r10,%rcx,4)
sete %sil
cmoveq %rax, %r15
addl %edx, %esi
cmpl $0x1, %esi
jne 0x1bdd8
movq 0x18(%r15), %rax
movq 0x18(%rax), %rax
cmpq %rdi, %rax
je 0x1bdd8
movslq 0x4(%rax), %rcx
movl (%r10,%rcx,4), %ecx
cmpl %r9d, %ecx
jl 0x1bdd8
movq 0x20(%r15), %rdx
movq 0x18(%rdx), %rdx
movq 0x18(%rdx), %rdx
movslq 0x4(%rdx), %r11
movl (%r10,%r11,4), %esi
movq 0x20(%rax), %rdx
movq 0x10(%rdx), %r8
movq 0x18(%rdx), %rdx
cmpl $0x4, %esi
jne 0x1bdc2
movslq %ecx, %r11
shlq $0x15, %r11
movq -0x40(%rsp), %rcx
subl %esi, %ecx
movslq %ecx, %rcx
shlq $0xb, %rcx
addq %r11, %rcx
movq 0x10(%rax), %r11
movq 0x18(%rax), %rsi
movslq 0x4(%rsi), %rsi
movslq (%r10,%rsi,4), %rsi
movslq 0x4(%r11), %r11
movslq (%r10,%r11,4), %r14
movq 0x10(%r8), %r8
movslq 0x4(%r8), %r8
movslq (%r10,%r8,4), %r8
movq 0x18(%rdx), %rdx
movslq 0x4(%rdx), %rdx
movslq (%r10,%rdx,4), %rbx
leaq (%rcx,%rsi,4), %rdx
leaq (%rdx,%r14,2), %rdx
addq %r8, %rdx
subq %rbx, %rdx
cmpq -0x38(%rsp), %rdx
jg 0x1be8b
jne 0x1bd8f
movq -0x18(%rsp), %rdi
movslq (%rdi), %rdx
leal 0x1(%rdx), %r11d
movl %r11d, (%rdi)
movq -0x28(%rsp), %rdi
movq %rax, (%rdi,%rdx,8)
movq -0x8(%rsp), %rdi
movq -0x48(%rsp), %r9
leaq (%rcx,%rsi,2), %rcx
leaq (%rcx,%r14,4), %rcx
subq %r8, %rcx
addq %rbx, %rcx
cmpq -0x38(%rsp), %rcx
jg 0x1be8b
jne 0x1bdd8
movq -0x20(%rsp), %rsi
movslq (%rsi), %rcx
leal 0x1(%rcx), %edx
movl %edx, (%rsi)
movq -0x30(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
jmp 0x1bdd8
movq %rdx, %rbx
movq 0x18(%rbx), %rbx
cmpq %r8, %rbx
je 0x1bd0a
cmpl %r11d, 0x4(%rbx)
jne 0x1bdc5
incq %r12
jmp 0x1bc43
cmpq %rdi, %r12
je 0x1bc1c
movslq 0x4(%r15), %rcx
cmpl $0x4, (%r10,%rcx,4)
jne 0x1bc1c
movq 0x20(%r15), %rcx
movq 0x18(%rcx), %rcx
movq 0x18(%rcx), %rcx
movslq 0x4(%rcx), %rdx
movl (%r10,%rdx,4), %r8d
movq 0x20(%r12), %rcx
movq 0x10(%rcx), %rsi
movq 0x18(%rcx), %rcx
cmpl $0x4, %r8d
jne 0x1bea6
shlq $0x15, %rbp
movq -0x40(%rsp), %rdx
subl %r8d, %edx
movslq %edx, %r8
shlq $0xb, %r8
addq %rbp, %r8
movq 0x10(%rsi), %rdx
movslq 0x4(%rdx), %rdx
movslq (%r10,%rdx,4), %rsi
movq 0x18(%rcx), %rcx
movslq 0x4(%rcx), %rcx
movslq (%r10,%rcx,4), %rcx
leaq (,%rax,4), %rdx
leaq (%rdx,%r13,2), %rdx
addq %r8, %rdx
addq %rsi, %rdx
subq %rcx, %rdx
cmpq %r14, %rdx
movq -0x48(%rsp), %r9
jg 0x1be8b
addq %rax, %rax
leaq (%rax,%r13,4), %rax
addq %r8, %rax
subq %rsi, %rax
addq %rcx, %rax
cmpq -0x38(%rsp), %rax
jle 0x1bc23
movq 0x38(%rsp), %rax
andl $0x0, (%rax)
movq -0x10(%rsp), %rax
andl $0x0, (%rax)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, %rbx
movq 0x18(%rbx), %rbx
cmpq %rsi, %rbx
je 0x1be23
cmpl %edx, 0x4(%rbx)
jne 0x1bea9
jmp 0x1bc1c