// File: /workspace/github_c_makefile_star2_O3/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:
testl %ecx, %ecx
jle 0xe2205
pushq %rbp
pushq %r14
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, %r10
movl %r10d, %r11d
addq %rdi, %r9
addq %rdi, %rax
pxor %xmm0, %xmm0
movdqa 0x300e6(%rip), %xmm1    # 0x112190
movdqa 0x4ab7e(%rip), %xmm2    # 0x12cc30
movdqa 0x4ab46(%rip), %xmm3    # 0x12cc00
testl %esi, %esi
je 0xe2127
cmpl $0x4, %edx
jl 0xe212c
xorl %ebx, %ebx
movq %rbx, %r14
movdqu (%rdi,%rbx,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,%rbx,4)
addq $0x4, %rbx
addq $0x8, %r14
cmpq %r10, %r14
jle 0xe20c5
jmp 0xe2192
cmpl $0x4, %edx
jge 0xe2130
xorl %ebx, %ebx
jmp 0xe2192
xorl %ebx, %ebx
movq %rbx, %r14
movdqu (%rdi,%rbx,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,%rbx,4)
addq $0x4, %rbx
addq $0x8, %r14
cmpq %r10, %r14
jle 0xe2132
cmpl %edx, %ebx
jge 0xe21ea
movl %ebx, %ebx
movzbl (%r9,%rbx,4), %ebp
cmpl $0xff, %ebp
je 0xe21e2
imull $0x8081, %ebp, %ebp     # imm = 0x8081
movzbl (%rax,%rbx,4), %r14d
imull %ebp, %r14d
shrl $0x17, %r14d
movb %r14b, (%rax,%rbx,4)
movzbl 0x1(%rax,%rbx,4), %r14d
imull %ebp, %r14d
shrl $0x17, %r14d
movb %r14b, 0x1(%rax,%rbx,4)
movzbl 0x2(%rax,%rbx,4), %r14d
imull %ebp, %r14d
shrl $0x17, %r14d
movb %r14b, 0x2(%rax,%rbx,4)
incq %rbx
cmpq %rbx, %r11
jne 0xe2198
leal -0x1(%rcx), %ebx
addq %r8, %rdi
addq %r8, %r9
addq %r8, %rax
cmpl $0x1, %ecx
movl %ebx, %ecx
jg 0xe20ba
popq %rbx
popq %r14
popq %rbp
retq