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

/* The Q-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 Q-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->next.
   *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).
*/
{
    int i,j,w,z1,z2;
    long thistype,besttype;
    EDGE *e,*e1,*ew,*ewlast;

    besttype = ((long)degree[ref->end]<<10)
               + degree[ref->next->end] + degree[ref->prev->end];
    good_or[0] = ref;
    *ngood_or = *ngood_ref = 1;

    e = ref->next;
    thistype = ((long)degree[e->end]<<10)
               + degree[e->next->end] + degree[e->prev->end];
    if (thistype >= besttype)
    {
        good_mir[0] = e;
	*ngood_mir = *ngood_mir_ref = 1;
    }
    else
	*ngood_mir = *ngood_mir_ref = 0;

    if (thistype > besttype)
    {
	*ngood_or = *ngood_ref = 0;
	besttype = thistype;
    }
 
    for (i = 0; i < nv; ++i)
    if (degree[i] == 4)
    {
        e = firstedge[i];
        e1 = e->next->next;
        for (j = 0; j < 4; ++j, e=e->next, e1=e1->next)
        {
            if (degree[e->prev->end] < 6 || degree[e1->end] < 6) continue;
            if (e == ref) continue;
            w = e1->invers->prev->prev->end;

	    z1 = e->end;
	    z2 = e->next->end;
            ew = ewlast = firstedge[w];
            do
            {
                if (ew->end == z1 || ew->end == z2) break;
                ew = ew->next;
            } while (ew != ewlast);
            if (ew->end == z1 || ew->end == z2) continue;

            thistype = ((long)degree[z1]<<10)
				+ degree[z2] + degree[e->prev->end];
            if (thistype > besttype)
            {
                *ngood_ref = *ngood_mir_ref = 0;
                return;
            }
	    else if (thistype == besttype)
                good_or[(*ngood_or)++] = e;

	    thistype = ((long)degree[z2]<<10) + degree[z1] + degree[e1->end];
            if (thistype > besttype)
            {   
                *ngood_ref = *ngood_mir_ref = 0;
                return;
            }
            else if (thistype == besttype)
                good_mir[(*ngood_mir)++] = e->next;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %r9, -0x20(%rsp)
movq %r8, -0x28(%rsp)
movq 0x38(%rsp), %rbx
movslq 0x4(%rdi), %rax
leaq 0xa074(%rip), %r10      # 0x27bf0
movslq (%r10,%rax,4), %rax
shlq $0xa, %rax
movq 0x10(%rdi), %r8
movq 0x18(%rdi), %r9
movslq 0x4(%r9), %r9
movslq (%r10,%r9,4), %r9
addq %rax, %r9
movslq 0x4(%r8), %rax
movslq (%r10,%rax,4), %r11
addq %r9, %r11
movq %rsi, -0x10(%rsp)
movq %rdi, (%rsi)
movl $0x1, %eax
movl %eax, (%rcx)
movl %eax, (%rdx)
movq 0x18(%rdi), %r9
movslq 0x4(%r9), %rax
movslq (%r10,%rax,4), %rax
shlq $0xa, %rax
movq 0x10(%r9), %rsi
movq 0x18(%r9), %r8
movslq 0x4(%r8), %r8
movslq (%r10,%r8,4), %r8
addq %rax, %r8
movslq 0x4(%rsi), %rax
movslq (%r10,%rax,4), %rax
addq %r8, %rax
xorl %esi, %esi
cmpq %r11, %rax
jl 0x1dbf5
movq -0x28(%rsp), %rsi
movq %r9, (%rsi)
movl $0x1, %esi
movl %esi, (%rbx)
movq -0x20(%rsp), %r8
movl %esi, (%r8)
cmpq %r11, %rax
jle 0x1dc0d
xorl %esi, %esi
movl %esi, (%rcx)
movl %esi, (%rdx)
movq %rax, %r11
movq %rcx, -0x18(%rsp)
movslq 0x2269f7(%rip), %rax    # 0x244610
movq %rax, -0x8(%rsp)
testq %rax, %rax
jle 0x1dd59
xorl %r14d, %r14d
leaq 0x9dbf(%rip), %r9       # 0x279f0
cmpl $0x4, (%r10,%r14,4)
jne 0x1dd39
movq (%r9,%r14,8), %r12
movq 0x18(%r12), %r13
xorl %ebp, %ebp
movq 0x18(%r13), %r13
movq 0x10(%r12), %rax
movslq 0x4(%rax), %rax
movslq (%r10,%rax,4), %rbx
cmpq $0x6, %rbx
jge 0x1dc6f
incl %ebp
movq 0x18(%r12), %r12
cmpl $0x4, %ebp
jne 0x1dc47
jmp 0x1dd39
movslq 0x4(%r13), %rax
cmpl $0x6, (%r10,%rax,4)
jl 0x1dc5e
cmpq %rdi, %r12
je 0x1dc5e
movq 0x20(%r13), %rax
movq 0x10(%rax), %rax
movq 0x10(%rax), %rax
movslq 0x4(%rax), %rsi
movslq 0x4(%r12), %rax
movq 0x18(%r12), %rcx
movslq 0x4(%rcx), %rcx
movq (%r9,%rsi,8), %rsi
movq %rsi, %r8
movl 0x4(%r8), %r15d
cmpl %eax, %r15d
je 0x1dcbb
cmpl %ecx, %r15d
je 0x1dcbb
movq 0x18(%r8), %r8
cmpq %rsi, %r8
jne 0x1dca4
movl 0x4(%r8), %esi
cmpl %eax, %esi
je 0x1dc5e
cmpl %ecx, %esi
je 0x1dc5e
movslq (%r10,%rax,4), %rsi
shlq $0xa, %rsi
movslq (%r10,%rcx,4), %r8
addq %rbx, %r8
addq %rsi, %r8
cmpq %r11, %r8
jg 0x1dd49
jne 0x1dcf3
movslq (%rdx), %rsi
leal 0x1(%rsi), %r8d
movl %r8d, (%rdx)
movq -0x10(%rsp), %r8
movq %r12, (%r8,%rsi,8)
movslq (%r10,%rcx,4), %rcx
shlq $0xa, %rcx
movslq (%r10,%rax,4), %rax
addq %rcx, %rax
movslq 0x4(%r13), %rcx
movslq (%r10,%rcx,4), %rcx
addq %rax, %rcx
cmpq %r11, %rcx
jg 0x1dd49
jne 0x1dc5e
movq 0x18(%r12), %rax
movq -0x20(%rsp), %r8
movslq (%r8), %rcx
leal 0x1(%rcx), %esi
movl %esi, (%r8)
movq -0x28(%rsp), %rsi
movq %rax, (%rsi,%rcx,8)
jmp 0x1dc5e
incq %r14
cmpq -0x8(%rsp), %r14
jne 0x1dc31
jmp 0x1dd59
xorl %eax, %eax
movq 0x38(%rsp), %rcx
movl %eax, (%rcx)
movq -0x18(%rsp), %rcx
movl %eax, (%rcx)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq