// File: /workspace/github_c_makefile_star2_O1/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 $0x78, %rsp
movq %r9, 0x58(%rsp)
movq %r8, 0x28(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdx, 0x50(%rsp)
movq %rsi, 0x20(%rsp)
movq 0x10(%rdi), %rcx
movq 0x18(%rdi), %rdx
movq 0x18(%rdx), %rax
movslq 0x4(%rdi), %rsi
leaq 0xe47d(%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
xorl %edx, %edx
movl %edx, (%rsp)
movl %edx, 0x4(%rsp)
cmpl %ebp, %ebx
jl 0x197ba
movq %rcx, %rsi
shlq $0xa, %rsi
addq %r10, %rsi
movq %r10, %rdx
shlq $0xa, %rdx
addq %rcx, %rdx
cmpq %rdx, %rsi
movq %rdx, %r9
cmovgq %rsi, %r9
movq %r9, %r11
movl %ebx, 0x10(%rsp)
movl %ebp, 0x14(%rsp)
cmpl %ebp, %ebx
jg 0x197ef
movq %r10, %r8
shlq $0xa, %r8
addq %rcx, %r8
shlq $0xa, %rcx
addq %r10, %rcx
cmpq %rcx, %r8
movq %rcx, %r11
cmovgq %r8, %r11
movq %r11, %r12
movl %ebp, 0x10(%rsp)
movl %ebx, 0x14(%rsp)
cmpq %r12, %r9
cmovgq %r9, %r12
cmpl %ebp, %ebx
cmovneq %r11, %r12
jl 0x19827
cmpq %r12, %rsi
jne 0x19813
movl $0x1, 0x4(%rsp)
movq 0x20(%rsp), %rsi
movq %rdi, (%rsi)
cmpq %r12, %rdx
jne 0x19827
movl $0x1, (%rsp)
movq 0x28(%rsp), %rdx
movq %rdi, (%rdx)
cmpl %ebp, %ebx
jg 0x1985d
cmpq %r12, %r8
jne 0x19845
movslq 0x4(%rsp), %rdx
leal 0x1(%rdx), %esi
movl %esi, 0x4(%rsp)
movq 0x20(%rsp), %rsi
movq %rax, (%rsi,%rdx,8)
cmpq %r12, %rcx
jne 0x1985d
movslq (%rsp), %rcx
leal 0x1(%rcx), %edx
movl %edx, (%rsp)
movq 0x28(%rsp), %rdx
movq %rax, (%rdx,%rcx,8)
movl 0x4(%rsp), %ecx
movq 0x18(%rsp), %rdx
movl %ecx, (%rdx)
movl (%rsp), %ecx
movq 0xb0(%rsp), %rdx
movl %ecx, (%rdx)
movl 0xc819(%rip), %ecx      # 0x26094
leal 0x2(%rcx), %edx
movl %edx, 0xc810(%rip)      # 0x26094
cmpl $0x752f, %ecx           # imm = 0x752F
jl 0x198b6
movl $0x2, 0xc7fe(%rip)      # 0x26094
movl $0x30, %ecx
leaq 0x22ad7e(%rip), %rdx    # 0x244620
movl $0x0, (%rcx,%rdx)
addq $0x40, %rcx
cmpq $0x46630, %rcx          # imm = 0x46630
jne 0x198a2
movl 0xc7d8(%rip), %edx      # 0x26094
movq 0x20(%rdi), %rcx
movl %edx, 0x30(%rcx)
movq 0x20(%rax), %rax
movl %edx, 0x44(%rsp)
movl %edx, 0x30(%rax)
movslq 0x22ad3b(%rip), %rcx    # 0x244610
movl 0x4(%rsp), %eax
movl %eax, 0x8(%rsp)
movl (%rsp), %eax
movl %eax, 0xc(%rsp)
movq %rcx, 0x68(%rsp)
testq %rcx, %rcx
jle 0x19ae6
movl %ebx, 0x40(%rsp)
movl %ebp, 0x3c(%rsp)
xorl %ebp, %ebp
movq %r12, 0x60(%rsp)
movl 0x10(%rsp), %eax
cmpl %eax, (%r15,%rbp,4)
jle 0x19943
leaq 0xe0de(%rip), %rax      # 0x279f0
movq (%rax,%rbp,8), %rbx
movq %rbx, %r14
movslq 0x4(%r14), %rax
cmpl $0x4, (%r15,%rax,4)
jne 0x19935
movq 0x20(%r14), %rdi
callq 0x1a4f0
testl %eax, %eax
jne 0x19b46
movq 0x18(%r14), %r14
cmpq %rbx, %r14
jne 0x19919
jmp 0x19ad8
jne 0x19ad8
leaq 0xe0a0(%rip), %rax      # 0x279f0
movq (%rax,%rbp,8), %rsi
movq %rsi, %r13
movq %rsi, 0x30(%rsp)
movslq 0x4(%r13), %rax
cmpl $0x4, (%r15,%rax,4)
jne 0x19971
movl 0x44(%rsp), %eax
cmpl %eax, 0x30(%r13)
jne 0x1997f
movq 0x18(%r13), %r13
cmpq %rsi, %r13
jne 0x1995c
jmp 0x19ad8
movq %rbp, %r14
movq 0x20(%r13), %rbx
movq 0x18(%rbx), %rax
movq %rax, 0x70(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x48(%rsp)
movslq 0x4(%rax), %rbp
movq %r15, %r12
movl (%r15,%rbp,4), %r15d
cmpl 0x14(%rsp), %r15d
jle 0x199bf
movq %rbx, %rdi
callq 0x1a4f0
movq 0x30(%rsp), %rsi
testl %eax, %eax
jne 0x19b46
movl 0x14(%rsp), %edx
cmpl %edx, 0x10(%rsp)
setg %al
cmpq %rbp, %r14
movq %r14, %rbp
setl %cl
cmpl %edx, %r15d
jne 0x19ac6
orb %cl, %al
movq %r12, %r15
je 0x19971
movq %rbx, %rdi
callq 0x1a4f0
testl %eax, %eax
movq 0x60(%rsp), %r12
je 0x19ace
movq 0x10(%rbx), %rax
movslq 0x4(%rax), %rax
movslq (%r15,%rax,4), %rdx
movq 0x70(%rsp), %rax
movslq 0x4(%rax), %rax
movslq (%r15,%rax,4), %rcx
movq %rdx, %rax
shlq $0xa, %rax
addq %rcx, %rax
cmpq %r12, %rax
jg 0x19b46
shlq $0xa, %rcx
addq %rdx, %rcx
cmpq %r12, %rcx
jg 0x19b46
cmpq %r12, %rax
jne 0x19a4f
movl 0x8(%rsp), %esi
movslq %esi, %rdx
incl %esi
movl %esi, 0x8(%rsp)
movq 0x20(%rsp), %rsi
movq %rbx, (%rsi,%rdx,8)
cmpq %r12, %rcx
jne 0x19a6a
movl 0xc(%rsp), %esi
movslq %esi, %rdx
incl %esi
movl %esi, 0xc(%rsp)
movq 0x28(%rsp), %rsi
movq %rbx, (%rsi,%rdx,8)
movq 0x30(%rsp), %rsi
movl 0x3c(%rsp), %edx
cmpl %edx, 0x40(%rsp)
jne 0x19971
cmpq %r12, %rcx
jne 0x19a9d
movl 0x8(%rsp), %edx
movslq %edx, %rcx
incl %edx
movl %edx, 0x8(%rsp)
movq 0x20(%rsp), %rdx
movq 0x48(%rsp), %rdi
movq %rdi, (%rdx,%rcx,8)
cmpq %r12, %rax
jne 0x19971
movl 0xc(%rsp), %ecx
movslq %ecx, %rax
incl %ecx
movl %ecx, 0xc(%rsp)
movq 0x28(%rsp), %rcx
movq 0x48(%rsp), %rdx
movq %rdx, (%rcx,%rax,8)
jmp 0x19971
movq %r12, %r15
jmp 0x19971
movq 0x30(%rsp), %rsi
jmp 0x19971
incq %rbp
cmpq 0x68(%rsp), %rbp
jne 0x19901
movl 0x8(%rsp), %ecx
movl %ecx, 0x4(%rsp)
movl 0xc(%rsp), %eax
movl %eax, (%rsp)
movq 0x18(%rsp), %rax
cmpl (%rax), %ecx
jg 0x19b0d
movl (%rsp), %eax
movq 0xb0(%rsp), %rcx
cmpl (%rcx), %eax
jle 0x19b31
leaq 0x4(%rsp), %rsi
movq %rsp, %r8
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rdx
movq 0x28(%rsp), %rcx
movq 0xb0(%rsp), %r9
callq 0xe385
movl 0x4(%rsp), %eax
movq 0x50(%rsp), %rcx
movl %eax, (%rcx)
movl (%rsp), %eax
movq 0x58(%rsp), %rcx
jmp 0x19b66
movl 0x8(%rsp), %eax
movl %eax, 0x4(%rsp)
movl 0xc(%rsp), %eax
movl %eax, (%rsp)
xorl %eax, %eax
movq 0xb0(%rsp), %rcx
movl %eax, (%rcx)
movq 0x18(%rsp), %rcx
movl %eax, (%rcx)
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq