// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/libraries/libwebp/src/dsp/rescaler_sse2.c
// Function: RescalerImportRowShrink_SSE2
static void RescalerImportRowShrink_SSE2(WebPRescaler* const wrk,
                                         const uint8_t* src) {
  const int x_sub = wrk->x_sub;
  int accum = 0;
  const __m128i zero = _mm_setzero_si128();
  const __m128i mult0 = _mm_set1_epi16(x_sub);
  const __m128i mult1 = _mm_set1_epi32(wrk->fx_scale);
  const __m128i rounder = _mm_set_epi32(0, ROUNDER, 0, ROUNDER);
  __m128i sum = zero;
  rescaler_t* frow = wrk->frow;
  const rescaler_t* const frow_end = wrk->frow + 4 * wrk->dst_width;

  if (wrk->num_channels != 4 || wrk->x_add > (x_sub << 7)) {
    WebPRescalerImportRowShrink_C(wrk, src);
    return;
  }
  assert(!WebPRescalerInputDone(wrk));
  assert(!wrk->x_expand);

  for (; frow < frow_end; frow += 4) {
    __m128i base = zero;
    accum += wrk->x_add;
    while (accum > 0) {
      const __m128i A = _mm_cvtsi32_si128(WebPMemToInt32(src));
      src += 4;
      base = _mm_unpacklo_epi8(A, zero);
      // To avoid overflow, we need: base * x_add / x_sub < 32768
      // => x_add < x_sub << 7. That's a 1/128 reduction ratio limit.
      sum = _mm_add_epi16(sum, base);
      accum -= x_sub;
    }
    {    // Emit next horizontal pixel.
      const __m128i mult = _mm_set1_epi16(-accum);
      const __m128i frac0 = _mm_mullo_epi16(base, mult);  // 16b x 16b -> 32b
      const __m128i frac1 = _mm_mulhi_epu16(base, mult);
      const __m128i frac = _mm_unpacklo_epi16(frac0, frac1);  // frac is 32b
      const __m128i A0 = _mm_mullo_epi16(sum, mult0);
      const __m128i A1 = _mm_mulhi_epu16(sum, mult0);
      const __m128i B0 = _mm_unpacklo_epi16(A0, A1);      // sum * x_sub
      const __m128i frow_out = _mm_sub_epi32(B0, frac);   // sum * x_sub - frac
      const __m128i D0 = _mm_srli_epi64(frac, 32);
      const __m128i D1 = _mm_mul_epu32(frac, mult1);      // 32b x 16b -> 64b
      const __m128i D2 = _mm_mul_epu32(D0, mult1);
      const __m128i E1 = _mm_add_epi64(D1, rounder);
      const __m128i E2 = _mm_add_epi64(D2, rounder);
      const __m128i F1 = _mm_shuffle_epi32(E1, 1 | (3 << 2));
      const __m128i F2 = _mm_shuffle_epi32(E2, 1 | (3 << 2));
      const __m128i G = _mm_unpacklo_epi32(F1, F2);
      sum = _mm_packs_epi32(G, zero);
      _mm_storeu_si128((__m128i*)frow, frow_out);
    }
  }
  assert(accum == 0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x490, %rsp            # imm = 0x490
movq %rdi, -0x2f0(%rbp)
movq %rsi, -0x2f8(%rbp)
movq -0x2f0(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x2fc(%rbp)
movl $0x0, -0x300(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x2a0(%rbp)
movaps -0x2a0(%rbp), %xmm0
movaps %xmm0, -0x310(%rbp)
movw -0x2fc(%rbp), %ax
movw %ax, -0x1e2(%rbp)
movw -0x1e2(%rbp), %ax
movw %ax, -0x482(%rbp)
movw %ax, -0x22(%rbp)
movw %ax, -0x24(%rbp)
movw %ax, -0x26(%rbp)
movw %ax, -0x28(%rbp)
movw %ax, -0x2a(%rbp)
movw %ax, -0x2c(%rbp)
movw %ax, -0x2e(%rbp)
movw %ax, -0x30(%rbp)
movzwl -0x22(%rbp), %eax
movd %eax, %xmm1
movzwl -0x24(%rbp), %eax
movd %eax, %xmm0
punpcklwd %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
movzwl -0x26(%rbp), %eax
movd %eax, %xmm2
movzwl -0x28(%rbp), %eax
movd %eax, %xmm1
punpcklwd %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1],xmm1[2],xmm2[2],xmm1[3],xmm2[3]
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movzwl -0x2a(%rbp), %eax
movd %eax, %xmm0
movzwl -0x2c(%rbp), %eax
movd %eax, %xmm2
punpcklwd %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1],xmm2[2],xmm0[2],xmm2[3],xmm0[3]
movzwl -0x2e(%rbp), %eax
movd %eax, %xmm3
movzwl -0x30(%rbp), %eax
movd %eax, %xmm0
punpcklwd %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1],xmm0[2],xmm3[2],xmm0[3],xmm3[3]
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movaps %xmm0, -0x40(%rbp)
movaps -0x40(%rbp), %xmm0
movaps %xmm0, -0x320(%rbp)
movq -0x2f0(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0x2e4(%rbp)
movl -0x2e4(%rbp), %eax
movl %eax, -0x214(%rbp)
movl %eax, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
movl %eax, -0x220(%rbp)
movd -0x214(%rbp), %xmm0
movd -0x218(%rbp), %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movd -0x21c(%rbp), %xmm2
movd -0x220(%rbp), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movaps %xmm0, -0x230(%rbp)
movaps -0x230(%rbp), %xmm0
movaps %xmm0, -0x330(%rbp)
movl $0x0, -0x1e8(%rbp)
movl $0x80000000, -0x1ec(%rbp) # imm = 0x80000000
movl $0x0, -0x1f0(%rbp)
movl $0x80000000, -0x1f4(%rbp) # imm = 0x80000000
movd -0x1e8(%rbp), %xmm0
movd -0x1ec(%rbp), %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movd -0x1f0(%rbp), %xmm2
movd -0x1f4(%rbp), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movdqa %xmm0, -0x210(%rbp)
movdqa -0x210(%rbp), %xmm0
movdqa %xmm0, -0x340(%rbp)
movdqa -0x310(%rbp), %xmm0
movdqa %xmm0, -0x350(%rbp)
movq -0x2f0(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x358(%rbp)
movq -0x2f0(%rbp), %rax
movq 0x60(%rax), %rax
movq -0x2f0(%rbp), %rcx
movl 0x34(%rcx), %ecx
shll $0x2, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x360(%rbp)
movq -0x2f0(%rbp), %rax
cmpl $0x4, 0x8(%rax)
jne 0x16c93c
movq -0x2f0(%rbp), %rax
movl 0x24(%rax), %eax
movl -0x2fc(%rbp), %ecx
shll $0x7, %ecx
cmpl %ecx, %eax
jle 0x16c954
movq -0x2f0(%rbp), %rdi
movq -0x2f8(%rbp), %rsi
callq 0x150aa0
jmp 0x16cedd
movq -0x2f0(%rbp), %rdi
callq 0x16e0c0
cmpl $0x0, %eax
jne 0x16c967
jmp 0x16c986
leaq 0x534ce(%rip), %rdi     # 0x1bfe3c
leaq 0x5424b(%rip), %rsi     # 0x1c0bc0
movl $0x80, %edx
leaq 0x5429f(%rip), %rcx     # 0x1c0c20
callq 0x598a0
movq -0x2f0(%rbp), %rax
cmpl $0x0, (%rax)
jne 0x16c994
jmp 0x16c9b3
leaq 0x535a1(%rip), %rdi     # 0x1bff3c
leaq 0x5421e(%rip), %rsi     # 0x1c0bc0
movl $0x81, %edx
leaq 0x54272(%rip), %rcx     # 0x1c0c20
callq 0x598a0
jmp 0x16c9b5
movq -0x358(%rbp), %rax
cmpq -0x360(%rbp), %rax
jae 0x16ceb3
movdqa -0x310(%rbp), %xmm0
movdqa %xmm0, -0x370(%rbp)
movq -0x2f0(%rbp), %rax
movl 0x24(%rax), %eax
addl -0x300(%rbp), %eax
movl %eax, -0x300(%rbp)
cmpl $0x0, -0x300(%rbp)
jle 0x16cac8
movq -0x2f8(%rbp), %rdi
callq 0x16e240
movl %eax, -0x2a4(%rbp)
movd -0x2a4(%rbp), %xmm0
movaps %xmm0, -0x2c0(%rbp)
movaps -0x2c0(%rbp), %xmm0
movaps %xmm0, -0x380(%rbp)
movq -0x2f8(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x2f8(%rbp)
movaps -0x380(%rbp), %xmm1
movaps -0x310(%rbp), %xmm0
movaps %xmm1, -0x280(%rbp)
movaps %xmm0, -0x290(%rbp)
movaps -0x280(%rbp), %xmm0
movaps -0x290(%rbp), %xmm1
punpcklbw %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3],xmm0[4],xmm1[4],xmm0[5],xmm1[5],xmm0[6],xmm1[6],xmm0[7],xmm1[7]
movdqa %xmm0, -0x370(%rbp)
movdqa -0x350(%rbp), %xmm1
movdqa -0x370(%rbp), %xmm0
movdqa %xmm1, -0x1d0(%rbp)
movdqa %xmm0, -0x1e0(%rbp)
movdqa -0x1d0(%rbp), %xmm0
movdqa -0x1e0(%rbp), %xmm1
paddw %xmm1, %xmm0
movdqa %xmm0, -0x350(%rbp)
movl -0x2fc(%rbp), %ecx
movl -0x300(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x300(%rbp)
jmp 0x16c9ef
movw -0x300(%rbp), %ax
negw %ax
movw %ax, -0x1e4(%rbp)
movw -0x1e4(%rbp), %ax
movw %ax, -0x484(%rbp)
movw %ax, -0x2(%rbp)
movw %ax, -0x4(%rbp)
movw %ax, -0x6(%rbp)
movw %ax, -0x8(%rbp)
movw %ax, -0xa(%rbp)
movw %ax, -0xc(%rbp)
movw %ax, -0xe(%rbp)
movw %ax, -0x10(%rbp)
movzwl -0x2(%rbp), %eax
movd %eax, %xmm1
movzwl -0x4(%rbp), %eax
movd %eax, %xmm0
punpcklwd %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
movzwl -0x6(%rbp), %eax
movd %eax, %xmm2
movzwl -0x8(%rbp), %eax
movd %eax, %xmm1
punpcklwd %xmm2, %xmm1    # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1],xmm1[2],xmm2[2],xmm1[3],xmm2[3]
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movzwl -0xa(%rbp), %eax
movd %eax, %xmm0
movzwl -0xc(%rbp), %eax
movd %eax, %xmm2
punpcklwd %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1],xmm2[2],xmm0[2],xmm2[3],xmm0[3]
movzwl -0xe(%rbp), %eax
movd %eax, %xmm3
movzwl -0x10(%rbp), %eax
movd %eax, %xmm0
punpcklwd %xmm3, %xmm0    # xmm0 = xmm0[0],xmm3[0],xmm0[1],xmm3[1],xmm0[2],xmm3[2],xmm0[3],xmm3[3]
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movaps %xmm0, -0x20(%rbp)
movaps -0x20(%rbp), %xmm0
movaps %xmm0, -0x390(%rbp)
movaps -0x370(%rbp), %xmm1
movaps -0x390(%rbp), %xmm0
movaps %xmm1, -0x190(%rbp)
movaps %xmm0, -0x1a0(%rbp)
movaps -0x190(%rbp), %xmm0
movaps -0x1a0(%rbp), %xmm1
pmullw %xmm1, %xmm0
movaps %xmm0, -0x3a0(%rbp)
movaps -0x370(%rbp), %xmm1
movaps -0x390(%rbp), %xmm0
movaps %xmm1, -0x150(%rbp)
movaps %xmm0, -0x160(%rbp)
movaps -0x150(%rbp), %xmm0
movaps -0x160(%rbp), %xmm1
pmulhuw %xmm1, %xmm0
movaps %xmm0, -0x3b0(%rbp)
movaps -0x3a0(%rbp), %xmm1
movaps -0x3b0(%rbp), %xmm0
movaps %xmm1, -0x240(%rbp)
movaps %xmm0, -0x250(%rbp)
movaps -0x240(%rbp), %xmm0
movaps -0x250(%rbp), %xmm1
punpcklwd %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
movaps %xmm0, -0x3c0(%rbp)
movaps -0x350(%rbp), %xmm1
movaps -0x320(%rbp), %xmm0
movaps %xmm1, -0x1b0(%rbp)
movaps %xmm0, -0x1c0(%rbp)
movaps -0x1b0(%rbp), %xmm0
movaps -0x1c0(%rbp), %xmm1
pmullw %xmm1, %xmm0
movaps %xmm0, -0x3d0(%rbp)
movaps -0x350(%rbp), %xmm1
movaps -0x320(%rbp), %xmm0
movaps %xmm1, -0x170(%rbp)
movaps %xmm0, -0x180(%rbp)
movaps -0x170(%rbp), %xmm0
movaps -0x180(%rbp), %xmm1
pmulhuw %xmm1, %xmm0
movaps %xmm0, -0x3e0(%rbp)
movaps -0x3d0(%rbp), %xmm1
movaps -0x3e0(%rbp), %xmm0
movaps %xmm1, -0x260(%rbp)
movaps %xmm0, -0x270(%rbp)
movaps -0x260(%rbp), %xmm0
movaps -0x270(%rbp), %xmm1
punpcklwd %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1],xmm0[2],xmm1[2],xmm0[3],xmm1[3]
movaps %xmm0, -0x3f0(%rbp)
movaps -0x3f0(%rbp), %xmm1
movaps -0x3c0(%rbp), %xmm0
movaps %xmm1, -0x130(%rbp)
movaps %xmm0, -0x140(%rbp)
movaps -0x130(%rbp), %xmm0
movaps -0x140(%rbp), %xmm1
psubd %xmm1, %xmm0
movaps %xmm0, -0x400(%rbp)
movaps -0x3c0(%rbp), %xmm0
movaps %xmm0, -0x110(%rbp)
movl $0x20, -0x114(%rbp)
movaps -0x110(%rbp), %xmm0
movd -0x114(%rbp), %xmm1
psrlq %xmm1, %xmm0
movaps %xmm0, -0x410(%rbp)
movaps -0x3c0(%rbp), %xmm1
movaps -0x330(%rbp), %xmm0
movaps %xmm1, -0xd0(%rbp)
movaps %xmm0, -0xe0(%rbp)
movaps -0xd0(%rbp), %xmm0
movaps -0xe0(%rbp), %xmm1
pmuludq %xmm1, %xmm0
movaps %xmm0, -0x420(%rbp)
movaps -0x410(%rbp), %xmm1
movaps -0x330(%rbp), %xmm0
movaps %xmm1, -0xf0(%rbp)
movaps %xmm0, -0x100(%rbp)
movaps -0xf0(%rbp), %xmm0
movaps -0x100(%rbp), %xmm1
pmuludq %xmm1, %xmm0
movaps %xmm0, -0x430(%rbp)
movaps -0x420(%rbp), %xmm1
movaps -0x340(%rbp), %xmm0
movaps %xmm1, -0x90(%rbp)
movaps %xmm0, -0xa0(%rbp)
movaps -0x90(%rbp), %xmm0
movaps -0xa0(%rbp), %xmm1
paddq %xmm1, %xmm0
movaps %xmm0, -0x440(%rbp)
movaps -0x430(%rbp), %xmm1
movaps -0x340(%rbp), %xmm0
movaps %xmm1, -0xb0(%rbp)
movaps %xmm0, -0xc0(%rbp)
movaps -0xb0(%rbp), %xmm0
movaps -0xc0(%rbp), %xmm1
paddq %xmm1, %xmm0
movaps %xmm0, -0x450(%rbp)
movaps -0x440(%rbp), %xmm0
pshufd $0xd, %xmm0, %xmm0      # xmm0 = xmm0[1,3,0,0]
movaps %xmm0, -0x460(%rbp)
movaps -0x450(%rbp), %xmm0
pshufd $0xd, %xmm0, %xmm0      # xmm0 = xmm0[1,3,0,0]
movaps %xmm0, -0x470(%rbp)
movaps -0x460(%rbp), %xmm1
movaps -0x470(%rbp), %xmm0
movaps %xmm1, -0x70(%rbp)
movaps %xmm0, -0x80(%rbp)
movaps -0x70(%rbp), %xmm0
movaps -0x80(%rbp), %xmm1
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movdqa %xmm0, -0x480(%rbp)
movdqa -0x480(%rbp), %xmm1
movdqa -0x310(%rbp), %xmm0
movdqa %xmm1, -0x50(%rbp)
movdqa %xmm0, -0x60(%rbp)
movdqa -0x50(%rbp), %xmm0
movdqa -0x60(%rbp), %xmm1
packssdw %xmm1, %xmm0
movdqa %xmm0, -0x350(%rbp)
movq -0x358(%rbp), %rax
movdqa -0x400(%rbp), %xmm0
movq %rax, -0x2c8(%rbp)
movdqa %xmm0, -0x2e0(%rbp)
movdqa -0x2e0(%rbp), %xmm0
movq -0x2c8(%rbp), %rax
movdqu %xmm0, (%rax)
movq -0x358(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x358(%rbp)
jmp 0x16c9b5
cmpl $0x0, -0x300(%rbp)
jne 0x16cebe
jmp 0x16cedd
leaq 0x53023(%rip), %rdi     # 0x1bfee8
leaq 0x53cf4(%rip), %rsi     # 0x1c0bc0
movl $0xa4, %edx
leaq 0x53d48(%rip), %rcx     # 0x1c0c20
callq 0x598a0
addq $0x490, %rsp            # imm = 0x490
popq %rbp
retq
nopw %cs:(%rax,%rax)