// File: /workspace/github_c_makefile_star2_O1/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
movq %r15, %rdi
movl $0x7, %esi
callq 0xf09dd
movl %eax, 0xc(%rsp)
movq %r15, %rdi
movl $0x1, %esi
callq 0xf09dd
movq $0x0, 0x18(%rsp)
movl $0x0, %ecx
movq %rcx, 0x10(%rsp)
testl %eax, %eax
je 0xf28d8
movq %r15, %rdi
movl $0x4, %esi
callq 0xf0ada
movq %rax, 0x10(%rsp)
movq %r15, %rdi
movl $0x1, %esi
callq 0xf09dd
testl %eax, %eax
je 0xf28fb
movq %r15, %rdi
movl $0x4, %esi
callq 0xf0ada
movq %rax, 0x18(%rsp)
movq %r15, %rdi
movl $0x1, %esi
callq 0xf09dd
xorl %r12d, %r12d
movl $0x0, %r13d
testl %eax, %eax
je 0xf2925
movq %r15, %rdi
movl $0x4, %esi
callq 0xf0ada
movl %eax, %r13d
movq %r15, %rdi
movl $0x1, %esi
callq 0xf09dd
testl %eax, %eax
je 0xf2946
movq %r15, %rdi
movl $0x4, %esi
callq 0xf0ada
movl %eax, %r12d
movq %r15, %rdi
movl $0x1, %esi
callq 0xf09dd
movl %eax, %ecx
xorl %r14d, %r14d
movl $0x0, %eax
testl %ecx, %ecx
je 0xf296e
movq %r15, %rdi
movl $0x4, %esi
callq 0xf0ada
movl 0x84(%rbx), %ecx
leaq 0x424(%rbx), %r11
movl $0x7f, %esi
leaq 0x3c8e9(%rip), %rdi     # 0x12f270
leaq 0x3c962(%rip), %r8      # 0x12f2f0
movq %r11, 0x20(%rsp)
xorl %r9d, %r9d
testl %ecx, %ecx
je 0xf2a8f
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 $0x7f, %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 $0x7f, %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
movl $0x8, %ebp
cmovll %ebp, %edx
movl %edx, 0xc(%r11)
leal (%r10,%r12), %edx
cmpl $0x75, %edx
movl $0x75, %ebp
cmovgel %ebp, %edx
testl %edx, %edx
cmovlel %r14d, %edx
addl %eax, %r10d
cmpl %esi, %r10d
movl $0x7f, %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 0xf2ab4
movl 0xc(%rsp), %edx
movl %edx, %r10d
testq %r9, %r9
je 0xf29bd
movq 0x20(%rsp), %rdx
movups (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
movups %xmm1, 0x10(%r11)
movups %xmm0, (%r11)
incq %r9
addq $0x20, %r11
cmpq $0x4, %r9
jne 0xf2996
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq