// File: /workspace/github_c_makefile_star2_O3/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, %r14
movq %rax, (%rbx)
movl 0x10(%rbx), %eax
movq %rax, 0x10(%rsp)
incl %eax
movq %rax, 0x8(%rsp)
leaq (,%rax,4), %r13
movq %r13, %rdi
callq 0x1140
movq %rax, %r12
movq %r13, %rdi
callq 0x1140
movq %rax, %r15
testq %r14, %r14
je 0xc820
testq %r12, %r12
je 0xc820
testq %r15, %r15
je 0xc820
cmpl $0x0, 0x8(%rsp)
je 0xc512
movq %r15, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x10e0
movq %r12, %rdi
xorl %esi, %esi
movq %r13, %rdx
callq 0x10e0
testq %rbp, %rbp
je 0xc52c
movq 0x8(%rbx), %rax
xorl %ecx, %ecx
movl (%rax,%rcx,4), %edx
incl (%r12,%rdx,4)
incq %rcx
cmpq %rcx, %rbp
jne 0xc51d
cmpl $0x0, 0x10(%rsp)
je 0xc55e
movq 0x8(%rsp), %rcx
cmpl $0x3, %ecx
movl $0x2, %eax
cmovael %ecx, %eax
movl (%r15), %ecx
decq %rax
xorl %edx, %edx
addl (%r12,%rdx,4), %ecx
addl %ecx, %ecx
movl %ecx, 0x4(%r15,%rdx,4)
incq %rdx
cmpq %rdx, %rax
jne 0xc54b
testl %ebp, %ebp
je 0xc599
movq 0x8(%rbx), %rax
xorl %edx, %edx
movl (%rax,%rdx,4), %ecx
testq %rcx, %rcx
je 0xc591
movl (%r15,%rcx,4), %esi
leal 0x1(%rsi), %edi
movl %edi, (%r15,%rcx,4)
movl %esi, (%r14,%rdx,4)
movb (%rax,%rdx,4), %cl
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
shll %cl, %edi
notl %edi
andl %esi, %edi
movl %edi, (%r14,%rdx,4)
incq %rdx
cmpq %rdx, %rbp
jne 0xc568
movq %r12, %rdi
callq 0x1030
movq %r15, %rdi
callq 0x1030
movl $0x1, %edi
movl $0x800, %esi            # imm = 0x800
callq 0x10f0
movq %rax, %r15
movl $0x53, %eax
testq %r15, %r15
je 0xc835
testl %ebp, %ebp
je 0xc622
movq 0x8(%rbx), %rax
xorl %edx, %edx
movl (%rax,%rdx,4), %esi
cmpl $0xa, %esi
jb 0xc61a
movl (%r14,%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 0xc5ef
movl %r8d, %ecx
movl (%r15,%rcx,4), %edi
cmpl %esi, %edi
cmoval %edi, %esi
movl %esi, (%r15,%rcx,4)
incq %rdx
cmpq %rbp, %rdx
jne 0xc5d3
movl $0x200, %r14d           # imm = 0x200
xorl %eax, %eax
xorl %edx, %edx
movl (%r15,%rdx,4), %esi
leal -0x9(%rsi), %ecx
movl $0x1, %ebp
shll %cl, %ebp
cmpl $0xa, %esi
cmovbl %eax, %ebp
movq %r14, %r13
addq %rbp, %r14
incq %rdx
cmpq $0x200, %rdx            # imm = 0x200
jne 0xc62c
movq %r14, %rdi
callq 0x1140
movq %rax, %r12
movq %rax, 0x18(%rbx)
leaq (%r14,%r14), %rdi
callq 0x1140
movq %rax, 0x20(%rbx)
testq %r12, %r12
sete %cl
testq %rax, %rax
sete %al
orb %cl, %al
jne 0xc828
testq %r14, %r14
je 0xc69e
movl %ebp, %eax
addq %r13, %rax
xorl %ecx, %ecx
movq 0x18(%rbx), %rdx
movb $0x10, (%rdx,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0xc68e
movw $0x200, %dx             # imm = 0x200
xorl %eax, %eax
movl (%r15,%rax,4), %ecx
cmpl $0xa, %ecx
jb 0xc6ca
movq 0x18(%rbx), %rsi
movb %cl, (%rsi,%rax)
addb $-0x9, %cl
movl $0x1, %esi
shll %cl, %esi
movq 0x20(%rbx), %rcx
movw %dx, (%rcx,%rax,2)
addl %edx, %esi
movl %esi, %edx
incq %rax
cmpq $0x200, %rax            # imm = 0x200
jne 0xc6a4
movq %r15, %rdi
callq 0x1030
cmpl $0x0, 0x14(%rbx)
je 0xc7e1
xorl %edi, %edi
xorl %r8d, %r8d
movq 0x8(%rbx), %rax
movl (%rax,%rdi,4), %eax
testl %eax, %eax
je 0xc7cc
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 0xc709
incq %r8
cmpl $0x9, %eax
ja 0xc76d
movl $0x9, %edx
subl %eax, %edx
movl $0x1, %esi
leal -0x1(%rsi), %r10d
movl %eax, %ecx
shll %cl, %r10d
orl %r9d, %r10d
movq 0x18(%rbx), %rcx
cmpb $0x10, (%rcx,%r10)
jne 0xc866
movb %al, (%rcx,%r10)
movl %esi, %r11d
movl %edx, %ecx
shrl %cl, %r11d
movq 0x20(%rbx), %rcx
movw %di, (%rcx,%r10,2)
incl %esi
testl %r11d, %r11d
je 0xc734
jmp 0xc7cc
movl %r9d, %ecx
andl $0x1ff, %ecx            # imm = 0x1FF
movq 0x18(%rbx), %rdx
movzbl (%rdx,%rcx), %edx
subl %eax, %edx
jb 0xc866
movq 0x20(%rbx), %rsi
movzwl (%rsi,%rcx,2), %r10d
leal -0x9(%rax), %esi
shrl $0x9, %r9d
movl $0x1, %r11d
leal -0x1(%r11), %r15d
movl %esi, %ecx
shll %cl, %r15d
orl %r9d, %r15d
addl %r10d, %r15d
movq 0x18(%rbx), %rcx
movb %al, (%rcx,%r15)
movl %r11d, %r12d
movl %edx, %ecx
shrl %cl, %r12d
movq 0x20(%rbx), %rcx
movw %di, (%rcx,%r15,2)
incl %r11d
testl %r12d, %r12d
je 0xc79c
incq %rdi
movl 0x14(%rbx), %eax
cmpq %rax, %rdi
jb 0xc6ec
cmpq $0x2, %r8
jae 0xc844
testq %r14, %r14
je 0xc81c
movl %ebp, %eax
addq %rax, %r13
xorl %eax, %eax
movq 0x18(%rbx), %rcx
cmpb $0x10, (%rcx,%rax)
jne 0xc814
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 0xc7ed
xorl %eax, %eax
jmp 0xc835
movq %r12, %rdi
callq 0x1030
movq %r15, %rdi
callq 0x1030
movl $0x53, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %r14, %r14
je 0xc81c
movq 0x18(%rbx), %rdx
movl %ebp, %ecx
addq %rcx, %r13
xorl %ecx, %ecx
xorl %eax, %eax
cmpb $0x10, (%rdx,%rcx)
je 0xc866
incq %rcx
cmpq %rcx, %r13
jne 0xc856
jmp 0xc835
movl $0x37, %eax
jmp 0xc835