// File: /workspace/github_c_makefile_star2_O2/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
xorl %r9d, %r9d
testl %eax, %eax
cmovlel %r9d, %eax
movl $0x1fe, %r10d           # imm = 0x1FE
movl $0xff, %r11d
movl $0x2020000, %ebx        # imm = 0x2020000
cmpq %r9, %rax
je 0xd5823
movl (%rdi,%r9,8), %ebp
movl 0x4(%rdi,%r9,8), %r14d
movl %ebp, %r15d
movzbl %bpl, %r12d
shrl $0xf, %ebp
andl %r10d, %ebp
movl %r14d, %r13d
shrl $0xf, %r13d
andl %r10d, %r13d
addl %ebp, %r13d
shrl $0x7, %r15d
andl %r10d, %r15d
movl %r14d, %ebp
shrl $0x8, %ebp
andl %r11d, %ebp
leal (%r15,%rbp,2), %ebp
addl %r12d, %r12d
andl %r11d, %r14d
leal (%r12,%r14,2), %r15d
imull $0xffffda09, %r13d, %r14d # imm = 0xFFFFDA09
imull $0xffffb577, %ebp, %r12d # imm = 0xFFFFB577
addl %r14d, %r12d
imull $0x7080, %r15d, %r14d   # imm = 0x7080
addl %ebx, %r14d
addl %r12d, %r14d
shrl $0x12, %r14d
imull $0x7080, %r13d, %r12d   # imm = 0x7080
imull $0xffffa1cc, %ebp, %ebp # imm = 0xFFFFA1CC
addl %r12d, %ebp
imull $0xffffedb4, %r15d, %r15d # imm = 0xFFFFEDB4
addl %ebx, %r15d
addl %ebp, %r15d
shrl $0x12, %r15d
testl %r8d, %r8d
je 0xd57f9
movb %r14b, (%rsi,%r9)
movb %r15b, (%rdx,%r9)
jmp 0xd581b
movzbl (%rsi,%r9), %r12d
leal (%r14,%r12), %ebp
incl %ebp
shrl %ebp
movb %bpl, (%rsi,%r9)
movzbl (%rdx,%r9), %r14d
leal (%r15,%r14), %ebp
incl %ebp
shrl %ebp
movb %bpl, (%rdx,%r9)
incq %r9
jmp 0xd575d
testb $0x1, %cl
je 0xd58bf
leal (%rax,%rax), %ecx
movl (%rdi,%rcx,4), %ecx
movl %ecx, %edi
movzbl %cl, %r9d
movl %ecx, %r10d
shrl $0xe, %r10d
movl $0x3fc, %ecx            # imm = 0x3FC
andl %ecx, %r10d
shrl $0x6, %edi
andl %ecx, %edi
shll $0x2, %r9d
imull $0xffffda09, %r10d, %ecx # imm = 0xFFFFDA09
imull $0xffffb577, %edi, %r11d # imm = 0xFFFFB577
addl %ecx, %r11d
imull $0x7080, %r9d, %ecx     # imm = 0x7080
movl $0x2020000, %ebx        # imm = 0x2020000
addl %ebx, %ecx
addl %r11d, %ecx
shrl $0x12, %ecx
imull $0x7080, %r10d, %r10d   # imm = 0x7080
imull $0xffffa1cc, %edi, %r11d # imm = 0xFFFFA1CC
addl %r10d, %r11d
imull $0xffffedb4, %r9d, %edi # imm = 0xFFFFEDB4
addl %ebx, %edi
addl %r11d, %edi
shrl $0x12, %edi
testl %r8d, %r8d
je 0xd58a3
movb %cl, (%rsi,%rax)
movb %dil, (%rdx,%rax)
jmp 0xd58bf
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