// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
addq $0x18, %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0xf88b
jmp 0xfa8c
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
leaq 0x213ff(%rip), %rax     # 0x30cb0
cmpq %rax, -0x20(%rbp)
je 0xf8ca
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x11010
testb $0x1, %al
jne 0xf8ca
jmp 0xf8cf
jmp 0xfa8c
jmp 0xf8d1
cmpl $0x0, -0x14(%rbp)
jne 0xf8e0
movl $0xffffffff, -0x14(%rbp) # imm = 0xFFFFFFFF
jmp 0xf925
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x14(%rbp), %ecx
addl $-0x1, %ecx
movl %ecx, -0x14(%rbp)
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
xorl %eax, %eax
leaq 0x213ad(%rip), %rcx     # 0x30cb0
cmpq %rcx, -0x20(%rbp)
movb %al, -0x39(%rbp)
je 0xf91e
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x11010
xorb $-0x1, %al
movb %al, -0x39(%rbp)
movb -0x39(%rbp), %al
testb $0x1, %al
jne 0xf8d1
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rdi
callq 0x7550
movl 0x28(%rax), %edi
callq 0x5f80
movl -0x40(%rbp), %esi
movq %rax, %rdx
leaq 0x24ccf(%rip), %rdi     # 0x34621
movb $0x0, %al
callq 0x7540
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jae 0xfa8c
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jbe 0xf975
jmp 0xf994
leaq 0x23a86(%rip), %rdi     # 0x33402
leaq 0x234f1(%rip), %rsi     # 0x32e74
movl $0x574, %edx            # imm = 0x574
leaq 0x24cc1(%rip), %rcx     # 0x34650
callq 0x4100
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jae 0xf9a2
jmp 0xf9c1
leaq 0x24ce2(%rip), %rdi     # 0x3468b
leaq 0x234c4(%rip), %rsi     # 0x32e74
movl $0x575, %edx            # imm = 0x575
leaq 0x24c94(%rip), %rcx     # 0x34650
callq 0x4100
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x14(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
leaq 0x212d6(%rip), %rax     # 0x30cb0
cmpq %rax, -0x20(%rbp)
je 0xf9e2
jmp 0xfa01
leaq 0x24cb7(%rip), %rdi     # 0x346a0
leaq 0x23484(%rip), %rsi     # 0x32e74
movl $0x577, %edx            # imm = 0x577
leaq 0x24c54(%rip), %rcx     # 0x34650
callq 0x4100
movq -0x20(%rbp), %rdi
movl $0x80, %esi
callq 0x11080
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x81d0
movq %rax, -0x38(%rbp)
movl %edx, -0x30(%rbp)
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl -0x30(%rbp), %edx
callq 0x8420
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rsi
addq $0x8, %rsi
callq 0x6a80
movq -0x28(%rbp), %rdx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x14(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movl 0x28(%rax), %edi
callq 0x5f80
movq %rax, %rsi
movl -0x14(%rbp), %edx
leaq 0x24c52(%rip), %rdi     # 0x346c9
movb $0x0, %al
callq 0x7540
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0xf959
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)