// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jb 0x6359
movq -0x8(%rbp), %rax
movl $0xffffffff, 0x18(%rax) # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rax
movq $0x0, 0x20(%rax)
jmp 0x64f5
movl $0x0, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x64c2
movq -0x18(%rbp), %rax
movzbl (%rax), %edx
leaq -0x10(%rbp), %rdi
leaq -0xc(%rbp), %rsi
callq 0x6860
cmpl $0x0, -0x10(%rbp)
jne 0x6461
movq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
subq %rax, %rcx
addq $0x1, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x20(%rax)
cmpl $0xd, -0xc(%rbp)
jne 0x6439
movq -0x8(%rbp), %rax
cmpq $0x1, 0x20(%rax)
jne 0x63cf
jmp 0x63ee
leaq 0x29eba(%rip), %rdi     # 0x30290
leaq 0x29ec5(%rip), %rsi     # 0x302a2
movl $0x87, %edx
leaq 0x29ec4(%rip), %rcx     # 0x302ad
callq 0x4100
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jae 0x6432
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0xa, %eax
jne 0x6432
movq -0x8(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq 0x38(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x38(%rax)
movl $0xa, -0xc(%rbp)
movl -0xc(%rbp), %edi
callq 0x6210
testb $0x1, %al
jne 0x6447
jmp 0x6452
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x68f0
movl -0xc(%rbp), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x18(%rax)
jmp 0x64f5
cmpl $0xc, -0x10(%rbp)
jne 0x64ad
movq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
subq %rax, %rcx
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rdx
cmpq (%rdx), %rax
sete %al
andb $0x1, %al
movzbl %al, %eax
cltq
addq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rax
movl $0xfffd, 0x18(%rax)     # imm = 0xFFFD
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x68f0
jmp 0x64f5
jmp 0x64af
jmp 0x64b1
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x6372
movq -0x8(%rbp), %rax
movl $0xfffd, 0x18(%rax)     # imm = 0xFFFD
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rax
subq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x68f0
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)