// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/libraries/libwebp/src/dec/quant_dec.c
// Function: VP8ParseQuant
void VP8ParseQuant(VP8Decoder* const dec) {
  VP8BitReader* const br = &dec->br_;
  const int base_q0 = VP8GetValue(br, 7, "global-header");
  const int dqy1_dc = VP8Get(br, "global-header") ?
       VP8GetSignedValue(br, 4, "global-header") : 0;
  const int dqy2_dc = VP8Get(br, "global-header") ?
       VP8GetSignedValue(br, 4, "global-header") : 0;
  const int dqy2_ac = VP8Get(br, "global-header") ?
       VP8GetSignedValue(br, 4, "global-header") : 0;
  const int dquv_dc = VP8Get(br, "global-header") ?
       VP8GetSignedValue(br, 4, "global-header") : 0;
  const int dquv_ac = VP8Get(br, "global-header") ?
       VP8GetSignedValue(br, 4, "global-header") : 0;

  const VP8SegmentHeader* const hdr = &dec->segment_hdr_;
  int i;

  for (i = 0; i < NUM_MB_SEGMENTS; ++i) {
    int q;
    if (hdr->use_segment_) {
      q = hdr->quantizer_[i];
      if (!hdr->absolute_delta_) {
        q += base_q0;
      }
    } else {
      if (i > 0) {
        dec->dqm_[i] = dec->dqm_[0];
        continue;
      } else {
        q = base_q0;
      }
    }
    {
      VP8QuantMatrix* const m = &dec->dqm_[i];
      m->y1_mat_[0] = kDcTable[clip(q + dqy1_dc, 127)];
      m->y1_mat_[1] = kAcTable[clip(q + 0,       127)];

      m->y2_mat_[0] = kDcTable[clip(q + dqy2_dc, 127)] * 2;
      // For all x in [0..284], x*155/100 is bitwise equal to (x*101581) >> 16.
      // The smallest precision for that is '(x*6349) >> 12' but 16 is a good
      // word size.
      m->y2_mat_[1] = (kAcTable[clip(q + dqy2_ac, 127)] * 101581) >> 16;
      if (m->y2_mat_[1] < 8) m->y2_mat_[1] = 8;

      m->uv_mat_[0] = kDcTable[clip(q + dquv_dc, 117)];
      m->uv_mat_[1] = kAcTable[clip(q + dquv_ac, 127)];

      m->uv_quant_ = q + dquv_ac;   // for dithering strength evaluation
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdi, %rbx
leaq 0x10(%rdi), %r15
pushq $0x7
popq %rsi
movq %r15, %rdi
callq 0xe06e5
movl %eax, 0xc(%rsp)
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0xe06e5
movq $0x0, 0x18(%rsp)
movl $0x0, %ecx
movq %rcx, 0x10(%rsp)
testl %eax, %eax
je 0xe236e
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0xe0777
movq %rax, 0x10(%rsp)
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0xe06e5
testl %eax, %eax
je 0xe238d
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0xe0777
movq %rax, 0x18(%rsp)
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0xe06e5
xorl %r12d, %r12d
movl $0x0, %r13d
testl %eax, %eax
je 0xe23b3
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0xe0777
movl %eax, %r13d
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0xe06e5
testl %eax, %eax
je 0xe23d0
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0xe0777
movl %eax, %r12d
pushq $0x1
popq %rsi
movq %r15, %rdi
callq 0xe06e5
movl %eax, %ecx
xorl %r14d, %r14d
movl $0x0, %eax
testl %ecx, %ecx
je 0xe23f4
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0xe0777
movl 0x84(%rbx), %ecx
leaq 0x424(%rbx), %r11
pushq $0x7f
popq %rsi
leaq 0x3bda5(%rip), %rdi     # 0x11e1b0
leaq 0x3be1e(%rip), %r8      # 0x11e230
movq %r11, 0x20(%rsp)
xorl %r9d, %r9d
cmpq $0x4, %r9
je 0xe2541
testl %ecx, %ecx
je 0xe2510
movsbl 0x90(%rbx,%r9), %r15d
cmpl $0x0, 0x8c(%rbx)
movl $0x0, %r10d
cmovel 0xc(%rsp), %r10d
addl %r15d, %r10d
movq 0x10(%rsp), %rdx
leal (%r10,%rdx), %r15d
cmpl %esi, %r15d
cmovgel %esi, %r15d
testl %r15d, %r15d
cmovlel %r14d, %r15d
movzbl (%r15,%rdi), %r15d
cmpl %esi, %r10d
movl %esi, %edx
cmovll %r10d, %edx
movl %r15d, (%r11)
testl %edx, %edx
cmovlel %r14d, %edx
movq 0x18(%rsp), %r15
addl %r10d, %r15d
cmpl %esi, %r15d
cmovgel %esi, %r15d
movzwl (%r8,%rdx,2), %edx
testl %r15d, %r15d
cmovlel %r14d, %r15d
movl %edx, 0x4(%r11)
movzbl (%r15,%rdi), %edx
addl %edx, %edx
leal (%r10,%r13), %r15d
cmpl %esi, %r15d
movl %esi, %ebp
cmovll %r15d, %ebp
testl %ebp, %ebp
cmovlel %r14d, %ebp
movl %edx, 0x8(%r11)
movzwl (%r8,%rbp,2), %edx
imull $0x18ccd, %edx, %edx    # imm = 0x18CCD
shrl $0x10, %edx
cmpl $0x2, %r15d
pushq $0x8
popq %rbp
cmovll %ebp, %edx
movl %edx, 0xc(%r11)
leal (%r10,%r12), %edx
cmpl $0x75, %edx
pushq $0x75
popq %rbp
cmovgel %ebp, %edx
testl %edx, %edx
cmovlel %r14d, %edx
addl %eax, %r10d
cmpl %esi, %r10d
movl %esi, %r15d
cmovll %r10d, %r15d
movzbl (%rdx,%rdi), %edx
testl %r15d, %r15d
cmovlel %r14d, %r15d
movl %edx, 0x10(%r11)
movzwl (%r8,%r15,2), %edx
movl %edx, 0x14(%r11)
movl %r10d, 0x18(%r11)
jmp 0xe2535
movl 0xc(%rsp), %edx
movl %edx, %r10d
testq %r9, %r9
je 0xe244b
movq 0x20(%rsp), %rdx
movups (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
movups %xmm1, 0x10(%r11)
movups %xmm0, (%r11)
incq %r9
addq $0x20, %r11
jmp 0xe241a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq