// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/libraries/libwebp/src/utils/huffman_utils.c
// Function: VP8LBuildHuffmanTable
int VP8LBuildHuffmanTable(HuffmanTables* const root_table, int root_bits,
                          const int code_lengths[], int code_lengths_size) {
  const int total_size =
      BuildHuffmanTable(NULL, root_bits, code_lengths, code_lengths_size, NULL);
  assert(code_lengths_size <= MAX_CODE_LENGTHS_SIZE);
  if (total_size == 0 || root_table == NULL) return total_size;

  if (root_table->curr_segment->curr_table + total_size >=
      root_table->curr_segment->start + root_table->curr_segment->size) {
    // If 'root_table' does not have enough memory, allocate a new segment.
    // The available part of root_table->curr_segment is left unused because we
    // need a contiguous buffer.
    const int segment_size = root_table->curr_segment->size;
    struct HuffmanTablesSegment* next =
        (HuffmanTablesSegment*)WebPSafeMalloc(1, sizeof(*next));
    if (next == NULL) return 0;
    // Fill the new segment.
    // We need at least 'total_size' but if that value is small, it is better to
    // allocate a big chunk to prevent more allocations later. 'segment_size' is
    // therefore chosen (any other arbitrary value could be chosen).
    next->size = total_size > segment_size ? total_size : segment_size;
    next->start =
        (HuffmanCode*)WebPSafeMalloc(next->size, sizeof(*next->start));
    if (next->start == NULL) {
      WebPSafeFree(next);
      return 0;
    }
    next->curr_table = next->start;
    next->next = NULL;
    // Point to the new segment.
    root_table->curr_segment->next = next;
    root_table->curr_segment = next;
  }
  if (code_lengths_size <= SORTED_SIZE_CUTOFF) {
    // use local stack-allocated array.
    uint16_t sorted[SORTED_SIZE_CUTOFF];
    BuildHuffmanTable(root_table->curr_segment->curr_table, root_bits,
                      code_lengths, code_lengths_size, sorted);
  } else {  // rare case. Use heap allocation.
    uint16_t* const sorted =
        (uint16_t*)WebPSafeMalloc(code_lengths_size, sizeof(*sorted));
    if (sorted == NULL) return 0;
    BuildHuffmanTable(root_table->curr_segment->curr_table, root_bits,
                      code_lengths, code_lengths_size, sorted);
    WebPSafeFree(sorted);
  }
  return total_size;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movl %ecx, %ebx
movq %rdx, %r13
movl %esi, %r14d
movq %rdi, %r12
xorl %edi, %edi
xorl %r8d, %r8d
callq 0xe0d36
cmpl $0x919, %ebx            # imm = 0x919
jge 0xe0d17
movl %eax, %ebp
testl %eax, %eax
sete %al
testq %r12, %r12
sete %cl
orb %al, %cl
jne 0xe0cf0
movq 0x20(%r12), %rax
movq 0x8(%rax), %rdi
movslq %ebp, %rcx
leaq (%rdi,%rcx,4), %rcx
movslq 0x18(%rax), %r15
leaq (,%r15,4), %rdx
addq (%rax), %rdx
cmpq %rdx, %rcx
jb 0xe0c9e
movl %r14d, 0x4(%rsp)
movq %r13, 0x8(%rsp)
pushq $0x1
popq %rdi
pushq $0x20
popq %rsi
callq 0x57c90
xorl %r13d, %r13d
testq %rax, %rax
je 0xe0cf3
movq %rax, %r14
cmpl %r15d, %ebp
cmovgl %ebp, %r15d
movl %r15d, 0x18(%rax)
movslq %r15d, %rdi
pushq $0x4
popq %rsi
callq 0x57c90
movq %rax, (%r14)
testq %rax, %rax
je 0xe0d0d
movq %rax, %rdi
movq %rax, 0x8(%r14)
andq $0x0, 0x10(%r14)
movq 0x20(%r12), %rax
movq %r14, 0x10(%rax)
movq %r14, 0x20(%r12)
movq 0x8(%rsp), %r13
movl 0x4(%rsp), %r14d
cmpl $0x200, %ebx            # imm = 0x200
jg 0xe0cba
leaq 0x10(%rsp), %r8
movl %r14d, %esi
movq %r13, %rdx
movl %ebx, %ecx
callq 0xe0d36
jmp 0xe0cf0
movl %r14d, %r15d
movl %ebx, %edi
pushq $0x2
popq %rsi
callq 0x57c90
testq %rax, %rax
je 0xe0d08
movq %rax, %r14
movq 0x20(%r12), %rax
movq 0x8(%rax), %rdi
movl %r15d, %esi
movq %r13, %rdx
movl %ebx, %ecx
movq %r14, %r8
callq 0xe0d36
movq %r14, %rdi
callq 0x58480
movl %ebp, %r13d
movl %r13d, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r13d, %r13d
jmp 0xe0cf3
movq %r14, %rdi
callq 0x58480
jmp 0xe0cf3
leaq 0x3cca5(%rip), %rdi     # 0x11d9c3
leaq 0x3cc60(%rip), %rsi     # 0x11d985
leaq 0x3ccc2(%rip), %rcx     # 0x11d9ee
movl $0xe0, %edx
callq 0x56770