// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movl 0x14(%rdi), %ebp
leaq (,%rbp,4), %rdi
callq 0x1130
movq %rax, (%rsp)
movq %rax, (%rbx)
movl 0x10(%rbx), %r14d
leal 0x1(%r14), %r12d
leaq (,%r12,4), %r15
movq %r15, %rdi
callq 0x1130
movq %rax, %r13
movq %r15, %rdi
callq 0x1130
movq (%rsp), %r9
movq %rax, %r15
testq %r9, %r9
je 0xa9b5
testq %r13, %r13
je 0xa9b5
testq %r15, %r15
je 0xa9b5
xorl %eax, %eax
cmpq %rax, %r12
je 0xa9c2
andl $0x0, (%r15,%rax,4)
andl $0x0, (%r13,%rax,4)
incq %rax
jmp 0xa9a0
movq %r13, %rdi
callq 0x1030
jmp 0xab0d
xorl %eax, %eax
cmpq %rax, %rbp
je 0xa9da
movq 0x8(%rbx), %rcx
movl (%rcx,%rax,4), %ecx
incl (%r13,%rcx,4)
incq %rax
jmp 0xa9c4
pushq $0x1
popq %rax
cmpq %r14, %rax
ja 0xa9f7
movl -0x4(%r13,%rax,4), %ecx
addl -0x4(%r15,%rax,4), %ecx
addl %ecx, %ecx
movl %ecx, (%r15,%rax,4)
incq %rax
jmp 0xa9dd
xorl %eax, %eax
pushq $-0x1
popq %rdx
cmpq %rax, %rbp
je 0xaa31
movq 0x8(%rbx), %rcx
movl (%rcx,%rax,4), %esi
testq %rsi, %rsi
je 0xaa2c
movl (%r15,%rsi,4), %edi
leal 0x1(%rdi), %r8d
movl %r8d, (%r15,%rsi,4)
movl %edi, (%r9,%rax,4)
movb (%rcx,%rax,4), %cl
movl %edx, %esi
shll %cl, %esi
notl %esi
andl %edi, %esi
movl %esi, (%r9,%rax,4)
incq %rax
jmp 0xa9fc
movq %r13, %rdi
callq 0x1030
movq %r15, %rdi
callq 0x1030
movl $0x800, %edi            # imm = 0x800
callq 0x1130
testq %rax, %rax
je 0xab15
movq %rax, %r15
xorl %eax, %eax
cmpq $0x800, %rax            # imm = 0x800
je 0xaa6b
movb $0x0, (%r15,%rax)
incq %rax
jmp 0xaa59
xorl %r14d, %r14d
pushq $0x9
popq %r13
cmpq %r14, %rbp
je 0xaab2
movq 0x8(%rbx), %rax
movl (%rax,%r14,4), %r12d
cmpl $0xa, %r12d
jb 0xaaad
movq (%rsp), %rax
movl (%rax,%r14,4), %edi
leal -0x9(%r12), %ecx
shrl %cl, %edi
movl %r13d, %esi
callq 0xacb7
movl %eax, %eax
movl (%r15,%rax,4), %ecx
cmpl %r12d, %ecx
cmoval %ecx, %r12d
movl %r12d, (%r15,%rax,4)
incq %r14
jmp 0xaa72
movl $0x200, %r12d           # imm = 0x200
xorl %eax, %eax
pushq $0x1
popq %rbp
xorl %edx, %edx
cmpq $0x200, %rdx            # imm = 0x200
je 0xaae1
movl (%r15,%rdx,4), %esi
leal -0x9(%rsi), %ecx
movl %ebp, %edi
shll %cl, %edi
cmpl $0xa, %esi
cmovbl %eax, %edi
addq %rdi, %r12
incq %rdx
jmp 0xaabf
movq %r12, %rdi
callq 0x1130
movq %rax, %r13
movq %rax, 0x18(%rbx)
leaq (%r12,%r12), %rdi
callq 0x1130
movq %rax, 0x20(%rbx)
testq %r13, %r13
sete %cl
testq %rax, %rax
sete %al
orb %cl, %al
je 0xab29
movq %r15, %rdi
callq 0x1030
pushq $0x53
popq %rsi
movl %esi, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
cmpq %rax, %r12
je 0xab3d
movq 0x18(%rbx), %rcx
movb $0x10, (%rcx,%rax)
incq %rax
jmp 0xab2b
movw $0x200, %dx             # imm = 0x200
xorl %eax, %eax
cmpq $0x200, %rax            # imm = 0x200
je 0xab73
movl (%r15,%rax,4), %ecx
cmpl $0xa, %ecx
jb 0xab6e
movq 0x18(%rbx), %rsi
movb %cl, (%rsi,%rax)
addb $-0x9, %cl
movl %ebp, %esi
shll %cl, %esi
movq 0x20(%rbx), %rcx
movw %dx, (%rcx,%rax,2)
addl %edx, %esi
movl %esi, %edx
incq %rax
jmp 0xab43
movq %r15, %rdi
callq 0x1030
xorl %r15d, %r15d
pushq $0x37
popq %rbp
xorl %r13d, %r13d
movl 0x14(%rbx), %eax
cmpq %rax, %r13
jae 0xac5b
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movl (%rcx,%r13,4), %r14d
movl (%rax,%r13,4), %edi
movl %r14d, %esi
callq 0xacb7
testl %r14d, %r14d
je 0xac53
incq %r15
cmpl $0x9, %r14d
ja 0xabf7
pushq $0x9
popq %rdx
subl %r14d, %edx
xorl %esi, %esi
movl %esi, %edi
movl %edx, %ecx
shrl %cl, %edi
testl %edi, %edi
jne 0xac53
movl %esi, %edi
movl %r14d, %ecx
shll %cl, %edi
orl %eax, %edi
movq 0x18(%rbx), %rcx
cmpb $0x10, (%rcx,%rdi)
jne 0xacb0
movb %r14b, (%rcx,%rdi)
movq 0x20(%rbx), %rcx
movw %r13w, (%rcx,%rdi,2)
incl %esi
jmp 0xabc1
movl %eax, %ecx
andl $0x1ff, %ecx            # imm = 0x1FF
movq 0x18(%rbx), %rdx
movzbl (%rdx,%rcx), %edx
subl %r14d, %edx
jb 0xacb0
movq 0x20(%rbx), %rsi
movzwl (%rsi,%rcx,2), %edi
leal -0x9(%r14), %esi
shrl $0x9, %eax
xorl %r8d, %r8d
movl %r8d, %r9d
movl %edx, %ecx
shrl %cl, %r9d
testl %r9d, %r9d
jne 0xac53
movl %r8d, %r9d
movl %esi, %ecx
shll %cl, %r9d
orl %eax, %r9d
addl %edi, %r9d
movq 0x18(%rbx), %rcx
movb %r14b, (%rcx,%r9)
movq 0x20(%rbx), %rcx
movw %r13w, (%rcx,%r9,2)
incl %r8d
jmp 0xac22
incq %r13
jmp 0xab84
xorl %esi, %esi
xorl %eax, %eax
cmpq $0x2, %r15
jae 0xac99
cmpq %rax, %r12
je 0xab18
movq 0x18(%rbx), %rcx
cmpb $0x10, (%rcx,%rax)
jne 0xac94
xorl %edx, %edx
cmpq $0x200, %rax            # imm = 0x200
setae %dl
leal (%rdx,%rdx,8), %edx
incl %edx
movb %dl, (%rcx,%rax)
movq 0x20(%rbx), %rcx
orw $-0x1, (%rcx,%rax,2)
incq %rax
jmp 0xac65
cmpq %rax, %r12
je 0xab18
movq 0x18(%rbx), %rcx
cmpb $0x10, (%rcx,%rax)
leaq 0x1(%rax), %rax
jne 0xac99
movl %ebp, %esi
jmp 0xab18