// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/libraries/libwebp/src/dsp/alpha_processing_sse2.c
// Function: ExtractAlpha_SSE2
static int ExtractAlpha_SSE2(const uint8_t* WEBP_RESTRICT argb, int argb_stride,
                             int width, int height,
                             uint8_t* WEBP_RESTRICT alpha, int alpha_stride) {
  // alpha_and stores an 'and' operation of all the alpha[] values. The final
  // value is not 0xff if any of the alpha[] is not equal to 0xff.
  uint32_t alpha_and = 0xff;
  int i, j;
  const __m128i a_mask = _mm_set1_epi32(0xff);  // to preserve alpha
  const __m128i all_0xff = _mm_set_epi32(0, 0, ~0, ~0);
  __m128i all_alphas = all_0xff;

  // We must be able to access 3 extra bytes after the last written byte
  // 'src[4 * width - 4]', because we don't know if alpha is the first or the
  // last byte of the quadruplet.
  const int limit = (width - 1) & ~7;

  for (j = 0; j < height; ++j) {
    const __m128i* src = (const __m128i*)argb;
    for (i = 0; i < limit; i += 8) {
      // load 32 argb bytes
      const __m128i a0 = _mm_loadu_si128(src + 0);
      const __m128i a1 = _mm_loadu_si128(src + 1);
      const __m128i b0 = _mm_and_si128(a0, a_mask);
      const __m128i b1 = _mm_and_si128(a1, a_mask);
      const __m128i c0 = _mm_packs_epi32(b0, b1);
      const __m128i d0 = _mm_packus_epi16(c0, c0);
      // store
      _mm_storel_epi64((__m128i*)&alpha[i], d0);
      // accumulate eight alpha 'and' in parallel
      all_alphas = _mm_and_si128(all_alphas, d0);
      src += 2;
    }
    for (; i < width; ++i) {
      const uint32_t alpha_value = argb[4 * i];
      alpha[i] = alpha_value;
      alpha_and &= alpha_value;
    }
    argb += argb_stride;
    alpha += alpha_stride;
  }
  // Combine the eight alpha 'and' into a 8-bit mask.
  alpha_and &= _mm_movemask_epi8(_mm_cmpeq_epi8(all_alphas, all_0xff));
  return (alpha_and == 0xff);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1a0, %rsp            # imm = 0x1A0
movq %rdi, -0x148(%rbp)
movl %esi, -0x14c(%rbp)
movl %edx, -0x150(%rbp)
movl %ecx, -0x154(%rbp)
movq %r8, -0x160(%rbp)
movl %r9d, -0x164(%rbp)
movl $0xff, -0x168(%rbp)
movl $0xff, -0xf4(%rbp)
movl -0xf4(%rbp), %eax
movl %eax, -0xd4(%rbp)
movl %eax, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
movl %eax, -0xe0(%rbp)
movd -0xd4(%rbp), %xmm0
movd -0xd8(%rbp), %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movd -0xdc(%rbp), %xmm2
movd -0xe0(%rbp), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movaps %xmm0, -0xf0(%rbp)
movaps -0xf0(%rbp), %xmm0
movaps %xmm0, -0x180(%rbp)
movl $0x0, -0xb4(%rbp)
movl $0x0, -0xb8(%rbp)
movl $0xffffffff, -0xbc(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0xc0(%rbp) # imm = 0xFFFFFFFF
movd -0xb4(%rbp), %xmm0
movd -0xb8(%rbp), %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movd -0xbc(%rbp), %xmm2
movd -0xc0(%rbp), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movdqa %xmm0, -0xd0(%rbp)
movdqa -0xd0(%rbp), %xmm0
movdqa %xmm0, -0x190(%rbp)
movdqa -0x190(%rbp), %xmm0
movdqa %xmm0, -0x1a0(%rbp)
movl -0x150(%rbp), %eax
subl $0x1, %eax
andl $-0x8, %eax
movl %eax, -0x1a4(%rbp)
movl $0x0, -0x170(%rbp)
movl -0x170(%rbp), %eax
cmpl -0x154(%rbp), %eax
jge 0x156e60
movq -0x148(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movl $0x0, -0x16c(%rbp)
movl -0x16c(%rbp), %eax
cmpl -0x1a4(%rbp), %eax
jge 0x156daf
movq -0x1b0(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rax
movups (%rax), %xmm0
movaps %xmm0, -0x1c0(%rbp)
movq -0x1b0(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x108(%rbp)
movq -0x108(%rbp), %rax
movups (%rax), %xmm0
movaps %xmm0, -0x1d0(%rbp)
movaps -0x1c0(%rbp), %xmm1
movaps -0x180(%rbp), %xmm0
movaps %xmm1, -0x60(%rbp)
movaps %xmm0, -0x70(%rbp)
movaps -0x60(%rbp), %xmm0
movaps -0x70(%rbp), %xmm1
pand %xmm1, %xmm0
movaps %xmm0, -0x1e0(%rbp)
movaps -0x1d0(%rbp), %xmm1
movaps -0x180(%rbp), %xmm0
movaps %xmm1, -0x80(%rbp)
movaps %xmm0, -0x90(%rbp)
movaps -0x80(%rbp), %xmm0
movaps -0x90(%rbp), %xmm1
pand %xmm1, %xmm0
movaps %xmm0, -0x1f0(%rbp)
movaps -0x1e0(%rbp), %xmm1
movaps -0x1f0(%rbp), %xmm0
movaps %xmm1, -0x10(%rbp)
movaps %xmm0, -0x20(%rbp)
movaps -0x10(%rbp), %xmm0
movaps -0x20(%rbp), %xmm1
packssdw %xmm1, %xmm0
movaps %xmm0, -0x200(%rbp)
movaps -0x200(%rbp), %xmm0
movaps %xmm0, -0x130(%rbp)
movaps %xmm0, -0x140(%rbp)
movaps -0x130(%rbp), %xmm0
movaps -0x140(%rbp), %xmm1
packuswb %xmm1, %xmm0
movaps %xmm0, -0x210(%rbp)
movq -0x160(%rbp), %rax
movslq -0x16c(%rbp), %rcx
addq %rcx, %rax
movaps -0x210(%rbp), %xmm0
movq %rax, -0x110(%rbp)
movaps %xmm0, -0x120(%rbp)
movq -0x120(%rbp), %rcx
movq -0x110(%rbp), %rax
movq %rcx, (%rax)
movdqa -0x1a0(%rbp), %xmm1
movdqa -0x210(%rbp), %xmm0
movdqa %xmm1, -0xa0(%rbp)
movdqa %xmm0, -0xb0(%rbp)
movdqa -0xa0(%rbp), %xmm0
pand -0xb0(%rbp), %xmm0
movdqa %xmm0, -0x1a0(%rbp)
movq -0x1b0(%rbp), %rax
addq $0x20, %rax
movq %rax, -0x1b0(%rbp)
movl -0x16c(%rbp), %eax
addl $0x8, %eax
movl %eax, -0x16c(%rbp)
jmp 0x156c17
jmp 0x156db1
movl -0x16c(%rbp), %eax
cmpl -0x150(%rbp), %eax
jge 0x156e18
movq -0x148(%rbp), %rax
movl -0x16c(%rbp), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x214(%rbp)
movl -0x214(%rbp), %eax
movb %al, %dl
movq -0x160(%rbp), %rax
movslq -0x16c(%rbp), %rcx
movb %dl, (%rax,%rcx)
movl -0x214(%rbp), %eax
andl -0x168(%rbp), %eax
movl %eax, -0x168(%rbp)
movl -0x16c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x16c(%rbp)
jmp 0x156db1
movl -0x14c(%rbp), %ecx
movq -0x148(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x148(%rbp)
movl -0x164(%rbp), %ecx
movq -0x160(%rbp), %rax
movslq %ecx, %rcx
addq %rcx, %rax
movq %rax, -0x160(%rbp)
movl -0x170(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x170(%rbp)
jmp 0x156bed
movaps -0x1a0(%rbp), %xmm1
movaps -0x190(%rbp), %xmm0
movaps %xmm1, -0x30(%rbp)
movaps %xmm0, -0x40(%rbp)
movaps -0x30(%rbp), %xmm0
movaps -0x40(%rbp), %xmm1
pcmpeqb %xmm1, %xmm0
movdqa %xmm0, -0x50(%rbp)
movdqa -0x50(%rbp), %xmm0
pmovmskb %xmm0, %eax
andl -0x168(%rbp), %eax
movl %eax, -0x168(%rbp)
cmpl $0xff, -0x168(%rbp)
sete %al
andb $0x1, %al
movzbl %al, %eax
addq $0x1a0, %rsp            # imm = 0x1A0
popq %rbp
retq
nopw (%rax,%rax)