// File: /workspace/github_c_makefile_star2_O0/craigbarnes[P]lua-gumbo/lib/parser.c
// Function: gumbo_parse_with_options
HOT GumboOutput* gumbo_parse_with_options (
  const GumboOptions* options,
  const char* buffer,
  size_t length
) {
  GumboParser parser;
  parser._options = options;
  output_init(&parser);
  gumbo_tokenizer_state_init(&parser, buffer, length);
  parser_state_init(&parser);

  if (options->fragment_context != GUMBO_TAG_LAST) {
    fragment_parser_init (
      &parser,
      options->fragment_context,
      options->fragment_namespace
    );
  }

  GumboParserState* state = parser._parser_state;
  gumbo_debug (
    "Parsing %.*s.\n",
    (int) length,
    buffer
  );

  // Sanity check so that infinite loops die with an assertion failure instead
  // of hanging the process before we ever get an error.
  uint_fast32_t loop_count = 0;

  const unsigned int max_tree_depth = options->max_tree_depth;
  GumboToken token;
  bool has_error = false;

  do {
    if (state->_reprocess_current_token) {
      state->_reprocess_current_token = false;
    } else {
      GumboNode* current_node = get_current_node(&parser);
      gumbo_tokenizer_set_is_current_node_foreign (
        &parser,
        current_node &&
          current_node->v.element.tag_namespace != GUMBO_NAMESPACE_HTML
      );
      has_error = !gumbo_lex(&parser, &token) || has_error;
    }

    const char* token_type = "text";
    switch (token.type) {
      case GUMBO_TOKEN_DOCTYPE:
        token_type = "doctype";
        break;
      case GUMBO_TOKEN_START_TAG:
        token_type = gumbo_normalized_tagname(token.v.start_tag.tag);
        break;
      case GUMBO_TOKEN_END_TAG:
        token_type = gumbo_normalized_tagname(token.v.end_tag);
        break;
      case GUMBO_TOKEN_COMMENT:
        token_type = "comment";
        break;
      default:
        break;
    }
    gumbo_debug (
      "Handling %s token @%zu:%zu in state %u.\n",
      (char*) token_type,
      token.position.line,
      token.position.column,
      state->_insertion_mode
    );

    state->_current_token = &token;
    state->_self_closing_flag_acknowledged =
      !(
        token.type == GUMBO_TOKEN_START_TAG
        && token.v.start_tag.is_self_closing
      );

    has_error = !handle_token(&parser, &token) || has_error;

    // Check for memory leaks when ownership is transferred from start tag
    // tokens to nodes.
    assert (
      state->_reprocess_current_token
      || token.type != GUMBO_TOKEN_START_TAG
      || token.v.start_tag.attributes.data == NULL
    );

    if (!state->_self_closing_flag_acknowledged) {
      GumboError* error = parser_add_parse_error(&parser, &token);
      if (error) {
        error->type = GUMBO_ERR_UNACKNOWLEDGED_SELF_CLOSING_TAG;
      }
    }

    if (unlikely(state->_open_elements.length > max_tree_depth)) {
      parser._output->status = GUMBO_STATUS_TREE_TOO_DEEP;
      gumbo_debug("Tree depth limit exceeded.\n");
      break;
    }

    ++loop_count;
    assert(loop_count < 1000000000UL);

  } while (
    (token.type != GUMBO_TOKEN_EOF || state->_reprocess_current_token)
    && !(options->stop_on_first_error && has_error)
  );

  finish_parsing(&parser);
  // For API uniformity reasons, if the doctype still has nulls, convert them to
  // empty strings.
  GumboDocument* doc_type = &parser._output->document->v.document;
  if (doc_type->name == NULL) {
    doc_type->name = gumbo_strdup("");
  }
  if (doc_type->public_identifier == NULL) {
    doc_type->public_identifier = gumbo_strdup("");
  }
  if (doc_type->system_identifier == NULL) {
    doc_type->system_identifier = gumbo_strdup("");
  }

  parser_state_destroy(&parser);
  gumbo_tokenizer_state_destroy(&parser);
  return parser._output;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x7280
movq -0x10(%rbp), %rsi
movq -0x18(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x11910
leaq -0x38(%rbp), %rdi
callq 0x72e0
movq -0x8(%rbp), %rax
cmpl $0x97, 0x10(%rax)
je 0x6ea6
movq -0x8(%rbp), %rax
movl 0x10(%rax), %esi
movq -0x8(%rbp), %rax
movl 0x14(%rax), %edx
leaq -0x38(%rbp), %rdi
callq 0x73d0
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movl %eax, %esi
movq -0x10(%rbp), %rdx
leaq 0x2bf01(%rip), %rdi     # 0x32dc0
movb $0x0, %al
callq 0x7540
movq $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x4c(%rbp)
movb $0x0, -0xa1(%rbp)
movq -0x40(%rbp), %rax
testb $0x1, 0x50(%rax)
je 0x6ef6
movq -0x40(%rbp), %rax
movb $0x0, 0x50(%rax)
jmp 0x6f7c
leaq -0x38(%rbp), %rdi
callq 0x7550
movq %rax, -0xb0(%rbp)
xorl %eax, %eax
cmpq $0x0, -0xb0(%rbp)
movb %al, -0xc9(%rbp)
je 0x6f2c
movq -0xb0(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
setne %al
movb %al, -0xc9(%rbp)
movb -0xc9(%rbp), %al
movzbl %al, %esi
andl $0x1, %esi
leaq -0x38(%rbp), %rdi
callq 0x11bd0
leaq -0x38(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x11c50
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0xca(%rbp)
jne 0x6f62
jmp 0x6f6e
movb -0xa1(%rbp), %al
movb %al, -0xca(%rbp)
movb -0xca(%rbp), %al
andb $0x1, %al
movb %al, -0xa1(%rbp)
leaq 0x28785(%rip), %rax     # 0x2f708
movq %rax, -0xb8(%rbp)
movl -0xa0(%rbp), %eax
movq %rax, -0xd8(%rbp)
subq $0x3, %rax
ja 0x6ff6
movq -0xd8(%rbp), %rax
leaq 0x295a5(%rip), %rcx     # 0x30550
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x286dc(%rip), %rax     # 0x2f697
movq %rax, -0xb8(%rbp)
jmp 0x6ff8
movl -0x70(%rbp), %edi
callq 0x5f80
movq %rax, -0xb8(%rbp)
jmp 0x6ff8
movl -0x70(%rbp), %edi
callq 0x5f80
movq %rax, -0xb8(%rbp)
jmp 0x6ff8
leaq 0x2bde2(%rip), %rax     # 0x32dcf
movq %rax, -0xb8(%rbp)
jmp 0x6ff8
jmp 0x6ff8
movq -0xb8(%rbp), %rsi
movq -0x98(%rbp), %rdx
movq -0x90(%rbp), %rcx
movq -0x40(%rbp), %rax
movl (%rax), %r8d
leaq 0x2bdbc(%rip), %rdi     # 0x32dd7
movb $0x0, %al
callq 0x7540
movq -0x40(%rbp), %rax
leaq -0xa0(%rbp), %rcx
movq %rcx, 0x98(%rax)
xorl %eax, %eax
cmpl $0x1, -0xa0(%rbp)
movb %al, -0xd9(%rbp)
jne 0x704e
movb -0x58(%rbp), %al
movb %al, -0xd9(%rbp)
movb -0xd9(%rbp), %cl
xorb $-0x1, %cl
movq -0x40(%rbp), %rax
andb $0x1, %cl
movb %cl, 0x51(%rax)
leaq -0x38(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x7630
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0xda(%rbp)
jne 0x7082
jmp 0x708e
movb -0xa1(%rbp), %al
movb %al, -0xda(%rbp)
movb -0xda(%rbp), %al
andb $0x1, %al
movb %al, -0xa1(%rbp)
movq -0x40(%rbp), %rax
testb $0x1, 0x50(%rax)
jne 0x70b6
cmpl $0x1, -0xa0(%rbp)
jne 0x70b6
cmpq $0x0, -0x68(%rbp)
jne 0x70b8
jmp 0x70d7
leaq 0x2bd41(%rip), %rdi     # 0x32e00
leaq 0x2bdae(%rip), %rsi     # 0x32e74
movl $0x11a8, %edx           # imm = 0x11A8
leaq 0x2bdaf(%rip), %rcx     # 0x32e81
callq 0x4100
movq -0x40(%rbp), %rax
testb $0x1, 0x51(%rax)
jne 0x7111
leaq -0x38(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x78a0
movq %rax, -0xc0(%rbp)
cmpq $0x0, -0xc0(%rbp)
je 0x710f
movq -0xc0(%rbp), %rax
movl $0x29, (%rax)
jmp 0x7111
movq -0x40(%rbp), %rax
movl 0x10(%rax), %eax
cmpl -0x4c(%rbp), %eax
jbe 0x713b
movq -0x30(%rbp), %rax
movl $0x1, 0x20(%rax)
leaq 0x2bda4(%rip), %rdi     # 0x32ed3
movb $0x0, %al
callq 0x7540
jmp 0x71c9
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
cmpq $0x3b9aca00, -0x48(%rbp) # imm = 0x3B9ACA00
jae 0x7153
jmp 0x7172
leaq 0x2bd95(%rip), %rdi     # 0x32eef
leaq 0x2bd13(%rip), %rsi     # 0x32e74
movl $0x11b8, %edx           # imm = 0x11B8
leaq 0x2bd14(%rip), %rcx     # 0x32e81
callq 0x4100
jmp 0x7174
cmpl $0x8, -0xa0(%rbp)
jne 0x718f
movq -0x40(%rbp), %rcx
xorl %eax, %eax
testb $0x1, 0x50(%rcx)
movb %al, -0xdb(%rbp)
je 0x71bb
movq -0x8(%rbp), %rcx
xorl %eax, %eax
testb $0x1, 0x4(%rcx)
movb %al, -0xdc(%rbp)
je 0x71ad
movb -0xa1(%rbp), %al
movb %al, -0xdc(%rbp)
movb -0xdc(%rbp), %al
xorb $-0x1, %al
movb %al, -0xdb(%rbp)
movb -0xdb(%rbp), %al
testb $0x1, %al
jne 0x6edf
leaq -0x38(%rbp), %rdi
callq 0x7a30
movq -0x30(%rbp), %rax
movq (%rax), %rax
addq $0x18, %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x720c
leaq 0x2d002(%rip), %rdi     # 0x341fb
callq 0x17da0
movq %rax, %rcx
movq -0xc8(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0xc8(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x7234
leaq 0x2cfda(%rip), %rdi     # 0x341fb
callq 0x17da0
movq %rax, %rcx
movq -0xc8(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0xc8(%rbp), %rax
cmpq $0x0, 0x28(%rax)
jne 0x725c
leaq 0x2cfb2(%rip), %rdi     # 0x341fb
callq 0x17da0
movq %rax, %rcx
movq -0xc8(%rbp), %rax
movq %rcx, 0x28(%rax)
leaq -0x38(%rbp), %rdi
callq 0x7af0
leaq -0x38(%rbp), %rdi
callq 0x11b00
movq -0x30(%rbp), %rax
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax,%rax)