// File: /workspace/github_c_makefile_star2_O1/craigbarnes[P]lua-gumbo/lib/parser.c
// Function: reconstruct_active_formatting_elements
static void reconstruct_active_formatting_elements(GumboParser* parser) {
  GumboVector* elements = &parser->_parser_state->_active_formatting_elements;
  // Step 1
  if (elements->length == 0) {
    return;
  }

  // Step 2 & 3
  unsigned int i = elements->length - 1;
  GumboNode* element = elements->data[i];
  if (
    element == &kActiveFormattingScopeMarker
    || is_open_element(parser, element)
  ) {
    return;
  }

  // Step 6
  do {
    if (i == 0) {
      // Step 4
      i = -1;  // Incremented to 0 below.
      break;
    }
    // Step 5
    element = elements->data[--i];
  } while (
    element != &kActiveFormattingScopeMarker
    && !is_open_element(parser, element)
  );

  ++i;
  gumbo_debug (
    "Reconstructing elements from %u on %s parent.\n",
    i,
    gumbo_normalized_tagname(get_current_node(parser)->v.element.tag)
  );
  for (; i < elements->length; ++i) {
    // Step 7 & 8.
    assert(elements->length > 0);
    assert(i < elements->length);
    element = elements->data[i];
    assert(element != &kActiveFormattingScopeMarker);
    GumboNode* clone = clone_node (
      element,
      GUMBO_INSERTION_RECONSTRUCTED_FORMATTING_ELEMENT
    );
    // Step 9.
    InsertionLocation location =
        get_appropriate_insertion_location(parser, NULL);
    insert_node(clone, location);
    gumbo_vector_add (
      (void*) clone,
      &parser->_parser_state->_open_elements
    );

    // Step 10.
    elements->data[i] = clone;
    gumbo_debug (
      "Reconstructed %s element at %u.\n",
      gumbo_normalized_tagname(clone->v.element.tag),
      i
    );
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x18(%rdi), %r15
movl 0x20(%r15), %eax
testl %eax, %eax
je 0xbe9e
movq %rdi, %rbx
decl %eax
movq 0x18(%r15), %rcx
movq (%rcx,%rax,8), %rdi
leaq 0xfc75(%rip), %r12      # 0x1ba08
cmpq %r12, %rdi
je 0xbe9e
movl 0x10(%r15), %edx
testq %rdx, %rdx
setne %sil
movl %esi, %r8d
je 0xbdd8
movq 0x8(%r15), %r8
cmpq %rdi, (%r8)
je 0xbe9e
movl $0x1, %r10d
movq %r10, %r9
cmpq %r10, %rdx
je 0xbdd1
leaq 0x1(%r9), %r10
cmpq %rdi, (%r8,%r9,8)
jne 0xbdbf
cmpq %rdx, %r9
setb %r8b
testb %r8b, %r8b
jne 0xbe9e
movl %eax, %ebp
subl $0x1, %eax
jb 0xbe2a
movl %eax, %edi
movq (%rcx,%rdi,8), %rdi
cmpq %r12, %rdi
je 0xbe2c
movl %esi, %r8d
testq %rdx, %rdx
je 0xbe23
movq 0x8(%r15), %r8
cmpq %rdi, (%r8)
je 0xbe2c
movl $0x1, %r10d
movq %r10, %r9
cmpq %r10, %rdx
je 0xbe1c
leaq 0x1(%r9), %r10
cmpq %rdi, (%r8,%r9,8)
jne 0xbe0a
cmpq %rdx, %r9
setb %r8b
testb %r8b, %r8b
je 0xbde1
jmp 0xbe2c
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x8107
movl 0x28(%rax), %edi
callq 0x7a30
cmpl 0x20(%r15), %ebp
jae 0xbe9e
movl %ebp, %r13d
movq 0x18(%r15), %rax
movq (%rax,%r13,8), %rdi
cmpq %r12, %rdi
je 0xbead
movl $0x80, %esi
callq 0xccd1
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8864
movq %r14, %rdi
movq %rax, %rsi
callq 0x897d
movq 0x18(%rbx), %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0x7ef9
movq 0x18(%r15), %rax
movq %r14, (%rax,%r13,8)
movl 0x28(%r14), %edi
callq 0x7a30
incq %r13
cmpl 0x20(%r15), %r13d
jb 0xbe45
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x12ea2(%rip), %rdi     # 0x1ed56
leaq 0x11955(%rip), %rsi     # 0x1d810
leaq 0x12e59(%rip), %rcx     # 0x1ed1b
movl $0x577, %edx            # imm = 0x577
callq 0x4100