// File: /workspace/github_c_makefile_star2_O3/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 0xb5b7
decl %eax
movq 0x18(%r15), %rcx
movq (%rcx,%rax,8), %rsi
leaq 0xe675(%rip), %r12      # 0x19b28
cmpq %r12, %rsi
je 0xb5b7
movq %rdi, %rbx
movl 0x10(%r15), %edx
testq %rdx, %rdx
je 0xb4f6
movq 0x8(%r15), %rdi
cmpq %rsi, (%rdi)
je 0xb5b7
movl $0x1, %r9d
movq %r9, %r8
cmpq %r9, %rdx
je 0xb4ed
leaq 0x1(%r8), %r9
cmpq %rsi, (%rdi,%r8,8)
jne 0xb4db
cmpq %rdx, %r8
jb 0xb5b7
xorl %ebp, %ebp
testq %rax, %rax
je 0xb542
leaq -0x1(%rax), %rsi
movl %esi, %edi
movq (%rcx,%rdi,8), %rdi
cmpq %r12, %rdi
je 0xb540
testq %rdx, %rdx
je 0xb537
movq 0x8(%r15), %r8
cmpq %rdi, (%r8)
je 0xb540
movl $0x1, %r10d
movq %r10, %r9
cmpq %r10, %rdx
je 0xb532
leaq 0x1(%r9), %r10
cmpq %rdi, (%r8,%r9,8)
jne 0xb520
cmpq %rdx, %r9
jb 0xb540
movq %rsi, %rax
testl %esi, %esi
jne 0xb4fd
jmp 0xb542
movl %eax, %ebp
movq %rbx, %rdi
callq 0x7d33
movl 0x28(%rax), %edi
callq 0x7694
cmpl 0x20(%r15), %ebp
jae 0xb5b7
movl %ebp, %r13d
movq 0x18(%r15), %rax
movq (%rax,%r13,8), %rdi
cmpq %r12, %rdi
je 0xb5c6
movl $0x80, %esi
callq 0xc2dd
movq %rax, %r14
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8437
movq %r14, %rdi
movq %rax, %rsi
callq 0x854d
movq 0x18(%rbx), %rsi
addq $0x8, %rsi
movq %r14, %rdi
callq 0x7b25
movq 0x18(%r15), %rax
movq %r14, (%rax,%r13,8)
movl 0x28(%r14), %edi
callq 0x7694
incq %r13
movl 0x20(%r15), %eax
cmpq %rax, %r13
jb 0xb55b
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x118a9(%rip), %rdi     # 0x1ce76
leaq 0x1035c(%rip), %rsi     # 0x1b930
leaq 0x11860(%rip), %rcx     # 0x1ce3b
movl $0x577, %edx            # imm = 0x577
callq 0x4100