// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/libraries/libwebp/src/dsp/dec_sse2.c
// Function: DoFilter4_SSE2
static WEBP_INLINE void DoFilter4_SSE2(__m128i* const p1, __m128i* const p0,
                                       __m128i* const q0, __m128i* const q1,
                                       const __m128i* const mask,
                                       int hev_thresh) {
  const __m128i zero = _mm_setzero_si128();
  const __m128i sign_bit = _mm_set1_epi8((char)0x80);
  const __m128i k64 = _mm_set1_epi8(64);
  const __m128i k3 = _mm_set1_epi8(3);
  const __m128i k4 = _mm_set1_epi8(4);
  __m128i not_hev;
  __m128i t1, t2, t3;

  // compute hev mask
  GetNotHEV_SSE2(p1, p0, q0, q1, hev_thresh, &not_hev);

  // convert to signed values
  FLIP_SIGN_BIT4(*p1, *p0, *q0, *q1);

  t1 = _mm_subs_epi8(*p1, *q1);        // p1 - q1
  t1 = _mm_andnot_si128(not_hev, t1);  // hev(p1 - q1)
  t2 = _mm_subs_epi8(*q0, *p0);        // q0 - p0
  t1 = _mm_adds_epi8(t1, t2);          // hev(p1 - q1) + 1 * (q0 - p0)
  t1 = _mm_adds_epi8(t1, t2);          // hev(p1 - q1) + 2 * (q0 - p0)
  t1 = _mm_adds_epi8(t1, t2);          // hev(p1 - q1) + 3 * (q0 - p0)
  t1 = _mm_and_si128(t1, *mask);       // mask filter values we don't care about

  t2 = _mm_adds_epi8(t1, k3);        // 3 * (q0 - p0) + hev(p1 - q1) + 3
  t3 = _mm_adds_epi8(t1, k4);        // 3 * (q0 - p0) + hev(p1 - q1) + 4
  SignedShift8b_SSE2(&t2);           // (3 * (q0 - p0) + hev(p1 - q1) + 3) >> 3
  SignedShift8b_SSE2(&t3);           // (3 * (q0 - p0) + hev(p1 - q1) + 4) >> 3
  *p0 = _mm_adds_epi8(*p0, t2);      // p0 += t2
  *q0 = _mm_subs_epi8(*q0, t3);      // q0 -= t3
  FLIP_SIGN_BIT2(*p0, *q0);

  // this is equivalent to signed (a + 1) >> 1 calculation
  t2 = _mm_add_epi8(t3, sign_bit);
  t3 = _mm_avg_epu8(t2, zero);
  t3 = _mm_sub_epi8(t3, k64);

  t3 = _mm_and_si128(not_hev, t3);   // if !hev
  *q1 = _mm_subs_epi8(*q1, t3);      // q1 -= t3
  *p1 = _mm_adds_epi8(*p1, t3);      // p1 += t3
  FLIP_SIGN_BIT2(*p1, *q1);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %r13
movq %rcx, %rbx
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movq %rsp, %rbp
movl %r9d, %r8d
movq %rbp, %r9
callq 0xd8833
movdqa 0x43e8c(%rip), %xmm0    # 0x11c9d0
movdqa (%r14), %xmm1
pxor %xmm0, %xmm1
movdqa %xmm1, (%r14)
movdqa (%r12), %xmm1
pxor %xmm0, %xmm1
movdqa %xmm1, (%r12)
movdqa (%r15), %xmm1
pxor %xmm0, %xmm1
movdqa %xmm1, (%r15)
movdqa (%rbx), %xmm1
pxor %xmm0, %xmm1
movdqa %xmm1, (%rbx)
movdqa (%r14), %xmm3
psubsb %xmm1, %xmm3
movdqa (%rbp), %xmm1
movdqa (%r15), %xmm4
movdqa (%r12), %xmm2
psubsb %xmm2, %xmm4
movdqa %xmm1, %xmm5
pandn %xmm3, %xmm5
paddsb %xmm4, %xmm5
paddsb %xmm4, %xmm5
paddsb %xmm4, %xmm5
pand (%r13), %xmm5
movdqa 0x43e45(%rip), %xmm3    # 0x11ca00
paddsb %xmm5, %xmm3
paddsb 0x43e49(%rip), %xmm5    # 0x11ca10
punpcklbw %xmm3, %xmm4    # xmm4 = xmm4[0],xmm3[0],xmm4[1],xmm3[1],xmm4[2],xmm3[2],xmm4[3],xmm3[3],xmm4[4],xmm3[4],xmm4[5],xmm3[5],xmm4[6],xmm3[6],xmm4[7],xmm3[7]
punpckhbw %xmm3, %xmm3    # xmm3 = xmm3[8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15]
psraw $0xb, %xmm4
psraw $0xb, %xmm3
packsswb %xmm3, %xmm4
punpcklbw %xmm5, %xmm3    # xmm3 = xmm3[0],xmm5[0],xmm3[1],xmm5[1],xmm3[2],xmm5[2],xmm3[3],xmm5[3],xmm3[4],xmm5[4],xmm3[5],xmm5[5],xmm3[6],xmm5[6],xmm3[7],xmm5[7]
punpckhbw %xmm5, %xmm5    # xmm5 = xmm5[8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15]
psraw $0xb, %xmm3
psraw $0xb, %xmm5
packsswb %xmm5, %xmm3
paddsb %xmm2, %xmm4
movdqa %xmm4, (%r12)
movdqa (%r15), %xmm2
psubsb %xmm3, %xmm2
movdqa %xmm2, (%r15)
movdqa (%r12), %xmm2
pxor %xmm0, %xmm2
movdqa %xmm2, (%r12)
movdqa (%r15), %xmm2
pxor %xmm0, %xmm2
pxor 0x43da4(%rip), %xmm3    # 0x11c9d0
pxor %xmm4, %xmm4
pavgb %xmm3, %xmm4
paddb 0x43de4(%rip), %xmm4    # 0x11ca20
movdqa %xmm2, (%r15)
movdqa (%rbx), %xmm2
pand %xmm1, %xmm4
psubsb %xmm4, %xmm2
movdqa %xmm2, (%rbx)
paddsb (%r14), %xmm4
pxor %xmm0, %xmm4
movdqa %xmm4, (%r14)
pxor (%rbx), %xmm0
movdqa %xmm0, (%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq