// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
movq %rdi, %rbx
movl 0x14(%rdi), %ebp
leaq (,%rbp,4), %rdi
callq 0x1140
movq %rax, %r15
movq %rax, (%rbx)
movl 0x10(%rbx), %eax
movq %rax, 0x10(%rsp)
leal 0x1(%rax), %r13d
leaq (,%r13,4), %r14
movq %r14, %rdi
callq 0x1140
movq %rax, %r12
movq %r14, %rdi
callq 0x1140
movq %rax, %r14
testq %r15, %r15
setne %al
testq %r12, %r12
setne %cl
andb %al, %cl
testq %r14, %r14
setne %sil
xorl %eax, %eax
movl $0x53, %edx
andb %cl, %sil
movb %sil, 0x3(%rsp)
cmovnel %eax, %edx
movl %edx, 0x4(%rsp)
je 0xc997
testl %r13d, %r13d
je 0xc647
movq %r13, 0x8(%rsp)
movl 0x8(%rsp), %r13d
shlq $0x2, %r13
movq %r14, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x10e0
movq %r12, %rdi
xorl %esi, %esi
movq %r13, %rdx
movq 0x8(%rsp), %r13
callq 0x10e0
testq %rbp, %rbp
je 0xc661
movq 0x8(%rbx), %rax
xorl %ecx, %ecx
movl (%rax,%rcx,4), %edx
incl (%r12,%rdx,4)
incq %rcx
cmpq %rcx, %rbp
jne 0xc652
cmpl $0x0, 0x10(%rsp)
je 0xc690
cmpl $0x3, %r13d
movl $0x2, %eax
cmovael %r13d, %eax
movl (%r14), %ecx
decq %rax
xorl %edx, %edx
addl (%r12,%rdx,4), %ecx
addl %ecx, %ecx
movl %ecx, 0x4(%r14,%rdx,4)
incq %rdx
cmpq %rdx, %rax
jne 0xc67d
movl 0x14(%rbx), %r13d
testq %r13, %r13
movl 0x4(%rsp), %ebp
je 0xc6d4
movq 0x8(%rbx), %rax
xorl %edx, %edx
movl (%rax,%rdx,4), %ecx
testq %rcx, %rcx
je 0xc6cc
movl (%r14,%rcx,4), %esi
leal 0x1(%rsi), %edi
movl %edi, (%r14,%rcx,4)
movl %esi, (%r15,%rdx,4)
movb (%rax,%rdx,4), %cl
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
shll %cl, %edi
notl %edi
andl %esi, %edi
movl %edi, (%r15,%rdx,4)
incq %rdx
cmpq %rdx, %r13
jne 0xc6a3
movq %r12, %rdi
callq 0x1030
movq %r14, %rdi
callq 0x1030
cmpb $0x0, 0x3(%rsp)
je 0xc9ab
movl $0x800, %edi            # imm = 0x800
callq 0x1140
testq %rax, %rax
je 0xc9bc
movq %rax, %r14
xorl %ebp, %ebp
movl $0x800, %edx            # imm = 0x800
movq %rax, %rdi
xorl %esi, %esi
callq 0x10e0
testq %r13, %r13
je 0xc770
movq 0x8(%rbx), %rax
xorl %edx, %edx
movl (%rax,%rdx,4), %esi
cmpl $0xa, %esi
jb 0xc768
movl (%r15,%rdx,4), %edi
leal -0x9(%rsi), %ecx
shrl %cl, %edi
xorl %r8d, %r8d
movl $0x8, %r9d
xorl %ecx, %ecx
xorl %r10d, %r10d
btl %r9d, %edi
setb %r10b
shll %cl, %r10d
orl %r10d, %r8d
incl %ecx
decl %r9d
cmpl $0x9, %ecx
jne 0xc73d
movl %r8d, %ecx
movl (%r14,%rcx,4), %edi
cmpl %esi, %edi
cmoval %edi, %esi
movl %esi, (%r14,%rcx,4)
incq %rdx
cmpq %r13, %rdx
jne 0xc721
movl $0x200, %r15d           # imm = 0x200
xorl %eax, %eax
movl (%r14,%rax,4), %edx
leal -0x9(%rdx), %ecx
movl $0x1, %r12d
shll %cl, %r12d
cmpl $0xa, %edx
cmovbl %ebp, %r12d
movq %r15, %r13
addq %r12, %r15
incq %rax
cmpq $0x200, %rax            # imm = 0x200
jne 0xc778
movq %r15, %rdi
callq 0x1140
movq %rax, %rbp
movq %rax, 0x18(%rbx)
leaq (%r15,%r15), %rdi
callq 0x1140
movq %rax, 0x20(%rbx)
testq %rbp, %rbp
sete %cl
testq %rax, %rax
sete %al
orb %cl, %al
movl $0x53, %ebp
jne 0xc9a3
testq %r15, %r15
je 0xc7f2
movl %r12d, %eax
addq %r13, %rax
xorl %ecx, %ecx
movq 0x18(%rbx), %rdx
movb $0x10, (%rdx,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0xc7e2
movl $0x200, %eax            # imm = 0x200
xorl %edx, %edx
movl (%r14,%rdx,4), %ecx
cmpl $0xa, %ecx
jb 0xc81e
movq 0x18(%rbx), %rsi
movb %cl, (%rsi,%rdx)
movq 0x20(%rbx), %rsi
movw %ax, (%rsi,%rdx,2)
addb $-0x9, %cl
movl $0x1, %esi
shll %cl, %esi
addq %rsi, %rax
incq %rdx
cmpq $0x200, %rdx            # imm = 0x200
jne 0xc7f9
movq %r14, %rdi
callq 0x1030
cmpl $0x0, 0x14(%rbx)
je 0xc953
xorl %edi, %edi
xorl %r8d, %r8d
movq 0x8(%rbx), %rax
movl (%rax,%rdi,4), %eax
movl $0x0, %r9d
testl %eax, %eax
je 0xc877
movq (%rbx), %rcx
movl (%rcx,%rdi,4), %edx
leal -0x1(%rax), %esi
xorl %r9d, %r9d
xorl %ecx, %ecx
xorl %r10d, %r10d
btl %esi, %edx
setb %r10b
shll %cl, %r10d
orl %r10d, %r9d
incl %ecx
addl $-0x1, %esi
jb 0xc860
testl %eax, %eax
je 0xc8cd
incq %r8
cmpl $0x9, %eax
ja 0xc8d4
movl $0x9, %edx
subl %eax, %edx
movl $0x1, %esi
movl $0x1, %r10d
leal -0x1(%r10), %r11d
movl %eax, %ecx
shll %cl, %r11d
orl %r9d, %r11d
movq 0x18(%rbx), %rcx
cmpb $0x10, (%rcx,%r11)
jne 0xc934
movb %al, (%rcx,%r11)
movl %r10d, %ebp
movl %edx, %ecx
shrl %cl, %ebp
movq 0x20(%rbx), %rcx
movw %di, (%rcx,%r11,2)
incl %r10d
testl %ebp, %ebp
je 0xc895
jmp 0xc932
movl $0x10, %esi
jmp 0xc934
movl %r9d, %ecx
andl $0x1ff, %ecx            # imm = 0x1FF
movq 0x18(%rbx), %rdx
movzbl (%rdx,%rcx), %edx
movl $0x1, %esi
subl %eax, %edx
jb 0xc934
movq 0x20(%rbx), %rsi
movzwl (%rsi,%rcx,2), %r10d
leal -0x9(%rax), %esi
shrl $0x9, %r9d
movl $0x1, %r11d
leal -0x1(%r11), %r14d
movl %esi, %ecx
shll %cl, %r14d
orl %r9d, %r14d
addl %r10d, %r14d
movq 0x18(%rbx), %rcx
movb %al, (%rcx,%r14)
movl %r11d, %ebp
movl %edx, %ecx
shrl %cl, %ebp
movq 0x20(%rbx), %rcx
movw %di, (%rcx,%r14,2)
incl %r11d
testl %ebp, %ebp
je 0xc904
xorl %esi, %esi
testb $0xf, %sil
jne 0xc9ea
incq %rdi
movl 0x14(%rbx), %eax
cmpq %rax, %rdi
jb 0xc841
cmpq $0x2, %r8
jae 0xc9c3
testq %r15, %r15
je 0xc9e6
movl %r12d, %eax
addq %rax, %r13
xorl %eax, %eax
xorl %ebp, %ebp
movq 0x18(%rbx), %rcx
cmpb $0x10, (%rcx,%rax)
jne 0xc98d
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
movw $0xffff, (%rcx,%rax,2)  # imm = 0xFFFF
incq %rax
cmpq %rax, %r13
jne 0xc966
jmp 0xc9ab
movq %r12, %rdi
callq 0x1030
movl 0x4(%rsp), %ebp
movq %r14, %rdi
callq 0x1030
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x53, %ebp
jmp 0xc9ab
testq %r15, %r15
je 0xc9e6
movq 0x18(%rbx), %rax
movl %r12d, %ecx
addq %rcx, %r13
xorl %ecx, %ecx
xorl %ebp, %ebp
cmpb $0x10, (%rax,%rcx)
je 0xc9ea
incq %rcx
cmpq %rcx, %r13
jne 0xc9d6
jmp 0xc9ab
xorl %ebp, %ebp
jmp 0xc9ab
movl $0x37, %ebp
jmp 0xc9ab