// File: /workspace/github_c_makefile_star2_O0/Joy-Division[P]tools-mgs/lodepng/lodepng.c
// Function: bpmnode_sort
static void bpmnode_sort(BPMNode* leaves, size_t num)
{
  BPMNode* mem = (BPMNode*)lodepng_malloc(sizeof(*leaves) * num);
  size_t width, counter = 0;
  for(width = 1; width < num; width *= 2)
  {
    BPMNode* a = (counter & 1) ? mem : leaves;
    BPMNode* b = (counter & 1) ? leaves : mem;
    size_t p;
    for(p = 0; p < num; p += 2 * width)
    {
      size_t q = (p + width > num) ? num : (p + width);
      size_t r = (p + 2 * width > num) ? num : (p + 2 * width);
      size_t i = p, j = q, k;
      for(k = p; k < r; k++)
      {
        if(i < q && (j >= r || a[i].weight <= a[j].weight)) b[k] = a[i++];
        else b[k] = a[j++];
      }
    }
    counter++;
  }
  if(counter & 1) memcpy(leaves, mem, sizeof(*leaves) * num);
  lodepng_free(mem);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
imulq $0x18, -0x10(%rbp), %rdi
callq 0x13b0
movq %rax, -0x18(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x1, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x1a89
movq -0x28(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x18b7
movq -0x18(%rbp), %rax
movq %rax, -0x70(%rbp)
jmp 0x18bf
movq -0x8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x18df
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x18e7
movq -0x18(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x10(%rbp), %rax
jae 0x1a6d
movq -0x40(%rbp), %rax
addq -0x20(%rbp), %rax
cmpq -0x10(%rbp), %rax
jbe 0x191d
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
jmp 0x1929
movq -0x40(%rbp), %rax
addq -0x20(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
shlq %rcx
addq %rcx, %rax
cmpq -0x10(%rbp), %rax
jbe 0x1952
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
jmp 0x1967
movq -0x40(%rbp), %rax
movq -0x20(%rbp), %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x1a57
movq -0x58(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x1a08
movq -0x60(%rbp), %rax
cmpq -0x50(%rbp), %rax
jae 0x19ca
movq -0x30(%rbp), %rax
imulq $0x18, -0x58(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
movq -0x30(%rbp), %rcx
imulq $0x18, -0x60(%rbp), %rdx
addq %rdx, %rcx
cmpl (%rcx), %eax
jg 0x1a08
movq -0x38(%rbp), %rax
imulq $0x18, -0x68(%rbp), %rcx
addq %rcx, %rax
movq -0x30(%rbp), %rcx
movq -0x58(%rbp), %rdx
movq %rdx, %rsi
addq $0x1, %rsi
movq %rsi, -0x58(%rbp)
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
jmp 0x1a44
movq -0x38(%rbp), %rax
imulq $0x18, -0x68(%rbp), %rcx
addq %rcx, %rax
movq -0x30(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq %rdx, %rsi
addq $0x1, %rsi
movq %rsi, -0x60(%rbp)
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
jmp 0x1a46
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0x198a
jmp 0x1a59
movq -0x20(%rbp), %rax
shlq %rax
addq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x18f7
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
shlq %rax
movq %rax, -0x20(%rbp)
jmp 0x1891
movq -0x28(%rbp), %rax
andq $0x1, %rax
cmpq $0x0, %rax
je 0x1aa9
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
imulq $0x18, -0x10(%rbp), %rdx
callq 0x10c0
movq -0x18(%rbp), %rdi
callq 0x1e60
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)