// File: /workspace/github_cpp_makefile_star2_O1/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 $0x38, %rsp
movl %edx, 0x4(%rsp)
movsd %xmm1, 0x18(%rsp)
movsd %xmm0, 0x10(%rsp)
movl %esi, %r15d
movq %rdi, %r14
movq 0x18(%rdi), %rsi
leaq 0x20(%rsp), %rdi
callq 0xccbe
movq 0x10(%r14), %rdi
callq 0x6e2a
movslq %eax, %rdi
shlq $0x4, %rdi
callq 0x3320
movq %rax, 0x8(%rsp)
movq %rax, %rbx
addq $0x8, %rbx
xorl %r12d, %r12d
movl $0x33333333, %ebp       # imm = 0x33333333
leaq 0xb094(%rip), %r13      # 0xf010
movq 0x10(%r14), %rdi
callq 0x6e2a
cltq
cmpq %rax, %r12
jge 0x3ff4
movq 0x20(%rsp), %rax
movl (%rax,%r12,4), %eax
andl %r15d, %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
xorl %ecx, %ecx
btl $0x18, %eax
setae %cl
movsd (%r13,%rcx,8), %xmm0
movapd %xmm0, %xmm1
mulsd 0x10(%rsp), %xmm1
mulsd 0x18(%rsp), %xmm0
movsd %xmm1, -0x8(%rbx)
movsd %xmm0, (%rbx)
incq %r12
addq $0x10, %rbx
jmp 0x3f7c
xorl %r12d, %r12d
movl %r15d, (%rsp)
movq 0x10(%r14), %rdi
callq 0x6e1c
cmpl %eax, %r12d
jge 0x40d8
movq %r14, %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x42b8
movl %eax, %r13d
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x10(%r14), %rdi
callq 0x6e2a
cltq
movq 0x10(%r14), %rdi
cmpq %rax, %rbx
jge 0x40b4
movq 0x28(%r14), %r15
movl %r12d, %esi
callq 0x6e0c
addl %r13d, %eax
cltq
movq (%r15,%rax,8), %rax
movsd (%rax,%rbp), %xmm0
movsd 0x8(%rax,%rbp), %xmm1
movq 0x8(%rsp), %rcx
subsd (%rcx,%rbp), %xmm0
subsd 0x8(%rcx,%rbp), %xmm1
movsd %xmm0, (%rax,%rbp)
movsd %xmm1, 0x8(%rax,%rbp)
movq 0x10(%r14), %rdi
movl %r12d, %esi
callq 0x6e0c
addl %r13d, %eax
cmpl 0x4(%rsp), %eax
jne 0x40a8
movq 0x10(%r14), %rdi
movq 0x28(%r14), %r15
movl %r12d, %esi
callq 0x6e0c
addl %r13d, %eax
cltq
movq (%r15,%rax,8), %rax
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax,%rbp)
incq %rbx
addq $0x10, %rbp
jmp 0x4022
movq 0x80(%r14), %rbx
movl %r12d, %esi
callq 0x6e0c
movl (%rsp), %r15d
addl %r13d, %eax
cltq
movb $0x1, (%rbx,%rax)
incl %r12d
jmp 0x3ffb
movq 0x8(%rsp), %rdi
callq 0x32e0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x40f9
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x410e
jmp 0x410e
jmp 0x410e
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4128
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq %rbx, %rdi
callq 0x3490