// File: /workspace/github_c_makefile_star2_O3/enzo1982[P]smooth/libraries/libwebp/src/dsp/yuv.c
// Function: WebPConvertARGBToUV_C
void WebPConvertARGBToUV_C(const uint32_t* argb, uint8_t* u, uint8_t* v,
                           int src_width, int do_store) {
  // No rounding. Last pixel is dealt with separately.
  const int uv_width = src_width >> 1;
  int i;
  for (i = 0; i < uv_width; ++i) {
    const uint32_t v0 = argb[2 * i + 0];
    const uint32_t v1 = argb[2 * i + 1];
    // VP8RGBToU/V expects four accumulated pixels. Hence we need to
    // scale r/g/b value by a factor 2. We just shift v0/v1 one bit less.
    const int r = ((v0 >> 15) & 0x1fe) + ((v1 >> 15) & 0x1fe);
    const int g = ((v0 >>  7) & 0x1fe) + ((v1 >>  7) & 0x1fe);
    const int b = ((v0 <<  1) & 0x1fe) + ((v1 <<  1) & 0x1fe);
    const int tmp_u = VP8RGBToU(r, g, b, YUV_HALF << 2);
    const int tmp_v = VP8RGBToV(r, g, b, YUV_HALF << 2);
    if (do_store) {
      u[i] = tmp_u;
      v[i] = tmp_v;
    } else {
      // Approximated average-of-four. But it's an acceptable diff.
      u[i] = (u[i] + tmp_u + 1) >> 1;
      v[i] = (v[i] + tmp_v + 1) >> 1;
    }
  }
  if (src_width & 1) {       // last pixel
    const uint32_t v0 = argb[2 * i + 0];
    const int r = (v0 >> 14) & 0x3fc;
    const int g = (v0 >>  6) & 0x3fc;
    const int b = (v0 <<  2) & 0x3fc;
    const int tmp_u = VP8RGBToU(r, g, b, YUV_HALF << 2);
    const int tmp_v = VP8RGBToV(r, g, b, YUV_HALF << 2);
    if (do_store) {
      u[i] = tmp_u;
      v[i] = tmp_v;
    } else {
      u[i] = (u[i] + tmp_u + 1) >> 1;
      v[i] = (v[i] + tmp_v + 1) >> 1;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl %ecx, %eax
sarl %eax
testl %eax, %eax
jle 0xe07c2
movq %rax, -0x8(%rsp)
movl %eax, %r9d
xorl %r10d, %r10d
movl $0x1fe, %r11d           # imm = 0x1FE
movl $0xff, %ebx
movl $0x2020000, %ebp        # imm = 0x2020000
movl (%rdi,%r10,8), %r15d
movl 0x4(%rdi,%r10,8), %r14d
movl %r15d, %r12d
movzbl %r15b, %r13d
shrl $0xf, %r15d
andl %r11d, %r15d
movl %r14d, %eax
shrl $0xf, %eax
andl %r11d, %eax
addl %r15d, %eax
shrl $0x7, %r12d
andl %r11d, %r12d
movl %r14d, %r15d
shrl $0x8, %r15d
andl %ebx, %r15d
leal (%r12,%r15,2), %r15d
addl %r13d, %r13d
andl %ebx, %r14d
leal (%r13,%r14,2), %r12d
imull $0xffffda09, %eax, %r14d # imm = 0xFFFFDA09
imull $0xffffb577, %r15d, %r13d # imm = 0xFFFFB577
addl %r14d, %r13d
imull $0x7080, %r12d, %r14d   # imm = 0x7080
addl %ebp, %r14d
addl %r13d, %r14d
shrl $0x12, %r14d
imull $0x7080, %eax, %eax     # imm = 0x7080
imull $0xffffa1cc, %r15d, %r13d # imm = 0xFFFFA1CC
addl %eax, %r13d
imull $0xffffedb4, %r12d, %r15d # imm = 0xFFFFEDB4
addl %ebp, %r15d
addl %r13d, %r15d
shrl $0x12, %r15d
testl %r8d, %r8d
je 0xe078f
movb %r14b, (%rsi,%r10)
movb %r15b, (%rdx,%r10)
jmp 0xe07af
movzbl (%rsi,%r10), %eax
addl %r14d, %eax
incl %eax
shrl %eax
movb %al, (%rsi,%r10)
movzbl (%rdx,%r10), %eax
addl %r15d, %eax
incl %eax
shrl %eax
movb %al, (%rdx,%r10)
incq %r10
cmpq %r10, %r9
jne 0xe06fa
movq -0x8(%rsp), %rbx
jmp 0xe07c4
xorl %ebx, %ebx
testb $0x1, %cl
je 0xe085e
leal (%rbx,%rbx), %eax
movl (%rdi,%rax,4), %eax
movl %eax, %edi
movzbl %al, %r9d
shrl $0xe, %eax
movl $0x3fc, %ecx            # imm = 0x3FC
andl %ecx, %eax
shrl $0x6, %edi
andl %ecx, %edi
shll $0x2, %r9d
imull $0xffffda09, %eax, %ecx # imm = 0xFFFFDA09
imull $0xffffb577, %edi, %r10d # imm = 0xFFFFB577
addl %ecx, %r10d
imull $0x7080, %r9d, %ecx     # imm = 0x7080
movl $0x2020000, %r11d       # imm = 0x2020000
addl %r11d, %ecx
addl %r10d, %ecx
shrl $0x12, %ecx
imull $0x7080, %eax, %eax     # imm = 0x7080
imull $0xffffa1cc, %edi, %r10d # imm = 0xFFFFA1CC
addl %eax, %r10d
imull $0xffffedb4, %r9d, %edi # imm = 0xFFFFEDB4
addl %r11d, %edi
addl %r10d, %edi
shrl $0x12, %edi
movl %ebx, %eax
testl %r8d, %r8d
je 0xe0842
movb %cl, (%rsi,%rax)
movb %dil, (%rdx,%rax)
jmp 0xe085e
movzbl (%rsi,%rax), %r8d
addl %r8d, %ecx
incl %ecx
shrl %ecx
movb %cl, (%rsi,%rax)
movzbl (%rdx,%rax), %ecx
addl %edi, %ecx
incl %ecx
shrl %ecx
movb %cl, (%rdx,%rax)
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq