// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/libraries/libwebp/src/dec/vp8l_dec.c
// Function: ReadHuffmanCodes
static int ReadHuffmanCodes(VP8LDecoder* const dec, int xsize, int ysize,
                            int color_cache_bits, int allow_recursion) {
  int i;
  VP8LBitReader* const br = &dec->br_;
  VP8LMetadata* const hdr = &dec->hdr_;
  uint32_t* huffman_image = NULL;
  HTreeGroup* htree_groups = NULL;
  HuffmanTables* huffman_tables = &hdr->huffman_tables_;
  int num_htree_groups = 1;
  int num_htree_groups_max = 1;
  int* mapping = NULL;
  int ok = 0;

  // Check the table has been 0 initialized (through InitMetadata).
  assert(huffman_tables->root.start == NULL);
  assert(huffman_tables->curr_segment == NULL);

  if (allow_recursion && VP8LReadBits(br, 1)) {
    // use meta Huffman codes.
    const int huffman_precision = VP8LReadBits(br, 3) + 2;
    const int huffman_xsize = VP8LSubSampleSize(xsize, huffman_precision);
    const int huffman_ysize = VP8LSubSampleSize(ysize, huffman_precision);
    const int huffman_pixs = huffman_xsize * huffman_ysize;
    if (!DecodeImageStream(huffman_xsize, huffman_ysize, /*is_level0=*/0, dec,
                           &huffman_image)) {
      goto Error;
    }
    hdr->huffman_subsample_bits_ = huffman_precision;
    for (i = 0; i < huffman_pixs; ++i) {
      // The huffman data is stored in red and green bytes.
      const int group = (huffman_image[i] >> 8) & 0xffff;
      huffman_image[i] = group;
      if (group >= num_htree_groups_max) {
        num_htree_groups_max = group + 1;
      }
    }
    // Check the validity of num_htree_groups_max. If it seems too big, use a
    // smaller value for later. This will prevent big memory allocations to end
    // up with a bad bitstream anyway.
    // The value of 1000 is totally arbitrary. We know that num_htree_groups_max
    // is smaller than (1 << 16) and should be smaller than the number of pixels
    // (though the format allows it to be bigger).
    if (num_htree_groups_max > 1000 || num_htree_groups_max > xsize * ysize) {
      // Create a mapping from the used indices to the minimal set of used
      // values [0, num_htree_groups)
      mapping = (int*)WebPSafeMalloc(num_htree_groups_max, sizeof(*mapping));
      if (mapping == NULL) {
        VP8LSetError(dec, VP8_STATUS_OUT_OF_MEMORY);
        goto Error;
      }
      // -1 means a value is unmapped, and therefore unused in the Huffman
      // image.
      memset(mapping, 0xff, num_htree_groups_max * sizeof(*mapping));
      for (num_htree_groups = 0, i = 0; i < huffman_pixs; ++i) {
        // Get the current mapping for the group and remap the Huffman image.
        int* const mapped_group = &mapping[huffman_image[i]];
        if (*mapped_group == -1) *mapped_group = num_htree_groups++;
        huffman_image[i] = *mapped_group;
      }
    } else {
      num_htree_groups = num_htree_groups_max;
    }
  }

  if (br->eos_) goto Error;

  if (!ReadHuffmanCodesHelper(color_cache_bits, num_htree_groups,
                              num_htree_groups_max, mapping, dec,
                              huffman_tables, &htree_groups)) {
    goto Error;
  }
  ok = 1;

  // All OK. Finalize pointers.
  hdr->huffman_image_ = huffman_image;
  hdr->num_htree_groups_ = num_htree_groups;
  hdr->htree_groups_ = htree_groups;

 Error:
  WebPSafeFree(mapping);
  if (!ok) {
    WebPSafeFree(huffman_image);
    VP8LHuffmanTablesDeallocate(huffman_tables);
    VP8LHtreeGroupsFree(htree_groups);
  }
  return ok;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movq -0x8(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
addq $0x98, %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq -0x30(%rbp), %rax
addq $0x50, %rax
movq %rax, -0x48(%rbp)
movl $0x1, -0x4c(%rbp)
movl $0x1, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x48(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x14773b
jmp 0x14775a
leaq 0x7613c(%rip), %rdi     # 0x1bd87e
leaq 0x75da0(%rip), %rsi     # 0x1bd4e9
movl $0x17b, %edx            # imm = 0x17B
leaq 0x7614c(%rip), %rcx     # 0x1bd8a1
callq 0x598a0
movq -0x48(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x147767
jmp 0x147786
leaq 0x76170(%rip), %rdi     # 0x1bd8de
leaq 0x75d74(%rip), %rsi     # 0x1bd4e9
movl $0x17c, %edx            # imm = 0x17C
leaq 0x76120(%rip), %rcx     # 0x1bd8a1
callq 0x598a0
cmpl $0x0, -0x18(%rbp)
je 0x147928
movq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0x1824b0
cmpl $0x0, %eax
je 0x147928
movq -0x28(%rbp), %rdi
movl $0x3, %esi
callq 0x1824b0
addl $0x2, %eax
movl %eax, -0x60(%rbp)
movl -0xc(%rbp), %edi
movl -0x60(%rbp), %esi
callq 0x147a50
movl %eax, -0x64(%rbp)
movl -0x10(%rbp), %edi
movl -0x60(%rbp), %esi
callq 0x147a50
movl %eax, -0x68(%rbp)
movl -0x64(%rbp), %eax
imull -0x68(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x64(%rbp), %edi
movl -0x68(%rbp), %esi
movq -0x8(%rbp), %rcx
xorl %edx, %edx
leaq -0x38(%rbp), %r8
callq 0x145310
cmpl $0x0, %eax
jne 0x147800
jmp 0x147986
movl -0x60(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x2c(%rax)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jge 0x14785b
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
shrl $0x8, %eax
andl $0xffff, %eax           # imm = 0xFFFF
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %edx
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x70(%rbp), %eax
cmpl -0x50(%rbp), %eax
jl 0x14784e
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x147850
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x147811
cmpl $0x3e8, -0x50(%rbp)     # imm = 0x3E8
jg 0x147876
movl -0x50(%rbp), %eax
movl -0xc(%rbp), %ecx
imull -0x10(%rbp), %ecx
cmpl %ecx, %eax
jle 0x147920
movslq -0x50(%rbp), %rdi
movl $0x4, %esi
callq 0x5b060
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x1478a2
movq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x144bc0
jmp 0x147986
movq -0x58(%rbp), %rdi
movslq -0x50(%rbp), %rdx
shlq $0x2, %rdx
movl $0xff, %esi
callq 0x5a200
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x6c(%rbp), %eax
jge 0x14791e
movq -0x58(%rbp), %rax
movq -0x38(%rbp), %rcx
movslq -0x1c(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
cmpl $-0x1, (%rax)
jne 0x147902
movl -0x4c(%rbp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x78(%rbp), %rax
movl %ecx, (%rax)
movq -0x78(%rbp), %rax
movl (%rax), %edx
movq -0x38(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1478c6
jmp 0x147926
movl -0x50(%rbp), %eax
movl %eax, -0x4c(%rbp)
jmp 0x147928
movq -0x28(%rbp), %rax
cmpl $0x0, 0x24(%rax)
je 0x147934
jmp 0x147986
movl -0x14(%rbp), %edi
movl -0x4c(%rbp), %esi
movl -0x50(%rbp), %edx
movq -0x58(%rbp), %rcx
movq -0x8(%rbp), %r8
movq -0x48(%rbp), %r9
leaq -0x40(%rbp), %rax
movq %rax, (%rsp)
callq 0x144730
cmpl $0x0, %eax
jne 0x14795d
jmp 0x147986
movl $0x1, -0x5c(%rbp)
movq -0x38(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x38(%rax)
movl -0x4c(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x40(%rax)
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x58(%rbp), %rdi
callq 0x5b920
cmpl $0x0, -0x5c(%rbp)
jne 0x1479b0
movq -0x38(%rbp), %rdi
callq 0x5b920
movq -0x48(%rbp), %rdi
callq 0x183150
movq -0x40(%rbp), %rdi
callq 0x182800
movl -0x5c(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)