// File: /workspace/github_c_makefile_star2_O2/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 $0x408, %rsp            # imm = 0x408
movzbl (%rsi), %ebp
movb $0x3a, 0x10(%rsp)
cmpl $0x3e, %ebp
movq %rdi, 0x8(%rsp)
ja 0xa9bf
leal 0x3f(%rbp), %eax
leaq 0x12(%rsp), %rdx
jmp 0xa9dd
leaq 0x15(%rsp), %rdx
movb $0x3f, -0x3(%rdx)
movl %ebp, %eax
shrb $0x6, %al
addb $0x3f, %al
movb %al, -0x2(%rdx)
movl %ebp, %eax
andb $0x3f, %al
addb $0x3f, %al
movb %al, -0x1(%rdx)
movb $0x7e, %al
incq %rsi
movb %al, 0x11(%rsp)
leal -0x1(%rbp), %eax
xorl %r8d, %r8d
testl %eax, %eax
je 0xa9f5
sarl %eax
incl %r8d
jmp 0xa9ea
leal -0x1(%r8), %r9d
pushq $0x6
popq %r10
xorl %r11d, %r11d
xorl %r12d, %r12d
xorl %ebx, %ebx
movl %r10d, %ecx
cmpl %ebp, %r11d
je 0xaaf7
leal -0x1(%r11), %edi
xorl %r14d, %r14d
movq %rsi, %r13
movl %r14d, %eax
movq %r13, %rsi
movzbl (%r13), %r14d
testl %r14d, %r14d
je 0xaaec
leal -0x1(%r14), %r15d
cmpl %r14d, %r11d
jae 0xaa4e
leaq 0x1(%rsi), %r13
cmpl %r11d, %r15d
jne 0xaa1e
leal 0x1(%rax), %r14d
testb $0x1, %al
movl %r14d, %eax
jne 0xaa1e
jmp 0xaa51
movl %eax, %r14d
addl %ebx, %ebx
cmpl %r12d, %r11d
jne 0xaa6b
decl %ecx
jne 0xaab6
addb $0x3f, %bl
movb %bl, (%rdx)
incq %rdx
xorl %ebx, %ebx
movl %r10d, %ecx
jmp 0xaab6
decl %ecx
je 0xaa74
orl $0x1, %ebx
jmp 0xaa81
addb $0x40, %bl
movb %bl, (%rdx)
incq %rdx
xorl %ebx, %ebx
movl %r10d, %ecx
cmpl %edi, %r12d
jge 0xaab6
movl %r8d, %r12d
movl %r11d, %r13d
addl %ebx, %ebx
subl $0x1, %r12d
jb 0xaa58
xorl %eax, %eax
btl %r9d, %r13d
setb %al
orl %ebx, %eax
decl %ecx
jne 0xaaaf
addb $0x3f, %al
movb %al, (%rdx)
incq %rdx
xorl %eax, %eax
movl %r10d, %ecx
addl %r13d, %r13d
movl %eax, %ebx
jmp 0xaa8c
incq %rsi
movl %r8d, %r12d
subl $0x1, %r12d
jb 0xaae4
xorl %eax, %eax
btl %r9d, %r15d
setb %al
leal (%rax,%rbx,2), %ebx
decl %ecx
jne 0xaadf
addb $0x3f, %bl
movb %bl, (%rdx)
incq %rdx
xorl %ebx, %ebx
movl %r10d, %ecx
addl %r15d, %r15d
jmp 0xaabc
movl %r11d, %r12d
jmp 0xaa18
incl %r11d
incq %rsi
jmp 0xaa08
cmpl $0x6, %ecx
je 0xab0e
shll %cl, %ebx
pushq $-0x1
popq %rax
shll %cl, %eax
notl %eax
orl %ebx, %eax
addb $0x3f, %al
movb %al, (%rdx)
incq %rdx
movq 0x8(%rsp), %rcx
movb $0xa, (%rdx)
leaq 0x10(%rsp), %rdi
subl %edi, %edx
incl %edx
movslq %edx, %rbx
pushq $0x1
popq %rsi
movq %rbx, %rdx
callq 0x10c0
cmpq %rbx, %rax
jne 0xab44
addq $0x408, %rsp            # imm = 0x408
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x194ad(%rip), %rax     # 0x23ff8
movq (%rax), %rdi
movq 0x1955b(%rip), %rdx     # 0x240b0
leaq 0x13985(%rip), %rsi     # 0x1e4e1
xorl %eax, %eax
callq 0x1050
leaq 0x1390b(%rip), %rdi     # 0x1e475
callq 0x1090
pushq $0x1
popq %rdi
callq 0x10b0