// File: /workspace/github_c_makefile_star2_O1/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 0x7c7f
xorl %esi, %esi
leaq 0x1364b(%rip), %r8      # 0x1b250
movq %rax, %rdi
xorl %r9d, %r9d
xorl %r14d, %r14d
movzbl (%rdi), %r10d
movzbl (%r10,%r8), %ecx
testl %r9d, %r9d
je 0x7c29
andl $0x3f, %r10d
shll $0x6, %r14d
orl %r10d, %r14d
jmp 0x7c35
movl $0xff, %r14d
shrl %cl, %r14d
andl %r10d, %r14d
movl %r9d, %r9d
movl %ecx, %ecx
addq %r9, %rcx
movzbl 0x100(%rcx,%r8), %r9d
cmpl $0xc, %r9d
je 0x7ce7
testl %r9d, %r9d
je 0x7c90
incq %rdi
decq %rsi
cmpq %rdx, %rdi
jne 0x7c0e
movl $0xfffd, 0x18(%rbx)     # imm = 0xFFFD
movq 0x10(%rbx), %rax
subq (%rbx), %rax
movq %rax, 0x20(%rbx)
movq %rbx, %rdi
movl $0x1, %esi
jmp 0x7d02
movl $0xffffffff, 0x18(%rbx) # imm = 0xFFFFFFFF
movq $0x0, 0x20(%rbx)
jmp 0x7cdf
movl $0x1, %ecx
subq %rsi, %rcx
movq %rcx, 0x20(%rbx)
cmpl $0xd, %r14d
jne 0x7cc8
testq %rsi, %rsi
jne 0x7d40
incq %rdi
movl $0xa, %r14d
cmpq %rdx, %rdi
jae 0x7cc8
cmpb $0xa, (%rdi)
jne 0x7cc8
incq %rax
movq %rax, (%rbx)
incq 0x38(%rbx)
leal -0x1(%r14), %eax
cmpl $0x8, %eax
jae 0x7d0e
movq %rbx, %rdi
xorl %esi, %esi
callq 0x7e60
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 0x7e60
cmpl $0xb, %r14d
je 0x7cd1
movl %r14d, %eax
notl %eax
testl $0xfffe, %eax           # imm = 0xFFFE
je 0x7cd1
leal -0xfdd0(%r14), %eax
cmpl $0x20, %eax
jb 0x7cd1
leal -0xe(%r14), %eax
cmpl $0x12, %eax
jb 0x7cd1
leal -0x7f(%r14), %eax
cmpl $0x20, %eax
ja 0x7cdb
jmp 0x7cd1
leaq 0x134c9(%rip), %rdi     # 0x1b210
leaq 0x134d4(%rip), %rsi     # 0x1b222
leaq 0x134d8(%rip), %rcx     # 0x1b22d
movl $0x87, %edx
callq 0x4100