// File: /workspace/github_c_makefile_star2_O1/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 %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
testq %rsi, %rsi
jne 0x8891
movq 0x8(%r14), %rax
cmpq $0x0, 0x8(%rax)
je 0x888e
movq %r14, %rdi
callq 0x8107
movq %rax, %rbx
jmp 0x8891
movq (%rax), %rbx
movq 0x18(%r14), %rax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpb $0x1, 0x54(%rax)
jne 0x896d
leaq 0x14b4d(%rip), %rsi     # 0x1d3f8
movq %rbx, %rdi
callq 0x8b24
testb %al, %al
je 0x896d
movq 0x18(%r14), %rbx
cmpl $0x0, 0x10(%rbx)
je 0x891b
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
xorl %r14d, %r14d
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x8(%rbx), %rax
movq (%rax,%r14,8), %rdi
xorl %esi, %esi
movl $0x9, %edx
callq 0x8b69
testb %al, %al
cmovnel %r14d, %ebp
movq 0x8(%rbx), %rax
movq (%rax,%r14,8), %rdi
xorl %esi, %esi
movl $0x5f, %edx
callq 0x8b69
movl %r14d, %ecx
testb %al, %al
jne 0x890b
movl %r15d, %ecx
incq %r14
movl 0x10(%rbx), %eax
movl %ecx, %r15d
cmpq %rax, %r14
jb 0x88d3
jmp 0x8925
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl $-0x1, %ebp
je 0x8933
cmpl $-0x1, %ecx
je 0x8951
cmpl %ecx, %ebp
jg 0x8951
movq 0x8(%rbx), %rax
cmpl $-0x1, %ecx
je 0x895e
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
movq 0x8(%rdx), %rbx
testq %rbx, %rbx
je 0x8963
movl 0x10(%rdx), %ebp
jmp 0x896d
movq 0x8(%rbx), %rax
movslq %ebp, %rcx
movq (%rax,%rcx,8), %rbx
jmp 0x8968
movq (%rax), %rbx
jmp 0x8968
movq -0x8(%rax,%rcx,8), %rbx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq %rbx, %rax
movl %ebp, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq