// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/external/expat-2.0.1/lib/xmltok.c
// Function: initScan
static int
initScan(const ENCODING * const *encodingTable,
         const INIT_ENCODING *enc,
         int state,
         const char *ptr,
         const char *end,
         const char **nextTokPtr)
{
  const ENCODING **encPtr;

  if (ptr == end)
    return XML_TOK_NONE;
  encPtr = enc->encPtr;
  if (ptr + 1 == end) {
    /* only a single byte available for auto-detection */
#ifndef XML_DTD /* FIXME */
    /* a well-formed document entity must have more than one byte */
    if (state != XML_CONTENT_STATE)
      return XML_TOK_PARTIAL;
#endif
    /* so we're parsing an external text entity... */
    /* if UTF-16 was externally specified, then we need at least 2 bytes */
    switch (INIT_ENC_INDEX(enc)) {
    case UTF_16_ENC:
    case UTF_16LE_ENC:
    case UTF_16BE_ENC:
      return XML_TOK_PARTIAL;
    }
    switch ((unsigned char)*ptr) {
    case 0xFE:
    case 0xFF:
    case 0xEF: /* possibly first byte of UTF-8 BOM */
      if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC
          && state == XML_CONTENT_STATE)
        break;
      /* fall through */
    case 0x00:
    case 0x3C:
      return XML_TOK_PARTIAL;
    }
  }
  else {
    switch (((unsigned char)ptr[0] << 8) | (unsigned char)ptr[1]) {
    case 0xFEFF:
      if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC
          && state == XML_CONTENT_STATE)
        break;
      *nextTokPtr = ptr + 2;
      *encPtr = encodingTable[UTF_16BE_ENC];
      return XML_TOK_BOM;
    /* 00 3C is handled in the default case */
    case 0x3C00:
      if ((INIT_ENC_INDEX(enc) == UTF_16BE_ENC
           || INIT_ENC_INDEX(enc) == UTF_16_ENC)
          && state == XML_CONTENT_STATE)
        break;
      *encPtr = encodingTable[UTF_16LE_ENC];
      return XmlTok(*encPtr, state, ptr, end, nextTokPtr);
    case 0xFFFE:
      if (INIT_ENC_INDEX(enc) == ISO_8859_1_ENC
          && state == XML_CONTENT_STATE)
        break;
      *nextTokPtr = ptr + 2;
      *encPtr = encodingTable[UTF_16LE_ENC];
      return XML_TOK_BOM;
    case 0xEFBB:
      /* Maybe a UTF-8 BOM (EF BB BF) */
      /* If there's an explicitly specified (external) encoding
         of ISO-8859-1 or some flavour of UTF-16
         and this is an external text entity,
         don't look for the BOM,
         because it might be a legal data.
      */
      if (state == XML_CONTENT_STATE) {
        int e = INIT_ENC_INDEX(enc);
        if (e == ISO_8859_1_ENC || e == UTF_16BE_ENC
            || e == UTF_16LE_ENC || e == UTF_16_ENC)
          break;
      }
      if (ptr + 2 == end)
        return XML_TOK_PARTIAL;
      if ((unsigned char)ptr[2] == 0xBF) {
        *nextTokPtr = ptr + 3;
        *encPtr = encodingTable[UTF_8_ENC];
        return XML_TOK_BOM;
      }
      break;
    default:
      if (ptr[0] == '\0') {
        /* 0 isn't a legal data character. Furthermore a document
           entity can only start with ASCII characters.  So the only
           way this can fail to be big-endian UTF-16 if it it's an
           external parsed general entity that's labelled as
           UTF-16LE.
        */
        if (state == XML_CONTENT_STATE && INIT_ENC_INDEX(enc) == UTF_16LE_ENC)
          break;
        *encPtr = encodingTable[UTF_16BE_ENC];
        return XmlTok(*encPtr, state, ptr, end, nextTokPtr);
      }
      else if (ptr[1] == '\0') {
        /* We could recover here in the case:
            - parsing an external entity
            - second byte is 0
            - no externally specified encoding
            - no encoding declaration
           by assuming UTF-16LE.  But we don't, because this would mean when
           presented just with a single byte, we couldn't reliably determine
           whether we needed further bytes.
        */
        if (state == XML_CONTENT_STATE)
          break;
        *encPtr = encodingTable[UTF_16LE_ENC];
        return XmlTok(*encPtr, state, ptr, end, nextTokPtr);
      }
      break;
    }
  }
  *encPtr = encodingTable[INIT_ENC_INDEX(enc)];
  return XmlTok(*encPtr, state, ptr, end, nextTokPtr);
}

// Assembly:
pushq %rbp
pushq %rbx
cmpq %rcx, %rdx
je 0x266dc4
movq 0x88(%rdi), %r9
leaq 0x1(%rdx), %rax
cmpq %rcx, %rax
je 0x266dce
movzbl (%rdx), %r10d
movl %r10d, %r11d
shll $0x8, %r11d
movzbl 0x1(%rdx), %eax
orl %eax, %r11d
movzwl %r11w, %r11d
cmpl $0xfefe, %r11d          # imm = 0xFEFE
jg 0x266e21
cmpl $0x3c00, %r11d          # imm = 0x3C00
je 0x266e8d
cmpl $0xefbb, %r11d          # imm = 0xEFBB
jne 0x266e55
cmpl $0x1, %esi
jne 0x266d9b
movzbl 0x85(%rdi), %eax
cmpl $0x5, %eax
ja 0x266d9b
movl $0x39, %r10d
btl %eax, %r10d
jb 0x266f12
leaq 0x2(%rdx), %rax
cmpq %rcx, %rax
je 0x266f3b
cmpb $-0x41, (%rax)
jne 0x266f12
addq $0x3, %rdx
movq %rdx, (%r8)
leaq 0x25a219(%rip), %rax    # 0x4c0fd8
jmp 0x266eba
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
jmp 0x266ec2
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x1, %esi
jne 0x266ec2
movb 0x85(%rdi), %r10b
leal -0x3(%r10), %r11d
cmpb $0x3, %r11b
jb 0x266ec2
movzbl (%rdx), %r11d
leal -0xef(%r11), %ebx
cmpl $0x10, %ebx
ja 0x266f07
movl $0x18001, %ebp          # imm = 0x18001
btl %ebx, %ebp
jae 0x266f07
testb %r10b, %r10b
jne 0x266ec2
jmp 0x266f12
cmpl $0xfffe, %r11d          # imm = 0xFFFE
je 0x266e9e
cmpl $0xfeff, %r11d          # imm = 0xFEFF
jne 0x266e55
cmpl $0x1, %esi
jne 0x266e45
cmpb $0x0, 0x85(%rdi)
je 0x266f12
addq $0x2, %rdx
movq %rdx, (%r8)
leaq 0x25a355(%rip), %rax    # 0x4c11a8
jmp 0x266eba
testb %r10b, %r10b
je 0x266edf
testb %al, %al
setne %al
cmpl $0x1, %esi
sete %r10b
orb %al, %r10b
jne 0x266f12
leaq 0x25a4fe(%rip), %rdi    # 0x4c1378
movq %rdi, (%r9)
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %rcx
popq %rbx
popq %rbp
jmp 0x25fd23
movb 0x85(%rdi), %al
cmpb $0x4, %al
jne 0x266ec5
cmpl $0x1, %esi
jne 0x266ed6
jmp 0x266f12
cmpl $0x1, %esi
jne 0x266eac
cmpb $0x0, 0x85(%rdi)
je 0x266f12
addq $0x2, %rdx
movq %rdx, (%r8)
leaq 0x25a4be(%rip), %rax    # 0x4c1378
movq %rax, (%r9)
movl $0xe, %eax
popq %rbx
popq %rbp
retq
cmpb $0x3, %al
sete %al
cmpl $0x1, %esi
sete %r10b
testb %al, %r10b
jne 0x266f12
leaq 0x25a49b(%rip), %rdi    # 0x4c1378
jmp 0x266ef4
cmpl $0x1, %esi
jne 0x266eed
cmpb $0x5, 0x85(%rdi)
je 0x266f12
leaq 0x25a2b4(%rip), %rdi    # 0x4c11a8
movq %rdi, (%r9)
movl %esi, %eax
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %rcx
popq %rbx
popq %rbp
jmpq *(%rdi,%rax,8)
testl %r11d, %r11d
je 0x266ec2
cmpl $0x3c, %r11d
je 0x266ec2
movsbq 0x85(%rdi), %rax
leaq 0x25a07f(%rip), %rdi    # 0x4c0fa0
movq (%rdi,%rax,8), %rdi
movq %rdi, (%r9)
movl %esi, %eax
movq (%rdi,%rax,8), %rax
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %rcx
popq %rbx
popq %rbp
jmpq *%rax
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x266ec2