// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/libraries/libwebp/src/dsp/yuv_sse2.c
// Function: ConvertARGBToUV_SSE2
static void ConvertARGBToUV_SSE2(const uint32_t* argb,
                                 uint8_t* u, uint8_t* v,
                                 int src_width, int do_store) {
  const int max_width = src_width & ~31;
  int i;
  for (i = 0; i < max_width; i += 32, u += 16, v += 16) {
    __m128i rgb[6], U0, V0, U1, V1;
    RGB32PackedToPlanar_SSE2(&argb[i], rgb);
    HorizontalAddPack_SSE2(&rgb[0], &rgb[1], &rgb[0]);
    HorizontalAddPack_SSE2(&rgb[2], &rgb[3], &rgb[2]);
    HorizontalAddPack_SSE2(&rgb[4], &rgb[5], &rgb[4]);
    ConvertRGBToUV_SSE2(&rgb[0], &rgb[2], &rgb[4], &U0, &V0);

    RGB32PackedToPlanar_SSE2(&argb[i + 16], rgb);
    HorizontalAddPack_SSE2(&rgb[0], &rgb[1], &rgb[0]);
    HorizontalAddPack_SSE2(&rgb[2], &rgb[3], &rgb[2]);
    HorizontalAddPack_SSE2(&rgb[4], &rgb[5], &rgb[4]);
    ConvertRGBToUV_SSE2(&rgb[0], &rgb[2], &rgb[4], &U1, &V1);

    U0 = _mm_packus_epi16(U0, U1);
    V0 = _mm_packus_epi16(V0, V1);
    if (!do_store) {
      const __m128i prev_u = LOAD_16(u);
      const __m128i prev_v = LOAD_16(v);
      U0 = _mm_avg_epu8(U0, prev_u);
      V0 = _mm_avg_epu8(V0, prev_v);
    }
    STORE_16(U0, u);
    STORE_16(V0, v);
  }
  if (i < src_width) {  // left-over
    WebPConvertARGBToUV_C(argb + i, u, v, src_width - i, do_store);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %r8d, 0x8(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
movl %ecx, 0xc(%rsp)
movl %ecx, %eax
andl $-0x20, %eax
cltq
movq %rax, 0x18(%rsp)
xorl %eax, %eax
cmpq 0x18(%rsp), %rax
jge 0xdfb16
movq %rax, 0x10(%rsp)
movq %r12, %rdi
leaq 0x20(%rsp), %r13
movq %r13, %rsi
callq 0xe025f
movdqa 0x20(%rsp), %xmm0
movdqa 0x3da34(%rip), %xmm2    # 0x11d3e0
pmaddwd %xmm2, %xmm0
movdqa 0x30(%rsp), %xmm1
pmaddwd %xmm2, %xmm1
packssdw %xmm1, %xmm0
movdqa %xmm0, 0x20(%rsp)
movdqa 0x40(%rsp), %xmm0
pmaddwd %xmm2, %xmm0
movdqa 0x50(%rsp), %xmm1
pmaddwd %xmm2, %xmm1
packssdw %xmm1, %xmm0
movdqa %xmm0, 0x40(%rsp)
movdqa 0x60(%rsp), %xmm0
pmaddwd %xmm2, %xmm0
movdqa 0x70(%rsp), %xmm1
pmaddwd %xmm2, %xmm1
packssdw %xmm1, %xmm0
movdqa %xmm0, 0x60(%rsp)
movq %r13, %rdi
leaq 0x40(%rsp), %rbp
movq %rbp, %rsi
leaq 0x60(%rsp), %rbx
movq %rbx, %rdx
leaq 0xb0(%rsp), %rcx
leaq 0xa0(%rsp), %r8
callq 0xe036b
leaq 0x40(%r12), %rdi
movq %r13, %rsi
callq 0xe025f
movdqa 0x20(%rsp), %xmm0
movdqa 0x3d99d(%rip), %xmm2    # 0x11d3e0
pmaddwd %xmm2, %xmm0
movdqa 0x30(%rsp), %xmm1
pmaddwd %xmm2, %xmm1
packssdw %xmm1, %xmm0
movdqa %xmm0, 0x20(%rsp)
movdqa 0x40(%rsp), %xmm0
pmaddwd %xmm2, %xmm0
movdqa 0x50(%rsp), %xmm1
pmaddwd %xmm2, %xmm1
packssdw %xmm1, %xmm0
movdqa %xmm0, 0x40(%rsp)
movdqa 0x60(%rsp), %xmm0
pmaddwd %xmm2, %xmm0
movdqa 0x70(%rsp), %xmm1
pmaddwd %xmm2, %xmm1
packssdw %xmm1, %xmm0
movdqa %xmm0, 0x60(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
leaq 0x90(%rsp), %rcx
leaq 0x80(%rsp), %r8
callq 0xe036b
movdqa 0xb0(%rsp), %xmm0
packuswb 0x90(%rsp), %xmm0
movdqa 0xa0(%rsp), %xmm1
packuswb 0x80(%rsp), %xmm1
cmpl $0x0, 0x8(%rsp)
jne 0xdfaf2
movdqu (%r15), %xmm2
movdqu (%r14), %xmm3
pavgb %xmm2, %xmm0
pavgb %xmm3, %xmm1
movq 0x10(%rsp), %rax
movdqu %xmm0, (%r15)
movdqu %xmm1, (%r14)
addq $0x20, %rax
addq $0x10, %r15
addq $0x10, %r14
subq $-0x80, %r12
jmp 0xdf97e
movl 0xc(%rsp), %ecx
cmpl %ecx, %eax
jge 0xdfb44
subl %eax, %ecx
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movl 0x8(%rsp), %r8d
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd5735
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq