// File: /workspace/github_c_makefile_star2_O1/mishun[P]plantri/plantri.c
// Function: canon_edge_oriented
static int 
canon_edge_oriented(EDGE *edgelist_or[], int num_edges_or, int can_edges_or,
		    EDGE *edgelist_inv[], int num_edges_inv, int can_edges_inv,
		    int lcolour[], EDGE *can_numberings[][MAXE], 
		    int *nbtot, int *nbop)

/* 
   IT IS ASSUMED that the values of the colour function are positive
   and at most INT_MAX-MAXN.

   This routine checks all num_edges_or elements of edgelist_or just for one 
   orientation and all num_edges_inv elements of the list edgelist_inv just
   for the other. It returns 1 if and only if one of the first can_edges_or
   elements of the first list or first can_edges_inv elements of the second 
   give an optimal numbering among all the possibilities provided by the
   lists.

   Edges given are not in minimal form -- but it is guaranteed that all
   colours of the startpoints are the same and all colours of the endpoints
   are the same.

   In case of only the identity automorphism, the entries of can_numberings[][]
   are undefined.

   Otherwise in can_numberings[][] the canonical numberings are stored as
   sequences of oriented edges.  For every 0 <= i,j < *nbtot
   and every 0 <= k < ne the edges can_numberings[i][k] and
   can_numberings[j][k] can be mapped onto each other by an automorphism.
   The first *nbop numberings are orientation
   preserving while the rest are orientation reversing.

   In case of an orientation preserving numbering the edges are listed in 
   ->next direction, otherwise in ->prev direction.

   Works OK if at least one vertex has valence >= 3. Otherwise some numberings 
   are computed twice, since changing the orientation (the cyclic order around 
   each vertex) doesn't change anything */
{
    int i, test;
    int representation[MAXE];
    EDGE *numblist[MAXE], *numblist_mirror[MAXE]; /* lists of edges where 
                            starting gives a canonical representation */
    int numbs = 1, numbs_mirror = 0;
    int colour[MAXN];

    for (i=0; i<nv; i++) colour[i]=lcolour[i]+MAXN;
			     /* to distinguish colours from vertices */

/* First we have to determine the smallest representation possible with
   edgelist_or */

    if (can_edges_or > 0)
      { testcanon_first_init(edgelist_or[0], representation, colour);
	numblist[0] = edgelist_or[0];
	for (i=1; i<can_edges_or; i++)
	  { test = testcanon_init(edgelist_or[i], representation, colour);
	    if (test == 1) { numblist[numbs] = edgelist_or[i]; numbs++; }
	    else if (test == 2) 
	      { numbs = 1; numblist[0] = edgelist_or[i]; }
	  }
	i=0; /* the next for-loop can start at the beginning */
      }
    else
      { numbs=0; numbs_mirror=1;
        testcanon_first_init_mirror(edgelist_inv[0], representation, colour);
        numblist_mirror[0] = edgelist_inv[0];
	i=1; /* the next for-loop must start at position 1 */
      }

    for (   ; i<can_edges_inv; i++)
      { test = testcanon_mirror_init(edgelist_inv[i], representation, colour);
        if (test == 1)
          { numblist_mirror[numbs_mirror] = edgelist_inv[i]; numbs_mirror++; }
	else if (test == 2) 
	  { numbs = 0; numbs_mirror=1; numblist_mirror[0] = edgelist_inv[i]; }
      }


    /* now we know the best we can get for a "canonical edge".
       Next we will check all the others. We can return 0 at once if we find a 
       better one */

    for (i=can_edges_or ; i < num_edges_or; i++)
      { test = testcanon(edgelist_or[i], representation, colour);
        if (test == 1) { numblist[numbs] = edgelist_or[i]; numbs++; }
        else if (test == 2) return 0;
      }
    for (i=can_edges_inv ; i < num_edges_inv; i++)
      { test = testcanon_mirror(edgelist_inv[i], representation, colour);
        if (test == 1) 
          { numblist_mirror[numbs_mirror] = edgelist_inv[i]; numbs_mirror++; }
        else if (test == 2) return 0;
      }

    *nbop = numbs;
    *nbtot = numbs+numbs_mirror;

    if (*nbtot > 1)
      {
        for (i = 0; i < numbs; i++) 
            construct_numb(numblist[i], can_numberings[i]); 
        for (i = 0; i < numbs_mirror; i++, numbs++) 
            construct_numb_mirror(numblist_mirror[i],can_numberings[numbs]);
      }

    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1e48, %rsp           # imm = 0x1E48
movl %r9d, %ebp
movq %r8, 0x18(%rsp)
movq %rcx, 0x8(%rsp)
movl %edx, %r14d
movq %rsi, 0x20(%rsp)
movq %rdi, (%rsp)
movslq 0x237f8b(%rip), %rbx    # 0x244610
testq %rbx, %rbx
jle 0xc6a6
movq 0x1e80(%rsp), %rax
xorl %ecx, %ecx
movl (%rax,%rcx,4), %edx
addl $0x40, %edx
movl %edx, 0x30(%rsp,%rcx,4)
incq %rcx
cmpq %rcx, %rbx
jne 0xc694
testl %r14d, %r14d
movl %ebp, 0x14(%rsp)
movl %r14d, 0x2c(%rsp)
jle 0xc766
movq (%rsp), %rbx
movq (%rbx), %rdi
leaq 0x130(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0xbae0
movq (%rbx), %rax
movq %rax, 0x12a0(%rsp)
xorl %ebx, %ebx
movl $0x1, %r13d
cmpl $0x1, %r14d
je 0xc892
movl %r14d, %r14d
movl $0x1, %r13d
movl $0x1, %r15d
leaq 0x130(%rsp), %r12
leaq 0x30(%rsp), %rbp
movq (%rsp), %rax
movq (%rax,%r15,8), %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0xbd6a
cmpl $0x2, %eax
je 0xc73f
cmpl $0x1, %eax
jne 0xc755
movq (%rsp), %rax
movq (%rax,%r15,8), %rax
movslq %r13d, %r13
movq %rax, 0x12a0(%rsp,%r13,8)
incl %r13d
jmp 0xc755
movq (%rsp), %rax
movq (%rax,%r15,8), %rax
movq %rax, 0x12a0(%rsp)
movl $0x1, %r13d
incq %r15
cmpq %r15, %r14
jne 0xc70a
movl 0x14(%rsp), %ebp
jmp 0xc892
movq 0x8(%rsp), %rax
movq (%rax), %r12
testl %ebx, %ebx
jle 0xc789
leaq (,%rbx,4), %rdx
leaq 0x700(%rsp), %rdi
xorl %esi, %esi
callq 0x1030
movslq (%r12), %rcx
movl $0x1, 0x700(%rsp,%rcx,4)
movslq 0x4(%r12), %rax
movl $0x1, %edx
movl $0x1, %esi
cmpl %eax, %ecx
je 0xc7c8
movl $0x2, 0x700(%rsp,%rax,4)
movq 0x20(%r12), %rax
movq %rax, 0x12a8(%rsp)
movl $0x2, %esi
leaq 0x130(%rsp), %rax
cmpl %ebx, %esi
jge 0xc83c
movl $0x1, %edx
movq %r12, %rcx
movq 0x10(%rcx), %rdi
cmpq %rcx, %rdi
je 0xc821
movslq 0x4(%rdi), %r9
movl 0x700(%rsp,%r9,4), %r8d
testl %r8d, %r8d
jne 0xc814
movq 0x20(%rdi), %r8
movslq %esi, %rsi
movq %r8, 0x12a0(%rsp,%rsi,8)
incl %esi
movl %esi, 0x700(%rsp,%r9,4)
movl 0x30(%rsp,%r9,4), %r8d
movl %r8d, (%rax)
addq $0x4, %rax
movq 0x10(%rdi), %rdi
jmp 0xc7e0
movl $0x0, (%rax)
addq $0x4, %rax
movq 0x12a0(%rsp,%rdx,8), %rcx
incq %rdx
cmpl %ebx, %esi
jl 0xc7dc
jmp 0xc83f
movq %r12, %rcx
cmpl %ebx, %edx
jg 0xc882
movl %edx, %edx
movq 0x10(%rcx), %rsi
cmpq %rcx, %rsi
je 0xc865
movslq 0x4(%rsi), %rdi
movl 0x700(%rsp,%rdi,4), %edi
movl %edi, (%rax)
addq $0x4, %rax
movq 0x10(%rsi), %rsi
jmp 0xc849
movl $0x0, (%rax)
addq $0x4, %rax
movq 0x12a0(%rsp,%rdx,8), %rcx
leaq 0x1(%rdx), %rsi
cmpl %edx, %ebx
movq %rsi, %rdx
jg 0xc845
movq %r12, 0x700(%rsp)
movl $0x1, %ebx
xorl %r13d, %r13d
cmpl %ebp, %ebx
jge 0xc900
movl %ebx, %r15d
movl %ebp, %r14d
leaq 0x130(%rsp), %rbp
leaq 0x30(%rsp), %r12
movq 0x8(%rsp), %rax
movq (%rax,%r15,8), %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0xbbf5
cmpl $0x2, %eax
je 0xc8df
cmpl $0x1, %eax
jne 0xc8f8
movq 0x8(%rsp), %rax
movq (%rax,%r15,8), %rax
movslq %ebx, %rbx
movq %rax, 0x700(%rsp,%rbx,8)
incl %ebx
jmp 0xc8f8
movq 0x8(%rsp), %rax
movq (%rax,%r15,8), %rax
movq %rax, 0x700(%rsp)
movl $0x1, %ebx
xorl %r13d, %r13d
incq %r15
cmpq %r15, %r14
jne 0xc8a9
movq 0x20(%rsp), %rax
movl 0x2c(%rsp), %ecx
subl %ecx, %eax
movq %rax, 0x20(%rsp)
jle 0xc963
movslq %ecx, %rax
movq (%rsp), %rcx
leaq (%rcx,%rax,8), %r14
xorl %r12d, %r12d
leaq 0x30(%rsp), %r15
movq (%r14,%r12,8), %rbp
movq %rbp, %rdi
leaq 0x130(%rsp), %rsi
movq %r15, %rdx
callq 0xbedf
cmpl $0x1, %eax
je 0xc94b
cmpl $0x2, %eax
jne 0xc959
jmp 0xca59
movslq %r13d, %r13
movq %rbp, 0x12a0(%rsp,%r13,8)
incl %r13d
incq %r12
cmpl %r12d, 0x20(%rsp)
jne 0xc925
movq 0x18(%rsp), %rax
movl 0x14(%rsp), %ecx
subl %ecx, %eax
movq %rax, 0x18(%rsp)
jle 0xc9c7
movslq %ecx, %rax
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %rbp
xorl %r14d, %r14d
leaq 0x30(%rsp), %r15
movq (%rbp,%r14,8), %r12
movq %r12, %rdi
leaq 0x130(%rsp), %rsi
movq %r15, %rdx
callq 0xc009
cmpl $0x1, %eax
je 0xc9b0
cmpl $0x2, %eax
jne 0xc9bd
jmp 0xca59
movslq %ebx, %rbx
movq %r12, 0x700(%rsp,%rbx,8)
incl %ebx
incq %r14
cmpl %r14d, 0x18(%rsp)
jne 0xc989
movq 0x1e90(%rsp), %rax
movq 0x1e88(%rsp), %rcx
movl %r13d, (%rax)
leal (%rbx,%r13), %edx
movl %edx, (%rcx)
movl $0x1, %eax
cmpl $0x2, %edx
jl 0xca5b
leaq 0x1b2ff(%rip), %r14     # 0x27cf0
testl %r13d, %r13d
jle 0xca1d
movl %r13d, %r12d
xorl %ebp, %ebp
movq %r14, %r15
movq 0x12a0(%rsp,%rbp,8), %rdi
movq %r15, %rsi
callq 0xc133
incq %rbp
addq $0xba0, %r15            # imm = 0xBA0
cmpq %rbp, %r12
jne 0xc9fe
testl %ebx, %ebx
jle 0xca52
movslq %r13d, %rax
movl %ebx, %ebx
imulq $0xba0, %rax, %rax      # imm = 0xBA0
addq %rax, %r14
xorl %r15d, %r15d
movq 0x700(%rsp,%r15,8), %rdi
movq %r14, %rsi
callq 0xc25c
incq %r15
addq $0xba0, %r14            # imm = 0xBA0
cmpq %r15, %rbx
jne 0xca33
movl $0x1, %eax
jmp 0xca5b
xorl %eax, %eax
addq $0x1e48, %rsp           # imm = 0x1E48
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq