// File: /workspace/github_c_makefile_star2_O0/enzo1982[P]smooth/libraries/libwebp/src/dsp/rescaler_sse2.c
// Function: RescalerImportRowExpand_SSE2
static void RescalerImportRowExpand_SSE2(WebPRescaler* const wrk,
                                         const uint8_t* src) {
  rescaler_t* frow = wrk->frow;
  const rescaler_t* const frow_end = frow + wrk->dst_width * wrk->num_channels;
  const int x_add = wrk->x_add;
  int accum = x_add;
  __m128i cur_pixels;

  // SSE2 implementation only works with 16b signed arithmetic at max.
  if (wrk->src_width < 8 || accum >= (1 << 15)) {
    WebPRescalerImportRowExpand_C(wrk, src);
    return;
  }

  assert(!WebPRescalerInputDone(wrk));
  assert(wrk->x_expand);
  if (wrk->num_channels == 4) {
    LoadTwoPixels_SSE2(src, &cur_pixels);
    src += 4;
    while (1) {
      const __m128i mult = _mm_set1_epi32(((x_add - accum) << 16) | accum);
      const __m128i out = _mm_madd_epi16(cur_pixels, mult);
      _mm_storeu_si128((__m128i*)frow, out);
      frow += 4;
      if (frow >= frow_end) break;
      accum -= wrk->x_sub;
      if (accum < 0) {
        LoadTwoPixels_SSE2(src, &cur_pixels);
        src += 4;
        accum += x_add;
      }
    }
  } else {
    int left;
    const uint8_t* const src_limit = src + wrk->src_width - 8;
    LoadEightPixels_SSE2(src, &cur_pixels);
    src += 7;
    left = 7;
    while (1) {
      const __m128i mult = _mm_cvtsi32_si128(((x_add - accum) << 16) | accum);
      const __m128i out = _mm_madd_epi16(cur_pixels, mult);
      assert(sizeof(*frow) == sizeof(uint32_t));
      WebPInt32ToMem((uint8_t*)frow, _mm_cvtsi128_si32(out));
      frow += 1;
      if (frow >= frow_end) break;
      accum -= wrk->x_sub;
      if (accum < 0) {
        if (--left) {
          cur_pixels = _mm_srli_si128(cur_pixels, 2);
        } else if (src <= src_limit) {
          LoadEightPixels_SSE2(src, &cur_pixels);
          src += 7;
          left = 7;
        } else {   // tail
          cur_pixels = _mm_srli_si128(cur_pixels, 2);
          cur_pixels = _mm_insert_epi16(cur_pixels, src[1], 1);
          src += 1;
          left = 1;
        }
        accum += x_add;
      }
    }
  }
  assert(accum == 0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdi, -0xd0(%rbp)
movq %rsi, -0xd8(%rbp)
movq -0xd0(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
movq -0xd0(%rbp), %rcx
movl 0x34(%rcx), %ecx
movq -0xd0(%rbp), %rdx
imull 0x8(%rdx), %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0xe8(%rbp)
movq -0xd0(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, -0xec(%rbp)
movl -0xec(%rbp), %eax
movl %eax, -0xf0(%rbp)
movq -0xd0(%rbp), %rax
cmpl $0x8, 0x2c(%rax)
jl 0x16c2dd
cmpl $0x8000, -0xf0(%rbp)    # imm = 0x8000
jl 0x16c2f5
movq -0xd0(%rbp), %rdi
movq -0xd8(%rbp), %rsi
callq 0x150890
jmp 0x16c6eb
movq -0xd0(%rbp), %rdi
callq 0x16e0c0
cmpl $0x0, %eax
jne 0x16c308
jmp 0x16c327
leaq 0x53b2d(%rip), %rdi     # 0x1bfe3c
leaq 0x548aa(%rip), %rsi     # 0x1c0bc0
movl $0x3c, %edx
leaq 0x548b6(%rip), %rcx     # 0x1c0bd8
callq 0x598a0
movq -0xd0(%rbp), %rax
cmpl $0x0, (%rax)
je 0x16c335
jmp 0x16c354
leaq 0x53c01(%rip), %rdi     # 0x1bff3d
leaq 0x5487d(%rip), %rsi     # 0x1c0bc0
movl $0x3d, %edx
leaq 0x54889(%rip), %rcx     # 0x1c0bd8
callq 0x598a0
movq -0xd0(%rbp), %rax
cmpl $0x4, 0x8(%rax)
jne 0x16c4ce
movq -0xd8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x16e0e0
movq -0xd8(%rbp), %rax
addq $0x4, %rax
movq %rax, -0xd8(%rbp)
movl -0xec(%rbp), %eax
movl -0xf0(%rbp), %ecx
subl %ecx, %eax
shll $0x10, %eax
orl %ecx, %eax
movl %eax, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
movl %eax, -0x4(%rbp)
movl %eax, -0x8(%rbp)
movl %eax, -0xc(%rbp)
movl %eax, -0x10(%rbp)
movd -0x4(%rbp), %xmm0
movd -0x8(%rbp), %xmm1
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movd -0xc(%rbp), %xmm2
movd -0x10(%rbp), %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movdqa %xmm0, -0x20(%rbp)
movdqa -0x20(%rbp), %xmm0
movdqa %xmm0, -0x110(%rbp)
movdqa -0x100(%rbp), %xmm1
movdqa -0x110(%rbp), %xmm0
movdqa %xmm1, -0x90(%rbp)
movdqa %xmm0, -0xa0(%rbp)
movdqa -0x90(%rbp), %xmm0
movdqa -0xa0(%rbp), %xmm1
pmaddwd %xmm1, %xmm0
movdqa %xmm0, -0x120(%rbp)
movq -0xe0(%rbp), %rax
movdqa -0x120(%rbp), %xmm0
movq %rax, -0x68(%rbp)
movdqa %xmm0, -0x80(%rbp)
movdqa -0x80(%rbp), %xmm0
movq -0x68(%rbp), %rax
movdqu %xmm0, (%rax)
movq -0xe0(%rbp), %rax
addq $0x10, %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
cmpq -0xe8(%rbp), %rax
jb 0x16c46c
jmp 0x16c4c9
movq -0xd0(%rbp), %rax
movl 0x28(%rax), %ecx
movl -0xf0(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xf0(%rbp)
cmpl $0x0, -0xf0(%rbp)
jge 0x16c4c4
movq -0xd8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x16e0e0
movq -0xd8(%rbp), %rax
addq $0x4, %rax
movq %rax, -0xd8(%rbp)
movl -0xec(%rbp), %eax
addl -0xf0(%rbp), %eax
movl %eax, -0xf0(%rbp)
jmp 0x16c38a
jmp 0x16c6c1
movq -0xd8(%rbp), %rax
movq -0xd0(%rbp), %rcx
movslq 0x2c(%rcx), %rcx
addq %rcx, %rax
addq $-0x8, %rax
movq %rax, -0x130(%rbp)
movq -0xd8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x16e190
movq -0xd8(%rbp), %rax
addq $0x7, %rax
movq %rax, -0xd8(%rbp)
movl $0x7, -0x124(%rbp)
movl -0xec(%rbp), %eax
movl -0xf0(%rbp), %ecx
subl %ecx, %eax
shll $0x10, %eax
orl %ecx, %eax
movl %eax, -0x44(%rbp)
movd -0x44(%rbp), %xmm0
movaps %xmm0, -0x60(%rbp)
movaps -0x60(%rbp), %xmm0
movaps %xmm0, -0x140(%rbp)
movaps -0x100(%rbp), %xmm1
movaps -0x140(%rbp), %xmm0
movaps %xmm1, -0xb0(%rbp)
movaps %xmm0, -0xc0(%rbp)
movaps -0xb0(%rbp), %xmm0
movaps -0xc0(%rbp), %xmm1
pmaddwd %xmm1, %xmm0
movaps %xmm0, -0x150(%rbp)
movq -0xe0(%rbp), %rdi
movaps -0x150(%rbp), %xmm0
movaps %xmm0, -0x30(%rbp)
movaps -0x30(%rbp), %xmm0
movaps %xmm0, -0x40(%rbp)
movl -0x40(%rbp), %esi
callq 0x16e1f0
movq -0xe0(%rbp), %rax
addq $0x4, %rax
movq %rax, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
cmpq -0xe8(%rbp), %rax
jb 0x16c5c5
jmp 0x16c6bf
movq -0xd0(%rbp), %rax
movl 0x28(%rax), %ecx
movl -0xf0(%rbp), %eax
subl %ecx, %eax
movl %eax, -0xf0(%rbp)
cmpl $0x0, -0xf0(%rbp)
jge 0x16c6ba
movl -0x124(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x124(%rbp)
cmpl $0x0, %eax
je 0x16c617
movaps -0x100(%rbp), %xmm0
psrldq $0x2, %xmm0             # xmm0 = xmm0[2,3,4,5,6,7,8,9,10,11,12,13,14,15],zero,zero
movdqa %xmm0, -0x100(%rbp)
jmp 0x16c6a8
movq -0xd8(%rbp), %rax
cmpq -0x130(%rbp), %rax
ja 0x16c658
movq -0xd8(%rbp), %rdi
leaq -0x100(%rbp), %rsi
callq 0x16e190
movq -0xd8(%rbp), %rax
addq $0x7, %rax
movq %rax, -0xd8(%rbp)
movl $0x7, -0x124(%rbp)
jmp 0x16c6a6
movaps -0x100(%rbp), %xmm0
psrldq $0x2, %xmm0             # xmm0 = xmm0[2,3,4,5,6,7,8,9,10,11,12,13,14,15],zero,zero
movaps %xmm0, -0x100(%rbp)
movaps -0x100(%rbp), %xmm0
movq -0xd8(%rbp), %rax
movzbl 0x1(%rax), %eax
pinsrw $0x1, %eax, %xmm0
movdqa %xmm0, -0x100(%rbp)
movq -0xd8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xd8(%rbp)
movl $0x1, -0x124(%rbp)
jmp 0x16c6a8
movl -0xec(%rbp), %eax
addl -0xf0(%rbp), %eax
movl %eax, -0xf0(%rbp)
jmp 0x16c51d
jmp 0x16c6c1
cmpl $0x0, -0xf0(%rbp)
jne 0x16c6cc
jmp 0x16c6eb
leaq 0x53815(%rip), %rdi     # 0x1bfee8
leaq 0x544e6(%rip), %rsi     # 0x1c0bc0
movl $0x6d, %edx
leaq 0x544f2(%rip), %rcx     # 0x1c0bd8
callq 0x598a0
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
nopw %cs:(%rax,%rax)