// File: /workspace/github_c_makefile_star2_O3/craigbarnes[P]lua-gumbo/lib/tokenizer.c
// Function: gumbo_lex
HOT bool gumbo_lex(GumboParser* parser, GumboToken* output) {
  // Because of the spec requirements that...
  //
  // 1. Tokens be handled immediately by the parser upon emission.
  // 2. Some states (eg. CDATA, or various error conditions) require the
  // emission of multiple tokens in the same states.
  // 3. The tokenizer often has to reconsume the same character in a different
  // state.
  //
  // ...all state must be held in the GumboTokenizer struct instead of in local
  // variables in this function. That allows us to return from this method with
  // a token, and then immediately jump back to the same state with the same
  // input if we need to return a different token. The various emit_* functions
  // are responsible for changing state (eg. flushing the chardata buffer,
  // reading the next input character) to avoid an infinite loop.
  GumboTokenizerState* tokenizer = parser->_tokenizer_state;

  if (tokenizer->_buffered_emit_char != kGumboNoChar) {
    tokenizer->_reconsume_current_input = true;
    emit_char(parser, tokenizer->_buffered_emit_char, output);
    // And now that we've avoided advancing the input, make sure we set
    // _reconsume_current_input back to false to make sure the *next* character
    // isn't consumed twice.
    tokenizer->_reconsume_current_input = false;
    tokenizer->_buffered_emit_char = kGumboNoChar;
    return true;
  }

  if (maybe_emit_from_temporary_buffer(parser, output)) {
    return true;
  }

  while (1) {
    assert(!tokenizer->_temporary_buffer_emit);
    assert(tokenizer->_buffered_emit_char == kGumboNoChar);
    int c = utf8iterator_current(&tokenizer->_input);
    GumboTokenizerEnum state = tokenizer->_state;
    gumbo_debug("Lexing character '%c' (%d) in state %u.\n", c, c, state);
    StateResult result = dispatch_table[state](parser, tokenizer, c, output);
    // We need to clear reconsume_current_input before returning to prevent
    // certain infinite loop states.
    bool should_advance = !tokenizer->_reconsume_current_input;
    tokenizer->_reconsume_current_input = false;

    if (result == RETURN_SUCCESS) {
      return true;
    } else if (result == RETURN_ERROR) {
      return false;
    }

    if (should_advance) {
      utf8iterator_next(&tokenizer->_input);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %r15
movq 0x10(%rdi), %rbx
movl 0x8(%rbx), %ebp
leaq 0x1a731(%rip), %rax     # 0x20940
movl (%rax), %r12d
cmpl %r12d, %ebp
jne 0x62a5
movq %r15, %rdi
movq %r14, %rsi
callq 0xc919
movb $0x1, %cl
testb %al, %al
jne 0x62c0
cmpq $0x0, 0x28(%rbx)
jne 0x6286
leaq 0xe8(%rbx), %r13
leaq 0x4d01b(%rip), %r12     # 0x53260
cmpl %ebp, 0x8(%rbx)
jne 0x62d5
movl (%rbx), %eax
movl 0x100(%rbx), %edx
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rcx
callq *(%r12,%rax,8)
movb 0x4(%rbx), %cl
movb $0x0, 0x4(%rbx)
testl %eax, %eax
je 0x62d1
cmpl $0x1, %eax
je 0x62be
testb %cl, %cl
jne 0x627f
movq %r13, %rdi
callq 0x43e3
cmpq $0x0, 0x28(%rbx)
je 0x6245
leaq 0x17683(%rip), %rdi     # 0x1d910
leaq 0x175d0(%rip), %rsi     # 0x1d864
leaq 0x17698(%rip), %rcx     # 0x1d933
movl $0xc89, %edx            # imm = 0xC89
callq 0x4100
movb $0x1, 0x4(%rbx)
movq %r15, %rdi
movl %ebp, %esi
movq %r14, %rdx
callq 0x62f4
movb $0x0, 0x4(%rbx)
movl %r12d, 0x8(%rbx)
movb $0x1, %cl
movl %ecx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ecx, %ecx
jmp 0x62c0
leaq 0x17684(%rip), %rdi     # 0x1d960
leaq 0x17581(%rip), %rsi     # 0x1d864
leaq 0x17649(%rip), %rcx     # 0x1d933
movl $0xc8a, %edx            # imm = 0xC8A
callq 0x4100