// File: /workspace/github_c_makefile_star2_O0/Joy-Division[P]tools-mgs/lodepng/lodepng.c
// Function: HuffmanTree_makeFromLengths2
static unsigned HuffmanTree_makeFromLengths2(HuffmanTree* tree)
{
  uivector blcount;
  uivector nextcode;
  unsigned error = 0;
  unsigned bits, n;

  uivector_init(&blcount);
  uivector_init(&nextcode);

  tree->tree1d = (unsigned*)lodepng_malloc(tree->numcodes * sizeof(unsigned));
  if(!tree->tree1d) error = 83; /*alloc fail*/

  if(!uivector_resizev(&blcount, tree->maxbitlen + 1, 0)
  || !uivector_resizev(&nextcode, tree->maxbitlen + 1, 0))
    error = 83; /*alloc fail*/

  if(!error)
  {
    /*step 1: count number of instances of each code length*/
    for(bits = 0; bits != tree->numcodes; ++bits) ++blcount.data[tree->lengths[bits]];
    /*step 2: generate the nextcode values*/
    for(bits = 1; bits <= tree->maxbitlen; ++bits)
    {
      nextcode.data[bits] = (nextcode.data[bits - 1] + blcount.data[bits - 1]) << 1;
    }
    /*step 3: generate all the codes*/
    for(n = 0; n != tree->numcodes; ++n)
    {
      if(tree->lengths[n] != 0) tree->tree1d[n] = nextcode.data[tree->lengths[n]]++;
    }
  }

  uivector_cleanup(&blcount);
  uivector_cleanup(&nextcode);

  if(!error) return HuffmanTree_make2DTree(tree);
  else return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl $0x0, -0x44(%rbp)
leaq -0x28(%rbp), %rdi
callq 0xb750
leaq -0x40(%rbp), %rdi
callq 0xb750
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x13b0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0xb5e4
movl $0x53, -0x44(%rbp)
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
xorl %edx, %edx
callq 0xb780
cmpl $0x0, %eax
je 0xb620
movq -0x10(%rbp), %rax
movl 0x18(%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
leaq -0x40(%rbp), %rdi
xorl %edx, %edx
callq 0xb780
cmpl $0x0, %eax
jne 0xb627
movl $0x53, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0xb710
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
je 0xb66a
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x48(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xb638
movl $0x1, -0x48(%rbp)
movl -0x48(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x18(%rcx), %eax
ja 0xb6b2
movq -0x40(%rbp), %rax
movl -0x48(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edx
movq -0x28(%rbp), %rax
movl -0x48(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
addl (%rax,%rcx,4), %edx
shll %edx
movq -0x40(%rbp), %rax
movl -0x48(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xb671
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
je 0xb70e
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
cmpl $0x0, (%rax,%rcx,4)
je 0xb701
movq -0x40(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x4c(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
movl (%rax,%rcx,4), %edx
movl %edx, %esi
addl $0x1, %esi
movl %esi, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x4c(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
jmp 0xb703
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0xb6b9
jmp 0xb710
leaq -0x28(%rbp), %rdi
callq 0xb800
leaq -0x40(%rbp), %rdi
callq 0xb800
cmpl $0x0, -0x44(%rbp)
jne 0xb736
movq -0x10(%rbp), %rdi
callq 0xb850
movl %eax, -0x4(%rbp)
jmp 0xb73c
movl -0x44(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)