// File: /workspace/github_c_makefile_star2_O1/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 0xe1692
movl %eax, %r9d
xorl %eax, %eax
movl $0x1fe, %r10d           # imm = 0x1FE
movl $0x2020000, %r11d       # imm = 0x2020000
movl (%rdi,%rax,8), %r14d
movl 0x4(%rdi,%rax,8), %r15d
movl %r14d, %ebp
shrl $0xf, %ebp
andl %r10d, %ebp
movl %r15d, %ebx
shrl $0xf, %ebx
andl %r10d, %ebx
addl %ebp, %ebx
movl %r14d, %r12d
shrl $0x7, %r12d
andl %r10d, %r12d
movl %r15d, %r13d
shrl $0x8, %r13d
movl $0xff, %ebp
andl %ebp, %r13d
leal (%r12,%r13,2), %r12d
andl %ebp, %r14d
addl %r14d, %r14d
andl %ebp, %r15d
leal (%r14,%r15,2), %r15d
imull $0xffffda09, %ebx, %r14d # imm = 0xFFFFDA09
imull $0xffffb577, %r12d, %r13d # imm = 0xFFFFB577
addl %r14d, %r13d
imull $0x7080, %r15d, %r14d   # imm = 0x7080
addl %r11d, %r14d
addl %r13d, %r14d
shrl $0x12, %r14d
cmpl %ebp, %r14d
jl 0xe162d
movl $0xff, %r14d
imull $0x7080, %ebx, %ebx     # imm = 0x7080
imull $0xffffa1cc, %r12d, %r12d # imm = 0xFFFFA1CC
addl %ebx, %r12d
imull $0xffffedb4, %r15d, %ebx # imm = 0xFFFFEDB4
addl %r11d, %ebx
addl %r12d, %ebx
shrl $0x12, %ebx
cmpl %ebp, %ebx
jl 0xe1656
movl $0xff, %ebx
testl %r8d, %r8d
je 0xe1664
movb %r14b, (%rsi,%rax)
movb %bl, (%rdx,%rax)
jmp 0xe1684
movzbl (%rsi,%rax), %r15d
leal (%r14,%r15), %ebp
incl %ebp
shrl %ebp
movb %bpl, (%rsi,%rax)
movzbl (%rdx,%rax), %r14d
addl %r14d, %ebx
incl %ebx
shrl %ebx
movb %bl, (%rdx,%rax)
incq %rax
cmpq %rax, %r9
jne 0xe15b9
jmp 0xe1694
xorl %eax, %eax
testb $0x1, %cl
je 0xe1743
leal (%rax,%rax), %ecx
movl (%rdi,%rcx,4), %edi
movl %edi, %r10d
shrl $0xe, %r10d
movl $0x3fc, %ecx            # imm = 0x3FC
andl %ecx, %r10d
movl %edi, %r11d
shrl $0x6, %r11d
andl %ecx, %r11d
movl $0xff, %r9d
andl %r9d, %edi
shll $0x2, %edi
imull $0xffffda09, %r10d, %ecx # imm = 0xFFFFDA09
imull $0xffffb577, %r11d, %ebx # imm = 0xFFFFB577
addl %ecx, %ebx
imull $0x7080, %edi, %ecx     # imm = 0x7080
movl $0x2020000, %ebp        # imm = 0x2020000
addl %ebp, %ecx
addl %ebx, %ecx
shrl $0x12, %ecx
cmpl %r9d, %ecx
cmovgel %r9d, %ecx
imull $0x7080, %r10d, %r10d   # imm = 0x7080
imull $0xffffa1cc, %r11d, %r11d # imm = 0xFFFFA1CC
addl %r10d, %r11d
imull $0xffffedb4, %edi, %edi # imm = 0xFFFFEDB4
addl %ebp, %edi
addl %r11d, %edi
shrl $0x12, %edi
cmpl %r9d, %edi
cmovgel %r9d, %edi
movl %eax, %eax
testl %r8d, %r8d
je 0xe1727
movb %cl, (%rsi,%rax)
movb %dil, (%rdx,%rax)
jmp 0xe1743
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