// File: /workspace/github_cpp_makefile_star2_O3/lvandeve[P]lodepng/pngdetail.cpp
// Function: rescale(std::vector<unsigned char, std::allocator<unsigned char>> const&, int, int, int, int, bool)
std::vector<unsigned char> rescale(const std::vector<unsigned char>& in,
                                   int w0, int h0, int w1, int h1, bool smooth) {
  int numchannels = in.size() / (w0 * h0);
  std::vector<unsigned char> out(w1 * h1 * numchannels);
  if(smooth) {
    // box filter.
    std::vector<unsigned char> temp(w1 * h0 * numchannels);
    for(int c = 0; c < numchannels; c++) {
      for(int x = 0; x < w1; x++) {
        float xaf = x * 1.0 * w0 / w1;
        float xbf = (x + 1.0) * w0 / w1;
        int xa = (int)xaf;
        int xb = (int)xbf;
        double norm = 1.0 / (xbf - xaf);
        xaf -= std::floor(xaf);
        xbf -= std::floor(xbf);
        for(int y = 0; y < h0; y++) {
          int index1 = x * numchannels + y * w1 * numchannels;
          double val = 0;
          for(int x0 = xa; x0 <= xb && x0 < w0; x0++) {
            int index0 = x0 * numchannels + y * w0 * numchannels;
            double v = 1;
            if(x0 == xa) v -= xaf;
            if(x0 == xb) v -= (1 - xbf);
            val += v * in[index0 + c];
          }
          temp[index1 + c] = val * norm;
        }
      }
      for(int y = 0; y < h1; y++) {
        float yaf = y * 1.0 * h0 / h1;
        float ybf = (y + 1.0) * h0 / h1;
        int ya = (int)yaf;
        int yb = (int)ybf;
        double norm = 1.0 / (ybf - yaf);
        yaf -= std::floor(yaf);
        ybf -= std::floor(ybf);
        for(int x = 0; x < w1; x++) {
          int index1 = x * numchannels + y * w1 * numchannels;
          double val = 0;
          for(int y0 = ya; y0 <= yb && y0 < h0; y0++) {
            int index0 = x * numchannels + y0 * w1 * numchannels;
            double v = 1;
            if(y0 == ya) v -= yaf;
            if(y0 == yb) v -= (1 - ybf);
            val += v * temp[index0 + c];
          }
          out[index1 + c] = val * norm;
        }
      }
    }
  } else {
    for(int y = 0; y < h1; y++) {
      int y0 = (int)((y + 0.5) * h0 / h1 - 0.5);
      for (int x = 0; x < w1; x++) {
        int x0 = (int)((x + 0.5) * w0 / w1 - 0.5);
        int index0 = x0 * numchannels + y0 * w0 * numchannels;
        int index1 = x * numchannels + y * w1 * numchannels;
        for (int c = 0; c < numchannels; c++) {
          out[index1 + c] = in[index0 + c];
        }
      }
    }
  }
  return out;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movl %r8d, %ebp
movl %ecx, %ebx
movq %rsi, %r15
movq %rdi, %r13
movq 0x8(%rsi), %rax
subq (%rsi), %rax
movl %edx, 0x8(%rsp)
imull %edx, %ecx
movslq %ecx, %rcx
xorl %edx, %edx
divq %rcx
movq %rax, %r12
movl %r12d, %r14d
imull %r8d, %r14d
movl %r14d, %eax
movl %r9d, 0xc(%rsp)
imull %r9d, %eax
movslq %eax, %rsi
leaq 0x98(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0x7(%rsp), %rcx
callq 0x1e32c
cmpb $0x0, 0x130(%rsp)
je 0x173c7
movq %r15, 0x88(%rsp)
movq %r13, 0x40(%rsp)
imull %ebx, %r14d
movslq %r14d, %rsi
leaq 0x7(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0x98(%rsp), %rdi
leaq 0x17(%rsp), %rcx
callq 0x1e32c
testl %r12d, %r12d
jle 0x173ab
movl %ebx, %r11d
movl 0x8(%rsp), %eax
cvtsi2sd %eax, %xmm0
cvtsi2sd %ebp, %xmm1
cvtsi2sd %ebx, %xmm2
movl 0xc(%rsp), %ecx
cvtsi2sd %ecx, %xmm3
movslq %eax, %r13
movslq %ebx, %r14
movl %ebp, %eax
movq %rax, 0x48(%rsp)
movl %ebx, %eax
movq %rax, 0x90(%rsp)
movl %ecx, %eax
movq %rax, 0x80(%rsp)
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
movapd %xmm0, 0xe0(%rsp)
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
movapd %xmm1, 0xd0(%rsp)
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
movapd %xmm2, 0xc0(%rsp)
unpcklpd %xmm3, %xmm3            # xmm3 = xmm3[0,0]
movapd %xmm3, 0xb0(%rsp)
xorl %r15d, %r15d
movsd 0xbffe(%rip), %xmm5     # 0x23030
testl %ebp, %ebp
jle 0x171e1
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, 0x20(%rsp)
leal 0x1(%rcx), %eax
movl %eax, 0x18(%rsp)
testl %r11d, %r11d
jle 0x171d5
movss 0x20(%rsp), %xmm0
movss 0x18(%rsp), %xmm1
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
cvtdq2pd %xmm0, %xmm0
mulpd 0xe0(%rsp), %xmm0
divpd 0xd0(%rsp), %xmm0
cvtpd2ps %xmm0, %xmm2
movapd %xmm2, 0x50(%rsp)
movapd %xmm2, %xmm0
shufps $0x55, %xmm2, %xmm0     # xmm0 = xmm0[1,1],xmm2[1,1]
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, %xmm1
subss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
divsd %xmm1, %xmm5
movsd %xmm5, 0x38(%rsp)
cvttps2dq %xmm2, %xmm1
movaps %xmm1, 0x60(%rsp)
callq 0x20b0
movss %xmm0, 0x10(%rsp)
movaps 0x50(%rsp), %xmm0
callq 0x20b0
movsd 0x38(%rsp), %xmm6
movsd 0xbf60(%rip), %xmm5     # 0x23030
movl %ebx, %r11d
movaps 0x50(%rsp), %xmm1
subss %xmm0, %xmm1
movdqa 0x60(%rsp), %xmm0
movd %xmm0, %ecx
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %edx
cmpl %edx, %ecx
setle %sil
cmpl 0x8(%rsp), %ecx
setl %al
andb %sil, %al
cvtss2sd %xmm1, %xmm1
movapd %xmm5, %xmm0
subsd %xmm1, %xmm0
movss 0x10(%rsp), %xmm1
subss 0x70(%rsp), %xmm1
addss 0xbe75(%rip), %xmm1     # 0x22f94
cvtss2sd %xmm1, %xmm1
movslq %ecx, %rcx
movslq %edx, %rdx
xorl %esi, %esi
xorpd %xmm2, %xmm2
testb %al, %al
je 0x1719c
movq 0x88(%rsp), %rdi
movq (%rdi), %rdi
movl %esi, %r8d
imull 0x8(%rsp), %r8d
xorl %r9d, %r9d
movq %rcx, %r10
movapd %xmm0, %xmm3
subq $0x1, %r9
jb 0x1715b
movapd %xmm5, %xmm3
cmpq %r10, %rdx
jne 0x17164
subsd %xmm1, %xmm3
leal (%r8,%r10), %r11d
imull %r12d, %r11d
addl %r15d, %r11d
movslq %r11d, %r11
movzbl (%rdi,%r11), %r11d
xorps %xmm4, %xmm4
cvtsi2sd %r11d, %xmm4
mulsd %xmm3, %xmm4
addsd %xmm4, %xmm2
cmpq %rdx, %r10
jge 0x17199
incq %r10
cmpq %r13, %r10
movl %ebx, %r11d
jl 0x1714d
jmp 0x1719c
movl %ebx, %r11d
mulsd %xmm6, %xmm2
movl %esi, %edi
imull %ebp, %edi
addl 0x20(%rsp), %edi
imull %r12d, %edi
cvttsd2si %xmm2, %r8d
addl %r15d, %edi
movslq %edi, %rdi
movq 0x98(%rsp), %r9
movb %r8b, (%r9,%rdi)
incq %rsi
cmpq 0x90(%rsp), %rsi
jne 0x1712b
movl 0x18(%rsp), %eax
cmpl %ebp, %eax
jne 0x1703c
cmpl $0x0, 0xc(%rsp)
jle 0x1739f
xorl %eax, %eax
movq %rax, %rcx
incq %rax
movq %rax, 0x18(%rsp)
testl %ebp, %ebp
jle 0x1738c
movq %rcx, 0x50(%rsp)
movd %ecx, %xmm0
movd 0x18(%rsp), %xmm1
punpcklqdq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0]
movdqa 0xbf84(%rip), %xmm1     # 0x231a0
por %xmm1, %xmm0
subpd %xmm1, %xmm0
mulpd 0xc0(%rsp), %xmm0
divpd 0xb0(%rsp), %xmm0
cvtpd2ps %xmm0, %xmm2
movapd %xmm2, 0x20(%rsp)
movapd %xmm2, %xmm0
shufps $0x55, %xmm2, %xmm0     # xmm0 = xmm0[1,1],xmm2[1,1]
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, %xmm1
subss %xmm2, %xmm1
cvtss2sd %xmm1, %xmm1
divsd %xmm1, %xmm5
movsd %xmm5, 0x38(%rsp)
cvttps2dq %xmm2, %xmm1
movaps %xmm1, 0x60(%rsp)
callq 0x20b0
movss %xmm0, 0x10(%rsp)
movaps 0x20(%rsp), %xmm0
callq 0x20b0
movsd 0x38(%rsp), %xmm6
movsd 0xbda2(%rip), %xmm5     # 0x23030
movl %ebx, %r11d
movaps 0x20(%rsp), %xmm1
subss %xmm0, %xmm1
movq 0x50(%rsp), %rcx
imulq 0x48(%rsp), %rcx
movdqa 0x60(%rsp), %xmm0
movd %xmm0, %edi
pshufd $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movd %xmm0, %edx
cmpl %edx, %edi
setle %sil
cmpl %ebx, %edi
setl %al
andb %sil, %al
cvtss2sd %xmm1, %xmm1
movapd %xmm5, %xmm0
subsd %xmm1, %xmm0
movss 0x10(%rsp), %xmm1
subss 0x70(%rsp), %xmm1
addss 0xbcae(%rip), %xmm1     # 0x22f94
cvtss2sd %xmm1, %xmm1
movslq %edi, %rsi
movq %rsi, 0x20(%rsp)
movslq %edx, %rdx
xorl %esi, %esi
xorpd %xmm2, %xmm2
testb %al, %al
je 0x1735c
movq 0x98(%rsp), %rdi
xorl %r8d, %r8d
movq 0x20(%rsp), %r9
movapd %xmm0, %xmm3
subq $0x1, %r8
jb 0x1731d
movapd %xmm5, %xmm3
cmpq %r9, %rdx
jne 0x17326
subsd %xmm1, %xmm3
movl %r9d, %r10d
imull %ebp, %r10d
addl %esi, %r10d
imull %r12d, %r10d
addl %r15d, %r10d
movslq %r10d, %r10
movzbl (%rdi,%r10), %r10d
xorps %xmm4, %xmm4
cvtsi2sd %r10d, %xmm4
mulsd %xmm3, %xmm4
addsd %xmm4, %xmm2
cmpq %rdx, %r9
jge 0x1735c
incq %r9
cmpq %r14, %r9
jl 0x1730f
mulsd %xmm6, %xmm2
leal (%rsi,%rcx), %edi
imull %r12d, %edi
cvttsd2si %xmm2, %r8d
addl %r15d, %edi
movslq %edi, %rdi
movq 0x40(%rsp), %r9
movq (%r9), %r9
movb %r8b, (%r9,%rdi)
incq %rsi
cmpq 0x48(%rsp), %rsi
jne 0x172f7
movq 0x18(%rsp), %rax
cmpq 0x80(%rsp), %rax
jne 0x171ee
incl %r15d
cmpl %r12d, %r15d
jl 0x17032
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x173bd
callq 0x2210
movq 0x40(%rsp), %r13
jmp 0x174ab
movl 0xc(%rsp), %r14d
testl %r14d, %r14d
jle 0x174ab
cvtsi2sd %ebx, %xmm0
cvtsi2sd %r14d, %xmm1
cvtsi2sdl 0x8(%rsp), %xmm2
cvtsi2sd %ebp, %xmm3
movslq %r12d, %rax
movl %ebp, %ecx
movl %r14d, %edx
movq %rdx, 0x20(%rsp)
xorl %esi, %esi
movsd 0xbd61(%rip), %xmm4     # 0x23160
movsd 0xbd61(%rip), %xmm5     # 0x23168
testl %ebp, %ebp
jle 0x1749d
xorps %xmm6, %xmm6
cvtsi2sd %esi, %xmm6
addsd %xmm4, %xmm6
mulsd %xmm0, %xmm6
divsd %xmm1, %xmm6
addsd %xmm5, %xmm6
cvttsd2si %xmm6, %edi
imull 0x8(%rsp), %edi
movq %rsi, %r8
imulq %rcx, %r8
xorl %r9d, %r9d
testl %r12d, %r12d
jle 0x17495
leal (%r9,%r8), %r11d
xorps %xmm6, %xmm6
cvtsi2sd %r9d, %xmm6
imull %r12d, %r11d
addsd %xmm4, %xmm6
mulsd %xmm2, %xmm6
divsd %xmm3, %xmm6
addsd %xmm5, %xmm6
cvttsd2si %xmm6, %r10d
addl %edi, %r10d
imull %r12d, %r10d
movslq %r10d, %r10
movslq %r11d, %r11
xorl %ebx, %ebx
movq (%r15), %r14
addq %rbx, %r14
movb (%r10,%r14), %r14b
movq %r15, %rdx
movq (%r13), %r15
addq %rbx, %r15
movb %r14b, (%r11,%r15)
movq %rdx, %r15
incq %rbx
cmpq %rax, %rbx
jl 0x17472
incq %r9
cmpq %rcx, %r9
jne 0x17439
incq %rsi
cmpq 0x20(%rsp), %rsi
jne 0x17407
movq %r13, %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x40(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x174d5
callq 0x2210
movq %r14, %rdi
callq 0x23a0