// File: /workspace/github_c_makefile_star2_O1/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 0xb7ba
leal 0x3f(%rdi), %ecx
leaq 0x2(%rsp), %rdx
movb %cl, -0x1(%rdx)
jmp 0xb7db
leaq 0x5(%rsp), %rdx
movw $0x3f7e, -0x4(%rdx)     # imm = 0x3F7E
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)
xorl %r8d, %r8d
movl %edi, %ecx
movl $0x0, %r9d
decl %ecx
je 0xb7fe
xorl %r9d, %r9d
movl %ecx, %r10d
sarl %r10d
incl %r9d
cmpl $0x1, %ecx
movl %r10d, %ecx
ja 0xb7f0
testl %edi, %edi
je 0xb930
incq %rsi
leal -0x1(%r9), %r10d
xorl %r8d, %r8d
movl $0x6, %ecx
xorl %ebp, %ebp
xorl %r11d, %r11d
movb (%rsi), %r14b
incq %rsi
testb %r14b, %r14b
je 0xb922
leal -0x1(%r11), %ebx
xorl %r12d, %r12d
movzbl %r14b, %r14d
leal -0x1(%r14), %r15d
cmpl %r14d, %r11d
jae 0xb856
cmpl %r11d, %r15d
jne 0xb913
leal 0x1(%r12), %r14d
testb $0x1, %r12b
je 0xb859
jmp 0xb910
movl %r12d, %r14d
addl %r8d, %r8d
cmpl %ebp, %r11d
je 0xb8bf
decl %ecx
je 0xb86b
orl $0x1, %r8d
jmp 0xb87d
addb $0x40, %r8b
movb %r8b, (%rdx)
incq %rdx
movl $0x6, %ecx
xorl %r8d, %r8d
cmpl %ebx, %ebp
jge 0xb8d7
testl %r9d, %r9d
je 0xb8b9
movl %r9d, %ebp
movl %r11d, %r12d
xorl %r13d, %r13d
btl %r10d, %r12d
setb %r13b
leal (%r13,%r8,2), %r8d
decl %ecx
jne 0xb8b2
addb $0x3f, %r8b
movb %r8b, (%rdx)
incq %rdx
movl $0x6, %ecx
xorl %r8d, %r8d
addl %r12d, %r12d
decl %ebp
jne 0xb88c
addl %r8d, %r8d
movl %r11d, %ebp
decl %ecx
jne 0xb8da
addb $0x3f, %r8b
movb %r8b, (%rdx)
incq %rdx
movl $0x6, %ecx
xorl %r8d, %r8d
jmp 0xb8da
movl %r11d, %ebp
testl %r9d, %r9d
je 0xb910
movl %r9d, %r12d
xorl %r13d, %r13d
btl %r10d, %r15d
setb %r13b
leal (%r13,%r8,2), %r8d
decl %ecx
jne 0xb908
addb $0x3f, %r8b
movb %r8b, (%rdx)
incq %rdx
movl $0x6, %ecx
xorl %r8d, %r8d
addl %r15d, %r15d
decl %r12d
jne 0xb8e2
movl %r14d, %r12d
movb (%rsi), %r14b
incq %rsi
testb %r14b, %r14b
jne 0xb830
incl %r11d
cmpl %edi, %r11d
jne 0xb81a
jmp 0xb935
movl $0x6, %ecx
cmpl $0x6, %ecx
je 0xb953
shll %cl, %r8d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
shll %cl, %esi
notl %esi
orl %r8d, %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 0x10f0
cmpq %rbx, %rax
jne 0xb987
addq $0x3f8, %rsp            # imm = 0x3F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x27fe