// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/libraries/libwebp/src/dec/vp8_dec.c
// Function: ParseResiduals
static int ParseResiduals(VP8Decoder* const dec,
                          VP8MB* const mb, VP8BitReader* const token_br) {
  const VP8BandProbas* (* const bands)[16 + 1] = dec->proba_.bands_ptr_;
  const VP8BandProbas* const * ac_proba;
  VP8MBData* const block = dec->mb_data_ + dec->mb_x_;
  const VP8QuantMatrix* const q = &dec->dqm_[block->segment_];
  int16_t* dst = block->coeffs_;
  VP8MB* const left_mb = dec->mb_info_ - 1;
  uint8_t tnz, lnz;
  uint32_t non_zero_y = 0;
  uint32_t non_zero_uv = 0;
  int x, y, ch;
  uint32_t out_t_nz, out_l_nz;
  int first;

  memset(dst, 0, 384 * sizeof(*dst));
  if (!block->is_i4x4_) {    // parse DC
    int16_t dc[16] = { 0 };
    const int ctx = mb->nz_dc_ + left_mb->nz_dc_;
    const int nz = GetCoeffs(token_br, bands[1], ctx, q->y2_mat_, 0, dc);
    mb->nz_dc_ = left_mb->nz_dc_ = (nz > 0);
    if (nz > 1) {   // more than just the DC -> perform the full transform
      VP8TransformWHT(dc, dst);
    } else {        // only DC is non-zero -> inlined simplified transform
      int i;
      const int dc0 = (dc[0] + 3) >> 3;
      for (i = 0; i < 16 * 16; i += 16) dst[i] = dc0;
    }
    first = 1;
    ac_proba = bands[0];
  } else {
    first = 0;
    ac_proba = bands[3];
  }

  tnz = mb->nz_ & 0x0f;
  lnz = left_mb->nz_ & 0x0f;
  for (y = 0; y < 4; ++y) {
    int l = lnz & 1;
    uint32_t nz_coeffs = 0;
    for (x = 0; x < 4; ++x) {
      const int ctx = l + (tnz & 1);
      const int nz = GetCoeffs(token_br, ac_proba, ctx, q->y1_mat_, first, dst);
      l = (nz > first);
      tnz = (tnz >> 1) | (l << 7);
      nz_coeffs = NzCodeBits(nz_coeffs, nz, dst[0] != 0);
      dst += 16;
    }
    tnz >>= 4;
    lnz = (lnz >> 1) | (l << 7);
    non_zero_y = (non_zero_y << 8) | nz_coeffs;
  }
  out_t_nz = tnz;
  out_l_nz = lnz >> 4;

  for (ch = 0; ch < 4; ch += 2) {
    uint32_t nz_coeffs = 0;
    tnz = mb->nz_ >> (4 + ch);
    lnz = left_mb->nz_ >> (4 + ch);
    for (y = 0; y < 2; ++y) {
      int l = lnz & 1;
      for (x = 0; x < 2; ++x) {
        const int ctx = l + (tnz & 1);
        const int nz = GetCoeffs(token_br, bands[2], ctx, q->uv_mat_, 0, dst);
        l = (nz > 0);
        tnz = (tnz >> 1) | (l << 3);
        nz_coeffs = NzCodeBits(nz_coeffs, nz, dst[0] != 0);
        dst += 16;
      }
      tnz >>= 2;
      lnz = (lnz >> 1) | (l << 5);
    }
    // Note: we don't really need the per-4x4 details for U/V blocks.
    non_zero_uv |= nz_coeffs << (4 * ch);
    out_t_nz |= (tnz << 4) << ch;
    out_l_nz |= (lnz & 0xf0) << ch;
  }
  mb->nz_ = out_t_nz;
  left_mb->nz_ = out_l_nz;

  block->non_zero_y_ = non_zero_y;
  block->non_zero_uv_ = non_zero_uv;

  // We look at the mode-code of each block and check if some blocks have less
  // than three non-zero coeffs (code < 2). This is to avoid dithering flat and
  // empty blocks.
  block->dither_ = (non_zero_uv & 0xaaaa) ? 0 : q->dither_;

  return !(non_zero_y | non_zero_uv);  // will be used for further optimization
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rax
addq $0x4a8, %rax            # imm = 0x4A8
addq $0x428, %rax            # imm = 0x428
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0xb60(%rax), %rax
movq -0x8(%rbp), %rcx
movslq 0xb58(%rcx), %rcx
imulq $0x320, %rcx, %rcx      # imm = 0x320
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x8(%rbp), %rax
addq $0x424, %rax            # imm = 0x424
movq -0x30(%rbp), %rcx
movzbl 0x31e(%rcx), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0xb10(%rax), %rax
addq $-0x2, %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x54(%rbp)
movq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x300, %edx            # imm = 0x300
callq 0x5a200
movq -0x30(%rbp), %rax
cmpb $0x0, 0x300(%rax)
jne 0x143620
leaq -0x90(%rbp), %rdi
xorl %esi, %esi
movl $0x20, %edx
callq 0x5a200
movq -0x10(%rbp), %rax
movzbl 0x1(%rax), %eax
movq -0x48(%rbp), %rcx
movzbl 0x1(%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x94(%rbp)
movq 0xd58f5(%rip), %rax     # 0x218e40
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq $0x88, %rsi
movl -0x94(%rbp), %edx
movq -0x38(%rbp), %rcx
addq $0x8, %rcx
leaq -0x90(%rbp), %r9
xorl %r8d, %r8d
callq *%rax
movl %eax, -0x98(%rbp)
cmpl $0x0, -0x98(%rbp)
setg %al
andb $0x1, %al
movzbl %al, %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movb %cl, 0x1(%rax)
movq -0x10(%rbp), %rax
movb %cl, 0x1(%rax)
cmpl $0x1, -0x98(%rbp)
jle 0x1435bb
leaq 0xd5907(%rip), %rax     # 0x218eb0
movq (%rax), %rax
leaq -0x90(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq *%rax
jmp 0x14360f
movswl -0x90(%rbp), %eax
addl $0x3, %eax
sarl $0x3, %eax
movl %eax, -0xa0(%rbp)
movl $0x0, -0x9c(%rbp)
cmpl $0x100, -0x9c(%rbp)     # imm = 0x100
jge 0x14360d
movl -0xa0(%rbp), %eax
movw %ax, %dx
movq -0x40(%rbp), %rax
movslq -0x9c(%rbp), %rcx
movw %dx, (%rax,%rcx,2)
movl -0x9c(%rbp), %eax
addl $0x10, %eax
movl %eax, -0x9c(%rbp)
jmp 0x1435d8
jmp 0x14360f
movl $0x1, -0x6c(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x143635
movl $0x0, -0x6c(%rbp)
movq -0x20(%rbp), %rax
addq $0x198, %rax            # imm = 0x198
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
andl $0xf, %eax
movb %al, -0x49(%rbp)
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
andl $0xf, %eax
movb %al, -0x4a(%rbp)
movl $0x0, -0x5c(%rbp)
cmpl $0x4, -0x5c(%rbp)
jge 0x14376f
movzbl -0x4a(%rbp), %eax
andl $0x1, %eax
movl %eax, -0xa4(%rbp)
movl $0x0, -0xa8(%rbp)
movl $0x0, -0x58(%rbp)
cmpl $0x4, -0x58(%rbp)
jge 0x143734
movl -0xa4(%rbp), %eax
movzbl -0x49(%rbp), %ecx
andl $0x1, %ecx
addl %ecx, %eax
movl %eax, -0xac(%rbp)
movq 0xd579c(%rip), %rax     # 0x218e40
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0xac(%rbp), %edx
movq -0x38(%rbp), %rcx
movl -0x6c(%rbp), %r8d
movq -0x40(%rbp), %r9
callq *%rax
movl %eax, -0xb0(%rbp)
movl -0xb0(%rbp), %eax
cmpl -0x6c(%rbp), %eax
setg %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xa4(%rbp)
movzbl -0x49(%rbp), %eax
sarl %eax
movl -0xa4(%rbp), %ecx
shll $0x7, %ecx
orl %ecx, %eax
movb %al, -0x49(%rbp)
movl -0xa8(%rbp), %edi
movl -0xb0(%rbp), %esi
movq -0x40(%rbp), %rax
movswl (%rax), %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %edx
callq 0x144500
movl %eax, -0xa8(%rbp)
movq -0x40(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x40(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x14367e
movzbl -0x49(%rbp), %eax
sarl $0x4, %eax
movb %al, -0x49(%rbp)
movzbl -0x4a(%rbp), %eax
sarl %eax
movl -0xa4(%rbp), %ecx
shll $0x7, %ecx
orl %ecx, %eax
movb %al, -0x4a(%rbp)
movl -0x50(%rbp), %eax
shll $0x8, %eax
orl -0xa8(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x143656
movzbl -0x49(%rbp), %eax
movl %eax, -0x64(%rbp)
movzbl -0x4a(%rbp), %eax
sarl $0x4, %eax
movl %eax, -0x68(%rbp)
movl $0x0, -0x60(%rbp)
cmpl $0x4, -0x60(%rbp)
jge 0x143916
movl $0x0, -0xb4(%rbp)
movq -0x10(%rbp), %rax
movzbl (%rax), %eax
movl -0x60(%rbp), %ecx
addl $0x4, %ecx
sarl %cl, %eax
movb %al, -0x49(%rbp)
movq -0x48(%rbp), %rax
movzbl (%rax), %eax
movl -0x60(%rbp), %ecx
addl $0x4, %ecx
sarl %cl, %eax
movb %al, -0x4a(%rbp)
movl $0x0, -0x5c(%rbp)
cmpl $0x2, -0x5c(%rbp)
jge 0x1438ce
movzbl -0x4a(%rbp), %eax
andl $0x1, %eax
movl %eax, -0xb8(%rbp)
movl $0x0, -0x58(%rbp)
cmpl $0x2, -0x58(%rbp)
jge 0x1438a2
movl -0xb8(%rbp), %eax
movzbl -0x49(%rbp), %ecx
andl $0x1, %ecx
addl %ecx, %eax
movl %eax, -0xbc(%rbp)
movq 0xd5636(%rip), %rax     # 0x218e40
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
addq $0x110, %rsi            # imm = 0x110
movl -0xbc(%rbp), %edx
movq -0x38(%rbp), %rcx
addq $0x10, %rcx
movq -0x40(%rbp), %r9
xorl %r8d, %r8d
callq *%rax
movl %eax, -0xc0(%rbp)
cmpl $0x0, -0xc0(%rbp)
setg %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0xb8(%rbp)
movzbl -0x49(%rbp), %eax
sarl %eax
movl -0xb8(%rbp), %ecx
shll $0x3, %ecx
orl %ecx, %eax
movb %al, -0x49(%rbp)
movl -0xb4(%rbp), %edi
movl -0xc0(%rbp), %esi
movq -0x40(%rbp), %rax
movswl (%rax), %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movzbl %al, %edx
callq 0x144500
movl %eax, -0xb4(%rbp)
movq -0x40(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x40(%rbp)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x1437e4
movzbl -0x49(%rbp), %eax
sarl $0x2, %eax
movb %al, -0x49(%rbp)
movzbl -0x4a(%rbp), %eax
sarl %eax
movl -0xb8(%rbp), %ecx
shll $0x5, %ecx
orl %ecx, %eax
movb %al, -0x4a(%rbp)
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x1437c6
movl -0xb4(%rbp), %eax
movl -0x60(%rbp), %ecx
shll $0x2, %ecx
shll %cl, %eax
orl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
movzbl -0x49(%rbp), %eax
shll $0x4, %eax
movl -0x60(%rbp), %ecx
shll %cl, %eax
orl -0x64(%rbp), %eax
movl %eax, -0x64(%rbp)
movzbl -0x4a(%rbp), %eax
andl $0xf0, %eax
movl -0x60(%rbp), %ecx
shll %cl, %eax
orl -0x68(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x60(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x60(%rbp)
jmp 0x143787
movl -0x64(%rbp), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, (%rax)
movl -0x68(%rbp), %eax
movb %al, %cl
movq -0x48(%rbp), %rax
movb %cl, (%rax)
movl -0x50(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x314(%rax)
movl -0x54(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x318(%rax)
movl -0x54(%rbp), %eax
andl $0xaaaa, %eax           # imm = 0xAAAA
cmpl $0x0, %eax
je 0x14395d
xorl %eax, %eax
movl %eax, -0xc4(%rbp)
jmp 0x14396a
movq -0x38(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
movb %al, %cl
movq -0x30(%rbp), %rax
movb %cl, 0x31c(%rax)
movl -0x50(%rbp), %eax
orl -0x54(%rbp), %eax
cmpl $0x0, %eax
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax,%rax)