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

    RGB24PackedToPlanar_SSE2(bgr, bgr_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.
      b = _mm_unpacklo_epi8(bgr_plane[0 + j], zero);
      g = _mm_unpacklo_epi8(bgr_plane[2 + j], zero);
      r = _mm_unpacklo_epi8(bgr_plane[4 + j], zero);
      ConvertRGBToY_SSE2(&r, &g, &b, &Y0);

      // Convert to 16-bit Y.
      b = _mm_unpackhi_epi8(bgr_plane[0 + j], zero);
      g = _mm_unpackhi_epi8(bgr_plane[2 + j], zero);
      r = _mm_unpackhi_epi8(bgr_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, bgr += 3) {  // left-over
    y[i] = VP8RGBToY(bgr[2], bgr[1], bgr[0], YUV_HALF);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %r15
movl %edx, 0x8(%rsp)
andl $-0x20, %edx
movl %edx, 0xc(%rsp)
leaq 0x2(%rdi), %r8
xorl %r14d, %r14d
leaq 0x50(%rsp), %r12
leaq 0x40(%rsp), %r13
leaq 0x30(%rsp), %rbp
leaq 0x90(%rsp), %rbx
movq %rsi, 0x10(%rsp)
cmpl 0xc(%rsp), %r14d
jge 0xdfe8c
movq %r8, 0x28(%rsp)
movq %rdi, 0x20(%rsp)
leaq 0xb0(%rsp), %rsi
callq 0xe0425
movq %r14, 0x18(%rsp)
movslq %r14d, %r14
addq %r15, %r14
xorl %r15d, %r15d
cmpq $0x20, %r15
je 0xdfe68
movdqa 0xb0(%rsp,%r15), %xmm0
movdqa %xmm0, 0x80(%rsp)
movdqa 0xd0(%rsp,%r15), %xmm3
movdqa %xmm3, 0x60(%rsp)
movdqa 0xf0(%rsp,%r15), %xmm1
movdqa %xmm1, 0x70(%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, 0x30(%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, 0x40(%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, 0x50(%rsp)
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
leaq 0xa0(%rsp), %rcx
callq 0xe02fc
movdqa 0x80(%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, 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, 0x40(%rsp)
movdqa 0x70(%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, 0x50(%rsp)
movq %r12, %rdi
movq %r13, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0xe02fc
movdqa 0xa0(%rsp), %xmm0
packuswb 0x90(%rsp), %xmm0
movdqu %xmm0, (%r14,%r15)
addq $0x10, %r15
jmp 0xdfd82
movq 0x18(%rsp), %r14
addl %r15d, %r14d
movq 0x20(%rsp), %rdi
addq $0x60, %rdi
movq 0x28(%rsp), %r8
addq $0x60, %r8
movq 0x10(%rsp), %r15
jmp 0xdfd52
movslq %r14d, %rax
movslq 0x8(%rsp), %rcx
cmpq %rcx, %rax
jge 0xdfed3
movzbl (%r8), %edx
movzbl -0x1(%r8), %esi
movzbl -0x2(%r8), %edi
imull $0x41c7, %edx, %edx     # imm = 0x41C7
imull $0x8123, %esi, %esi     # imm = 0x8123
addl %edx, %esi
imull $0x1914, %edi, %edx     # imm = 0x1914
addl %esi, %edx
addl $0x108000, %edx         # imm = 0x108000
shrl $0x10, %edx
movb %dl, (%r15,%rax)
incq %rax
addq $0x3, %r8
jmp 0xdfe94
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq