// File: /workspace/github_cpp_makefile_star2_O2/UCBASiCS[P]SPRIGHT/src/backend.cpp
// Function: BackEnd::peelFrom(int, std::complex<double>, int)
void BackEnd::peelFrom(int spectralIndex, ffast_complex amplitude, int binIndex)
{
    int hash;
    // peel the contribution of the ball from all stages
    
    std::vector<int> delays = frontEnd->getDelays();
    ffast_complex* toSubtract = (ffast_complex *) malloc(config->getDelaysNb() * sizeof(ffast_complex));
    
    for (int i =0; i < config->getDelaysNb(); i++) {
        int currDelay = delays[i];
        toSubtract[i] = amplitude * (numOnes(currDelay & spectralIndex) % 2 ? -1.0 : 1.0);
    }

    for (int stage = 0; stage < config->getBinsNb(); stage++)
    {
        // index of the bin the ball is connected to at this stage
        hash = getHash(stage, spectralIndex);
        for (int delayIndex = 0; delayIndex < config->getDelaysNb(); delayIndex++)
        {
            observationMatrix[hash + config->getBinOffset(stage)][delayIndex] -= toSubtract[delayIndex];
            if (hash + config->getBinOffset(stage) == binIndex)
                observationMatrix[hash + config->getBinOffset(stage)][delayIndex] = 0;
            
        }
        changed[hash + config->getBinOffset(stage)] = true;
    }

    free(toSubtract);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, 0xc(%rsp)
movapd %xmm1, 0x10(%rsp)
movapd %xmm0, 0x20(%rsp)
movl %esi, %ebp
movq %rdi, %r14
movq 0x18(%rdi), %rsi
leaq 0x30(%rsp), %rdi
callq 0xb038
movq 0x10(%r14), %rdi
callq 0x67d8
movslq %eax, %rdi
shlq $0x4, %rdi
callq 0x3320
movapd 0x20(%rsp), %xmm0
unpcklpd 0x10(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0]
movapd %xmm0, 0x20(%rsp)
xorl %ebx, %ebx
leaq 0x837f(%rip), %r12      # 0xc010
movq %rax, 0x10(%rsp)
movq %rax, %r13
movq 0x10(%r14), %rdi
callq 0x67d8
cltq
cmpq %rax, %rbx
movapd 0x20(%rsp), %xmm1
jge 0x3ce4
movq 0x30(%rsp), %rax
movl (%rax,%rbx,4), %eax
andl %ebp, %eax
movl %eax, %ecx
shrl $0x10, %ecx
xorl %eax, %ecx
xorl %eax, %eax
xorb %ch, %cl
setp %al
movsd (%r12,%rax,8), %xmm0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm1, %xmm0
movupd %xmm0, (%r13)
incq %rbx
addq $0x10, %r13
jmp 0x3c99
xorl %r12d, %r12d
movl %ebp, 0x8(%rsp)
movq 0x10(%r14), %rdi
callq 0x67ca
cmpl %eax, %r12d
jge 0x3db9
movq %r14, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x3eec
movl %eax, %r13d
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x10(%r14), %rdi
callq 0x67d8
cltq
movq 0x10(%r14), %rdi
cmpq %rax, %rbx
jge 0x3d95
movq 0x28(%r14), %r15
movl %r12d, %esi
callq 0x67ba
addl %r13d, %eax
cltq
movq (%r15,%rax,8), %rax
movq 0x10(%rsp), %rcx
movupd (%rcx,%rbp), %xmm0
movupd (%rax,%rbp), %xmm1
subpd %xmm0, %xmm1
movupd %xmm1, (%rax,%rbp)
movq 0x10(%r14), %rdi
movl %r12d, %esi
callq 0x67ba
addl %r13d, %eax
cmpl 0xc(%rsp), %eax
jne 0x3d89
movq 0x10(%r14), %rdi
movq 0x28(%r14), %r15
movl %r12d, %esi
callq 0x67ba
addl %r13d, %eax
cltq
movq (%r15,%rax,8), %rax
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax,%rbp)
incq %rbx
addq $0x10, %rbp
jmp 0x3d11
movq 0x80(%r14), %rbx
movl %r12d, %esi
callq 0x67ba
movl 0x8(%rsp), %ebp
addl %r13d, %eax
cltq
movb $0x1, (%rbx,%rax)
incl %r12d
jmp 0x3ceb
movq 0x10(%rsp), %rdi
callq 0x32d0
leaq 0x30(%rsp), %rdi
callq 0x41c6
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3de2
jmp 0x3de2
jmp 0x3de2
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x41c6
movq %rbx, %rdi
callq 0x3490
nop