// File: /workspace/github_c_makefile_star2_O0/tditlu[P]shadetabler/src/lodepng/lodepng.c
// Function: HuffmanTree_makeFromLengths2
static unsigned HuffmanTree_makeFromLengths2(HuffmanTree* tree) {
  unsigned* blcount;
  unsigned* nextcode;
  unsigned error = 0;
  unsigned bits, n;

  tree->codes = (unsigned*)lodepng_malloc(tree->numcodes * sizeof(unsigned));
  blcount = (unsigned*)lodepng_malloc((tree->maxbitlen + 1) * sizeof(unsigned));
  nextcode = (unsigned*)lodepng_malloc((tree->maxbitlen + 1) * sizeof(unsigned));
  if(!tree->codes || !blcount || !nextcode) error = 83; /*alloc fail*/

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

  lodepng_free(blcount);
  lodepng_free(nextcode);

  if(!error) error = HuffmanTree_makeTable(tree);
  return error;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x3de0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x3de0
movq %rax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x3de0
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
je 0x1150d
cmpq $0x0, -0x10(%rbp)
je 0x1150d
cmpq $0x0, -0x18(%rbp)
jne 0x11514
movl $0x53, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x11663
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
movl 0x10(%rcx), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x1155d
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
movl $0x0, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
movl $0x0, (%rax,%rcx,4)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x11525
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x14(%rcx), %eax
je 0x11596
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl -0x20(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x11564
movl $0x1, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
ja 0x115de
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movl (%rax,%rcx,4), %edx
movq -0x10(%rbp), %rax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
addl (%rax,%rcx,4), %edx
shll %edx
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x1159d
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x14(%rcx), %eax
je 0x11661
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x24(%rbp), %ecx
cmpl $0x0, (%rax,%rcx,4)
je 0x11654
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl -0x24(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
movl (%rax,%rcx,4), %edx
movl %edx, %esi
addl $0x1, %esi
movl %esi, (%rax,%rcx,4)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x24(%rbp), %ecx
movl %edx, (%rax,%rcx,4)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x24(%rbp), %ecx
movl (%rax,%rcx,4), %ecx
movl $0x1, %edx
shll %cl, %edx
subl $0x1, %edx
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x24(%rbp), %ecx
andl (%rax,%rcx,4), %edx
movl %edx, (%rax,%rcx,4)
jmp 0x11656
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x115e5
jmp 0x11663
movq -0x10(%rbp), %rdi
callq 0x5060
movq -0x18(%rbp), %rdi
callq 0x5060
cmpl $0x0, -0x1c(%rbp)
jne 0x11687
movq -0x8(%rbp), %rdi
callq 0x11690
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq