// File: /workspace/github_c_makefile_star2_O3/craigbarnes[P]lua-gumbo/lib/utf8.c
// Function: read_char
static void read_char(Utf8Iterator* iter) {
  if (iter->_start >= iter->_end) {
    // No input left to consume; emit an EOF and set width = 0.
    iter->_current = -1;
    iter->_width = 0;
    return;
  }

  uint32_t code_point = 0;
  uint32_t state = UTF8_ACCEPT;
  for (const char* c = iter->_start; c < iter->_end; ++c) {
    decode(&state, &code_point, (uint32_t)(unsigned char) (*c));
    if (state == UTF8_ACCEPT) {
      iter->_width = c - iter->_start + 1;
      // This is the special handling for carriage returns that is mandated by
      // the HTML5 spec. Since we're looking for particular 7-bit literal
      // characters, we operate in terms of chars and only need a check for iter
      // overrun, instead of having to read in a full next code point.
      // https://html.spec.whatwg.org/multipage/parsing.html#preprocessing-the-input-stream
      if (code_point == '\r') {
        assert(iter->_width == 1);
        const char* next = c + 1;
        if (next < iter->_end && *next == '\n') {
          // Advance the iter, as if the carriage return didn't exist.
          ++iter->_start;
          // Preserve the true offset, since other tools that look at it may be
          // unaware of HTML5's rules for converting \r into \n.
          ++iter->_pos.offset;
        }
        code_point = '\n';
      }
      if (utf8_is_invalid_code_point(code_point)) {
        // Invalid code points are errors, but are not replaced by U+FFFD.
        // https://html.spec.whatwg.org/multipage/parsing.html#preprocessing-the-input-stream
        add_error(iter, GUMBO_ERR_UTF8_INVALID);
      }
      iter->_current = code_point;
      return;
    } else if (state == UTF8_REJECT) {
      // We don't want to consume the invalid continuation byte of a multi-byte
      // run, but we do want to skip past an invalid first byte.
      iter->_width = c - iter->_start + (c == iter->_start);
      iter->_current = UNICODE_REPLACEMENT_CHAR;
      add_error(iter, GUMBO_ERR_UTF8_INVALID);
      return;
    }
  }
  // If we got here without exiting early, then we've reached the end of the
  // iterator. Add an error for truncated input, set the width to consume the
  // rest of the iterator, and emit a replacement character. The next time we
  // enter this method, it will detect that there's no input to consume and
  // output an EOF.
  iter->_current = UNICODE_REPLACEMENT_CHAR;
  iter->_width = iter->_end - iter->_start;
  add_error(iter, GUMBO_ERR_UTF8_TRUNCATED);
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq (%rdi), %rax
movq 0x10(%rdi), %rdx
cmpq %rdx, %rax
jae 0x78d7
movq %rdx, %rdi
subq %rax, %rdi
xorl %esi, %esi
leaq 0x119c5(%rip), %r8      # 0x19230
movq %rax, %r9
xorl %r10d, %r10d
xorl %r14d, %r14d
movzbl (%r9), %r11d
movzbl (%r11,%r8), %ecx
testl %r10d, %r10d
je 0x788f
andl $0x3f, %r11d
shll $0x6, %r14d
orl %r11d, %r14d
jmp 0x789b
movl $0xff, %r14d
shrl %cl, %r14d
andl %r11d, %r14d
movl %r10d, %r10d
movl %ecx, %ecx
addq %r10, %rcx
movzbl 0x100(%rcx,%r8), %r10d
cmpl $0xc, %r10d
je 0x7913
testl %r10d, %r10d
je 0x78e8
incq %r9
decq %rsi
cmpq %rdx, %r9
jne 0x7874
movl $0xfffd, 0x18(%rbx)     # imm = 0xFFFD
movq %rdi, 0x20(%rbx)
movq %rbx, %rdi
movl $0x1, %esi
jmp 0x792e
movl $0xffffffff, 0x18(%rbx) # imm = 0xFFFFFFFF
movq $0x0, 0x20(%rbx)
jmp 0x790b
movl $0x1, %ecx
subq %rsi, %rcx
movq %rcx, 0x20(%rbx)
leal -0x1(%r14), %ecx
cmpl $0x8, %ecx
jae 0x793a
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7a8d
movl %r14d, 0x18(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r14
retq
cmpq $0x1, %rsi
sbbq $0x0, %rsi
negq %rsi
movq %rsi, 0x20(%rbx)
movl $0xfffd, 0x18(%rbx)     # imm = 0xFFFD
movq %rbx, %rdi
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x7a8d
cmpl $0xb, %r14d
je 0x78fd
cmpl $0xd, %r14d
jne 0x7965
testq %rsi, %rsi
jne 0x799c
incq %rax
movl $0xa, %r14d
cmpq %rdx, %rax
jae 0x7965
cmpb $0xa, (%rax)
jne 0x7965
movq %rax, (%rbx)
incq 0x38(%rbx)
movl %r14d, %eax
notl %eax
testl $0xfffe, %eax           # imm = 0xFFFE
je 0x78fd
leal -0xfdd0(%r14), %eax
cmpl $0x20, %eax
jb 0x78fd
leal -0xe(%r14), %eax
cmpl $0x12, %eax
jb 0x78fd
leal -0x7f(%r14), %eax
cmpl $0x20, %eax
ja 0x7907
jmp 0x78fd
leaq 0x1184d(%rip), %rdi     # 0x191f0
leaq 0x11858(%rip), %rsi     # 0x19202
leaq 0x1185c(%rip), %rcx     # 0x1920d
movl $0x87, %edx
callq 0x4100