// File: /workspace/github_c_makefile_star2_O1/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, %rbx
movq %rsi, -0x30(%rsp)
movq 0x40(%rsp), %r12
movslq 0x4(%rdi), %rcx
leaq 0xa82f(%rip), %rax      # 0x27bf0
movslq (%rax,%rcx,4), %rcx
movq %rcx, -0x28(%rsp)
shlq $0x15, %rcx
movslq 0x22723b(%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, %r10
subq %r8, %r10
movq 0x10(%rdi), %r8
movslq 0x4(%rsi), %rsi
movslq (%rax,%rsi,4), %rsi
movslq 0x4(%r8), %r8
movslq (%rax,%r8,4), %r8
shlq $0xb, %r10
addq %rcx, %r10
leaq (%r10,%rsi,4), %rcx
leaq (%r10,%rsi,2), %rsi
movq 0x20(%rdi), %r10
leaq (%rcx,%r8,2), %r15
leaq (%rsi,%r8,4), %r14
movq 0x10(%r10), %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(%r10), %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 0x1d472
xorl %esi, %esi
movq -0x38(%rsp), %rcx
movq %rdi, (%rcx)
movl $0x1, %ecx
cmpq %r14, %r15
jne 0x1d482
movq -0x30(%rsp), %rsi
movq %rdi, (%rsi)
movl $0x1, %esi
movq %r15, %r14
movl %esi, (%rbx)
movl %esi, (%rdx)
movl %ecx, (%r8)
movl %ecx, (%r9)
testq %r12, %r12
movq %rbx, -0x20(%rsp)
movq %r9, -0x10(%rsp)
movq %rdx, -0x8(%rsp)
je 0x1d5d6
movslq 0x4(%r12), %rsi
movq 0x18(%r12), %rcx
movq 0x18(%rcx), %r15
movslq (%rax,%rsi,4), %rbp
cmpl -0x28(%rsp), %ebp
jl 0x1d5d6
movslq (%r12), %rsi
cmpl $0x4, (%rax,%rsi,4)
jne 0x1d5d6
movslq 0x4(%rcx), %rcx
movslq (%rax,%rcx,4), %r13
cmpq $0x4, %r13
je 0x1d5d6
movq 0x10(%r12), %rcx
movslq 0x4(%rcx), %rcx
movslq (%rax,%rcx,4), %rdx
cmpq $0x4, %rdx
je 0x1d5d6
cmpq %rdi, %r12
je 0x1d5d6
movslq 0x4(%r15), %rcx
cmpl $0x4, (%rax,%rcx,4)
jne 0x1d5d6
movq 0x20(%r15), %rcx
movq 0x18(%rcx), %rcx
movq 0x18(%rcx), %rcx
movslq 0x4(%rcx), %rcx
movl (%rax,%rcx,4), %ebx
cmpl $0x4, %ebx
sete %sil
je 0x1d54a
movq 0x20(%r12), %rsi
movq 0x10(%rsi), %r8
movq 0x18(%rsi), %r10
movq 0x18(%r10), %r10
cmpq %r8, %r10
sete %sil
je 0x1d54a
cmpl %ecx, 0x4(%r10)
jne 0x1d537
testb %sil, %sil
je 0x1d5d6
shlq $0x15, %rbp
movl %r11d, %ecx
subl %ebx, %ecx
movslq %ecx, %rcx
shlq $0xb, %rcx
addq %rbp, %rcx
movq 0x20(%r12), %rsi
movq 0x10(%rsi), %r8
movq 0x18(%rsi), %r10
movq 0x10(%r8), %rsi
movslq 0x4(%rsi), %rsi
movslq (%rax,%rsi,4), %rsi
movq 0x18(%r10), %r8
movslq 0x4(%r8), %r8
movslq (%rax,%r8,4), %r8
leaq (,%r13,4), %r10
leaq (%r10,%rdx,2), %r10
addq %rcx, %r10
addq %rsi, %r10
subq %r8, %r10
cmpq %r14, %r10
jg 0x1d5c1
addq %r13, %r13
leaq (,%rdx,4), %r10
addq %r13, %r10
addq %rcx, %r10
subq %rsi, %r10
addq %r8, %r10
cmpq %r14, %r10
jle 0x1d5d6
xorl %eax, %eax
movq 0x38(%rsp), %rcx
movl %eax, (%rcx)
movq -0x20(%rsp), %rcx
movl %eax, (%rcx)
jmp 0x1d793
testl %r11d, %r11d
jle 0x1d793
xorl %r12d, %r12d
leaq 0xa407(%rip), %r13      # 0x279f0
movq %rdi, -0x18(%rsp)
cmpl $0x4, (%rax,%r12,4)
jne 0x1d787
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), %r10d
cmpl $0x4, (%rax,%rsi,4)
cmovnel %r8d, %r10d
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 %r10d, %r8d
movq 0x18(%rcx), %rcx
movslq 0x4(%rcx), %rsi
xorl %r10d, %r10d
cmpl $0x4, (%rax,%rsi,4)
sete %r10b
cmoveq %rcx, %r15
addl %r8d, %r10d
cmpl $0x1, %r10d
jne 0x1d787
movq 0x18(%r15), %rcx
movq 0x18(%rcx), %rbp
cmpq %rdi, %rbp
je 0x1d787
movslq 0x4(%rbp), %rcx
movl (%rax,%rcx,4), %ecx
cmpl -0x28(%rsp), %ecx
jl 0x1d787
movq 0x20(%r15), %rsi
movq 0x18(%rsi), %rsi
movq 0x18(%rsi), %rsi
movslq 0x4(%rsi), %rsi
movl (%rax,%rsi,4), %r8d
cmpl $0x4, %r8d
jne 0x1d769
movslq %ecx, %rcx
shlq $0x15, %rcx
movl %r11d, %esi
subl %r8d, %esi
movslq %esi, %rbx
shlq $0xb, %rbx
addq %rcx, %rbx
movq 0x10(%rbp), %rcx
movq 0x18(%rbp), %rsi
movslq 0x4(%rsi), %rsi
movslq (%rax,%rsi,4), %r10
movslq 0x4(%rcx), %rcx
movslq (%rax,%rcx,4), %rcx
movq 0x20(%rbp), %rsi
movq 0x10(%rsi), %r8
movq 0x18(%rsi), %rsi
movq 0x10(%r8), %r8
movslq 0x4(%r8), %r8
movslq (%rax,%r8,4), %r8
movq 0x18(%rsi), %rsi
movslq 0x4(%rsi), %rsi
movslq (%rax,%rsi,4), %rsi
leaq (%rbx,%r10,4), %r9
leaq (%r9,%rcx,2), %r9
addq %r8, %r9
subq %rsi, %r9
cmpq %r14, %r9
jg 0x1d5c1
jne 0x1d738
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 (%rbx,%r10,2), %rdx
leaq (%rdx,%rcx,4), %rcx
subq %r8, %rcx
addq %rsi, %rcx
cmpq %r14, %rcx
jg 0x1d5c1
jne 0x1d787
movq -0x10(%rsp), %rsi
movslq (%rsi), %rcx
leal 0x1(%rcx), %edx
movl %edx, (%rsi)
movq -0x38(%rsp), %rdx
movq %rbp, (%rdx,%rcx,8)
jmp 0x1d787
movq 0x20(%rbp), %rbx
movq 0x10(%rbx), %r10
movq 0x18(%rbx), %rbx
movq 0x18(%rbx), %rbx
cmpq %r10, %rbx
je 0x1d6a7
cmpl %esi, 0x4(%rbx)
jne 0x1d775
incq %r12
cmpq %r11, %r12
jne 0x1d5ee
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq