// File: /workspace/github_cpp_makefile_star2_O3/shirat74[P]resample/Resampler.cc
// Function: Resampler::setupContributorForDownsample(float, int, int)
void
Resampler::setupContributorForDownsample (float   scale,
                                          int32_t dstSize,
                                          int32_t boundary)
{
  float supportSize = support / scale;

  contributor.resize(dstSize);

  for (int32_t i = 0; i < dstSize; i++) {
    contributor[i].n = 0;
    std::vector<Contrib> p((int) (supportSize * 2 + 1));
    contributor[i].p = p;
    float center = (float) i / scale;
    float left   = ceil (center - supportSize);
    float right  = floor(center + supportSize);
    float total  = 0.0; // Normalization required
    for (int32_t k = left; k <= right; k++) {
      total += (*filter_fn)((center - k) * scale);
    }
    for (int32_t j = left; j <= right; j++) {
      int32_t n = j;
      float weight = (*filter_fn)((center - j) * scale) / total;
      // reflect at boundary
      if (j < 0) {
        n = - j; // or periodic: dstSize - j
      } else if (j >= boundary) {
        n = (boundary - j) + boundary - 1; // j - boundary
      }
      int k = contributor[i].n++;
      contributor[i].p[k].pixel  = n;      // positio of kth contributor
      contributor[i].p[k].weight = weight; // weight
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, 0x38(%rsp)
movl %esi, %ebp
movss %xmm0, 0x10(%rsp)
movq %rdi, %r14
movss 0x8(%rdi), %xmm0
movss %xmm0, 0xc(%rsp)
leaq 0x10(%rdi), %r15
movslq %esi, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x458c
testl %r12d, %r12d
jle 0x3faa
movss 0xc(%rsp), %xmm0
divss 0x10(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
addss %xmm0, %xmm0
addss 0x2387(%rip), %xmm0     # 0x619c
cvttss2si %xmm0, %eax
cltq
movq %rax, 0x48(%rsp)
movl %ebp, %eax
movq %rax, 0x40(%rsp)
movq 0x38(%rsp), %rax
leal -0x1(,%rax,2), %eax
movq %rax, 0x50(%rsp)
xorl %r13d, %r13d
movq (%r15), %rax
movq %r13, %r12
shlq $0x5, %r12
movl $0x0, (%rax,%r12)
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
movq 0x48(%rsp), %rsi
leaq 0x1f(%rsp), %rdx
callq 0x45bc
movq (%r15), %rax
leaq (%rax,%r12), %rdi
addq $0x8, %rdi
movq %rbx, %rsi
callq 0x46fa
xorps %xmm0, %xmm0
cvtsi2ss %r13d, %xmm0
divss 0x10(%rsp), %xmm0
movss %xmm0, 0x18(%rsp)
subss 0xc(%rsp), %xmm0
callq 0x21a0
movaps %xmm0, 0x20(%rsp)
movss 0xc(%rsp), %xmm0
addss 0x18(%rsp), %xmm0
callq 0x2100
movaps 0x20(%rsp), %xmm2
cvttps2dq %xmm2, %xmm1
cvtdq2ps %xmm1, %xmm1
movss %xmm0, 0x14(%rsp)
ucomiss %xmm1, %xmm0
jb 0x3f85
cvttss2si %xmm2, %ebp
leal 0x1(%rbp), %ebx
xorps %xmm0, %xmm0
movss %xmm0, 0x20(%rsp)
movaps %xmm1, 0x70(%rsp)
movss 0x18(%rsp), %xmm0
subss %xmm1, %xmm0
mulss 0x10(%rsp), %xmm0
callq *(%r14)
xorps %xmm1, %xmm1
cvtsi2ss %ebx, %xmm1
movss 0x20(%rsp), %xmm2
addss %xmm0, %xmm2
movss %xmm2, 0x20(%rsp)
incl %ebx
movss 0x14(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jae 0x3edc
movss 0x14(%rsp), %xmm0
movaps 0x70(%rsp), %xmm1
ucomiss %xmm1, %xmm0
jb 0x3f85
movl %ebp, %ebx
negl %ebx
movss 0x18(%rsp), %xmm0
subss %xmm1, %xmm0
mulss 0x10(%rsp), %xmm0
callq *(%r14)
divss 0x20(%rsp), %xmm0
movq 0x50(%rsp), %rax
addl %ebx, %eax
cmpl 0x38(%rsp), %ebp
cmovll %ebp, %eax
testl %ebp, %ebp
cmovsl %ebx, %eax
movq (%r15), %rcx
movslq (%rcx,%r12), %rdx
leal 0x1(%rdx), %esi
movl %esi, (%rcx,%r12)
movq 0x8(%rcx,%r12), %rcx
movl %eax, (%rcx,%rdx,8)
incl %ebp
xorps %xmm1, %xmm1
cvtsi2ss %ebp, %xmm1
movss %xmm0, 0x4(%rcx,%rdx,8)
decl %ebx
movss 0x14(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jae 0x3f27
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x3f9c
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x22d0
incq %r13
cmpq 0x40(%rsp), %r13
jne 0x3e3b
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3fc0
jmp 0x3fc0
movq %rax, %rbx
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x3fda
movq 0x68(%rsp), %rsi
subq %rdi, %rsi
callq 0x22d0
movq %rbx, %rdi
callq 0x2400