// File: /workspace/github_cpp_makefile_star2_O2/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 $0x98, %rsp
movl %r9d, %r15d
movl %r8d, %r14d
movl %edx, %r12d
movq 0x8(%rsi), %rax
movq %rsi, 0x50(%rsp)
subq (%rsi), %rax
movl %ecx, 0x8(%rsp)
imull %edx, %ecx
movslq %ecx, %rcx
xorl %ebx, %ebx
xorl %edx, %edx
divq %rcx
movq %rax, %r13
movl %r13d, %ebp
imull %r8d, %ebp
movl %ebp, %eax
imull %r9d, %eax
movslq %eax, %rsi
leaq 0x80(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0x3(%rsp), %rcx
movq %rdi, 0x28(%rsp)
callq 0x191aa
cmpb $0x0, 0xd0(%rsp)
movl %r12d, 0x18(%rsp)
je 0x14096
movl 0x8(%rsp), %ebx
imull %ebx, %ebp
movslq %ebp, %rsi
leaq 0x3(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0x80(%rsp), %rdi
leaq 0x1f(%rsp), %rcx
callq 0x191aa
movl 0x18(%rsp), %ecx
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x70(%rsp)
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x68(%rsp)
cvtsi2sd %ebx, %xmm0
movsd %xmm0, 0x60(%rsp)
movl %r15d, %eax
cvtsi2sd %r15d, %xmm0
movsd %xmm0, 0x58(%rsp)
movslq %ecx, %rbp
xorl %r15d, %r15d
testl %ebx, %ebx
movl $0x0, %ecx
cmovgl %ebx, %ecx
movq %rcx, 0x78(%rsp)
testl %r14d, %r14d
movl $0x0, %ecx
cmovgl %r14d, %ecx
movq %rcx, 0x48(%rsp)
movslq %ebx, %rbx
testl %eax, %eax
cmovlel %r15d, %eax
movl %eax, 0x44(%rsp)
movsd 0xa197(%rip), %xmm5     # 0x1def8
cmpl %r13d, %r15d
jge 0x14187
xorl %eax, %eax
xorpd %xmm3, %xmm3
cmpl 0x48(%rsp), %eax
je 0x13efc
movsd 0x70(%rsp), %xmm1
movapd %xmm1, %xmm0
mulsd %xmm3, %xmm0
movsd 0x68(%rsp), %xmm2
divsd %xmm2, %xmm0
cvtsd2ss %xmm0, %xmm4
movq %rax, 0x8(%rsp)
incl %eax
movl %eax, 0x14(%rsp)
cvtsi2sd %eax, %xmm0
mulsd %xmm1, %xmm0
divsd %xmm2, %xmm0
cvtsd2ss %xmm0, %xmm1
movss %xmm1, 0x20(%rsp)
movaps %xmm4, %xmm0
movss %xmm4, 0x4(%rsp)
cvttss2si %xmm4, %eax
movl %eax, 0x10(%rsp)
addsd %xmm5, %xmm3
movsd %xmm3, 0x38(%rsp)
cvttss2si %xmm1, %r12d
subss %xmm4, %xmm1
cvtss2sd %xmm1, %xmm1
divsd %xmm1, %xmm5
movsd %xmm5, 0x30(%rsp)
callq 0x20a0
movss 0x4(%rsp), %xmm1
subss %xmm0, %xmm1
movss %xmm1, 0x4(%rsp)
movss 0x20(%rsp), %xmm0
callq 0x20a0
movsd 0x30(%rsp), %xmm6
movsd 0xa0e1(%rip), %xmm5     # 0x1def8
cvtss2sd 0x4(%rsp), %xmm2
movapd %xmm5, %xmm1
subsd %xmm2, %xmm1
subss 0x20(%rsp), %xmm0
addss 0x9f5d(%rip), %xmm0     # 0x1dd90
cvtss2sd %xmm0, %xmm0
movslq 0x10(%rsp), %rax
movslq %r12d, %rcx
movq %rcx, %rdx
subq %rax, %rdx
xorl %esi, %esi
cmpq 0x78(%rsp), %rsi
movl 0x18(%rsp), %r10d
je 0x13eed
movl %esi, %edi
imull %r14d, %edi
addl 0x8(%rsp), %edi
movq 0x50(%rsp), %r8
movq (%r8), %r8
movl %esi, %r9d
imull %r10d, %r9d
xorpd %xmm2, %xmm2
xorl %r10d, %r10d
movq %rax, %r11
leaq (%rax,%r10), %r12
cmpq %rcx, %r12
jg 0x13ec6
cmpq %rbp, %r12
jge 0x13ec6
movapd %xmm1, %xmm3
testq %r10, %r10
je 0x13e95
movapd %xmm5, %xmm3
cmpq %r10, %rdx
jne 0x13e9e
subsd %xmm0, %xmm3
leal (%r9,%r11), %r12d
imull %r13d, %r12d
addl %r15d, %r12d
movslq %r12d, %r12
movzbl (%r8,%r12), %r12d
cvtsi2sd %r12d, %xmm4
mulsd %xmm3, %xmm4
addsd %xmm4, %xmm2
incq %r11
incq %r10
jmp 0x13e7a
imull %r13d, %edi
mulsd %xmm6, %xmm2
cvttsd2si %xmm2, %r8d
addl %r15d, %edi
movslq %edi, %rdi
movq 0x80(%rsp), %r9
movb %r8b, (%r9,%rdi)
incq %rsi
jmp 0x13e47
movl 0x14(%rsp), %eax
movsd 0x38(%rsp), %xmm3
jmp 0x13d70
xorl %r12d, %r12d
xorpd %xmm3, %xmm3
cmpl 0x44(%rsp), %r12d
je 0x1408e
movsd 0x60(%rsp), %xmm1
movapd %xmm1, %xmm0
mulsd %xmm3, %xmm0
movsd 0x58(%rsp), %xmm2
divsd %xmm2, %xmm0
cvtsd2ss %xmm0, %xmm4
leal 0x1(%r12), %eax
movl %eax, 0x38(%rsp)
cvtsi2sd %eax, %xmm0
mulsd %xmm1, %xmm0
divsd %xmm2, %xmm0
cvtsd2ss %xmm0, %xmm1
movss %xmm1, 0x4(%rsp)
movaps %xmm4, %xmm0
movss %xmm4, 0x8(%rsp)
cvttss2si %xmm4, %eax
movl %eax, 0x14(%rsp)
addsd %xmm5, %xmm3
movsd %xmm3, 0x20(%rsp)
cvttss2si %xmm1, %eax
movl %eax, 0x10(%rsp)
subss %xmm4, %xmm1
cvtss2sd %xmm1, %xmm1
divsd %xmm1, %xmm5
movsd %xmm5, 0x30(%rsp)
callq 0x20a0
movss 0x8(%rsp), %xmm1
subss %xmm0, %xmm1
movss %xmm1, 0x8(%rsp)
movss 0x4(%rsp), %xmm0
callq 0x20a0
movsd 0x30(%rsp), %xmm6
movsd 0x9f4c(%rip), %xmm5     # 0x1def8
imull %r14d, %r12d
cvtss2sd 0x8(%rsp), %xmm2
movapd %xmm5, %xmm1
subsd %xmm2, %xmm1
subss 0x4(%rsp), %xmm0
addss 0x9dc4(%rip), %xmm0     # 0x1dd90
cvtss2sd %xmm0, %xmm0
movslq 0x14(%rsp), %rax
movslq 0x10(%rsp), %rcx
movq %rcx, %rdx
subq %rax, %rdx
xorl %esi, %esi
cmpq 0x48(%rsp), %rsi
je 0x1407c
leal (%r12,%rsi), %edi
xorpd %xmm2, %xmm2
movq 0x80(%rsp), %r8
xorl %r9d, %r9d
movq %rax, %r10
leaq (%rax,%r9), %r11
cmpq %rcx, %r11
jg 0x14055
cmpq %rbx, %r11
jge 0x14055
movapd %xmm1, %xmm3
testq %r9, %r9
je 0x1401e
movapd %xmm5, %xmm3
cmpq %r9, %rdx
jne 0x14027
subsd %xmm0, %xmm3
movl %r10d, %r11d
imull %r14d, %r11d
addl %esi, %r11d
imull %r13d, %r11d
addl %r15d, %r11d
movslq %r11d, %r11
movzbl (%r8,%r11), %r11d
cvtsi2sd %r11d, %xmm4
mulsd %xmm3, %xmm4
addsd %xmm4, %xmm2
incq %r10
incq %r9
jmp 0x14003
imull %r13d, %edi
mulsd %xmm6, %xmm2
cvttsd2si %xmm2, %r8d
addl %r15d, %edi
movslq %edi, %rdi
movq 0x28(%rsp), %r9
movq (%r9), %r9
movb %r8b, (%r9,%rdi)
incq %rsi
jmp 0x13fe2
movl 0x38(%rsp), %eax
movl %eax, %r12d
movsd 0x20(%rsp), %xmm3
jmp 0x13f03
incl %r15d
jmp 0x13d61
cvtsi2sdl 0x8(%rsp), %xmm0
cvtsi2sd %r15d, %xmm1
cvtsi2sd %r12d, %xmm2
cvtsi2sd %r14d, %xmm3
testl %r14d, %r14d
movl $0x0, %r12d
cmovgl %r14d, %r12d
movslq %r13d, %rcx
testl %r15d, %r15d
cmovlel %ebx, %r15d
xorpd %xmm4, %xmm4
movsd 0x9f42(%rip), %xmm5     # 0x1e010
movsd 0x9f42(%rip), %xmm6     # 0x1e018
movsd 0x9e1a(%rip), %xmm7     # 0x1def8
movq 0x28(%rsp), %rax
movl %r15d, %ebp
cmpl %ebp, %ebx
je 0x14199
movapd %xmm4, %xmm8
addsd %xmm5, %xmm8
mulsd %xmm0, %xmm8
divsd %xmm1, %xmm8
addsd %xmm6, %xmm8
cvttsd2si %xmm8, %edx
imull 0x18(%rsp), %edx
movl %ebx, %esi
imull %r14d, %esi
xorl %edi, %edi
cmpq %r12, %rdi
je 0x1417c
cvtsi2sd %edi, %xmm8
addsd %xmm5, %xmm8
mulsd %xmm2, %xmm8
divsd %xmm3, %xmm8
addsd %xmm6, %xmm8
cvttsd2si %xmm8, %r9d
addl %edx, %r9d
imull %r13d, %r9d
leal (%rsi,%rdi), %r8d
imull %r13d, %r8d
movslq %r8d, %r8
movslq %r9d, %r9
xorl %r10d, %r10d
cmpq %rcx, %r10
jge 0x14177
movq 0x50(%rsp), %r11
movq (%r11), %r11
addq %r10, %r11
movb (%r9,%r11), %r11b
movq (%rax), %r15
addq %r10, %r15
movb %r11b, (%r8,%r15)
incq %r10
jmp 0x14154
incq %rdi
jmp 0x14119
addsd %xmm7, %xmm4
incl %ebx
jmp 0x140e6
leaq 0x80(%rsp), %rdi
callq 0xea4c
movq 0x28(%rsp), %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x141ad
movq %rax, %r14
movq 0x28(%rsp), %rdi
callq 0xea4c
movq %r14, %rdi
callq 0x23a0
movq %rax, %rdi
callq 0xe69c