// File: /workspace/github_cpp_makefile_star2_O3/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 0xcb4c
movq 0x10(%r14), %rdi
callq 0x6cf0
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 0xa0e7(%rip), %r12      # 0xe010
movq %rax, 0x10(%rsp)
movq %rax, %r13
movq 0x10(%r14), %rdi
callq 0x6cf0
cltq
cmpq %rax, %rbx
movapd 0x20(%rsp), %xmm1
jge 0x3f7c
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 0x3f31
xorl %r12d, %r12d
movl %ebp, 0x8(%rsp)
movq 0x10(%r14), %rdi
callq 0x6ce2
cmpl %eax, %r12d
jge 0x4051
movq %r14, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x4232
movl %eax, %r13d
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x10(%r14), %rdi
callq 0x6cf0
cltq
movq 0x10(%r14), %rdi
cmpq %rax, %rbx
jge 0x402d
movq 0x28(%r14), %r15
movl %r12d, %esi
callq 0x6cd2
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 0x6cd2
addl %r13d, %eax
cmpl 0xc(%rsp), %eax
jne 0x4021
movq 0x10(%r14), %rdi
movq 0x28(%r14), %r15
movl %r12d, %esi
callq 0x6cd2
addl %r13d, %eax
cltq
movq (%r15,%rax,8), %rax
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax,%rbp)
incq %rbx
addq $0x10, %rbp
jmp 0x3fa9
movq 0x80(%r14), %rbx
movl %r12d, %esi
callq 0x6cd2
movl 0x8(%rsp), %ebp
addl %r13d, %eax
cltq
movb $0x1, (%rbx,%rax)
incl %r12d
jmp 0x3f83
movq 0x10(%rsp), %rdi
callq 0x32e0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x4072
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4087
jmp 0x4087
jmp 0x4087
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x40a1
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq %rbx, %rdi
callq 0x3490
nop