// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movss %xmm0, -0xc(%rbp)
movl %esi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x78(%rbp)
movss 0x8(%rdi), %xmm0
divss -0xc(%rbp), %xmm0
movss %xmm0, -0x18(%rbp)
addq $0x10, %rdi
movslq -0x10(%rbp), %rsi
callq 0x7be0
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x6f72
movq -0x78(%rbp), %rdi
addq $0x10, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x7c70
movl $0x0, (%rax)
movss -0x18(%rbp), %xmm0
addss %xmm0, %xmm0
movss 0x64a3(%rip), %xmm1     # 0xd17c
addss %xmm1, %xmm0
cvttss2si %xmm0, %eax
cltq
movq %rax, -0x88(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x80(%rbp)
callq 0x7c90
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x7cb0
jmp 0x6d0d
leaq -0x39(%rbp), %rdi
callq 0x7d20
movq -0x78(%rbp), %rdi
addq $0x10, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x7c70
movq %rax, %rdi
addq $0x8, %rdi
leaq -0x38(%rbp), %rsi
callq 0x7d40
jmp 0x6d39
cvtsi2ssl -0x1c(%rbp), %xmm0
movss -0xc(%rbp), %xmm1
divss %xmm1, %xmm0
movss %xmm0, -0x50(%rbp)
movss -0x50(%rbp), %xmm0
movss -0x18(%rbp), %xmm1
subss %xmm1, %xmm0
callq 0x7f90
movss %xmm0, -0x8c(%rbp)
jmp 0x6d69
movss -0x8c(%rbp), %xmm0
movss %xmm0, -0x54(%rbp)
movss -0x50(%rbp), %xmm0
movss -0x18(%rbp), %xmm1
addss %xmm1, %xmm0
callq 0x7fb0
movss %xmm0, -0x90(%rbp)
jmp 0x6d93
movss -0x90(%rbp), %xmm0
movss %xmm0, -0x58(%rbp)
xorps %xmm0, %xmm0
movss %xmm0, -0x5c(%rbp)
cvttss2si -0x54(%rbp), %eax
movl %eax, -0x60(%rbp)
cvtsi2ssl -0x60(%rbp), %xmm1
movss -0x58(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jb 0x6e3a
movq -0x78(%rbp), %rax
movq (%rax), %rax
movss -0x50(%rbp), %xmm0
cvtsi2ssl -0x60(%rbp), %xmm1
subss %xmm1, %xmm0
movss -0xc(%rbp), %xmm1
mulss %xmm1, %xmm0
callq *%rax
movss %xmm0, -0x94(%rbp)
jmp 0x6de9
movss -0x94(%rbp), %xmm0
addss -0x5c(%rbp), %xmm0
movss %xmm0, -0x5c(%rbp)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x6db0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x7d20
jmp 0x6f7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x7ff0
jmp 0x6f7b
cvttss2si -0x54(%rbp), %eax
movl %eax, -0x64(%rbp)
cvtsi2ssl -0x64(%rbp), %xmm1
movss -0x58(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jb 0x6f5b
movq -0x78(%rbp), %rax
movl -0x64(%rbp), %ecx
movl %ecx, -0x68(%rbp)
movq (%rax), %rax
movss -0x50(%rbp), %xmm0
cvtsi2ssl -0x64(%rbp), %xmm1
subss %xmm1, %xmm0
movss -0xc(%rbp), %xmm1
mulss %xmm1, %xmm0
callq *%rax
movss %xmm0, -0x98(%rbp)
jmp 0x6e85
movss -0x98(%rbp), %xmm0
divss -0x5c(%rbp), %xmm0
movss %xmm0, -0x6c(%rbp)
cmpl $0x0, -0x64(%rbp)
jge 0x6ea7
xorl %eax, %eax
subl -0x64(%rbp), %eax
movl %eax, -0x68(%rbp)
jmp 0x6ec0
movl -0x64(%rbp), %eax
cmpl -0x14(%rbp), %eax
jl 0x6ebe
movl -0x14(%rbp), %eax
subl -0x64(%rbp), %eax
addl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x6ec0
movq -0x78(%rbp), %rdi
addq $0x10, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x7c70
movq -0x78(%rbp), %rdi
movq %rax, %rcx
movl (%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, (%rcx)
movl %eax, -0x70(%rbp)
movl -0x68(%rbp), %eax
movl %eax, -0xa0(%rbp)
addq $0x10, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x7c70
movq %rax, %rdi
addq $0x8, %rdi
movslq -0x70(%rbp), %rsi
callq 0x7fd0
movl -0xa0(%rbp), %ecx
movq -0x78(%rbp), %rdi
movl %ecx, (%rax)
movss -0x6c(%rbp), %xmm0
movss %xmm0, -0x9c(%rbp)
addq $0x10, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x7c70
movq %rax, %rdi
addq $0x8, %rdi
movslq -0x70(%rbp), %rsi
callq 0x7fd0
movss -0x9c(%rbp), %xmm0
movss %xmm0, 0x4(%rax)
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x6e42
leaq -0x38(%rbp), %rdi
callq 0x7ff0
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x6ca5
addq $0xa0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x34f0
nopw %cs:(%rax,%rax)