// File: /workspace/github_c_makefile_star2_O0/craigbarnes[P]lua-gumbo/lib/char_ref.c
// Function: consume_numeric_ref
static bool consume_numeric_ref (
  struct GumboParser* parser,
  Utf8Iterator* input,
  int* output
) {
  utf8iterator_next(input);
  bool is_hex = false;
  int c = utf8iterator_current(input);
  if (c == 'x' || c == 'X') {
    is_hex = true;
    utf8iterator_next(input);
    c = utf8iterator_current(input);
  }

  int digit = parse_digit(c, is_hex);
  if (digit == -1) {
    // First digit was invalid; add a parse error and return.
    add_no_digit_error(parser, input);
    utf8iterator_reset(input);
    *output = kGumboNoChar;
    return false;
  }

  uint32_t codepoint = 0;
  bool status = true;
  do {
    codepoint = (codepoint * (is_hex ? 16 : 10)) + digit;
    utf8iterator_next(input);
    digit = parse_digit(utf8iterator_current(input), is_hex);
  } while (digit != -1);

  if (utf8iterator_current(input) != ';') {
    add_codepoint_error (
      parser,
      input,
      GUMBO_ERR_NUMERIC_CHAR_REF_WITHOUT_SEMICOLON,
      codepoint
    );
    status = false;
  } else {
    utf8iterator_next(input);
  }

  uint32_t replacement = maybe_replace_codepoint(codepoint);
  if (replacement != 0) {
    add_codepoint_error (
      parser,
      input,
      GUMBO_ERR_NUMERIC_CHAR_REF_INVALID,
      codepoint
    );
    *output = replacement;
    return false;
  }

  if ((codepoint >= 0xd800 && codepoint <= 0xdfff) || codepoint > 0x10ffff) {
    add_codepoint_error (
      parser,
      input,
      GUMBO_ERR_NUMERIC_CHAR_REF_INVALID,
      codepoint
    );
    *output = 0xfffd;
    return false;
  }

  if (utf8_is_invalid_code_point(codepoint)) {
    add_codepoint_error (
      parser,
      input,
      GUMBO_ERR_NUMERIC_CHAR_REF_INVALID,
      codepoint
    );
    status = false;
    // But return it anyway, per spec.
  }
  *output = codepoint;
  return status;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x18(%rbp), %rdi
callq 0x6500
movb $0x0, -0x21(%rbp)
movq -0x18(%rbp), %rdi
callq 0x17f10
movl %eax, -0x28(%rbp)
cmpl $0x78, -0x28(%rbp)
je 0x17f69
cmpl $0x58, -0x28(%rbp)
jne 0x17f82
movb $0x1, -0x21(%rbp)
movq -0x18(%rbp), %rdi
callq 0x6500
movq -0x18(%rbp), %rdi
callq 0x17f10
movl %eax, -0x28(%rbp)
movl -0x28(%rbp), %edi
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x2e2d0
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
jne 0x17fc4
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x2e350
movq -0x18(%rbp), %rdi
callq 0x67d0
movq -0x20(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movb $0x0, -0x1(%rbp)
jmp 0x180f9
movl $0x0, -0x30(%rbp)
movb $0x1, -0x31(%rbp)
movl -0x30(%rbp), %eax
movb -0x21(%rbp), %sil
movl $0xa, %ecx
movl $0x10, %edx
testb $0x1, %sil
cmovnel %edx, %ecx
imull %ecx, %eax
addl -0x2c(%rbp), %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rdi
callq 0x6500
movq -0x18(%rbp), %rdi
callq 0x17f10
movl %eax, %edi
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %esi
callq 0x2e2d0
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
jne 0x17fcf
movq -0x18(%rbp), %rdi
callq 0x17f10
cmpl $0x3b, %eax
je 0x18043
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x30(%rbp), %ecx
movl $0x4, %edx
callq 0x2e3a0
movb $0x0, -0x31(%rbp)
jmp 0x1804c
movq -0x18(%rbp), %rdi
callq 0x6500
movl -0x30(%rbp), %edi
callq 0x2e400
movl %eax, -0x38(%rbp)
cmpl $0x0, -0x38(%rbp)
je 0x18081
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x30(%rbp), %ecx
movl $0x5, %edx
callq 0x2e3a0
movl -0x38(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movb $0x0, -0x1(%rbp)
jmp 0x180f9
cmpl $0xd800, -0x30(%rbp)    # imm = 0xD800
jb 0x18093
cmpl $0xdfff, -0x30(%rbp)    # imm = 0xDFFF
jbe 0x1809c
cmpl $0x10ffff, -0x30(%rbp)  # imm = 0x10FFFF
jbe 0x180c1
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x30(%rbp), %ecx
movl $0x5, %edx
callq 0x2e3a0
movq -0x20(%rbp), %rax
movl $0xfffd, (%rax)         # imm = 0xFFFD
movb $0x0, -0x1(%rbp)
jmp 0x180f9
movl -0x30(%rbp), %edi
callq 0x6210
testb $0x1, %al
jne 0x180cf
jmp 0x180e8
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x30(%rbp), %ecx
movl $0x5, %edx
callq 0x2e3a0
movb $0x0, -0x31(%rbp)
movl -0x30(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movb -0x31(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)