// File: phillip-h[P]fractal-gen/lodepng.cpp
// Function: bpmnode_create(BPMLists*, int, unsigned int, BPMNode*)
static BPMNode* bpmnode_create(BPMLists* lists, int weight, unsigned index, BPMNode* tail)
{
  unsigned i;
  BPMNode* result;

  /*memory full, so garbage collect*/
  if(lists->nextfree >= lists->numfree)
  {
    /*mark only those that are in use*/
    for(i = 0; i != lists->memsize; ++i) lists->memory[i].in_use = 0;
    for(i = 0; i != lists->listsize; ++i)
    {
      BPMNode* node;
      for(node = lists->chains0[i]; node != 0; node = node->tail) node->in_use = 1;
      for(node = lists->chains1[i]; node != 0; node = node->tail) node->in_use = 1;
    }
    /*collect those that are free*/
    lists->numfree = 0;
    for(i = 0; i != lists->memsize; ++i)
    {
      if(!lists->memory[i].in_use) lists->freelist[lists->numfree++] = &lists->memory[i];
    }
    lists->nextfree = 0;
  }

  result = lists->freelist[lists->nextfree++];
  result->weight = weight;
  result->index = index;
  result->tail = tail;
  return result;
}

// Assembly:
movq %rdi, -0x8(%rsp)
movl %esi, -0xc(%rsp)
movl %edx, -0x10(%rsp)
movq %rcx, -0x18(%rsp)
movq -0x8(%rsp), %rax
movl 0x14(%rax), %eax
movq -0x8(%rsp), %rcx
cmpl 0x10(%rcx), %eax
jb 0x763e
movl $0x0, -0x1c(%rsp)
movl -0x1c(%rsp), %eax
movq -0x8(%rsp), %rcx
cmpl (%rcx), %eax
je 0x7515
movq -0x8(%rsp), %rax
movq 0x8(%rax), %rax
movl -0x1c(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x10(%rax)
movl -0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rsp)
jmp 0x74e0
movl $0x0, -0x1c(%rsp)
movl -0x1c(%rsp), %eax
movq -0x8(%rsp), %rcx
cmpl 0x20(%rcx), %eax
je 0x75b5
movq -0x8(%rsp), %rax
movq 0x28(%rax), %rax
movl -0x1c(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rsp)
cmpq $0x0, -0x30(%rsp)
je 0x7569
movq -0x30(%rsp), %rax
movl $0x1, 0x10(%rax)
movq -0x30(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rsp)
jmp 0x7545
movq -0x8(%rsp), %rax
movq 0x30(%rax), %rax
movl -0x1c(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rsp)
cmpq $0x0, -0x30(%rsp)
je 0x75a3
movq -0x30(%rsp), %rax
movl $0x1, 0x10(%rax)
movq -0x30(%rsp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x30(%rsp)
jmp 0x757f
jmp 0x75a5
movl -0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rsp)
jmp 0x751d
movq -0x8(%rsp), %rax
movl $0x0, 0x10(%rax)
movl $0x0, -0x1c(%rsp)
movl -0x1c(%rsp), %eax
movq -0x8(%rsp), %rcx
cmpl (%rcx), %eax
je 0x7632
movq -0x8(%rsp), %rax
movq 0x8(%rax), %rax
movl -0x1c(%rsp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x10(%rax)
jne 0x7623
movq -0x8(%rsp), %rax
movq 0x8(%rax), %rdx
movl -0x1c(%rsp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rdx
movq -0x8(%rsp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rsp), %rsi
movl 0x10(%rsi), %ecx
movl %ecx, %edi
addl $0x1, %edi
movl %edi, 0x10(%rsi)
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
jmp 0x7625
movl -0x1c(%rsp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rsp)
jmp 0x75c9
movq -0x8(%rsp), %rax
movl $0x0, 0x14(%rax)
movq -0x8(%rsp), %rax
movq 0x18(%rax), %rax
movq -0x8(%rsp), %rdx
movl 0x14(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x14(%rdx)
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x28(%rsp)
movl -0xc(%rsp), %ecx
movq -0x28(%rsp), %rax
movl %ecx, (%rax)
movl -0x10(%rsp), %ecx
movq -0x28(%rsp), %rax
movl %ecx, 0x4(%rax)
movq -0x18(%rsp), %rcx
movq -0x28(%rsp), %rax
movq %rcx, 0x8(%rax)
movq -0x28(%rsp), %rax
retq
nopl (%rax)