// File: /workspace/github_c_makefile_star2_O2/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 %rbp
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq (%rdi), %rax
movq 0x10(%rdi), %rdx
cmpq %rdx, %rax
jae 0x7527
xorl %esi, %esi
leaq 0xfd5e(%rip), %rdi      # 0x17230
xorl %ebp, %ebp
xorl %r9d, %r9d
movq %rax, %r8
cmpq %rdx, %r8
jae 0x7532
movzbl (%r8), %r10d
movzbl (%r10,%rdi), %ecx
testl %r9d, %r9d
je 0x74f9
andl $0x3f, %r10d
shll $0x6, %ebp
orl %r10d, %ebp
jmp 0x7503
movl $0xff, %ebp
shrl %cl, %ebp
andl %r10d, %ebp
movl %r9d, %r9d
movl %ecx, %ecx
addq %r9, %rcx
movzbl 0x100(%rcx,%rdi), %r9d
cmpl $0xc, %r9d
je 0x7548
testl %r9d, %r9d
je 0x756e
incq %r8
decq %rsi
jmp 0x74da
orl $-0x1, 0x18(%rbx)
andq $0x0, 0x20(%rbx)
jmp 0x75b1
movl $0xfffd, 0x18(%rbx)     # imm = 0xFFFD
subq %rax, %rdx
movq %rdx, 0x20(%rbx)
pushq $0x1
popq %rsi
movq %rbx, %rdi
jmp 0x7563
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 %rbp
jmp 0x769d
pushq $0x1
popq %rcx
subq %rsi, %rcx
movq %rcx, 0x20(%rbx)
cmpl $0xd, %ebp
jne 0x7599
testq %rsi, %rsi
jne 0x75b8
incq %rax
pushq $0xa
popq %rbp
cmpq %rdx, %rax
jae 0x7599
cmpb $0xa, (%rax)
jne 0x7599
movq %rax, (%rbx)
incq 0x38(%rbx)
movl %ebp, %edi
callq 0x7458
testb %al, %al
je 0x75ae
movq %rbx, %rdi
xorl %esi, %esi
callq 0x769d
movl %ebp, 0x18(%rbx)
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0xfc31(%rip), %rdi      # 0x171f0
leaq 0xfc3c(%rip), %rsi      # 0x17202
leaq 0xfc40(%rip), %rcx      # 0x1720d
movl $0x87, %edx
callq 0x4100