// File: phillip-h[P]fractal-gen/lodepng.cpp
// Function: boundaryPM(BPMLists*, BPMNode*, unsigned long, int, int)
static void boundaryPM(BPMLists* lists, BPMNode* leaves, size_t numpresent, int c, int num)
{
  unsigned lastindex = lists->chains1[c]->index;

  if(c == 0)
  {
    if(lastindex >= numpresent) return;
    lists->chains0[c] = lists->chains1[c];
    lists->chains1[c] = bpmnode_create(lists, leaves[lastindex].weight, lastindex + 1, 0);
  }
  else
  {
    /*sum of the weights of the head nodes of the previous lookahead chains.*/
    int sum = lists->chains0[c - 1]->weight + lists->chains1[c - 1]->weight;
    lists->chains0[c] = lists->chains1[c];
    if(lastindex < numpresent && sum > leaves[lastindex].weight)
    {
      lists->chains1[c] = bpmnode_create(lists, leaves[lastindex].weight, lastindex + 1, lists->chains1[c]->tail);
      return;
    }
    lists->chains1[c] = bpmnode_create(lists, sum, lastindex, lists->chains1[c - 1]);
    /*in the end we are only interested in the chain of the last list, so no
    need to recurse if we're at the last one (this gives measurable speedup)*/
    if(num + 1 < (int)(2 * numpresent - 2))
    {
      boundaryPM(lists, leaves, numpresent, c - 1, num);
      boundaryPM(lists, leaves, numpresent, c - 1, num);
    }
  }
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movl %ecx, 0xc(%rsp)
movl %r8d, 0x8(%rsp)
movq 0x20(%rsp), %rax
movq 0x30(%rax), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x4(%rax), %eax
movl %eax, 0x4(%rsp)
cmpl $0x0, 0xc(%rsp)
jne 0x7741
movl 0x4(%rsp), %eax
cmpq 0x10(%rsp), %rax
jb 0x76dc
jmp 0x78a5
movq 0x20(%rsp), %rax
movq 0x30(%rax), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x20(%rsp), %rax
movq 0x28(%rax), %rax
movslq 0xc(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movl 0x4(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %esi
movl 0x4(%rsp), %edx
addl $0x1, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x74b0
movq %rax, %rdx
movq 0x20(%rsp), %rax
movq 0x30(%rax), %rax
movslq 0xc(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x78a5
movq 0x20(%rsp), %rax
movq 0x28(%rax), %rax
movl 0xc(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movl (%rax), %eax
movq 0x20(%rsp), %rcx
movq 0x30(%rcx), %rcx
movl 0xc(%rsp), %edx
subl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
addl (%rcx), %eax
movl %eax, (%rsp)
movq 0x20(%rsp), %rax
movq 0x30(%rax), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rdx
movq 0x20(%rsp), %rax
movq 0x28(%rax), %rax
movslq 0xc(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x4(%rsp), %eax
cmpq 0x10(%rsp), %rax
jae 0x780f
movl (%rsp), %eax
movq 0x18(%rsp), %rcx
movl 0x4(%rsp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jle 0x780f
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rax
movl 0x4(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %esi
movl 0x4(%rsp), %edx
addl $0x1, %edx
movq 0x20(%rsp), %rax
movq 0x30(%rax), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rcx
callq 0x74b0
movq %rax, %rdx
movq 0x20(%rsp), %rax
movq 0x30(%rax), %rax
movslq 0xc(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x78a5
movq 0x20(%rsp), %rdi
movl (%rsp), %esi
movl 0x4(%rsp), %edx
movq 0x20(%rsp), %rax
movq 0x30(%rax), %rax
movl 0xc(%rsp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rcx
callq 0x74b0
movq %rax, %rdx
movq 0x20(%rsp), %rax
movq 0x30(%rax), %rax
movslq 0xc(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x8(%rsp), %eax
addl $0x1, %eax
movq 0x10(%rsp), %rcx
shlq %rcx
subq $0x2, %rcx
cmpl %ecx, %eax
jge 0x78a3
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
movl 0xc(%rsp), %ecx
subl $0x1, %ecx
movl 0x8(%rsp), %r8d
callq 0x7690
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x10(%rsp), %rdx
movl 0xc(%rsp), %ecx
subl $0x1, %ecx
movl 0x8(%rsp), %r8d
callq 0x7690
jmp 0x78a5
addq $0x28, %rsp
retq
nopw (%rax,%rax)