// File: /workspace/github_c_makefile_star2_O3/imaya[P]zopfli-for-emscripten/katajainen.c
// Function: BoundaryPM
static void BoundaryPM(Node* (*lists)[2], int maxbits,
    Node* leaves, int numsymbols, NodePool* pool, int index, char final) {
  Node* newchain;
  Node* oldchain;
  int lastcount = lists[index][1]->count;  /* Count of last chain of list. */

  if (index == 0 && lastcount >= numsymbols) return;

  newchain = GetFreeNode(lists, maxbits, pool);
  oldchain = lists[index][1];

  /* These are set up before the recursive calls below, so that there is a list
  pointing to the new node, to let the garbage collection know it's in use. */
  lists[index][0] = oldchain;
  lists[index][1] = newchain;

  if (index == 0) {
    /* New leaf node in list 0. */
    InitNode(leaves[lastcount].weight, lastcount + 1, 0, newchain);
  } else {
    size_t sum = lists[index - 1][0]->weight + lists[index - 1][1]->weight;
    if (lastcount < numsymbols && sum > leaves[lastcount].weight) {
      /* New leaf inserted in list, so count is incremented. */
      InitNode(leaves[lastcount].weight, lastcount + 1, oldchain->tail,
          newchain);
    } else {
      InitNode(sum, lastcount, lists[index - 1][1], newchain);
      if (!final) {
        /* Two lookahead chains of previous list used up, create new ones. */
        BoundaryPM(lists, maxbits, leaves, numsymbols, pool, index - 1, 0);
        BoundaryPM(lists, maxbits, leaves, numsymbols, pool, index - 1, 0);
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, 0x28(%rsp)
movq %rdx, 0x18(%rsp)
movl %esi, 0x14(%rsp)
movslq %r9d, %rbx
movq %rbx, %rax
shlq $0x4, %rax
movq %rdi, 0x20(%rsp)
movq 0x8(%rdi,%rax), %rdx
movl 0x10(%rdx), %edi
movl %ecx, 0x10(%rsp)
cmpl %ecx, %edi
setl %bpl
testl %ebx, %ebx
setne %r13b
jne 0x612b
cmpl 0x10(%rsp), %edi
jge 0x623c
cmpb $0x0, 0x70(%rsp)
movq 0x20(%rsp), %rcx
leaq 0x8(%rcx,%rax), %r14
sete %r15b
leaq -0x1(%rbx), %r12
decl %ebx
movq %rbx, 0x30(%rsp)
movl %edi, %ebx
movq 0x20(%rsp), %rdi
movl 0x14(%rsp), %esi
movq 0x28(%rsp), %rdx
callq 0x624b
movq (%r14), %rcx
movq %rcx, -0x8(%r14)
movq %rax, (%r14)
testb $0x1, %r13b
je 0x6214
movq -0x18(%r14), %rdx
movq -0x10(%r14), %rsi
movq (%rsi), %rdi
addq (%rdx), %rdi
testb $0x1, %bpl
je 0x619f
movslq %ebx, %rdx
leaq (%rdx,%rdx,2), %rdx
movq 0x18(%rsp), %r8
movq (%r8,%rdx,8), %rdx
cmpq %rdx, %rdi
ja 0x6228
movq %rdi, (%rax)
movl %ebx, 0x10(%rax)
movq %rsi, 0x8(%rax)
movb $0x1, 0x14(%rax)
testb $0x1, %r15b
movq 0x30(%rsp), %rbx
je 0x623c
movl $0x0, (%rsp)
movq 0x20(%rsp), %rdi
movl 0x14(%rsp), %esi
movq 0x18(%rsp), %rdx
movl 0x10(%rsp), %ebp
movl %ebp, %ecx
movq 0x28(%rsp), %r8
movl %ebx, %r9d
callq 0x60dc
movq -0x10(%r14), %rax
addq $-0x10, %r14
movl 0x10(%rax), %edi
cmpl %ebp, %edi
setl %bpl
decl %ebx
movb $0x1, %r15b
addq $-0x1, %r12
setb %r13b
jb 0x6144
cmpl 0x10(%rsp), %edi
jl 0x6144
jmp 0x623c
movslq %ebx, %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x18(%rsp), %rdx
movq (%rdx,%rcx,8), %rdx
xorl %ecx, %ecx
jmp 0x622c
movq 0x8(%rcx), %rcx
incl %ebx
movq %rdx, (%rax)
movl %ebx, 0x10(%rax)
movq %rcx, 0x8(%rax)
movb $0x1, 0x14(%rax)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq