// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/external/expat-2.0.1/lib/xmltok.c
// Function: utf8_toUtf16
static void PTRCALL
utf8_toUtf16(const ENCODING *enc,
             const char **fromP, const char *fromLim,
             unsigned short **toP, const unsigned short *toLim)
{
  unsigned short *to = *toP;
  const char *from = *fromP;
  while (from != fromLim && to != toLim) {
    switch (((struct normal_encoding *)enc)->type[(unsigned char)*from]) {
    case BT_LEAD2:
      *to++ = (unsigned short)(((from[0] & 0x1f) << 6) | (from[1] & 0x3f));
      from += 2;
      break;
    case BT_LEAD3:
      *to++ = (unsigned short)(((from[0] & 0xf) << 12)
                               | ((from[1] & 0x3f) << 6) | (from[2] & 0x3f));
      from += 3;
      break;
    case BT_LEAD4:
      {
        unsigned long n;
        if (to + 1 == toLim)
          goto after;
        n = ((from[0] & 0x7) << 18) | ((from[1] & 0x3f) << 12)
            | ((from[2] & 0x3f) << 6) | (from[3] & 0x3f);
        n -= 0x10000;
        to[0] = (unsigned short)((n >> 10) | 0xD800);
        to[1] = (unsigned short)((n & 0x3FF) | 0xDC00);
        to += 2;
        from += 4;
      }
      break;
    default:
      *to++ = *from++;
      break;
    }
  }
after:
  *fromP = from;
  *toP = to;
}

// Assembly:
movq %rdi, -0x8(%rsp)
movq %rsi, -0x10(%rsp)
movq %rdx, -0x18(%rsp)
movq %rcx, -0x20(%rsp)
movq %r8, -0x28(%rsp)
movq -0x20(%rsp), %rax
movq (%rax), %rax
movq %rax, -0x30(%rsp)
movq -0x10(%rsp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rsp)
movq -0x38(%rsp), %rcx
xorl %eax, %eax
cmpq -0x18(%rsp), %rcx
movb %al, -0x41(%rsp)
je 0x38ace6
movq -0x30(%rsp), %rax
cmpq -0x28(%rsp), %rax
setne %al
movb %al, -0x41(%rsp)
movb -0x41(%rsp), %al
testb $0x1, %al
jne 0x38acf3
jmp 0x38aebc
movq -0x8(%rsp), %rax
movq -0x38(%rsp), %rcx
movzbl (%rcx), %ecx
movzbl 0x88(%rax,%rcx), %eax
movl %eax, -0x48(%rsp)
subl $0x5, %eax
je 0x38ad30
jmp 0x38ad13
movl -0x48(%rsp), %eax
subl $0x6, %eax
je 0x38ad76
jmp 0x38ad1e
movl -0x48(%rsp), %eax
subl $0x7, %eax
je 0x38adcd
jmp 0x38ae8c
movq -0x38(%rsp), %rax
movsbl (%rax), %eax
andl $0x1f, %eax
shll $0x6, %eax
movq -0x38(%rsp), %rcx
movsbl 0x1(%rcx), %ecx
andl $0x3f, %ecx
orl %ecx, %eax
movw %ax, %cx
movq -0x30(%rsp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x30(%rsp)
movw %cx, (%rax)
movq -0x38(%rsp), %rax
addq $0x2, %rax
movq %rax, -0x38(%rsp)
jmp 0x38aeb7
movq -0x38(%rsp), %rax
movsbl (%rax), %eax
andl $0xf, %eax
shll $0xc, %eax
movq -0x38(%rsp), %rcx
movsbl 0x1(%rcx), %ecx
andl $0x3f, %ecx
shll $0x6, %ecx
orl %ecx, %eax
movq -0x38(%rsp), %rcx
movsbl 0x2(%rcx), %ecx
andl $0x3f, %ecx
orl %ecx, %eax
movw %ax, %cx
movq -0x30(%rsp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x30(%rsp)
movw %cx, (%rax)
movq -0x38(%rsp), %rax
addq $0x3, %rax
movq %rax, -0x38(%rsp)
jmp 0x38aeb7
movq -0x30(%rsp), %rax
addq $0x2, %rax
cmpq -0x28(%rsp), %rax
jne 0x38ade2
jmp 0x38aebe
movq -0x38(%rsp), %rax
movsbl (%rax), %eax
andl $0x7, %eax
shll $0x12, %eax
movq -0x38(%rsp), %rcx
movsbl 0x1(%rcx), %ecx
andl $0x3f, %ecx
shll $0xc, %ecx
orl %ecx, %eax
movq -0x38(%rsp), %rcx
movsbl 0x2(%rcx), %ecx
andl $0x3f, %ecx
shll $0x6, %ecx
orl %ecx, %eax
movq -0x38(%rsp), %rcx
movsbl 0x3(%rcx), %ecx
andl $0x3f, %ecx
orl %ecx, %eax
cltq
movq %rax, -0x40(%rsp)
movq -0x40(%rsp), %rax
subq $0x10000, %rax          # imm = 0x10000
movq %rax, -0x40(%rsp)
movq -0x40(%rsp), %rax
shrq $0xa, %rax
orq $0xd800, %rax           # imm = 0xD800
movw %ax, %cx
movq -0x30(%rsp), %rax
movw %cx, (%rax)
movq -0x40(%rsp), %rax
andq $0x3ff, %rax            # imm = 0x3FF
orq $0xdc00, %rax           # imm = 0xDC00
movw %ax, %cx
movq -0x30(%rsp), %rax
movw %cx, 0x2(%rax)
movq -0x30(%rsp), %rax
addq $0x4, %rax
movq %rax, -0x30(%rsp)
movq -0x38(%rsp), %rax
addq $0x4, %rax
movq %rax, -0x38(%rsp)
jmp 0x38aeb7
movq -0x38(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x38(%rsp)
movsbl (%rax), %eax
movw %ax, %cx
movq -0x30(%rsp), %rax
movq %rax, %rdx
addq $0x2, %rdx
movq %rdx, -0x30(%rsp)
movw %cx, (%rax)
jmp 0x38acc3
jmp 0x38aebe
movq -0x38(%rsp), %rcx
movq -0x10(%rsp), %rax
movq %rcx, (%rax)
movq -0x30(%rsp), %rcx
movq -0x20(%rsp), %rax
movq %rcx, (%rax)
retq
nopl (%rax)