// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x10(%rbp)
movl $0xffffffff, -0x8(%rbp) # imm = 0xFFFFFFFF
cmpq $0x0, -0x10(%rbp)
jne 0x8235
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
cmpq $0x0, 0x8(%rax)
je 0x821a
movq -0x18(%rbp), %rdi
callq 0x7550
movq %rax, -0xe0(%rbp)
jmp 0x822a
movq -0x18(%rbp), %rdi
callq 0x8660
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
testb $0x1, 0x54(%rax)
je 0x8290
movq -0x10(%rbp), %rax
movq %rax, -0xe8(%rbp)
leaq -0xb8(%rbp), %rdi
xorl %esi, %esi
movl $0x98, %edx
callq 0x4120
leaq -0xb8(%rbp), %rdi
leaq 0x28569(%rip), %rsi     # 0x307d8
movl $0x98, %edx
callq 0x41a0
movq -0xe8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x8680
testb $0x1, %al
jne 0x8295
jmp 0x840e
movl $0xffffffff, -0xbc(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0xc0(%rbp) # imm = 0xFFFFFFFF
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
addq $0x8, %rax
movq %rax, -0xc8(%rbp)
movl $0x0, -0xcc(%rbp)
movl -0xcc(%rbp), %eax
movq -0xc8(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jae 0x834e
movq -0xc8(%rbp), %rax
movq (%rax), %rax
movl -0xcc(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movl $0x9, %esi
callq 0x8700
testb $0x1, %al
jne 0x82fc
jmp 0x8308
movl -0xcc(%rbp), %eax
movl %eax, -0xbc(%rbp)
movq -0xc8(%rbp), %rax
movq (%rax), %rax
movl -0xcc(%rbp), %ecx
movq (%rax,%rcx,8), %rdi
movl $0x5f, %esi
callq 0x8700
testb $0x1, %al
jne 0x832c
jmp 0x8338
movl -0xcc(%rbp), %eax
movl %eax, -0xc0(%rbp)
jmp 0x833a
movl -0xcc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xcc(%rbp)
jmp 0x82c6
cmpl $-0x1, -0xbc(%rbp)
je 0x838c
cmpl $-0x1, -0xc0(%rbp)
je 0x836e
movl -0xbc(%rbp), %eax
cmpl -0xc0(%rbp), %eax
jle 0x838c
movq -0xc8(%rbp), %rax
movq (%rax), %rax
movslq -0xbc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x10(%rbp)
jmp 0x840e
cmpl $-0x1, -0xc0(%rbp)
jne 0x83a8
movq -0xc8(%rbp), %rax
movq (%rax), %rax
movq (%rax), %rax
movq %rax, -0x10(%rbp)
jmp 0x840e
movq -0xc8(%rbp), %rax
movq (%rax), %rax
movslq -0xc0(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x83f0
movq -0xd8(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x10(%rbp)
movq -0xd8(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x8(%rbp)
jmp 0x840e
movq -0xc8(%rbp), %rax
movq (%rax), %rax
movl -0xc0(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl -0x8(%rbp), %edx
addq $0xf0, %rsp
popq %rbp
retq
nop