// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
testq %rsi, %rsi
jne 0x8000
movq 0x8(%r14), %rax
cmpq $0x0, 0x8(%rax)
je 0x7ffd
movq %r14, %rdi
callq 0x7913
movq %rax, %rbx
jmp 0x8000
movq (%rax), %rbx
movq 0x18(%r14), %rax
pushq $-0x1
popq %rbp
cmpb $0x1, 0x54(%rax)
jne 0x80c9
leaq 0x11470(%rip), %rsi     # 0x19488
movq %rbx, %rdi
callq 0x8272
testb %al, %al
je 0x80c9
movq 0x18(%r14), %r14
pushq $-0x1
popq %r15
xorl %r13d, %r13d
pushq $0x9
popq %rbx
pushq $0x5f
popq %rbp
movl %r15d, %r12d
movl 0x10(%r14), %eax
cmpq %rax, %r13
jae 0x807b
movq 0x8(%r14), %rax
movq (%rax,%r13,8), %rdi
movl %ebx, %esi
callq 0x82b7
testb %al, %al
cmovnel %r13d, %r15d
movq 0x8(%r14), %rax
movq (%rax,%r13,8), %rdi
movl %ebp, %esi
callq 0x82b7
movl %r13d, %ecx
testb %al, %al
jne 0x8073
movl %r12d, %ecx
incq %r13
movl %ecx, %r12d
jmp 0x803c
cmpl $-0x1, %r15d
je 0x8099
cmpl $-0x1, %r12d
je 0x808c
cmpl %r12d, %r15d
jle 0x809f
movq 0x8(%r14), %rax
movslq %r15d, %rcx
movq (%rax,%rcx,8), %rbx
jmp 0x80c6
cmpl $-0x1, %r12d
je 0x80bf
movq 0x8(%r14), %rax
movslq %r12d, %rcx
movq (%rax,%rcx,8), %rdx
movq 0x8(%rdx), %rbx
testq %rbx, %rbx
je 0x80b8
movl 0x10(%rdx), %ebp
jmp 0x80c9
movq -0x8(%rax,%rcx,8), %rbx
jmp 0x80c6
movq 0x8(%r14), %rax
movq (%rax), %rbx
pushq $-0x1
popq %rbp
movq %rbx, %rax
movl %ebp, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq