// File: /workspace/github_c_makefile_star2_O0/craigbarnes[P]lua-gumbo/lib/parser.c
// Function: get_appropriate_insertion_mode
static GumboInsertionMode get_appropriate_insertion_mode (
  const GumboParser* parser,
  int index
) {
  const GumboVector* open_elements = &parser->_parser_state->_open_elements;
  const GumboNode* node = open_elements->data[index];
  const bool is_last = index == 0;

  if (is_last && is_fragment_parser(parser)) {
    node = parser->_parser_state->_fragment_ctx;
  }

  assert(node->type == GUMBO_NODE_ELEMENT || node->type == GUMBO_NODE_TEMPLATE);
  if (node->v.element.tag_namespace != GUMBO_NAMESPACE_HTML) {
    return is_last ? GUMBO_INSERTION_MODE_IN_BODY : GUMBO_INSERTION_MODE_INITIAL;
  }

  switch (node->v.element.tag) {
    case GUMBO_TAG_SELECT: {
      if (is_last) {
        return GUMBO_INSERTION_MODE_IN_SELECT;
      }
      for (int i = index; i > 0; --i) {
        const GumboNode* ancestor = open_elements->data[i];
        if (node_html_tag_is(ancestor, GUMBO_TAG_TEMPLATE)) {
          return GUMBO_INSERTION_MODE_IN_SELECT;
        }
        if (node_html_tag_is(ancestor, GUMBO_TAG_TABLE)) {
          return GUMBO_INSERTION_MODE_IN_SELECT_IN_TABLE;
        }
      }
      return GUMBO_INSERTION_MODE_IN_SELECT;
    }
    case GUMBO_TAG_TD:
    case GUMBO_TAG_TH:
      if (!is_last) {
        return GUMBO_INSERTION_MODE_IN_CELL;
      }
      break;
    case GUMBO_TAG_TR:
      return GUMBO_INSERTION_MODE_IN_ROW;
    case GUMBO_TAG_TBODY:
    case GUMBO_TAG_THEAD:
    case GUMBO_TAG_TFOOT:
      return GUMBO_INSERTION_MODE_IN_TABLE_BODY;
    case GUMBO_TAG_CAPTION:
      return GUMBO_INSERTION_MODE_IN_CAPTION;
    case GUMBO_TAG_COLGROUP:
      return GUMBO_INSERTION_MODE_IN_COLUMN_GROUP;
    case GUMBO_TAG_TABLE:
      return GUMBO_INSERTION_MODE_IN_TABLE;
    case GUMBO_TAG_TEMPLATE:
      return get_current_template_insertion_mode(parser);
    case GUMBO_TAG_HEAD:
      if (!is_last) {
        return GUMBO_INSERTION_MODE_IN_HEAD;
      }
      break;
    case GUMBO_TAG_BODY:
      return GUMBO_INSERTION_MODE_IN_BODY;
    case GUMBO_TAG_FRAMESET:
      return GUMBO_INSERTION_MODE_IN_FRAMESET;
    case GUMBO_TAG_HTML:
      return parser->_parser_state->_head_element
        ? GUMBO_INSERTION_MODE_AFTER_HEAD
        : GUMBO_INSERTION_MODE_BEFORE_HEAD;
    default:
      break;
  }
  return is_last ? GUMBO_INSERTION_MODE_IN_BODY : GUMBO_INSERTION_MODE_INITIAL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq (%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rbp)
cmpl $0x0, -0x14(%rbp)
sete %al
andb $0x1, %al
movb %al, -0x29(%rbp)
testb $0x1, -0x29(%rbp)
je 0x8973
movq -0x10(%rbp), %rdi
callq 0x8b60
testb $0x1, %al
jne 0x8963
jmp 0x8973
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x48(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
cmpl $0x1, (%rax)
je 0x8985
movq -0x28(%rbp), %rax
cmpl $0x6, (%rax)
jne 0x8987
jmp 0x89a6
leaq 0x2a995(%rip), %rdi     # 0x33323
leaq 0x2a4df(%rip), %rsi     # 0x32e74
movl $0x275, %edx            # imm = 0x275
leaq 0x2a9c8(%rip), %rcx     # 0x33369
callq 0x4100
movq -0x28(%rbp), %rax
cmpl $0x0, 0x2c(%rax)
je 0x89c8
movb -0x29(%rbp), %dl
xorl %eax, %eax
movl $0x6, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x8b2f
movq -0x28(%rbp), %rax
movl 0x28(%rax), %eax
movq %rax, -0x40(%rbp)
subq $0x81, %rax
ja 0x8b1a
movq -0x40(%rbp), %rax
leaq 0x27b76(%rip), %rcx     # 0x30560
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
testb $0x1, -0x29(%rbp)
je 0x8a05
movl $0xf, -0x4(%rbp)
jmp 0x8b2f
movl -0x14(%rbp), %eax
movl %eax, -0x30(%rbp)
cmpl $0x0, -0x30(%rbp)
jle 0x8a71
movq -0x20(%rbp), %rax
movq (%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
movl $0x9, %esi
callq 0x8700
testb $0x1, %al
jne 0x8a38
jmp 0x8a44
movl $0xf, -0x4(%rbp)
jmp 0x8b2f
movq -0x38(%rbp), %rdi
movl $0x5f, %esi
callq 0x8700
testb $0x1, %al
jne 0x8a58
jmp 0x8a64
movl $0x10, -0x4(%rbp)
jmp 0x8b2f
jmp 0x8a66
movl -0x30(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x8a0b
movl $0xf, -0x4(%rbp)
jmp 0x8b2f
testb $0x1, -0x29(%rbp)
jne 0x8a8f
movl $0xe, -0x4(%rbp)
jmp 0x8b2f
jmp 0x8b1c
movl $0xd, -0x4(%rbp)
jmp 0x8b2f
movl $0xc, -0x4(%rbp)
jmp 0x8b2f
movl $0xa, -0x4(%rbp)
jmp 0x8b2f
movl $0xb, -0x4(%rbp)
jmp 0x8b2f
movl $0x8, -0x4(%rbp)
jmp 0x8b2f
movq -0x10(%rbp), %rdi
callq 0x8b80
movl %eax, -0x4(%rbp)
jmp 0x8b2f
testb $0x1, -0x29(%rbp)
jne 0x8ae4
movl $0x3, -0x4(%rbp)
jmp 0x8b2f
jmp 0x8b1c
movl $0x6, -0x4(%rbp)
jmp 0x8b2f
movl $0x13, -0x4(%rbp)
jmp 0x8b2f
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x38(%rax), %rdx
movl $0x2, %eax
movl $0x5, %ecx
cmpq $0x0, %rdx
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0x8b2f
jmp 0x8b1c
movb -0x29(%rbp), %dl
xorl %eax, %eax
movl $0x6, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)