// File: /workspace/github_c_makefile_star2_O1/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 %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 0xe83c9
popq %rax
jmp 0xdc63c
movl 0x3c(%rdi), %ecx
cmpl 0x30(%rdi), %ecx
jge 0xe859d
cmpl $0x0, (%rdi)
je 0xe85bc
movq 0x60(%rdi), %rcx
movslq 0x34(%rdi), %rdx
movslq 0x8(%rdi), %r9
imulq %r9, %rdx
leaq (%rcx,%rdx,4), %rdx
cmpl $0x4, %r9d
jne 0xe8506
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 0x45a63(%rip), %xmm1    # 0x12de80
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 0x45a48(%rip), %xmm2    # 0x12de90
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
addq $0x4, %rsi
movl %eax, %r8d
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 0xe84f8
subl 0x28(%rdi), %r8d
jns 0xe84f8
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
addq $0x4, %rsi
addl %eax, %r8d
cmpq %rdx, %rcx
jb 0xe846d
jmp 0xe8596
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
movl $0x7, %r10d
movl %eax, %r8d
movl %eax, %r11d
subl %r8d, %r11d
shll $0x10, %r11d
orl %r8d, %r11d
movd %r11d, %xmm2
pmaddwd %xmm1, %xmm2
movd %xmm2, (%rcx)
addq $0x4, %rcx
cmpq %rdx, %rcx
jae 0xe8591
subl 0x28(%rdi), %r8d
jns 0xe8591
decl %r10d
je 0xe855c
psrldq $0x2, %xmm1             # xmm1 = xmm1[2,3,4,5,6,7,8,9,10,11,12,13,14,15],zero,zero
jmp 0xe858e
cmpq %r9, %rsi
jbe 0xe857c
psrldq $0x2, %xmm1             # xmm1 = xmm1[2,3,4,5,6,7,8,9,10,11,12,13,14,15],zero,zero
movzbl 0x1(%rsi), %r10d
incq %rsi
pinsrw $0x1, %r10d, %xmm1
movl $0x1, %r10d
jmp 0xe858e
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 $0x7, %r10d
addl %eax, %r8d
cmpq %rdx, %rcx
jb 0xe8527
testl %r8d, %r8d
jne 0xe85db
popq %rax
retq
leaq 0x449d2(%rip), %rdi     # 0x12cf76
leaq 0x45915(%rip), %rsi     # 0x12dec0
leaq 0x45926(%rip), %rcx     # 0x12ded8
movl $0x3c, %edx
callq 0x55710
leaq 0x44ab4(%rip), %rdi     # 0x12d077
leaq 0x458f6(%rip), %rsi     # 0x12dec0
leaq 0x45907(%rip), %rcx     # 0x12ded8
movl $0x3d, %edx
callq 0x55710
leaq 0x44a40(%rip), %rdi     # 0x12d022
leaq 0x458d7(%rip), %rsi     # 0x12dec0
leaq 0x458e8(%rip), %rcx     # 0x12ded8
movl $0x6d, %edx
callq 0x55710