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

/* The four-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 four-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 four-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-2.  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).
   Four-reductions have a priority: (maxdeg, mindeg) where those are
   the two degrees on the subdivided diagonal.  Bigger = better.
*/
{
    EDGE *e,*er;
    long deg1,deg2,deg3,deg4;
#define FOURTYPE(d3,d4) (((d3)<<10)+(d4))
    long besttype,etype1,etype2,ertype1,ertype2,etype,ertype;
    int bestdeg,nextdeg,nor,nmir,i,w;
    EDGE *ei,*eilast;

    e = ref;
    er = ref->next->next;
    deg1 = degree[e->end];
    deg2 = degree[er->end];
    deg3 = degree[e->prev->end];
    deg4 = degree[e->next->end];

    nor = nmir = 0;

    if (deg1 >= deg2)
    {
        bestdeg = deg1; nextdeg = deg2;
        etype1 = FOURTYPE(deg3,deg4);
        etype2 = FOURTYPE(deg4,deg3);
        besttype = etype = etype1 > etype2 ? etype1 : etype2;
    }

    if (deg1 <= deg2)
    {
        bestdeg = deg2; nextdeg = deg1;
        ertype1 = FOURTYPE(deg4,deg3);
        ertype2 = FOURTYPE(deg3,deg4);
	besttype = ertype = ertype1 > ertype2 ? ertype1 : ertype2;
    }

    if (deg1 == deg2) besttype = etype > ertype ? etype : ertype;

    if (deg1 >= deg2)
    {
	if (etype1 == besttype) good_or[nor++] = e;
	if (etype2 == besttype) good_mir[nmir++] = e;
    }
    if (deg1 <= deg2)
    {
        if (ertype1 == besttype) good_or[nor++] = er;
        if (ertype2 == besttype) good_mir[nmir++] = er;
    }

    *ngood_ref = nor;
    *ngood_mir_ref = nmir;

    RESETMARKS;
    MARKLO(e->invers);
    MARKLO(er->invers);

    for (i = 0; i < nv; ++i)
    if (degree[i] > bestdeg)
    {
	ei = eilast = firstedge[i];
	do
	{
	    if (degree[ei->end] == 4 && is_min4_four(ei->invers))
	    {
		*ngood_ref = *ngood_mir_ref = 0;
		return;
	    }
	    ei = ei->next;
	} while (ei != eilast);
    }
    else if (degree[i] == bestdeg)
    {
        ei = eilast = firstedge[i];
        do
        {
            if (degree[ei->end] == 4 && !ISMARKEDLO(ei))
	    {
		e = ei->invers;
	  	er = e->next->next;
		w = er->end;
		deg2 = degree[w];
		if (deg2 > nextdeg && is_min4_four(e))
		{
                    *ngood_ref = *ngood_mir_ref = 0;
                    return;
                }
		else if (deg2 == nextdeg && (bestdeg > nextdeg || i < w)
					 && is_min4_four(e))
		{
		    deg3 = degree[e->prev->end];
		    deg4 = degree[e->next->end];
                    etype1 = FOURTYPE(deg3,deg4);
                    etype2 = FOURTYPE(deg4,deg3);

                    if (etype1 > besttype || etype2 > besttype)
                    {
                        *ngood_ref = *ngood_mir_ref = 0;
                        return;
                    }
                    if (etype1 == besttype) good_or[nor++] = e;
                    if (etype2 == besttype) good_mir[nmir++] = e;

		    if (nextdeg == bestdeg)
		    {
                	ertype1 = FOURTYPE(deg4,deg3);
                	ertype2 = FOURTYPE(deg3,deg4);

                	if (ertype1 > besttype || ertype2 > besttype)
                	{
                    	    *ngood_ref = *ngood_mir_ref = 0;
                    	    return;
                	}

                	if (ertype1 == besttype) good_or[nor++] = er;
                	if (ertype2 == besttype) good_mir[nmir++] = er;
		    }
		}
	    }
	    ei = ei->next;
	} while (ei != eilast);
    }

    if (nor > *ngood_ref || nmir > *ngood_mir_ref)
        prune_oriented_lists(good_or,&nor,ngood_ref,
                             good_mir,&nmir,ngood_mir_ref);

    *ngood_or = nor;
    *ngood_mir = nmir;    
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %r9, 0x68(%rsp)
movq %r8, 0x38(%rsp)
movq %rcx, 0x28(%rsp)
movq %rdx, 0x60(%rsp)
movq %rsi, 0x30(%rsp)
movq 0x10(%rdi), %rcx
movq 0x18(%rdi), %rdx
movq 0x18(%rdx), %rax
movslq 0x4(%rdi), %rsi
leaq 0xe3c4(%rip), %r15      # 0x27bf0
movl (%r15,%rsi,4), %ebx
movslq 0x4(%rax), %rsi
movl (%r15,%rsi,4), %ebp
movslq 0x4(%rcx), %rcx
movslq (%r15,%rcx,4), %rcx
movslq 0x4(%rdx), %rdx
movslq (%r15,%rdx,4), %r10
cmpl %ebp, %ebx
jl 0x1986a
movq %rcx, %r8
shlq $0xa, %r8
addq %r10, %r8
movq %r10, %rdx
shlq $0xa, %rdx
addq %rcx, %rdx
cmpq %rdx, %r8
movq %rdx, %r9
cmovgq %r8, %r9
movq %r9, %r11
movl %ebx, 0x20(%rsp)
movl %ebp, 0x24(%rsp)
cmpl %ebp, %ebx
jg 0x1989f
movq %r10, %rsi
shlq $0xa, %rsi
addq %rcx, %rsi
shlq $0xa, %rcx
addq %r10, %rcx
cmpq %rcx, %rsi
movq %rcx, %r11
cmovgq %rsi, %r11
movq %r11, %r13
movl %ebp, 0x20(%rsp)
movl %ebx, 0x24(%rsp)
cmpq %r13, %r9
cmovgq %r9, %r13
xorl %r12d, %r12d
movl $0x0, %r9d
movq %r9, 0x10(%rsp)
cmpl %ebp, %ebx
cmovneq %r11, %r13
jl 0x198fd
xorl %r12d, %r12d
movl $0x0, %r9d
movq %r9, 0x10(%rsp)
cmpq %r13, %r8
jne 0x198e2
movq 0x30(%rsp), %r8
movq %rdi, (%r8)
movl $0x1, %r8d
movq %r8, 0x10(%rsp)
cmpq %r13, %rdx
jne 0x198fd
movl $0x1, 0x50(%rsp)
movq 0x38(%rsp), %rdx
movq %rdi, (%rdx)
movl $0x1, %r12d
cmpl %ebp, %ebx
jg 0x19937
cmpq %r13, %rsi
jne 0x19923
movq 0x10(%rsp), %rsi
movl %esi, %edx
incl %esi
movl %esi, 0x54(%rsp)
movq 0x30(%rsp), %r8
movq %rax, (%r8,%rdx,8)
movl %esi, %edx
movq %rdx, 0x10(%rsp)
cmpq %r13, %rcx
jne 0x19937
movl %r12d, %ecx
incl %r12d
movq 0x38(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
movq 0x28(%rsp), %rcx
movq 0x10(%rsp), %rdx
movl %edx, (%rcx)
movq 0xc0(%rsp), %rcx
movl %r12d, (%rcx)
movl 0xc738(%rip), %ecx      # 0x2608c
leal 0x2(%rcx), %r8d
movl %r8d, 0xc72d(%rip)      # 0x2608c
cmpl $0x752f, %ecx           # imm = 0x752F
jl 0x19997
movl $0x2, 0xc71b(%rip)      # 0x2608c
movl $0x30, %ecx
leaq 0x22aca3(%rip), %rdx    # 0x244620
movl $0x0, (%rcx,%rdx)
addq $0x40, %rcx
cmpq $0x46630, %rcx          # imm = 0x46630
jne 0x1997d
movl $0x2, %r8d
movq 0x20(%rdi), %rcx
movl %r8d, 0x30(%rcx)
movq 0x20(%rax), %rax
movl %r8d, 0x30(%rax)
movslq 0x22ac62(%rip), %rax    # 0x244610
movq %rax, 0x78(%rsp)
testq %rax, %rax
jle 0x19be7
movl %ebx, 0x4c(%rsp)
movl %ebp, 0x48(%rsp)
xorl %ebp, %ebp
movl %r8d, 0xc(%rsp)
movq %r13, 0x70(%rsp)
movl 0x20(%rsp), %eax
cmpl %eax, (%r15,%rbp,4)
jle 0x19a1c
leaq 0xe00f(%rip), %rax      # 0x279f0
movq (%rax,%rbp,8), %rbx
movq %rbx, %r14
movslq 0x4(%r14), %rax
cmpl $0x4, (%r15,%rax,4)
jne 0x19a04
movq 0x20(%r14), %rdi
callq 0x1a5ce
testl %eax, %eax
jne 0x19c4d
movq 0x18(%r14), %r14
cmpq %rbx, %r14
jne 0x199e8
movq %r12, 0x18(%rsp)
movl 0xc(%rsp), %r8d
jmp 0x19bd4
movq %r12, 0x18(%rsp)
jne 0x19bd4
leaq 0xdfc2(%rip), %rax      # 0x279f0
movq (%rax,%rbp,8), %r9
movq %r9, %r12
movq %r9, 0x40(%rsp)
movslq 0x4(%r12), %rax
cmpl $0x4, (%r15,%rax,4)
jne 0x19b70
cmpl %r8d, 0x30(%r12)
je 0x19b70
movq %rbp, %rbx
movq 0x20(%r12), %r14
movq 0x18(%r14), %rax
movq %rax, 0x80(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x58(%rsp)
movslq 0x4(%rax), %rbp
movq %r15, %r13
movl (%r15,%rbp,4), %r15d
cmpl 0x24(%rsp), %r15d
jle 0x19a94
movq %r14, %rdi
callq 0x1a5ce
testl %eax, %eax
jne 0x19c4d
movl 0x24(%rsp), %edx
cmpl %edx, 0x20(%rsp)
setg %al
cmpq %rbp, %rbx
movq %rbx, %rbp
setl %cl
cmpl %edx, %r15d
jne 0x19b63
orb %cl, %al
movq %r13, %r15
je 0x19b66
movq %r14, %rdi
callq 0x1a5ce
testl %eax, %eax
movq 0x70(%rsp), %r13
je 0x19b66
movq 0x10(%r14), %rax
movslq 0x4(%rax), %rax
movslq (%r15,%rax,4), %rdx
movq 0x80(%rsp), %rax
movslq 0x4(%rax), %rax
movslq (%r15,%rax,4), %rcx
movq %rdx, %rax
shlq $0xa, %rax
addq %rcx, %rax
cmpq %r13, %rax
jg 0x19c4d
shlq $0xa, %rcx
addq %rdx, %rcx
cmpq %r13, %rcx
jg 0x19c4d
cmpq %r13, %rax
jne 0x19b2d
movq 0x10(%rsp), %rsi
movslq %esi, %rdx
incl %esi
movq %rsi, 0x10(%rsp)
movq 0x30(%rsp), %rsi
movq %r14, (%rsi,%rdx,8)
movl 0xc(%rsp), %r8d
movq 0x40(%rsp), %r9
cmpq %r13, %rcx
jne 0x19b80
movq 0x18(%rsp), %rdx
leal 0x1(%rdx), %ecx
movslq %edx, %rdx
movq 0x38(%rsp), %rsi
movq %r14, (%rsi,%rdx,8)
movl 0x48(%rsp), %edx
cmpl %edx, 0x4c(%rsp)
je 0x19b8c
movl %ecx, %eax
movq %rax, 0x18(%rsp)
jmp 0x19b70
movq %r13, %r15
movl 0xc(%rsp), %r8d
movq 0x40(%rsp), %r9
movq 0x18(%r12), %r12
cmpq %r9, %r12
jne 0x19a3a
jmp 0x19bd4
movl 0x48(%rsp), %ecx
cmpl %ecx, 0x4c(%rsp)
je 0x19bb0
jmp 0x19b70
movq 0x10(%rsp), %rsi
movslq %esi, %rdx
incl %esi
movq 0x30(%rsp), %rdi
movq 0x58(%rsp), %r10
movq %r10, (%rdi,%rdx,8)
movq %rcx, 0x18(%rsp)
movl %esi, %ecx
movq %rcx, 0x10(%rsp)
cmpq %r13, %rax
jne 0x19b70
movq 0x18(%rsp), %rcx
movslq %ecx, %rax
incl %ecx
movq %rcx, 0x18(%rsp)
movq 0x38(%rsp), %rcx
movq 0x58(%rsp), %rdx
movq %rdx, (%rcx,%rax,8)
jmp 0x19b70
incq %rbp
cmpq 0x78(%rsp), %rbp
movq 0x18(%rsp), %r12
jne 0x199d0
movq 0x10(%rsp), %rcx
movl %ecx, 0x54(%rsp)
movl %r12d, 0x50(%rsp)
movq 0x28(%rsp), %rax
cmpl (%rax), %ecx
jg 0x19c0b
movq 0xc0(%rsp), %rax
cmpl (%rax), %r12d
jle 0x19c3c
leaq 0x54(%rsp), %rbx
leaq 0x50(%rsp), %r14
movq 0x30(%rsp), %rdi
movq %rbx, %rsi
movq 0x28(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq %r14, %r8
movq 0xc0(%rsp), %r9
callq 0xe49a
movl (%rbx), %ecx
movl (%r14), %r12d
movq 0x60(%rsp), %rax
movl %ecx, (%rax)
movq 0x68(%rsp), %rax
movl %r12d, (%rax)
jmp 0x19c60
xorl %eax, %eax
movq 0xc0(%rsp), %rcx
movl %eax, (%rcx)
movq 0x28(%rsp), %rcx
movl %eax, (%rcx)
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq