// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
movl %edx, %ebx
movq %rdi, %r14
movss 0x8(%rdi), %xmm1
movss %xmm0, 0x10(%rsp)
divss %xmm0, %xmm1
movss %xmm1, 0xc(%rsp)
addq $0x10, %rdi
movslq %esi, %r15
movq %rdi, 0x20(%rsp)
movq %r15, %rsi
callq 0x4220
movss 0xc(%rsp), %xmm0
addss %xmm0, %xmm0
addss 0x25e2(%rip), %xmm0     # 0x6110
cvttss2si %xmm0, %eax
xorl %ebp, %ebp
testl %r15d, %r15d
cmovlel %ebp, %r15d
movq %r15, 0x30(%rsp)
cltq
movq %rax, 0x28(%rsp)
movq %rbx, %r15
leal -0x1(,%rbx,2), %r12d
cmpq 0x30(%rsp), %rbp
je 0x3c97
movq 0x20(%rsp), %rbx
movq (%rbx), %rax
movq %rbp, %r13
shlq $0x5, %r13
andl $0x0, (%rax,%r13)
leaq 0x40(%rsp), %rdi
movq 0x28(%rsp), %rsi
leaq 0x1b(%rsp), %rdx
callq 0x4250
movq (%rbx), %rax
leaq (%rax,%r13), %rdi
addq $0x8, %rdi
leaq 0x40(%rsp), %rsi
callq 0x42a2
movq %rbp, 0x38(%rsp)
cvtsi2ss %ebp, %xmm0
divss 0x10(%rsp), %xmm0
movss %xmm0, 0x14(%rsp)
subss 0xc(%rsp), %xmm0
callq 0x21c0
movss %xmm0, 0x8(%rsp)
movss 0xc(%rsp), %xmm0
addss 0x14(%rsp), %xmm0
callq 0x2100
movss %xmm0, 0x1c(%rsp)
cvttss2si 0x8(%rsp), %ebp
xorps %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
movl %ebp, %ebx
cvtsi2ss %ebx, %xmm1
movss 0x1c(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jb 0x3c1e
movss 0x14(%rsp), %xmm0
subss %xmm1, %xmm0
mulss 0x10(%rsp), %xmm0
callq *(%r14)
movss 0x8(%rsp), %xmm1
addss %xmm0, %xmm1
movss %xmm1, 0x8(%rsp)
incl %ebx
jmp 0x3be8
movl %ebp, %ebx
negl %ebx
cvtsi2ss %ebp, %xmm1
movss 0x1c(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jb 0x3c80
movss 0x14(%rsp), %xmm0
subss %xmm1, %xmm0
mulss 0x10(%rsp), %xmm0
callq *(%r14)
divss 0x8(%rsp), %xmm0
leal (%r12,%rbx), %eax
cmpl %r15d, %ebp
cmovll %ebp, %eax
testl %ebp, %ebp
cmovsl %ebx, %eax
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
movslq (%rcx,%r13), %rdx
leal 0x1(%rdx), %esi
movl %esi, (%rcx,%r13)
movq 0x8(%rcx,%r13), %rcx
movl %eax, (%rcx,%rdx,8)
movss %xmm0, 0x4(%rcx,%rdx,8)
incl %ebp
decl %ebx
jmp 0x3c22
leaq 0x40(%rsp), %rdi
callq 0x4624
movq 0x38(%rsp), %rbp
incq %rbp
jmp 0x3b52
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3caa
jmp 0x3caa
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x4624
movq %rbx, %rdi
callq 0x2420
nop