// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/libraries/libwebp/src/dsp/yuv_sse2.c
// Function: ConvertRGB24ToY_SSE2
static void ConvertRGB24ToY_SSE2(const uint8_t* rgb, uint8_t* y, int width) {
  const int max_width = width & ~31;
  int i;
  for (i = 0; i < max_width; rgb += 3 * 16 * 2) {
    __m128i rgb_plane[6];
    int j;

    RGB24PackedToPlanar_SSE2(rgb, rgb_plane);

    for (j = 0; j < 2; ++j, i += 16) {
      const __m128i zero = _mm_setzero_si128();
      __m128i r, g, b, Y0, Y1;

      // Convert to 16-bit Y.
      r = _mm_unpacklo_epi8(rgb_plane[0 + j], zero);
      g = _mm_unpacklo_epi8(rgb_plane[2 + j], zero);
      b = _mm_unpacklo_epi8(rgb_plane[4 + j], zero);
      ConvertRGBToY_SSE2(&r, &g, &b, &Y0);

      // Convert to 16-bit Y.
      r = _mm_unpackhi_epi8(rgb_plane[0 + j], zero);
      g = _mm_unpackhi_epi8(rgb_plane[2 + j], zero);
      b = _mm_unpackhi_epi8(rgb_plane[4 + j], zero);
      ConvertRGBToY_SSE2(&r, &g, &b, &Y1);

      // Cast to 8-bit and store.
      STORE_16(_mm_packus_epi16(Y0, Y1), y + i);
    }
  }
  for (; i < width; ++i, rgb += 3) {   // left-over
    y[i] = VP8RGBToY(rgb[0], rgb[1], rgb[2], YUV_HALF);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsi, %r15
movl %edx, (%rsp)
andl $-0x20, %edx
movl %edx, 0x4(%rsp)
xorl %r14d, %r14d
leaq 0x40(%rsp), %r12
leaq 0x30(%rsp), %r13
leaq 0x20(%rsp), %rbp
leaq 0x80(%rsp), %rbx
movq %rsi, 0x8(%rsp)
cmpl 0x4(%rsp), %r14d
jge 0xdfcb9
movq %rdi, 0x18(%rsp)
leaq 0xa0(%rsp), %rsi
callq 0xe0425
movq %r14, 0x10(%rsp)
movslq %r14d, %r14
addq %r15, %r14
xorl %r15d, %r15d
cmpq $0x20, %r15
je 0xdfc9e
movdqa 0xa0(%rsp,%r15), %xmm0
movdqa %xmm0, 0x70(%rsp)
movdqa 0xc0(%rsp,%r15), %xmm3
movdqa %xmm3, 0x50(%rsp)
movdqa 0xe0(%rsp,%r15), %xmm1
movdqa %xmm1, 0x60(%rsp)
pxor %xmm2, %xmm2
punpcklbw %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1],xmm0[2],xmm2[2],xmm0[3],xmm2[3],xmm0[4],xmm2[4],xmm0[5],xmm2[5],xmm0[6],xmm2[6],xmm0[7],xmm2[7]
movdqa %xmm0, 0x40(%rsp)
movdqa %xmm3, %xmm0
punpcklbw %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1],xmm0[2],xmm2[2],xmm0[3],xmm2[3],xmm0[4],xmm2[4],xmm0[5],xmm2[5],xmm0[6],xmm2[6],xmm0[7],xmm2[7]
movdqa %xmm0, 0x30(%rsp)
movdqa %xmm1, %xmm0
punpcklbw %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1],xmm0[2],xmm2[2],xmm0[3],xmm2[3],xmm0[4],xmm2[4],xmm0[5],xmm2[5],xmm0[6],xmm2[6],xmm0[7],xmm2[7]
movdqa %xmm0, 0x20(%rsp)
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
leaq 0x90(%rsp), %rcx
callq 0xe02fc
movdqa 0x70(%rsp), %xmm0
pxor %xmm1, %xmm1
punpckhbw %xmm1, %xmm0    # xmm0 = xmm0[8],xmm1[8],xmm0[9],xmm1[9],xmm0[10],xmm1[10],xmm0[11],xmm1[11],xmm0[12],xmm1[12],xmm0[13],xmm1[13],xmm0[14],xmm1[14],xmm0[15],xmm1[15]
movdqa %xmm0, 0x40(%rsp)
movdqa 0x50(%rsp), %xmm0
punpckhbw %xmm1, %xmm0    # xmm0 = xmm0[8],xmm1[8],xmm0[9],xmm1[9],xmm0[10],xmm1[10],xmm0[11],xmm1[11],xmm0[12],xmm1[12],xmm0[13],xmm1[13],xmm0[14],xmm1[14],xmm0[15],xmm1[15]
movdqa %xmm0, 0x30(%rsp)
movdqa 0x60(%rsp), %xmm0
punpckhbw %xmm1, %xmm0    # xmm0 = xmm0[8],xmm1[8],xmm0[9],xmm1[9],xmm0[10],xmm1[10],xmm0[11],xmm1[11],xmm0[12],xmm1[12],xmm0[13],xmm1[13],xmm0[14],xmm1[14],xmm0[15],xmm1[15]
movdqa %xmm0, 0x20(%rsp)
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0xe02fc
movdqa 0x90(%rsp), %xmm0
packuswb 0x80(%rsp), %xmm0
movdqu %xmm0, (%r14,%r15)
addq $0x10, %r15
jmp 0xdfbbe
movq 0x10(%rsp), %r14
addl %r15d, %r14d
movq 0x18(%rsp), %rdi
addq $0x60, %rdi
movq 0x8(%rsp), %r15
jmp 0xdfb93
movslq %r14d, %rax
movslq (%rsp), %rcx
cmpq %rcx, %rax
jge 0xdfcfe
movzbl (%rdi), %edx
movzbl 0x1(%rdi), %esi
movzbl 0x2(%rdi), %r8d
imull $0x41c7, %edx, %edx     # imm = 0x41C7
imull $0x8123, %esi, %esi     # imm = 0x8123
addl %edx, %esi
imull $0x1914, %r8d, %edx     # imm = 0x1914
addl %esi, %edx
addl $0x108000, %edx         # imm = 0x108000
shrl $0x10, %edx
movb %dl, (%r15,%rax)
incq %rax
addq $0x3, %rdi
jmp 0xdfcc0
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq