// File: /workspace/github_c_makefile_star2_O3/mishun[P]plantri/plantri.c
// Function: write_code_as_sparse6
static void
write_code_as_sparse6(FILE *f, unsigned char code[])
 
/* Write a graph represented in planar_code to a file in sparse6 format.
   The imbedding is lost but the vertex numbering is the same.  This
   does not use any global variables and works to 255 vertices. */

{
    register unsigned char *pin,*pout;
    unsigned char s6[20+2*MAXE+2*MAXF];
    int n,nb,i,j,lastj,x,k,r,rr,topbit;
    int loopcount;

    pin = code;
    n = *pin++;
    pout = s6;
    *pout++ = ':';

    if (n <= 62)
        *pout++ = 63 + n;
    else
    {
        *pout++ = 63 + 63;
        *pout++ = 63 + 0;
        *pout++ = 63 + (n >> 6);
        *pout++ = 63 + (n & 0x3F);
    }

    for (i = n-1, nb = 0; i != 0 ; i >>= 1, ++nb) {}
    topbit = 1 << (nb-1);
    k = 6;
    x = 0;

    lastj = 0;
    for (j = 0; j < n; ++j)
    {
	loopcount = 0;   /* The input code shows loops once from each end,
                            but we want each loop just once in sparse6. */
        while ((i = *pin++) != 0)
        {
	    --i;
            if (i < j || (i == j && ((++loopcount)&1)))
            {
                if (j == lastj)
                {
                    x <<= 1;
                    if (--k == 0)
                    {
                        *pout++ = 63 + x;
                        k = 6;
                        x = 0;
                    }
                }
                else
                {
                    x = (x << 1) | 1;
                    if (--k == 0)
                    {
                        *pout++ = 63 + x;
                        k = 6;
                        x = 0;
                    }
                    if (j > lastj+1)
                    {
                        for (r = 0, rr = j; r < nb; ++r, rr <<= 1)
                        {
                            if (rr & topbit) x = (x << 1) | 1;
                            else             x <<= 1;
                            if (--k == 0)
                            {
                                *pout++ = 63 + x;
                                k = 6;
                                x = 0;
                            }
                        }
                        x <<= 1;
                        if (--k == 0)
                        {
                            *pout++ = 63 + x;
                            k = 6;
                            x = 0;
                        }
                    }
                    lastj = j;
                }
                for (r = 0, rr = i; r < nb; ++r, rr <<= 1)
                {
                    if (rr & topbit) x = (x << 1) | 1;
                    else             x <<= 1;
                    if (--k == 0)
                    {
                        *pout++ = 63 + x;
                        k = 6;
                        x = 0;
                    }
                }
            }
        }
    }

    if (k != 6) *pout++ = 63 + ((x << k) | ((1 << k) - 1));

    *pout++ = '\n';
    k = pout - s6;

    if (fwrite(s6,sizeof(unsigned char),(size_t)k,f) != k)
    {
        fprintf(stderr,">E %s: fwrite() failed\n",cmdname);
        perror(">E ");
        exit(1);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3f8, %rsp            # imm = 0x3F8
movq %rdi, %rax
movzbl (%rsi), %edi
movb $0x3a, (%rsp)
cmpl $0x3e, %edi
ja 0xb86e
leal 0x3f(%rdi), %ecx
leaq 0x2(%rsp), %rdx
jmp 0xb88f
leaq 0x5(%rsp), %rdx
movb $0x3f, -0x3(%rdx)
movl %edi, %ecx
shrb $0x6, %cl
addb $0x3f, %cl
movb %cl, -0x2(%rdx)
movl %edi, %ecx
andb $0x3f, %cl
addb $0x3f, %cl
movb %cl, -0x1(%rdx)
movb $0x7e, %cl
movb %cl, 0x1(%rsp)
movl %edi, %ecx
xorl %r8d, %r8d
decl %ecx
je 0xb8ad
movl %ecx, %r9d
sarl %r9d
incl %r8d
cmpl $0x1, %ecx
movl %r9d, %ecx
ja 0xb89f
testl %edi, %edi
je 0xb9f8
incq %rsi
leal -0x1(%r8), %r9d
xorl %r10d, %r10d
movl $0x6, %ecx
xorl %r15d, %r15d
xorl %r11d, %r11d
movb (%rsi), %bpl
incq %rsi
testb %bpl, %bpl
je 0xb9ce
leal -0x1(%r11), %ebx
xorl %r12d, %r12d
movzbl %bpl, %r13d
leal -0x1(%r13), %r14d
cmpl %r13d, %r11d
jae 0xb906
cmpl %r11d, %r14d
jne 0xb9bf
leal 0x1(%r12), %ebp
testb $0x1, %r12b
je 0xb909
jmp 0xb9bc
movl %r12d, %ebp
addl %r10d, %r10d
cmpl %r15d, %r11d
je 0xb96e
decl %ecx
je 0xb91b
orl $0x1, %r10d
jmp 0xb92d
addb $0x40, %r10b
movb %r10b, (%rdx)
incq %rdx
movl $0x6, %ecx
xorl %r10d, %r10d
cmpl %ebx, %r15d
jge 0xb984
testl %r8d, %r8d
je 0xb96b
movl %r8d, %r15d
movl %r11d, %r12d
xorl %r13d, %r13d
btl %r9d, %r12d
setb %r13b
leal (%r13,%r10,2), %r10d
decl %ecx
jne 0xb963
addb $0x3f, %r10b
movb %r10b, (%rdx)
incq %rdx
movl $0x6, %ecx
xorl %r10d, %r10d
addl %r12d, %r12d
decl %r15d
jne 0xb93d
addl %r10d, %r10d
decl %ecx
jne 0xb984
addb $0x3f, %r10b
movb %r10b, (%rdx)
incq %rdx
movl $0x6, %ecx
xorl %r10d, %r10d
testl %r8d, %r8d
je 0xb9b9
movl %r8d, %r15d
xorl %r12d, %r12d
btl %r9d, %r14d
setb %r12b
leal (%r12,%r10,2), %r10d
decl %ecx
jne 0xb9b1
addb $0x3f, %r10b
movb %r10b, (%rdx)
incq %rdx
movl $0x6, %ecx
xorl %r10d, %r10d
addl %r14d, %r14d
decl %r15d
jne 0xb98c
movl %r11d, %r15d
movl %ebp, %r12d
movb (%rsi), %bpl
incq %rsi
testb %bpl, %bpl
jne 0xb8e0
incl %r11d
cmpl %edi, %r11d
jne 0xb8ca
cmpl $0x6, %ecx
je 0xb9f8
shll %cl, %r10d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
shll %cl, %esi
notl %esi
orl %r10d, %esi
addb $0x3f, %sil
movb %sil, (%rdx)
incq %rdx
movb $0xa, (%rdx)
movq %rsp, %rdi
subl %edi, %edx
incl %edx
movslq %edx, %rbx
movl $0x1, %esi
movq %rbx, %rdx
movq %rax, %rcx
callq 0x10e0
cmpq %rbx, %rax
jne 0xba2c
addq $0x3f8, %rsp            # imm = 0x3F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2782