// File: /workspace/github_cpp_makefile_star2_O1/UCBASiCS[P]SPRIGHT/src/binprocessor.cpp
// Function: BinProcessor::estimateBinSignal()
void BinProcessor::estimateBinSignal()
{
    int delayIndex = 0;
    amplitude      = 0;

    for(auto delayIterator=delays.begin(); delayIterator != delays.end(); ++delayIterator)
    {
        directionVector[delayIndex] = (numOnes(*delayIterator & location) % 2) ? -1 : 1;
        amplitude += directionVector[delayIndex] * observationMatrix[binAbsoluteIndex][delayIndex];
        delayIndex++;
    }

    // average the found amplitudes
    amplitude /= delaysNb;

    noise = 0;

    for (int delayIndex=0; delayIndex<delaysNb; delayIndex++)
    {
        // compute the bin signal that would result from a tone with such amplitude and location
        signalVector[delayIndex] = amplitude*directionVector[delayIndex];
        // the residual between the actual bin measurement and the computed one is the noise
        noise += std::norm(observationMatrix[binAbsoluteIndex][delayIndex]-signalVector[delayIndex]);
    } 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
xorpd %xmm0, %xmm0
movupd %xmm0, 0x40(%rdi)
movq 0x88(%rdi), %r15
cmpq 0x90(%rdi), %r15
je 0x52ad
xorl %r12d, %r12d
movl $0x33333333, %ebp       # imm = 0x33333333
movq %rsp, %r14
movl 0x38(%rbx), %eax
andl (%r15), %eax
movl %eax, %ecx
shrl %ecx
andl $0x55555555, %ecx       # imm = 0x55555555
subl %ecx, %eax
movl %eax, %ecx
andl %ebp, %ecx
shrl $0x2, %eax
andl %ebp, %eax
addl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
addl %eax, %ecx
andl $0x10f0f0f, %ecx        # imm = 0x10F0F0F
imull $0x1010101, %ecx, %eax  # imm = 0x1010101
btl $0x18, %eax
movl $0x0, %eax
sbbl %eax, %eax
orl $0x1, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movq 0x80(%rbx), %rax
movsd %xmm0, (%rax,%r12)
movq $0x0, 0x8(%rax,%r12)
movq 0x18(%rbx), %rax
movq 0x80(%rbx), %rcx
movslq 0x58(%rbx), %rdx
movq (%rax,%rdx,8), %rsi
addq %r12, %rsi
movups (%rcx,%r12), %xmm0
movaps %xmm0, (%rsp)
movq %r14, %rdi
callq 0x5524
movsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm1
addsd 0x40(%rbx), %xmm0
addsd 0x48(%rbx), %xmm1
movsd %xmm0, 0x40(%rbx)
movsd %xmm1, 0x48(%rbx)
addq $0x4, %r15
addq $0x10, %r12
cmpq 0x90(%rbx), %r15
jne 0x51f7
movl 0x24(%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x40(%rbx), %xmm1
movsd 0x48(%rbx), %xmm2
divsd %xmm0, %xmm1
divsd %xmm0, %xmm2
movsd %xmm1, 0x40(%rbx)
movsd %xmm2, 0x48(%rbx)
movq $0x0, 0x70(%rbx)
testl %eax, %eax
jle 0x5367
leaq 0x40(%rbx), %r15
xorl %r12d, %r12d
movq %rsp, %r14
xorl %r13d, %r13d
movq 0x80(%rbx), %rsi
addq %r12, %rsi
movups (%r15), %xmm0
movaps %xmm0, (%rsp)
movq %r14, %rdi
callq 0x5524
movaps (%rsp), %xmm0
movq 0x50(%rbx), %rax
movups %xmm0, (%rax,%r12)
movslq 0x58(%rbx), %rax
movq 0x18(%rbx), %rcx
movq 0x50(%rbx), %rdx
movq (%rcx,%rax,8), %rax
movsd (%rax,%r12), %xmm0
movsd 0x8(%rax,%r12), %xmm1
subsd (%rdx,%r12), %xmm0
subsd 0x8(%rdx,%r12), %xmm1
mulsd %xmm1, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
addsd 0x70(%rbx), %xmm0
movsd %xmm0, 0x70(%rbx)
incq %r13
movslq 0x24(%rbx), %rax
addq $0x10, %r12
cmpq %rax, %r13
jl 0x52f0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq