// File: UCBASiCS[P]SPRIGHT/src/backend.cpp
// Function: BackEnd::process()
void BackEnd::process()
{
    chrono->start("BackEnd");
    binProcessor = new BinProcessor(chrono, config, observationMatrix, frontEnd->getDelays());
    int binAbsoluteIndex;
    bool singletonFound = true;
    initialize();
    maxBinUsed =0;
    while(singletonFound)
    {
        singletonFound = false;
        for (int stage = 0; stage < config->getBinsNb(); stage++)
        {
            binAbsoluteIndex = config->getBinOffset(stage);

            for (int binRelativeIndex = 0; binRelativeIndex < config->getBinNumItems(stage); binRelativeIndex++)
            {
                // Copies the values of bin index and related variables in binProcessor object.
                binProcessor->adjustTo(binAbsoluteIndex, binRelativeIndex, stage);
                // only check for singletons in the updated bins
                if (
                    changed[binAbsoluteIndex]
                    && binProcessor->isSingleton()
                    && decodedFrequencies.count(binProcessor->getLocation()) == 0
                   )
                {
                    singletonFound = true;
                    decodedFrequencies[binProcessor->getLocation()] = binProcessor->getAmplitude();
                    peelFrom(binProcessor->getLocation(), binProcessor->getAmplitude(), binAbsoluteIndex);
                    changed[binAbsoluteIndex] = false;
                }

                // mark this bin as processed
                // remark: this state can be changed if a ball is peeled from this bin
                changed[binAbsoluteIndex] = false;

                if ((int) decodedFrequencies.size() == config->getSignalSparsityPeeling())
                {
                    goto stopPeeling;
                }

                binAbsoluteIndex++;
            }
        }
    }


    stopPeeling:
    for (auto it = decodedFrequencies.cbegin(); it != decodedFrequencies.cend(); ++it)
    {
        realFrequenciesIndices.push_back(it->first);
    }

    delete binProcessor;

    chrono->stop("BackEnd");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0xe8(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0xe0(%rbp)
callq 0x4550
movq -0xe0(%rbp), %rdx
leaq 0x1b419(%rip), %rsi     # 0x2001c
leaq -0x28(%rbp), %rdi
callq 0x5a20
jmp 0x4c0e
movq -0xe8(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xc270
jmp 0x4c20
leaq -0x28(%rbp), %rdi
callq 0x4180
leaq -0x29(%rbp), %rdi
callq 0x4310
movl $0xa0, %edi
callq 0x42c0
movq %rax, %rcx
movq -0xf0(%rbp), %rax
movq %rcx, -0x110(%rbp)
movb $0x1, -0x59(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x108(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x100(%rbp)
movq 0x28(%rax), %rcx
movq %rcx, -0xf8(%rbp)
movq 0x18(%rax), %rsi
leaq -0x58(%rbp), %rdi
callq 0x1bb50
jmp 0x4c81
movq -0xf8(%rbp), %rcx
movq -0x100(%rbp), %rdx
movq -0x108(%rbp), %rsi
movq -0x110(%rbp), %rdi
leaq -0x58(%rbp), %r8
callq 0x9140
jmp 0x4ca8
movq -0xf0(%rbp), %rax
movq -0x110(%rbp), %rcx
movb $0x0, -0x59(%rbp)
movq %rcx, 0x20(%rax)
leaq -0x58(%rbp), %rdi
callq 0x5ad0
movq -0xf0(%rbp), %rdi
movb $0x1, -0x61(%rbp)
callq 0x5150
movq -0xf0(%rbp), %rax
movl $0x0, 0x88(%rax)
testb $0x1, -0x61(%rbp)
je 0x4fd6
movb $0x0, -0x61(%rbp)
movl $0x0, -0x68(%rbp)
movq -0xf0(%rbp), %rax
movl -0x68(%rbp), %ecx
movl %ecx, -0x114(%rbp)
movq 0x10(%rax), %rdi
callq 0xeb10
movl %eax, %ecx
movl -0x114(%rbp), %eax
cmpl %ecx, %eax
jge 0x4fd1
movq -0xf0(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x68(%rbp), %esi
callq 0xeac0
movl %eax, -0x60(%rbp)
movl $0x0, -0x6c(%rbp)
movq -0xf0(%rbp), %rax
movl -0x6c(%rbp), %ecx
movl %ecx, -0x118(%rbp)
movq 0x10(%rax), %rdi
movl -0x68(%rbp), %esi
callq 0xea50
movl %eax, %ecx
movl -0x118(%rbp), %eax
cmpl %ecx, %eax
jge 0x4fc1
movq -0xf0(%rbp), %rax
movq 0x20(%rax), %rdi
movl -0x60(%rbp), %esi
movl -0x6c(%rbp), %edx
movl -0x68(%rbp), %ecx
callq 0x9e80
movq -0xf0(%rbp), %rax
movq 0x80(%rax), %rcx
movslq -0x60(%rbp), %rdx
xorl %eax, %eax
testb $0x1, (%rcx,%rdx)
movb %al, -0x119(%rbp)
je 0x4e07
movq -0xf0(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x9ed0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x119(%rbp)
jne 0x4dc9
jmp 0x4e07
movq -0xf0(%rbp), %rax
movq %rax, %rcx
addq $0x30, %rcx
movq %rcx, -0x128(%rbp)
movq 0x20(%rax), %rdi
callq 0xa020
movq -0x128(%rbp), %rdi
movl %eax, -0x70(%rbp)
leaq -0x70(%rbp), %rsi
callq 0x5b30
cmpq $0x0, %rax
sete %al
movb %al, -0x119(%rbp)
movb -0x119(%rbp), %al
testb $0x1, %al
jne 0x4e16
jmp 0x4f64
movq -0xf0(%rbp), %rax
movb $0x1, -0x61(%rbp)
movq 0x20(%rax), %rdi
callq 0xa040
movq -0xf0(%rbp), %rax
movsd %xmm0, -0x80(%rbp)
movsd %xmm1, -0x78(%rbp)
movq %rax, %rcx
addq $0x30, %rcx
movq %rcx, -0x138(%rbp)
movq 0x20(%rax), %rdi
callq 0xa020
movq -0x138(%rbp), %rdi
movl %eax, -0x84(%rbp)
leaq -0x84(%rbp), %rsi
callq 0x5b60
movq %rax, %rcx
movq -0xf0(%rbp), %rax
movq -0x80(%rbp), %rdx
movq %rdx, (%rcx)
movq -0x78(%rbp), %rdx
movq %rdx, 0x8(%rcx)
movq 0x20(%rax), %rdi
callq 0xa020
movl %eax, %ecx
movq -0xf0(%rbp), %rax
movl %ecx, -0x12c(%rbp)
movq 0x20(%rax), %rdi
callq 0xa040
movl -0x12c(%rbp), %esi
movq -0xf0(%rbp), %rdi
movsd %xmm0, -0x98(%rbp)
movsd %xmm1, -0x90(%rbp)
movl -0x60(%rbp), %edx
movsd -0x98(%rbp), %xmm0
movsd -0x90(%rbp), %xmm1
callq 0x51d0
movq -0xf0(%rbp), %rax
movq 0x80(%rax), %rax
movslq -0x60(%rbp), %rcx
movb $0x0, (%rax,%rcx)
jmp 0x4f64
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x4f15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x4180
leaq -0x29(%rbp), %rdi
callq 0x4310
jmp 0x5138
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x4f46
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x5ad0
testb $0x1, -0x59(%rbp)
jne 0x4f4e
jmp 0x4f5f
movq -0x110(%rbp), %rdi
movl $0xa0, %esi
callq 0x42d0
jmp 0x5138
movq -0xf0(%rbp), %rdi
movq 0x80(%rdi), %rax
movslq -0x60(%rbp), %rcx
movb $0x0, (%rax,%rcx)
addq $0x30, %rdi
callq 0x5b90
movq %rax, %rcx
movq -0xf0(%rbp), %rax
movl %ecx, -0x13c(%rbp)
movq 0x10(%rax), %rdi
callq 0xea00
movl %eax, %ecx
movl -0x13c(%rbp), %eax
cmpl %ecx, %eax
jne 0x4faa
jmp 0x4fd8
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x4d43
jmp 0x4fc3
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x4cfd
jmp 0x4ce8
jmp 0x4fd8
movq -0xf0(%rbp), %rdi
addq $0x30, %rdi
callq 0x5bb0
movq %rax, -0xa0(%rbp)
movq -0xf0(%rbp), %rdi
addq $0x30, %rdi
callq 0x5c10
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x5be0
testb $0x1, %al
jne 0x501f
jmp 0x506a
movq -0xf0(%rbp), %rax
addq $0x68, %rax
movq %rax, -0x148(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x5c70
movq -0x148(%rbp), %rdi
cvtsi2sdl (%rax), %xmm0
movsd %xmm0, -0xb0(%rbp)
leaq -0xb0(%rbp), %rsi
callq 0x5c40
leaq -0xa0(%rbp), %rdi
callq 0x5ca0
jmp 0x4fef
movq -0xf0(%rbp), %rax
movq 0x20(%rax), %rax
movq %rax, -0x150(%rbp)
cmpq $0x0, %rax
je 0x508f
movq -0x150(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq -0xf0(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x160(%rbp)
leaq -0xd1(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x4550
movq -0x158(%rbp), %rdx
leaq 0x1af5a(%rip), %rsi     # 0x2001c
leaq -0xd0(%rbp), %rdi
callq 0x5a20
jmp 0x50d0
movq -0x160(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0xc340
jmp 0x50e5
leaq -0xd0(%rbp), %rdi
callq 0x4180
leaq -0xd1(%rbp), %rdi
callq 0x4310
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x512c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x4180
leaq -0xd1(%rbp), %rdi
callq 0x4310
movq -0x38(%rbp), %rdi
callq 0x4540
nopw %cs:(%rax,%rax)