// File: /workspace/github_c_makefile_star2_O3/craigbarnes[P]lua-gumbo/lib/parser.c
// Function: get_appropriate_insertion_location
static InsertionLocation get_appropriate_insertion_location (
  const GumboParser* parser,
  GumboNode* override_target
) {
  InsertionLocation retval = {override_target, -1};
  if (retval.target == NULL) {
    // No override target; default to the current node, but special-case the
    // root node since get_current_node() assumes the stack of open elements is
    // non-empty.
    retval.target = (parser->_output->root != NULL)
      ? get_current_node(parser)
      : get_document_node(parser)
    ;
  }
  if (
    !parser->_parser_state->_foster_parent_insertions
    || !node_tag_in_set(retval.target, &(const TagSet) {
      TAG(TABLE), TAG(TBODY), TAG(TFOOT), TAG(THEAD), TAG(TR)
    })
  ) {
    return retval;
  }

  // Foster-parenting case.
  int last_template_index = -1;
  int last_table_index = -1;
  const GumboVector* open_elements = &parser->_parser_state->_open_elements;
  for (unsigned int i = 0; i < open_elements->length; ++i) {
    if (node_html_tag_is(open_elements->data[i], GUMBO_TAG_TEMPLATE)) {
      last_template_index = i;
    }
    if (node_html_tag_is(open_elements->data[i], GUMBO_TAG_TABLE)) {
      last_table_index = i;
    }
  }
  if (
    last_template_index != -1
    && (last_table_index == -1 || last_template_index > last_table_index)
  ) {
    retval.target = open_elements->data[last_template_index];
    return retval;
  }
  if (last_table_index == -1) {
    retval.target = open_elements->data[0];
    return retval;
  }
  const GumboNode* last_table = open_elements->data[last_table_index];
  if (last_table->parent != NULL) {
    retval.target = last_table->parent;
    retval.index = last_table->index_within_parent;
    return retval;
  }

  retval.target = open_elements->data[last_table_index - 1];
  return retval;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %r15
testq %rsi, %rsi
jne 0x8465
movq 0x8(%r15), %rax
cmpq $0x0, 0x8(%rax)
je 0x8462
movq %r15, %rdi
callq 0x7d33
movq %rax, %r14
jmp 0x8465
movq (%rax), %r14
movq 0x18(%r15), %rax
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpb $0x1, 0x54(%rax)
jne 0x853f
leaq 0x13099(%rip), %rsi     # 0x1b518
movq %r14, %rdi
callq 0x86f4
testb %al, %al
je 0x853f
movq 0x18(%r15), %r14
cmpl $0x0, 0x10(%r14)
je 0x852c
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
xorl %r15d, %r15d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %rdi
xorl %esi, %esi
movl $0x9, %edx
callq 0x8739
testb %al, %al
cmovnel %r15d, %ebp
movq 0x8(%r14), %rax
movq (%rax,%r15,8), %rdi
xorl %esi, %esi
movl $0x5f, %edx
callq 0x8739
movl %r15d, %ecx
testb %al, %al
jne 0x84e4
movl %r12d, %ecx
incq %r15
movl 0x10(%r14), %eax
movl %ecx, %r12d
cmpq %rax, %r15
jb 0x84ac
cmpl $-0x1, %ebp
je 0x850e
cmpl $-0x1, %ecx
je 0x8501
cmpl %ecx, %ebp
jle 0x8513
movq 0x8(%r14), %rax
movslq %ebp, %rcx
movq (%rax,%rcx,8), %r14
jmp 0x853a
cmpl $-0x1, %ecx
je 0x852c
movq 0x8(%r14), %rax
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
movq 0x8(%rdx), %r14
testq %r14, %r14
je 0x8535
movl 0x10(%rdx), %ebx
jmp 0x853f
movq 0x8(%r14), %rax
movq (%rax), %r14
jmp 0x853f
movq -0x8(%rax,%rcx,8), %r14
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %r14, %rax
movl %ebx, %edx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq