// File: /workspace/github_c_makefile_star2_O2/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 0x20c33c
movq 0x88(%rdi), %r9
leaq 0x1(%rdx), %rax
cmpq %rcx, %rax
je 0x20c346
movzbl (%rdx), %r10d
movl %r10d, %r11d
shll $0x8, %r11d
movzbl 0x1(%rdx), %eax
orl %eax, %r11d
cmpw $0x3c00, %r11w          # imm = 0x3C00
je 0x20c407
movzwl %r11w, %r11d
cmpl $0xefbb, %r11d          # imm = 0xEFBB
je 0x20c395
cmpl $0xfffe, %r11d          # imm = 0xFFFE
je 0x20c3dc
cmpl $0xfeff, %r11d          # imm = 0xFEFF
jne 0x20c418
cmpl $0x1, %esi
jne 0x20c329
cmpb $0x0, 0x85(%rdi)
je 0x20c47d
addq $0x2, %rdx
movq %rdx, (%r8)
leaq 0x228e51(%rip), %rax    # 0x435188
jmp 0x20c3fc
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
jmp 0x20c404
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x1, %esi
jne 0x20c404
movb 0x85(%rdi), %r10b
leal -0x3(%r10), %r11d
cmpb $0x3, %r11b
jb 0x20c404
movzbl (%rdx), %r11d
leal -0xef(%r11), %ebx
cmpl $0x10, %ebx
ja 0x20c462
movl $0x18001, %ebp          # imm = 0x18001
btl %ebx, %ebp
jae 0x20c462
testb %r10b, %r10b
jne 0x20c404
jmp 0x20c47d
cmpl $0x1, %esi
jne 0x20c3b6
movzbl 0x85(%rdi), %eax
cmpl $0x5, %eax
ja 0x20c3b6
movl $0x39, %r10d
btl %eax, %r10d
jb 0x20c47d
leaq 0x2(%rdx), %rax
cmpq %rcx, %rax
je 0x20c4c0
cmpb $-0x41, (%rax)
jne 0x20c47d
addq $0x3, %rdx
movq %rdx, (%r8)
leaq 0x228bde(%rip), %rax    # 0x434fb8
jmp 0x20c3fc
cmpl $0x1, %esi
jne 0x20c3ee
cmpb $0x0, 0x85(%rdi)
je 0x20c47d
addq $0x2, %rdx
movq %rdx, (%r8)
leaq 0x228f5c(%rip), %rax    # 0x435358
movq %rax, (%r9)
movl $0xe, %eax
popq %rbx
popq %rbp
retq
movb 0x85(%rdi), %al
cmpb $0x4, %al
jne 0x20c448
cmpl $0x1, %esi
jne 0x20c459
jmp 0x20c47d
testb %r10b, %r10b
je 0x20c46f
testb %al, %al
setne %al
cmpl $0x1, %esi
sete %r10b
orb %al, %r10b
jne 0x20c47d
leaq 0x228f23(%rip), %rdi    # 0x435358
movq %rdi, (%r9)
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %rcx
popq %rbx
popq %rbp
jmp 0x2066fb
cmpb $0x3, %al
sete %al
cmpl $0x1, %esi
sete %r10b
testb %al, %r10b
jne 0x20c47d
leaq 0x228ef8(%rip), %rdi    # 0x435358
jmp 0x20c4ad
testl %r11d, %r11d
je 0x20c404
cmpl $0x3c, %r11d
je 0x20c404
jmp 0x20c47d
cmpl $0x1, %esi
jne 0x20c4a6
cmpb $0x5, 0x85(%rdi)
jne 0x20c4a6
movsbq 0x85(%rdi), %rax
leaq 0x228af4(%rip), %rdi    # 0x434f80
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
leaq 0x228cdb(%rip), %rdi    # 0x435188
movq %rdi, (%r9)
movl %esi, %eax
movq %rdx, %rsi
movq %rcx, %rdx
movq %r8, %rcx
popq %rbx
popq %rbp
jmpq *(%rdi,%rax,8)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x20c404