// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/libraries/libwebp/src/dsp/alpha_processing_sse2.c
// Function: ApplyAlphaMultiply_SSE2
void ApplyAlphaMultiply_SSE2(uint8_t* rgba, int alpha_first,
                                    int w, int h, int stride) {
  const __m128i zero = _mm_setzero_si128();
  const __m128i kMult = _mm_set1_epi16((short)0x8081);
  const __m128i kMask = _mm_set_epi16(0, 0xff, 0xff, 0, 0, 0xff, 0xff, 0);
  const int kSpan = 4;
  while (h-- > 0) {
    uint32_t* const rgbx = (uint32_t*)rgba;
    int i;
    if (!alpha_first) {
      for (i = 0; i + kSpan <= w; i += kSpan) {
        APPLY_ALPHA(rgbx[i], _MM_SHUFFLE(2, 3, 3, 3));
      }
    } else {
      for (i = 0; i + kSpan <= w; i += kSpan) {
        APPLY_ALPHA(rgbx[i], _MM_SHUFFLE(0, 0, 0, 1));
      }
    }
    // Finish with left-overs.
    for (; i < w; ++i) {
      uint8_t* const rgb = rgba + (alpha_first ? 1 : 0);
      const uint8_t* const alpha = rgba + (alpha_first ? 0 : 3);
      const uint32_t a = alpha[4 * i];
      if (a != 0xff) {
        const uint32_t mult = MULTIPLIER(a);
        rgb[4 * i + 0] = PREMULTIPLY(rgb[4 * i + 0], mult);
        rgb[4 * i + 1] = PREMULTIPLY(rgb[4 * i + 1], mult);
        rgb[4 * i + 2] = PREMULTIPLY(rgb[4 * i + 2], mult);
      }
    }
    rgba += stride;
  }
}

// Assembly:
pushq %rbx
xorl %eax, %eax
xorl %r9d, %r9d
testl %esi, %esi
setne %al
sete %r9b
leaq (%r9,%r9,2), %r9
movslq %r8d, %r8
movslq %edx, %rdx
addq %rdi, %r9
addq %rdi, %rax
pxor %xmm0, %xmm0
movdqa 0x464ab(%rip), %xmm1    # 0x11c920
movdqa 0x46493(%rip), %xmm2    # 0x11c910
movdqa 0x4645b(%rip), %xmm3    # 0x11c8e0
testl %ecx, %ecx
jle 0xd65c1
xorl %r10d, %r10d
testl %esi, %esi
je 0xd6551
leaq 0x4(%r10), %r11
cmpq %rdx, %r11
jg 0xd655a
movdqu (%rdi,%r10,4), %xmm4
movdqa %xmm4, %xmm5
punpcklbw %xmm0, %xmm5    # xmm5 = xmm5[0],xmm0[0],xmm5[1],xmm0[1],xmm5[2],xmm0[2],xmm5[3],xmm0[3],xmm5[4],xmm0[4],xmm5[5],xmm0[5],xmm5[6],xmm0[6],xmm5[7],xmm0[7]
punpckhbw %xmm0, %xmm4    # xmm4 = xmm4[8],xmm0[8],xmm4[9],xmm0[9],xmm4[10],xmm0[10],xmm4[11],xmm0[11],xmm4[12],xmm0[12],xmm4[13],xmm0[13],xmm4[14],xmm0[14],xmm4[15],xmm0[15]
pshuflw $0x1, %xmm5, %xmm6      # xmm6 = xmm5[1,0,0,0,4,5,6,7]
pshufhw $0x1, %xmm6, %xmm6      # xmm6 = xmm6[0,1,2,3,5,4,4,4]
por %xmm1, %xmm6
pshuflw $0x1, %xmm4, %xmm7      # xmm7 = xmm4[1,0,0,0,4,5,6,7]
pshufhw $0x1, %xmm7, %xmm7      # xmm7 = xmm7[0,1,2,3,5,4,4,4]
por %xmm1, %xmm7
pmullw %xmm5, %xmm6
pmullw %xmm4, %xmm7
pmulhuw %xmm2, %xmm6
pmulhuw %xmm2, %xmm7
psrlw $0x7, %xmm6
psrlw $0x7, %xmm7
packuswb %xmm7, %xmm6
movdqu %xmm6, (%rdi,%r10,4)
movq %r11, %r10
jmp 0xd6498
movdqu (%rdi,%r10,4), %xmm4
movdqa %xmm4, %xmm5
punpcklbw %xmm0, %xmm5    # xmm5 = xmm5[0],xmm0[0],xmm5[1],xmm0[1],xmm5[2],xmm0[2],xmm5[3],xmm0[3],xmm5[4],xmm0[4],xmm5[5],xmm0[5],xmm5[6],xmm0[6],xmm5[7],xmm0[7]
punpckhbw %xmm0, %xmm4    # xmm4 = xmm4[8],xmm0[8],xmm4[9],xmm0[9],xmm4[10],xmm0[10],xmm4[11],xmm0[11],xmm4[12],xmm0[12],xmm4[13],xmm0[13],xmm4[14],xmm0[14],xmm4[15],xmm0[15]
pshuflw $0xbf, %xmm5, %xmm6     # xmm6 = xmm5[3,3,3,2,4,5,6,7]
pshufhw $0xbf, %xmm6, %xmm6     # xmm6 = xmm6[0,1,2,3,7,7,7,6]
por %xmm3, %xmm6
pshuflw $0xbf, %xmm4, %xmm7     # xmm7 = xmm4[3,3,3,2,4,5,6,7]
pshufhw $0xbf, %xmm7, %xmm7     # xmm7 = xmm7[0,1,2,3,7,7,7,6]
por %xmm3, %xmm7
pmullw %xmm5, %xmm6
pmullw %xmm4, %xmm7
pmulhuw %xmm2, %xmm6
pmulhuw %xmm2, %xmm7
psrlw $0x7, %xmm6
psrlw $0x7, %xmm7
packuswb %xmm7, %xmm6
movdqu %xmm6, (%rdi,%r10,4)
movq %r11, %r10
leaq 0x4(%r10), %r11
cmpq %rdx, %r11
jle 0xd64fc
decl %ecx
andl $-0x4, %r10d
cmpq %rdx, %r10
jge 0xd65b3
movzbl (%r9,%r10,4), %r11d
cmpl $0xff, %r11d
je 0xd65ae
imull $0x8081, %r11d, %r11d   # imm = 0x8081
movzbl (%rax,%r10,4), %ebx
imull %r11d, %ebx
shrl $0x17, %ebx
movb %bl, (%rax,%r10,4)
movzbl 0x1(%rax,%r10,4), %ebx
imull %r11d, %ebx
shrl $0x17, %ebx
movb %bl, 0x1(%rax,%r10,4)
movzbl 0x2(%rax,%r10,4), %ebx
imull %r11d, %ebx
shrl $0x17, %ebx
movb %bl, 0x2(%rax,%r10,4)
incq %r10
jmp 0xd6560
addq %r8, %rdi
addq %r8, %r9
addq %r8, %rax
jmp 0xd6485
popq %rbx
retq