// File: /workspace/github_c_makefile_star2_O1/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), %eax
leaq 0x1c29f(%rip), %rcx     # 0x22820
movl (%rcx), %r13d
cmpl %r13d, %eax
jne 0x6615
movq %r15, %rdi
movq %r14, %rsi
callq 0xd2fd
movb $0x1, %bpl
testb %al, %al
jne 0x6662
leaq 0xe8(%rbx), %rax
movq %rax, (%rsp)
cmpq $0x0, 0x28(%rbx)
jne 0x66b6
cmpl %r13d, 0x8(%rbx)
jne 0x6697
movl (%rbx), %eax
movl 0x100(%rbx), %edx
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rcx
leaq 0x4ec85(%rip), %r8      # 0x55260
callq *(%r8,%rax,8)
movb 0x4(%rbx), %cl
movb $0x0, 0x4(%rbx)
cmpl $0x1, %eax
je 0x65f6
testl %eax, %eax
jne 0x65fe
xorl %r12d, %r12d
xorl %ebp, %ebp
jmp 0x660e
movb $0x1, %bpl
xorl %r12d, %r12d
jmp 0x660e
movb $0x1, %r12b
testb %cl, %cl
jne 0x660e
movq (%rsp), %rdi
callq 0x43e4
testb %r12b, %r12b
jne 0x65ae
jmp 0x6662
movb $0x1, 0x4(%rbx)
testl %eax, %eax
jle 0x6628
movl $0x6, %ecx
cmpb $0x0, 0x6(%rbx)
jne 0x6645
leal 0x1(%rax), %edx
cmpl $0x21, %edx
ja 0x6689
movl $0x4, %ecx
movabsq $0x200006c00, %rsi      # imm = 0x200006C00
btq %rdx, %rsi
jae 0x6677
movl %ecx, (%r14)
movl %eax, 0x30(%r14)
movq %r15, %rdi
movq %r14, %rsi
callq 0xd443
movb $0x0, 0x4(%rbx)
movl %r13d, 0x8(%rbx)
movb $0x1, %bpl
andb $0x1, %bpl
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rdx, %rdx
je 0x6690
cmpq $0x1, %rdx
jne 0x6689
movl $0x7, %ecx
jmp 0x6645
movl $0x5, %ecx
jmp 0x6645
movl $0x8, %ecx
jmp 0x6645
leaq 0x191a2(%rip), %rdi     # 0x1f840
leaq 0x1909f(%rip), %rsi     # 0x1f744
leaq 0x19167(%rip), %rcx     # 0x1f813
movl $0xc8a, %edx            # imm = 0xC8A
callq 0x4100
leaq 0x19133(%rip), %rdi     # 0x1f7f0
leaq 0x19080(%rip), %rsi     # 0x1f744
leaq 0x19148(%rip), %rcx     # 0x1f813
movl $0xc89, %edx            # imm = 0xC89
callq 0x4100
nopw %cs:(%rax,%rax)
nop