// File: /workspace/github_c_makefile_star2_O1/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, %rax
movl %edx, %r14d
movl %edi, %ecx
movl $0x1, %edx
movl %edi, 0x10(%rsp)
shll %cl, %edx
movq %rdx, 0x28(%rsp)
movq %rax, 0x30(%rsp)
testq %rax, %rax
sete %al
xorl %r12d, %r12d
movq 0x80(%rsp), %rbp
movb $0x1, %bl
cmpl %r14d, %esi
setne %cl
jg 0xd4a45
andb %al, %cl
jne 0xd4a45
movl %esi, %r13d
movl 0x10(%rsp), %edx
movslq %edx, %rax
leaq 0x55f0b(%rip), %rcx     # 0x12a5f0
movzwl (%rcx,%rax,2), %eax
movl %eax, 0xc(%rsp)
movl $0x118, %eax            # imm = 0x118
movq 0x28(%rsp), %rcx
addl %eax, %ecx
testl %edx, %edx
cmovlel %eax, %ecx
movslq %ecx, %rdi
movl $0x4, %esi
callq 0x56580
movq %rax, %r15
movl %r13d, %edi
callq 0xf0f14
movq %rax, (%rbp)
testq %rax, %rax
je 0xd4a4a
testq %r15, %r15
je 0xd4a4a
movl 0xc(%rsp), %edi
imull %r13d, %edi
movq 0x20(%rsp), %rsi
callq 0xf1607
testl %eax, %eax
je 0xd4a4a
movl $0x1, %r12d
testl %r14d, %r14d
jle 0xd4a67
movl %r14d, %eax
movq %rax, 0x38(%rsp)
xorl %r13d, %r13d
movq 0x30(%rsp), %r14
testq %r14, %r14
je 0xd4775
cmpl $-0x1, (%r14,%r13,4)
je 0xd4a00
testq %r14, %r14
movq %r13, 0x40(%rsp)
je 0xd4785
movl (%r14,%r13,4), %eax
jmp 0xd4788
movl %r13d, %eax
cltq
imulq $0x238, %rax, %r13      # imm = 0x238
addq (%rbp), %r13
movl $0x1, %ebx
xorl %ebp, %ebp
movl $0x0, 0x14(%rsp)
movl $0x0, 0xc(%rsp)
testq %rbp, %rbp
movl $0x0, %r14d
cmovel 0x28(%rsp), %r14d
cmpl $0x0, 0x10(%rsp)
leaq 0x55e19(%rip), %rax     # 0x12a5e0
movzwl (%rax,%rbp,2), %eax
movl $0x0, %ecx
cmovlel %ecx, %r14d
addl %eax, %r14d
movl %r14d, %edi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
movq 0x20(%rsp), %r12
movq %r12, %rcx
callq 0xd4ab6
movq 0x20(%r12), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, (%r13,%rbp,8)
testl %eax, %eax
je 0xd481d
xorl %r8d, %r8d
testl %ebx, %ebx
movl $0x0, %ebx
je 0xd482a
testb $0x3, %bpl
je 0xd4825
xorl %ebx, %ebx
cmpb $0x0, (%rcx)
sete %bl
jmp 0xd482a
movl $0x2, %r8d
jmp 0xd4871
movl $0x1, %ebx
movzbl (%rcx), %ecx
addl %ecx, 0xc(%rsp)
movq 0x20(%rsp), %rcx
movq 0x20(%rcx), %rcx
movslq %eax, %rdx
shlq $0x2, %rdx
addq %rdx, 0x8(%rcx)
cmpq $0x4, %rbp
je 0xd4871
movl (%r15), %ecx
cmpl $0x2, %r14d
jl 0xd486d
movl %r14d, %edx
movl $0x1, %esi
movl (%r15,%rsi,4), %edi
cmpl %ecx, %edi
cmovgl %edi, %ecx
incq %rsi
cmpq %rsi, %rdx
jne 0xd485c
addl %ecx, 0x14(%rsp)
testl %eax, %eax
je 0xd49cf
incq %rbp
cmpq $0x5, %rbp
jne 0xd47ac
movl %ebx, 0x28(%r13)
movl $0x0, 0x30(%r13)
testl %ebx, %ebx
je 0xd48e4
movq 0x8(%r13), %rax
movq 0x10(%r13), %rcx
movzwl 0x2(%rax), %eax
movzwl 0x2(%rcx), %ecx
movq 0x18(%r13), %rdx
movzwl 0x2(%rdx), %edx
shll $0x18, %edx
shll $0x10, %eax
orl %ecx, %eax
orl %edx, %eax
movl %eax, 0x2c(%r13)
cmpl $0x0, 0xc(%rsp)
jne 0xd48e4
movq (%r13), %rcx
movzwl 0x2(%rcx), %ecx
cmpl $0xff, %ecx
ja 0xd48e4
movl $0x1, 0x30(%r13)
shll $0x8, %ecx
orl %ecx, %eax
movl %eax, 0x2c(%r13)
cmpl $0x0, 0x30(%r13)
sete %al
cmpl $0x6, 0x14(%rsp)
setl %cl
andb %al, %cl
movzbl %cl, %eax
movl %eax, 0x34(%r13)
xorl %r8d, %r8d
cmpb $0x1, %al
jne 0xd49cf
movq $-0x40, %rbx
movl $0x38, %r12d
movq (%r13), %rcx
movzbl 0x100(%rcx,%rbx,4), %eax
movzwl 0x102(%rcx,%rbx,4), %edi
cmpl $0x100, %edi            # imm = 0x100
jb 0xd4948
orl $0x100, %eax            # imm = 0x100
movl %eax, 0x238(%r13,%rbx,8)
movl %edi, 0x23c(%r13,%rbx,8)
jmp 0xd49bf
leaq (%r12,%r13), %r14
movzbl 0x101(%rcx,%rbx,4), %ecx
movq $0x0, 0x238(%r13,%rbx,8)
shll $0x10, %edi
shll $0x8, %ecx
orl %eax, %edi
orl %ecx, %edi
movl $0x8, %esi
movq %r14, %rdx
callq 0xd77a3
leal 0x40(%rbx), %ebp
movl %eax, %ecx
shrl %cl, %ebp
movq 0x8(%r13), %rax
movl (%rax,%rbp,4), %edi
movl $0x10, %esi
movq %r14, %rdx
callq 0xd77a3
movl %eax, %ecx
shrl %cl, %ebp
movq 0x10(%r13), %rax
movl (%rax,%rbp,4), %edi
xorl %esi, %esi
movq %r14, %rdx
callq 0xd77a3
movl %eax, %ecx
shrl %cl, %ebp
movq 0x18(%r13), %rax
movl (%rax,%rbp,4), %edi
movl $0x18, %esi
movq %r14, %rdx
callq 0xd77a3
addq $0x8, %r12
incq %rbx
jne 0xd4915
xorl %r8d, %r8d
testl %r8d, %r8d
movl $0x1, %r12d
movq 0x80(%rsp), %rbp
movq 0x30(%rsp), %r14
movq 0x40(%rsp), %r13
jne 0xd4aa9
incq %r13
cmpq 0x38(%rsp), %r13
jne 0xd4765
jmp 0xd4a67
xorl %ebx, %ebx
xorl %eax, %eax
testq %rbx, %rbx
movl $0x0, %edi
cmovel 0x28(%rsp), %edi
cmpl $0x0, 0x10(%rsp)
leaq 0x55bc3(%rip), %rcx     # 0x12a5e0
movzwl (%rbx,%rcx), %ecx
cmovlel %eax, %edi
addl %ecx, %edi
movq 0x18(%rsp), %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xd4ab6
testl %eax, %eax
je 0xd4a6b
addq $0x2, %rbx
cmpq $0xa, %rbx
jne 0xd4a02
jmp 0xd49f0
xorl %r15d, %r15d
jmp 0xd4a70
movq 0x18(%rsp), %rax
movl (%rax), %eax
cmpl $0x5, %eax
je 0xd4a5a
testl %eax, %eax
jne 0xd4a70
movq 0x18(%rsp), %rax
movl $0x1, (%rax)
jmp 0xd4a70
xorl %ebx, %ebx
jmp 0xd4a70
xorl %r12d, %r12d
movb $0x1, %bl
movq %r15, %rdi
callq 0x57290
testb %bl, %bl
je 0xd4a97
movq 0x20(%rsp), %rdi
callq 0xf1647
movq (%rbp), %rdi
callq 0xf0f54
movq $0x0, (%rbp)
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r12d, %r12d
cmpl $0x2, %r8d
movb $0x1, %bl
je 0xd4a70
jmp 0xd4a97