// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x60(%rbp)
movl $0x0, -0xc(%rbp)
addq $0x40, %rdi
xorps %xmm0, %xmm0
callq 0x5e60
movq -0x60(%rbp), %rdi
addq $0x88, %rdi
callq 0xa270
movq %rax, -0x18(%rbp)
movq -0x60(%rbp), %rdi
addq $0x88, %rdi
callq 0xa2e0
movq %rax, -0x20(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0xa2a0
testb $0x1, %al
jne 0x9ce5
jmp 0x9d9c
leaq -0x18(%rbp), %rdi
callq 0xa310
movq %rax, %rcx
movq -0x60(%rbp), %rax
movl (%rcx), %edi
andl 0x38(%rax), %edi
callq 0x5dc0
movl $0x2, %ecx
cltd
idivl %ecx
movq -0x60(%rbp), %rax
movl %edx, %esi
movl $0x1, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmpl $0x0, %esi
cmovnel %edx, %ecx
cvtsi2sd %ecx, %xmm0
movq 0x80(%rax), %rdi
movslq -0xc(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
callq 0x5e60
movq -0x60(%rbp), %rcx
movq 0x80(%rcx), %rdi
movslq -0xc(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
movq 0x18(%rcx), %rax
movslq 0x58(%rcx), %rcx
movq (%rax,%rcx,8), %rsi
movslq -0xc(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
callq 0xa330
movq -0x60(%rbp), %rdi
movsd %xmm0, -0x30(%rbp)
movsd %xmm1, -0x28(%rbp)
addq $0x40, %rdi
leaq -0x30(%rbp), %rsi
callq 0xa370
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
leaq -0x18(%rbp), %rdi
callq 0xa3c0
jmp 0x9cbb
movq -0x60(%rbp), %rdi
cvtsi2sdl 0x24(%rdi), %xmm0
addq $0x40, %rdi
callq 0xa3e0
movq -0x60(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x70(%rax)
movl $0x0, -0x34(%rbp)
movq -0x60(%rbp), %rcx
movl -0x34(%rbp), %eax
cmpl 0x24(%rcx), %eax
jge 0x9e79
movq -0x60(%rbp), %rax
movq %rax, %rdi
addq $0x40, %rdi
movq 0x80(%rax), %rsi
movslq -0x34(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
callq 0xa330
movq -0x60(%rbp), %rax
movsd %xmm0, -0x48(%rbp)
movsd %xmm1, -0x40(%rbp)
movq 0x50(%rax), %rcx
movslq -0x34(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq -0x48(%rbp), %rdx
movq %rdx, (%rcx)
movq -0x40(%rbp), %rdx
movq %rdx, 0x8(%rcx)
movq 0x18(%rax), %rcx
movslq 0x58(%rax), %rdx
movq (%rcx,%rdx,8), %rdi
movslq -0x34(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rdi
movq 0x50(%rax), %rsi
movslq -0x34(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rsi
callq 0xa420
movsd %xmm0, -0x58(%rbp)
movsd %xmm1, -0x50(%rbp)
leaq -0x58(%rbp), %rdi
callq 0xa180
movq -0x60(%rbp), %rax
addsd 0x70(%rax), %xmm0
movsd %xmm0, 0x70(%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x9dc1
addq $0x60, %rsp
popq %rbp
retq
nop