// File: /workspace/github_cpp_makefile_star2_O1/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 $0xa8, %rsp
movl %r8d, %ebp
movl %ecx, %r15d
movq %rsi, %r14
movq %rdi, %r13
movb 0xe0(%rsp), %bl
movq 0x8(%rsi), %rax
subq (%rsi), %rax
movl %edx, 0x18(%rsp)
imull %edx, %ecx
movslq %ecx, %rcx
xorl %edx, %edx
divq %rcx
movq %rax, %r12
movl %r8d, %eax
movl %r9d, 0x1c(%rsp)
imull %r9d, %eax
imull %r12d, %eax
movslq %eax, %rsi
leaq 0x90(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0xf(%rsp), %rcx
callq 0x1e43a
testb %bl, %bl
movl %r15d, %ebx
je 0x175eb
movq %r14, 0x78(%rsp)
movq %r13, 0x50(%rsp)
movl %r12d, %eax
imull %ebp, %eax
imull %r15d, %eax
movslq %eax, %rsi
leaq 0xf(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0x90(%rsp), %rdi
leaq 0x3f(%rsp), %rcx
callq 0x1e43a
testl %r12d, %r12d
jle 0x175cf
movl %ebx, %r11d
movl 0x18(%rsp), %eax
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x70(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x68(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movsd %xmm0, 0x60(%rsp)
xorps %xmm0, %xmm0
cvtsi2sdl 0x1c(%rsp), %xmm0
movsd %xmm0, 0x58(%rsp)
movslq %eax, %r13
movslq %ebx, %r14
movl %ebx, %eax
movq %rax, 0x88(%rsp)
movl %ebp, %eax
movq %rax, 0x80(%rsp)
xorl %r15d, %r15d
movsd 0xbc0b(%rip), %xmm5     # 0x22e48
testl %ebp, %ebp
jle 0x173ff
xorl %eax, %eax
xorpd %xmm6, %xmm6
movl %eax, %ecx
movq %rcx, 0x20(%rsp)
leal 0x1(%rcx), %eax
movl %eax, 0x14(%rsp)
testl %r11d, %r11d
jle 0x173ef
movsd 0x70(%rsp), %xmm1
movapd %xmm1, %xmm0
mulsd %xmm6, %xmm0
movsd 0x68(%rsp), %xmm2
divsd %xmm2, %xmm0
xorps %xmm3, %xmm3
cvtsd2ss %xmm0, %xmm3
xorps %xmm0, %xmm0
cvtsi2sdl 0x14(%rsp), %xmm0
mulsd %xmm1, %xmm0
divsd %xmm2, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x38(%rsp)
movss %xmm3, 0x10(%rsp)
cvttss2si %xmm3, %eax
movl %eax, 0x34(%rsp)
cvttss2si %xmm0, %eax
movl %eax, 0x30(%rsp)
movaps %xmm0, %xmm1
subss %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
divsd %xmm1, %xmm5
movsd %xmm5, 0x40(%rsp)
movsd %xmm6, 0x48(%rsp)
callq 0x20b0
movss %xmm0, 0x2c(%rsp)
movss 0x10(%rsp), %xmm0
callq 0x20b0
movsd 0x40(%rsp), %xmm7
movsd 0x48(%rsp), %xmm6
movsd 0xbb51(%rip), %xmm5     # 0x22e48
movl %ebx, %r11d
movss 0x10(%rsp), %xmm1
subss %xmm0, %xmm1
movl 0x34(%rsp), %eax
movl 0x30(%rsp), %esi
cmpl %esi, %eax
setle %cl
cmpl 0x18(%rsp), %eax
movl %eax, %edx
setl %al
andb %cl, %al
cvtss2sd %xmm1, %xmm1
movapd %xmm5, %xmm0
subsd %xmm1, %xmm0
movss 0x2c(%rsp), %xmm1
subss 0x38(%rsp), %xmm1
addss 0xba28(%rip), %xmm1     # 0x22d64
cvtss2sd %xmm1, %xmm1
movslq %edx, %rcx
movslq %esi, %rdx
xorl %esi, %esi
xorpd %xmm2, %xmm2
testb %al, %al
je 0x173b6
movq 0x78(%rsp), %rdi
movq (%rdi), %rdi
movl %esi, %r8d
imull 0x18(%rsp), %r8d
xorl %r9d, %r9d
movq %rcx, %r10
movapd %xmm0, %xmm3
subq $0x1, %r9
jb 0x17375
movapd %xmm5, %xmm3
cmpq %r10, %rdx
jne 0x1737e
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 0x173b3
incq %r10
cmpq %r13, %r10
movl %ebx, %r11d
jl 0x17367
jmp 0x173b6
movl %ebx, %r11d
mulsd %xmm7, %xmm2
movl %esi, %edi
imull %ebp, %edi
addl 0x20(%rsp), %edi
imull %r12d, %edi
cvttsd2si %xmm2, %r8d
addl %r15d, %edi
movslq %edi, %rdi
movq 0x90(%rsp), %r9
movb %r8b, (%r9,%rdi)
incq %rsi
cmpq 0x88(%rsp), %rsi
jne 0x17348
addsd %xmm5, %xmm6
movl 0x14(%rsp), %eax
cmpl %ebp, %eax
jne 0x1724b
cmpl $0x0, 0x1c(%rsp)
jle 0x175c3
xorl %eax, %eax
xorpd %xmm6, %xmm6
movl %eax, %ecx
movq %rcx, 0x20(%rsp)
leal 0x1(%rcx), %eax
movl %eax, 0x14(%rsp)
testl %ebp, %ebp
jle 0x175b1
movsd 0x60(%rsp), %xmm1
movapd %xmm1, %xmm0
mulsd %xmm6, %xmm0
movsd 0x58(%rsp), %xmm2
divsd %xmm2, %xmm0
xorps %xmm3, %xmm3
cvtsd2ss %xmm0, %xmm3
xorps %xmm0, %xmm0
cvtsi2sdl 0x14(%rsp), %xmm0
mulsd %xmm1, %xmm0
divsd %xmm2, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x38(%rsp)
movss %xmm3, 0x10(%rsp)
cvttss2si %xmm3, %eax
movl %eax, 0x34(%rsp)
cvttss2si %xmm0, %eax
movl %eax, 0x30(%rsp)
movaps %xmm0, %xmm1
subss %xmm3, %xmm1
cvtss2sd %xmm1, %xmm1
divsd %xmm1, %xmm5
movsd %xmm5, 0x40(%rsp)
movsd %xmm6, 0x48(%rsp)
callq 0x20b0
movss %xmm0, 0x2c(%rsp)
movss 0x10(%rsp), %xmm0
callq 0x20b0
movsd 0x40(%rsp), %xmm7
movsd 0x48(%rsp), %xmm6
movsd 0xb98d(%rip), %xmm5     # 0x22e48
movl %ebx, %r11d
movss 0x10(%rsp), %xmm1
subss %xmm0, %xmm1
movq 0x20(%rsp), %rax
imull %ebp, %eax
movq %rax, 0x20(%rsp)
movl 0x34(%rsp), %eax
movl 0x30(%rsp), %esi
cmpl %esi, %eax
setle %cl
cmpl %ebx, %eax
movl %eax, %edx
setl %al
andb %cl, %al
cvtss2sd %xmm1, %xmm1
movapd %xmm5, %xmm0
subsd %xmm1, %xmm0
movss 0x2c(%rsp), %xmm1
subss 0x38(%rsp), %xmm1
addss 0xb859(%rip), %xmm1     # 0x22d64
cvtss2sd %xmm1, %xmm1
movslq %edx, %rcx
movslq %esi, %rdx
xorl %esi, %esi
xorpd %xmm2, %xmm2
testb %al, %al
je 0x1757a
movq 0x90(%rsp), %rdi
xorl %r8d, %r8d
movq %rcx, %r9
movapd %xmm0, %xmm3
subq $0x1, %r8
jb 0x1753b
movapd %xmm5, %xmm3
cmpq %r9, %rdx
jne 0x17544
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 0x1757a
incq %r9
cmpq %r14, %r9
jl 0x1752d
mulsd %xmm7, %xmm2
movq 0x20(%rsp), %rdi
addl %esi, %edi
imull %r12d, %edi
cvttsd2si %xmm2, %r8d
addl %r15d, %edi
movslq %edi, %rdi
movq 0x50(%rsp), %r9
movq (%r9), %r9
movb %r8b, (%r9,%rdi)
incq %rsi
cmpq 0x80(%rsp), %rsi
jne 0x17517
addsd %xmm5, %xmm6
movl 0x14(%rsp), %eax
cmpl 0x1c(%rsp), %eax
jne 0x17410
incl %r15d
cmpl %r12d, %r15d
jl 0x1723d
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x175e1
callq 0x2200
movq 0x50(%rsp), %r13
jmp 0x176cb
movl 0x1c(%rsp), %edx
testl %edx, %edx
jle 0x176cb
cvtsi2sd %ebx, %xmm0
cvtsi2sd %edx, %xmm1
cvtsi2sdl 0x18(%rsp), %xmm2
cvtsi2sd %ebp, %xmm3
movslq %r12d, %rax
movl %ebp, %ecx
movl %edx, %edx
movq %rdx, 0x20(%rsp)
xorl %esi, %esi
movsd 0xb951(%rip), %xmm4     # 0x22f70
movsd 0xb951(%rip), %xmm5     # 0x22f78
testl %ebp, %ebp
jle 0x176bd
xorps %xmm6, %xmm6
cvtsi2sd %esi, %xmm6
addsd %xmm4, %xmm6
mulsd %xmm0, %xmm6
divsd %xmm1, %xmm6
addsd %xmm5, %xmm6
cvttsd2si %xmm6, %edi
imull 0x18(%rsp), %edi
movq %rsi, %r8
imulq %rcx, %r8
xorl %r9d, %r9d
testl %r12d, %r12d
jle 0x176b5
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 %r14, %rdx
movq (%r14), %r14
addq %rbx, %r14
movb (%r10,%r14), %r14b
movq (%r13), %r15
addq %rbx, %r15
movb %r14b, (%r11,%r15)
movq %rdx, %r14
incq %rbx
cmpq %rax, %rbx
jl 0x17692
incq %r9
cmpq %rcx, %r9
jne 0x17659
incq %rsi
cmpq 0x20(%rsp), %rsi
jne 0x17627
movq %r13, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movq 0x50(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x176f5
callq 0x2200
movq %r14, %rdi
callq 0x2390