// File: /workspace/github_c_makefile_star2_O2/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
pushq %rbx
pushq %rax
movl 0x24(%rdi), %eax
movslq 0x2c(%rdi), %r8
cmpq $0x8, %r8
setl %cl
cmpl $0x8000, %eax           # imm = 0x8000
setge %dl
orb %cl, %dl
cmpb $0x1, %dl
jne 0xda91c
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0xd2f20
movl 0x3c(%rdi), %ecx
cmpl 0x30(%rdi), %ecx
jge 0xdaae2
cmpl $0x0, (%rdi)
je 0xdaafb
movq 0x60(%rdi), %rcx
movslq 0x34(%rdi), %rdx
movslq 0x8(%rdi), %r9
imulq %r9, %rdx
leaq (%rcx,%rdx,4), %rdx
cmpl $0x4, %r9d
jne 0xdaa50
movq (%rsi), %xmm2
pxor %xmm0, %xmm0
punpcklbw %xmm0, %xmm2    # xmm2 = xmm2[0],xmm0[0],xmm2[1],xmm0[1],xmm2[2],xmm0[2],xmm2[3],xmm0[3],xmm2[4],xmm0[4],xmm2[5],xmm0[5],xmm2[6],xmm0[6],xmm2[7],xmm0[7]
movdqa %xmm2, %xmm3
punpcklbw %xmm0, %xmm3    # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1],xmm3[2],xmm0[2],xmm3[3],xmm0[3],xmm3[4],xmm0[4],xmm3[5],xmm0[5],xmm3[6],xmm0[6],xmm3[7],xmm0[7]
pshufd $0xf6, %xmm3, %xmm4     # xmm4 = xmm3[2,1,3,3]
movdqa 0x42440(%rip), %xmm1    # 0x11cdb0
movdqa %xmm1, %xmm5
pandn %xmm4, %xmm5
punpckhbw %xmm0, %xmm2    # xmm2 = xmm2[8],xmm0[8],xmm2[9],xmm0[9],xmm2[10],xmm0[10],xmm2[11],xmm0[11],xmm2[12],xmm0[12],xmm2[13],xmm0[13],xmm2[14],xmm0[14],xmm2[15],xmm0[15]
pshufd $0xf9, %xmm2, %xmm4     # xmm4 = xmm2[1,2,3,3]
pand %xmm1, %xmm4
por %xmm5, %xmm4
pshufd $0xd0, %xmm2, %xmm2     # xmm2 = xmm2[0,0,1,3]
pshufhw $0xc4, %xmm2, %xmm5     # xmm5 = xmm2[0,1,2,3,4,5,4,7]
movdqa 0x42425(%rip), %xmm2    # 0x11cdc0
movdqa %xmm2, %xmm6
pandn %xmm5, %xmm6
pshuflw $0xec, %xmm3, %xmm3     # xmm3 = xmm3[0,3,2,3,4,5,6,7]
pshufd $0xdc, %xmm3, %xmm3     # xmm3 = xmm3[0,3,1,3]
pand %xmm2, %xmm3
por %xmm6, %xmm3
packuswb %xmm4, %xmm3
movl %eax, %r8d
addq $0x4, %rsi
movl %eax, %r9d
subl %r8d, %r9d
shll $0x10, %r9d
orl %r8d, %r9d
movd %r9d, %xmm4
pshufd $0x0, %xmm4, %xmm4      # xmm4 = xmm4[0,0,0,0]
pmaddwd %xmm3, %xmm4
movdqu %xmm4, (%rcx)
addq $0x10, %rcx
cmpq %rdx, %rcx
jae 0xdaad6
subl 0x28(%rdi), %r8d
jns 0xda9c0
movq (%rsi), %xmm3
punpcklbw %xmm0, %xmm3    # xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1],xmm3[2],xmm0[2],xmm3[3],xmm0[3],xmm3[4],xmm0[4],xmm3[5],xmm0[5],xmm3[6],xmm0[6],xmm3[7],xmm0[7]
movdqa %xmm3, %xmm4
punpcklbw %xmm0, %xmm4    # xmm4 = xmm4[0],xmm0[0],xmm4[1],xmm0[1],xmm4[2],xmm0[2],xmm4[3],xmm0[3],xmm4[4],xmm0[4],xmm4[5],xmm0[5],xmm4[6],xmm0[6],xmm4[7],xmm0[7]
pshufd $0xf6, %xmm4, %xmm5     # xmm5 = xmm4[2,1,3,3]
movdqa %xmm1, %xmm6
pandn %xmm5, %xmm6
punpckhbw %xmm0, %xmm3    # xmm3 = xmm3[8],xmm0[8],xmm3[9],xmm0[9],xmm3[10],xmm0[10],xmm3[11],xmm0[11],xmm3[12],xmm0[12],xmm3[13],xmm0[13],xmm3[14],xmm0[14],xmm3[15],xmm0[15]
pshufd $0xf9, %xmm3, %xmm5     # xmm5 = xmm3[1,2,3,3]
pand %xmm1, %xmm5
por %xmm6, %xmm5
pshufd $0xd0, %xmm3, %xmm3     # xmm3 = xmm3[0,0,1,3]
pshufhw $0xc4, %xmm3, %xmm3     # xmm3 = xmm3[0,1,2,3,4,5,4,7]
movdqa %xmm2, %xmm6
pandn %xmm3, %xmm6
pshuflw $0xec, %xmm4, %xmm3     # xmm3 = xmm4[0,3,2,3,4,5,6,7]
pshufd $0xdc, %xmm3, %xmm3     # xmm3 = xmm3[0,3,1,3]
pand %xmm2, %xmm3
por %xmm6, %xmm3
packuswb %xmm5, %xmm3
addl %eax, %r8d
jmp 0xda9bc
leaq (%rsi,%r8), %r9
addq $-0x8, %r9
movq (%rsi), %xmm1
pxor %xmm0, %xmm0
punpcklbw %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1],xmm1[2],xmm0[2],xmm1[3],xmm0[3],xmm1[4],xmm0[4],xmm1[5],xmm0[5],xmm1[6],xmm0[6],xmm1[7],xmm0[7]
addq $0x7, %rsi
pushq $0x7
popq %r10
pushq $0x1
popq %r11
movl %r10d, %ebx
movl %eax, %r8d
movl %eax, %ebp
subl %r8d, %ebp
shll $0x10, %ebp
orl %r8d, %ebp
movd %ebp, %xmm2
pmaddwd %xmm1, %xmm2
movd %xmm2, (%rcx)
addq $0x4, %rcx
cmpq %rdx, %rcx
jae 0xdaad6
subl 0x28(%rdi), %r8d
jns 0xdaa76
decl %ebx
je 0xdaaa7
psrldq $0x2, %xmm1             # xmm1 = xmm1[2,3,4,5,6,7,8,9,10,11,12,13,14,15],zero,zero
jmp 0xdaad1
cmpq %r9, %rsi
jbe 0xdaac2
psrldq $0x2, %xmm1             # xmm1 = xmm1[2,3,4,5,6,7,8,9,10,11,12,13,14,15],zero,zero
movzbl 0x1(%rsi), %ebx
incq %rsi
pinsrw $0x1, %ebx, %xmm1
movl %r11d, %ebx
jmp 0xdaad1
movq (%rsi), %xmm1
punpcklbw %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1],xmm1[2],xmm0[2],xmm1[3],xmm0[3],xmm1[4],xmm0[4],xmm1[5],xmm0[5],xmm1[6],xmm0[6],xmm1[7],xmm0[7]
addq $0x7, %rsi
movl %r10d, %ebx
addl %eax, %r8d
jmp 0xdaa76
testl %r8d, %r8d
jne 0xdab14
addq $0x8, %rsp
popq %rbx
popq %rbp
retq
leaq 0x413bd(%rip), %rdi     # 0x11bea6
leaq 0x42300(%rip), %rsi     # 0x11cdf0
leaq 0x42311(%rip), %rcx     # 0x11ce08
pushq $0x3c
jmp 0xdab2b
leaq 0x414a5(%rip), %rdi     # 0x11bfa7
leaq 0x422e7(%rip), %rsi     # 0x11cdf0
leaq 0x422f8(%rip), %rcx     # 0x11ce08
pushq $0x3d
jmp 0xdab2b
leaq 0x41437(%rip), %rdi     # 0x11bf52
leaq 0x422ce(%rip), %rsi     # 0x11cdf0
leaq 0x422df(%rip), %rcx     # 0x11ce08
pushq $0x6d
popq %rdx
callq 0x56770