// File: /workspace/github_cpp_makefile_star2_O3/drummyfish[P]flowchart/src/lodepng.cpp
// Function: HuffmanTree_makeFromLengths2(HuffmanTree*)
static unsigned HuffmanTree_makeFromLengths2(HuffmanTree* tree)
{
  uivector blcount;
  uivector nextcode;
  unsigned bits, n, error = 0;

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

  tree->tree1d = (unsigned*)mymalloc(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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbp
movl 0x1c(%rdi), %r14d
leaq (,%r14,4), %rdi
callq 0x2270
movq %rax, %rbx
movl 0x18(%rbp), %r13d
leal 0x1(%r13), %r12d
movl %r13d, %eax
movq %rbx, 0x8(%rbp)
incl %eax
jne 0xbe47
movq %r12, (%rsp)
xorl %r12d, %r12d
xorl %r15d, %r15d
jmp 0xbeb1
movq %rbp, 0x10(%rsp)
leaq (,%r12,8), %rbp
movq %rbp, %rdi
callq 0x2270
testq %rax, %rax
je 0xc120
movq %rax, %r15
movq %r12, (%rsp)
leaq (,%r12,4), %rdx
xorl %r12d, %r12d
movq %rax, %rdi
xorl %esi, %esi
movq %rdx, 0x8(%rsp)
callq 0x2100
movq %rbp, %rdi
callq 0x2270
testq %rax, %rax
je 0xc126
movq %rax, %rbp
movq %rax, %rdi
xorl %esi, %esi
movq 0x8(%rsp), %rdx
callq 0x2100
movq %rbp, %r12
movq 0x10(%rsp), %rbp
testq %rbx, %rbx
je 0xc126
testq %r14, %r14
je 0xbed4
movq 0x10(%rbp), %rax
xorl %ecx, %ecx
movl (%rax,%rcx,4), %edx
incl (%r15,%rdx,4)
incq %rcx
cmpq %rcx, %r14
jne 0xbec5
testl %r13d, %r13d
je 0xbf04
movq (%rsp), %rcx
cmpl $0x3, %ecx
movl $0x2, %eax
cmovael %ecx, %eax
movl (%r12), %ecx
decq %rax
xorl %edx, %edx
addl (%r15,%rdx,4), %ecx
addl %ecx, %ecx
movl %ecx, 0x4(%r12,%rdx,4)
incq %rdx
cmpq %rdx, %rax
jne 0xbef1
testq %r14, %r14
je 0xbf2d
movq 0x10(%rbp), %rax
xorl %ecx, %ecx
movl (%rax,%rcx,4), %edx
testq %rdx, %rdx
je 0xbf25
movl (%r12,%rdx,4), %esi
leal 0x1(%rsi), %edi
movl %edi, (%r12,%rdx,4)
movl %esi, (%rbx,%rcx,4)
incq %rcx
cmpq %rcx, %r14
jne 0xbf0f
movq %r15, %rdi
callq 0x2220
movq %r12, %rdi
callq 0x2220
leal (%r14,%r14), %r15d
leaq (,%r15,4), %rdi
callq 0x2270
movq %rax, (%rbp)
testq %rax, %rax
je 0xc136
testq %r15, %r15
je 0xc05f
leaq 0x3(%r15), %rcx
andq $-0x4, %rcx
leaq -0x1(%r15), %rdx
movq %rdx, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movdqa 0x60be(%rip), %xmm1     # 0x12040
movdqa 0x60c6(%rip), %xmm2     # 0x12050
xorl %edx, %edx
movdqa 0x60cc(%rip), %xmm3     # 0x12060
pxor %xmm3, %xmm0
pcmpeqd %xmm4, %xmm4
movdqa 0x614c(%rip), %xmm5     # 0x120f0
movdqa %xmm2, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %esi
notl %esi
testb $0x1, %sil
je 0xbfe0
movl $0x7fff, (%rax,%rdx,4)  # imm = 0x7FFF
pxor %xmm4, %xmm6
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0xbff7
movl $0x7fff, 0x4(%rax,%rdx,4) # imm = 0x7FFF
movdqa %xmm1, %xmm6
pxor %xmm3, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
pxor %xmm4, %xmm6
pextrw $0x0, %xmm6, %esi
testb $0x1, %sil
je 0xc037
movl $0x7fff, 0x8(%rax,%rdx,4) # imm = 0x7FFF
pextrw $0x4, %xmm6, %esi
testb $0x1, %sil
je 0xc04a
movl $0x7fff, 0xc(%rax,%rdx,4) # imm = 0x7FFF
addq $0x4, %rdx
paddq %xmm5, %xmm2
paddq %xmm5, %xmm1
cmpq %rdx, %rcx
jne 0xbfa4
testq %r14, %r14
je 0xc153
movq 0x10(%rbp), %rcx
xorl %edx, %edx
leal -0x2(%r14), %esi
xorl %r8d, %r8d
xorl %edi, %edi
movl (%rcx,%rdx,4), %r9d
testl %r9d, %r9d
je 0xc0f1
xorl %r10d, %r10d
cmpl %esi, %r8d
ja 0xc14c
movl (%rbx,%rdx,4), %r11d
movl %r10d, %ebp
notl %ebp
addl %r9d, %ebp
xorl %r12d, %r12d
btl %ebp, %r11d
setb %r12b
leal (%r12,%r8,2), %r11d
movl (%rax,%r11,4), %r8d
cmpl $0x7fff, %r8d           # imm = 0x7FFF
jne 0xc0c5
incl %r10d
cmpl %r9d, %r10d
jne 0xc0d0
movl %edx, (%rax,%r11,4)
xorl %r8d, %r8d
jmp 0xc0e5
subl %r14d, %r8d
incl %r10d
movl %r10d, %r9d
jmp 0xc0e5
movl %edi, %r8d
incl %r8d
addl %r14d, %edi
incl %edi
movl %edi, (%rax,%r11,4)
movl %r10d, %r9d
movl %r8d, %edi
movl %r9d, %r10d
movl (%rcx,%rdx,4), %r9d
cmpl %r9d, %r10d
jb 0xc083
incq %rdx
cmpq %r14, %rdx
jne 0xc077
testl %r15d, %r15d
je 0xc153
xorl %edx, %edx
xorl %ecx, %ecx
cmpl $0x7fff, (%rax,%rdx,4)  # imm = 0x7FFF
jne 0xc116
movl $0x0, (%rax,%rdx,4)
incq %rdx
cmpq %rdx, %r15
jne 0xc106
jmp 0xc13b
xorl %r12d, %r12d
xorl %r15d, %r15d
movq %r15, %rdi
callq 0x2220
movq %r12, %rdi
callq 0x2220
movl $0x53, %ecx
movl %ecx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x37, %ecx
jmp 0xc13b
xorl %ecx, %ecx
jmp 0xc13b