// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/libraries/libwebp/src/dec/vp8l_dec.c
// Function: ReadHuffmanCodesHelper
int ReadHuffmanCodesHelper(int color_cache_bits, int num_htree_groups,
                           int num_htree_groups_max, const int* const mapping,
                           VP8LDecoder* const dec,
                           HuffmanTables* const huffman_tables,
                           HTreeGroup** const htree_groups) {
  int i, j, ok = 0;
  const int max_alphabet_size =
      kAlphabetSize[0] + ((color_cache_bits > 0) ? 1 << color_cache_bits : 0);
  const int table_size = kTableSize[color_cache_bits];
  int* code_lengths = NULL;

  if ((mapping == NULL && num_htree_groups != num_htree_groups_max) ||
      num_htree_groups > num_htree_groups_max) {
    goto Error;
  }

  code_lengths =
      (int*)WebPSafeCalloc((uint64_t)max_alphabet_size, sizeof(*code_lengths));
  *htree_groups = VP8LHtreeGroupsNew(num_htree_groups);

  if (*htree_groups == NULL || code_lengths == NULL ||
      !VP8LHuffmanTablesAllocate(num_htree_groups * table_size,
                                 huffman_tables)) {
    VP8LSetError(dec, VP8_STATUS_OUT_OF_MEMORY);
    goto Error;
  }

  for (i = 0; i < num_htree_groups_max; ++i) {
    // If the index "i" is unused in the Huffman image, just make sure the
    // coefficients are valid but do not store them.
    if (mapping != NULL && mapping[i] == -1) {
      for (j = 0; j < HUFFMAN_CODES_PER_META_CODE; ++j) {
        int alphabet_size = kAlphabetSize[j];
        if (j == 0 && color_cache_bits > 0) {
          alphabet_size += (1 << color_cache_bits);
        }
        // Passing in NULL so that nothing gets filled.
        if (!ReadHuffmanCode(alphabet_size, dec, code_lengths, NULL)) {
          goto Error;
        }
      }
    } else {
      HTreeGroup* const htree_group =
          &(*htree_groups)[(mapping == NULL) ? i : mapping[i]];
      HuffmanCode** const htrees = htree_group->htrees;
      int size;
      int total_size = 0;
      int is_trivial_literal = 1;
      int max_bits = 0;
      for (j = 0; j < HUFFMAN_CODES_PER_META_CODE; ++j) {
        int alphabet_size = kAlphabetSize[j];
        if (j == 0 && color_cache_bits > 0) {
          alphabet_size += (1 << color_cache_bits);
        }
        size =
            ReadHuffmanCode(alphabet_size, dec, code_lengths, huffman_tables);
        htrees[j] = huffman_tables->curr_segment->curr_table;
        if (size == 0) {
          goto Error;
        }
        if (is_trivial_literal && kLiteralMap[j] == 1) {
          is_trivial_literal = (htrees[j]->bits == 0);
        }
        total_size += htrees[j]->bits;
        huffman_tables->curr_segment->curr_table += size;
        if (j <= ALPHA) {
          int local_max_bits = code_lengths[0];
          int k;
          for (k = 1; k < alphabet_size; ++k) {
            if (code_lengths[k] > local_max_bits) {
              local_max_bits = code_lengths[k];
            }
          }
          max_bits += local_max_bits;
        }
      }
      htree_group->is_trivial_literal = is_trivial_literal;
      htree_group->is_trivial_code = 0;
      if (is_trivial_literal) {
        const int red = htrees[RED][0].value;
        const int blue = htrees[BLUE][0].value;
        const int alpha = htrees[ALPHA][0].value;
        htree_group->literal_arb = ((uint32_t)alpha << 24) | (red << 16) | blue;
        if (total_size == 0 && htrees[GREEN][0].value < NUM_LITERAL_CODES) {
          htree_group->is_trivial_code = 1;
          htree_group->literal_arb |= htrees[GREEN][0].value << 8;
        }
      }
      htree_group->use_packed_table =
          !htree_group->is_trivial_code && (max_bits < HUFFMAN_PACKED_BITS);
      if (htree_group->use_packed_table) BuildPackedTable(htree_group);
    }
  }
  ok = 1;

 Error:
  WebPSafeFree(code_lengths);
  if (!ok) {
    VP8LHuffmanTablesDeallocate(huffman_tables);
    VP8LHtreeGroupsFree(*htree_groups);
    *htree_groups = NULL;
  }
  return ok;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r9, 0x20(%rsp)
movq %r8, 0x18(%rsp)
movq %rcx, %r8
movl %edi, %ecx
pushq $0x1
popq %rax
movl %edi, 0x4(%rsp)
shll %cl, %eax
movq %rax, 0x28(%rsp)
testq %r8, %r8
sete %al
xorl %r12d, %r12d
movq 0x80(%rsp), %rbx
movb $0x1, %bpl
cmpl %edx, %esi
setne %cl
jg 0xcbf31
andb %al, %cl
jne 0xcbf31
movl %esi, %r13d
movq %rdx, %rbp
movq %r8, 0x40(%rsp)
movl 0x4(%rsp), %edx
movslq %edx, %rax
leaq 0x4d939(%rip), %rcx     # 0x119550
movzwl (%rcx,%rax,2), %r14d
movl $0x118, %eax            # imm = 0x118
movq 0x28(%rsp), %rcx
addl %eax, %ecx
testl %edx, %edx
cmovlel %eax, %ecx
movslq %ecx, %rdi
pushq $0x4
popq %rsi
callq 0x57690
movq %rax, %r15
movl %r13d, %edi
callq 0xe0b7c
movq %rax, (%rbx)
testq %rax, %rax
je 0xcbf36
testq %r15, %r15
je 0xcbf36
imull %r13d, %r14d
movl %r14d, %edi
movq 0x20(%rsp), %rsi
callq 0xe12a1
testl %eax, %eax
je 0xcbf36
xorl %ecx, %ecx
testl %ebp, %ebp
cmovlel %ecx, %ebp
movq %rbp, 0x30(%rsp)
cmpq %rbp, %rcx
movq 0x40(%rsp), %rax
je 0xcbf73
testq %rax, %rax
movq %rcx, 0x38(%rsp)
je 0xcbceb
movl (%rax,%rcx,4), %eax
cmpl $-0x1, %eax
jne 0xcbced
xorl %ebx, %ebx
cmpq $0xa, %rbx
je 0xcbf17
xorl %r12d, %r12d
testq %rbx, %rbx
movl $0x0, %edi
cmovel 0x28(%rsp), %edi
cmpl $0x0, 0x4(%rsp)
leaq 0x4d87b(%rip), %rax     # 0x119540
movzwl (%rbx,%rax), %eax
cmovlel %r12d, %edi
addl %eax, %edi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xcbfb0
addq $0x2, %rbx
testl %eax, %eax
jne 0xcbc9f
jmp 0xcbf66
movl %ecx, %eax
cltq
imulq $0x238, %rax, %r8       # imm = 0x238
addq (%rbx), %r8
xorl %ebx, %ebx
xorl %edi, %edi
pushq $0x1
popq %r12
movl $0x0, 0x14(%rsp)
movq %r8, 0x8(%rsp)
cmpq $0x5, %rbx
je 0xcbddf
movl %edi, %r14d
xorl %edx, %edx
testq %rbx, %rbx
movl $0x0, %eax
cmovel 0x28(%rsp), %eax
cmpl $0x0, 0x4(%rsp)
leaq 0x4d80a(%rip), %rcx     # 0x119540
movzwl (%rcx,%rbx,2), %ecx
cmovlel %edx, %eax
movslq %eax, %r13
addq %rcx, %r13
movl %r13d, %edi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
movq 0x20(%rsp), %rbp
movq %rbp, %rcx
callq 0xcbfb0
movq 0x8(%rsp), %r8
movq 0x20(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, (%r8,%rbx,8)
testl %eax, %eax
je 0xcbf56
testl %r12d, %r12d
je 0xcbd8e
movb (%rcx), %cl
testb $0x3, %bl
movl %r14d, %edi
je 0xcbd98
xorl %r12d, %r12d
testb %cl, %cl
sete %r12b
jmp 0xcbd9c
movb (%rcx), %cl
xorl %r12d, %r12d
movl %r14d, %edi
jmp 0xcbd9c
pushq $0x1
popq %r12
movq 0x20(%rsp), %rdx
movq 0x20(%rdx), %rdx
cltq
shlq $0x2, %rax
addq %rax, 0x8(%rdx)
cmpq $0x4, %rbx
je 0xcbdd2
movl (%r15), %eax
pushq $0x1
popq %rdx
cmpq %r13, %rdx
jge 0xcbdce
movl (%r15,%rdx,4), %esi
cmpl %eax, %esi
cmovgl %esi, %eax
incq %rdx
jmp 0xcbdbb
addl %eax, 0x14(%rsp)
movzbl %cl, %eax
addl %eax, %edi
incq %rbx
jmp 0xcbd0e
movl %r12d, 0x28(%r8)
andl $0x0, 0x30(%r8)
movb $0x1, %al
testl %r12d, %r12d
je 0xcbe3b
movq 0x8(%r8), %rcx
movq 0x10(%r8), %rdx
movzwl 0x2(%rcx), %ecx
movzwl 0x2(%rdx), %edx
movq 0x18(%r8), %rsi
movzwl 0x2(%rsi), %esi
shll $0x18, %esi
shll $0x10, %ecx
orl %edx, %ecx
orl %esi, %ecx
movl %ecx, 0x2c(%r8)
testl %edi, %edi
jne 0xcbe3b
movq (%r8), %rdx
movzwl 0x2(%rdx), %edx
cmpl $0xff, %edx
ja 0xcbe3b
movl $0x1, 0x30(%r8)
shll $0x8, %edx
orl %edx, %ecx
movl %ecx, 0x2c(%r8)
xorl %eax, %eax
cmpl $0x6, 0x14(%rsp)
setl %cl
andb %al, %cl
movzbl %cl, %eax
movl %eax, 0x34(%r8)
cmpb $0x1, %al
jne 0xcbf17
leaq 0x38(%r8), %rbx
xorl %r14d, %r14d
xorl %r13d, %r13d
cmpq $0x40, %r13
je 0xcbf17
movq (%r8), %rcx
movzbl (%rcx,%r13,4), %eax
movzwl 0x2(%rcx,%r13,4), %edi
cmpl $0x100, %edi            # imm = 0x100
jb 0xcbe8e
orl $0x100, %eax            # imm = 0x100
movl %eax, (%rbx,%r13,8)
movl %edi, 0x4(%rbx,%r13,8)
jmp 0xcbf0b
leaq (%rbx,%r14), %r12
movzbl 0x1(%rcx,%r13,4), %ecx
andq $0x0, 0x38(%r8,%r13,8)
shll $0x10, %edi
shll $0x8, %ecx
orl %eax, %edi
orl %ecx, %edi
pushq $0x8
popq %rsi
movq %r12, %rdx
callq 0xce4bc
movl %r13d, %ebp
movl %eax, %ecx
shrl %cl, %ebp
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
movl (%rax,%rbp,4), %edi
pushq $0x10
popq %rsi
movq %r12, %rdx
callq 0xce4bc
movl %eax, %ecx
shrl %cl, %ebp
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rax,%rbp,4), %edi
xorl %esi, %esi
movq %r12, %rdx
callq 0xce4bc
movl %eax, %ecx
shrl %cl, %ebp
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl (%rax,%rbp,4), %edi
pushq $0x18
popq %rsi
movq %r12, %rdx
callq 0xce4bc
movq 0x8(%rsp), %r8
incq %r13
addq $0x8, %r14
jmp 0xcbe5e
movq 0x38(%rsp), %rcx
incq %rcx
movq 0x80(%rsp), %rbx
movq 0x30(%rsp), %rbp
jmp 0xcbc7d
xorl %r15d, %r15d
jmp 0xcbf7b
movq 0x18(%rsp), %rax
movl (%rax), %eax
cmpl $0x5, %eax
movb $0x1, %bpl
je 0xcbf49
testl %eax, %eax
jne 0xcbf7b
movq 0x18(%rsp), %rax
movl $0x1, (%rax)
jmp 0xcbf7b
movq 0x80(%rsp), %rbx
movb $0x1, %bpl
xorl %r12d, %r12d
jmp 0xcbf7b
movq 0x80(%rsp), %rbx
movb $0x1, %bpl
jmp 0xcbf7b
xorl %ebp, %ebp
pushq $0x1
popq %rax
movl %eax, %r12d
movq %r15, %rdi
callq 0x58480
testb %bpl, %bpl
je 0xcbf9e
movq 0x20(%rsp), %rdi
callq 0xe12da
movq (%rbx), %rdi
callq 0xe0bbf
andq $0x0, (%rbx)
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq