// File: UCBASiCS[P]SPRIGHT/src/frontend.cpp
// Function: FrontEnd::process()
void FrontEnd::process()
{
    chrono->start("FrontEnd");
    
    int realSignalBitLength = config->getSignalBitLength(); //ceil(log2(config->getSignalLength()))

    for (int binAbsoluteIndex=0; binAbsoluteIndex<config->getBinsSum(); binAbsoluteIndex++)
        for (int delayNb = 0; delayNb < config->getDelaysNb(); delayNb++)
            observationMatrix[binAbsoluteIndex][delayNb] = 0;

    for (int c = 0; c < config->getBinsNb(); c++)
    {
        int binIndices = config->getSamplingPattern(c);

        int b = config->getBinNumIndices(c);
        int B = pow(2,b); // number of bins in stage

        for (int delayIndex = 0; delayIndex < config->getDelaysNb(); delayIndex++)
        {
            int currDelay = delays[delayIndex];

            std::vector<ffast_complex> binTimeDomain = std::vector<ffast_complex>(B);
            for (int bin_iter = 0; bin_iter < B; bin_iter++)
            {
                int mlInt = mapToInt(bin_iter, b, binIndices, realSignalBitLength);
                int signalIndex = currDelay ^ mlInt;

                binTimeDomain[bin_iter] = input->getSignalAtIndex(signalIndex);

                if (!countSamplesDone && config->needToCountSamples())
                    usedSamples.insert(signalIndex);
            }


            std::vector<ffast_complex> a = std::vector<ffast_complex>(binTimeDomain);
            std::vector<ffast_complex> b = std::vector<ffast_complex>(B);
            std::vector<ffast_complex> tmp = std::vector<ffast_complex>(B);
            int ii, jj, ss;
            for (ii = B>>1; ii > 0; ii>>=1) {
                for (jj = 0; jj < B; jj++) {
                    ss = jj/ii%2;
                    b[jj]=a[(ss?-ii:0)+jj];
                    b[jj]+= ((ffast_complex) (ss?-1:1)) * a[(ss?0:ii)+jj];
                }
                tmp = a; a = b; b = tmp;
            }
            std::vector<ffast_complex> binTransform = std::vector<ffast_complex>(a);

            for (int binLoc = 0; binLoc < B; binLoc++)
                observationMatrix[config->getBinOffset(c)+binLoc][delayIndex] = binTransform[binLoc];
        }     
    }






    for (int stage = 0; stage < config->getBinsNb(); stage++) {
        for (int r = 0; r < config->getBinNumItems(stage); r++) {
            for (int c = 0; c < config->getDelaysNb(); c++) {
                ffast_complex val = observationMatrix[r + config->getBinOffset(stage)][c];
                // double multiplier = pow(1.0*config->getSignalLength() / config->getBinNumItems(stage),.5);
                double multiplier = 1.0/config->getBinNumItems(stage) * pow(config->getSignalLength(), .5);
                // double multiplier = 1.0/config->getBinNumItems(stage);

                observationMatrix[r + config->getBinOffset(stage)][c] = val * multiplier;
            }
        }
    }

    countSamplesDone = true;

    chrono->stop("FrontEnd");
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x1b0(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x4550
movq -0x1a8(%rbp), %rdx
leaq 0x5e9d(%rip), %rsi      # 0x20f00
leaq -0x28(%rbp), %rdi
callq 0x5a20
jmp 0x1b06e
movq -0x1b0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xc270
jmp 0x1b080
leaq -0x28(%rbp), %rdi
callq 0x4180
leaq -0x29(%rbp), %rdi
callq 0x4310
movq -0x1b8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0xe940
movl %eax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x1b8(%rbp), %rax
movl -0x44(%rbp), %ecx
movl %ecx, -0x1bc(%rbp)
movq 0x10(%rax), %rdi
callq 0xeaf0
movl %eax, %ecx
movl -0x1bc(%rbp), %eax
cmpl %ecx, %eax
jge 0x1b173
movl $0x0, -0x48(%rbp)
movq -0x1b8(%rbp), %rax
movl -0x48(%rbp), %ecx
movl %ecx, -0x1c0(%rbp)
movq 0x10(%rax), %rdi
callq 0xeb30
movl %eax, %ecx
movl -0x1c0(%rbp), %eax
cmpl %ecx, %eax
jge 0x1b163
movq -0x1b8(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movslq -0x48(%rbp), %rax
shlq $0x4, %rax
addq %rax, %rdi
xorps %xmm0, %xmm0
callq 0x5e60
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x1b0dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1b155
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 0x1baf2
jmp 0x1b165
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x1b0ac
movl $0x0, -0x4c(%rbp)
movq -0x1b8(%rbp), %rax
movl -0x4c(%rbp), %ecx
movl %ecx, -0x1c4(%rbp)
movq 0x10(%rax), %rdi
callq 0xeb10
movl %eax, %ecx
movl -0x1c4(%rbp), %eax
cmpl %ecx, %eax
jge 0x1b804
movq -0x1b8(%rbp), %rax
movq 0x10(%rax), %rdi
movl -0x4c(%rbp), %esi
callq 0xea20
movl %eax, %ecx
movq -0x1b8(%rbp), %rax
movl %ecx, -0x50(%rbp)
movq 0x10(%rax), %rdi
movl -0x4c(%rbp), %esi
callq 0xea90
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %esi
movl $0x2, %edi
callq 0xa240
cvttsd2si %xmm0, %eax
movl %eax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x1b8(%rbp), %rax
movl -0x5c(%rbp), %ecx
movl %ecx, -0x1c8(%rbp)
movq 0x10(%rax), %rdi
callq 0xeb30
movl %eax, %ecx
movl -0x1c8(%rbp), %eax
cmpl %ecx, %eax
jge 0x1b7f4
movq -0x1b8(%rbp), %rdi
addq $0x60, %rdi
movslq -0x5c(%rbp), %rsi
callq 0x5d60
movl (%rax), %eax
movl %eax, -0x60(%rbp)
movslq -0x58(%rbp), %rax
movq %rax, -0x1d8(%rbp)
leaq -0x79(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x12120
movq -0x1d8(%rbp), %rsi
movq -0x1d0(%rbp), %rdx
leaq -0x78(%rbp), %rdi
callq 0x12140
jmp 0x1b262
leaq -0x79(%rbp), %rdi
callq 0x121b0
movl $0x0, -0x80(%rbp)
movl -0x80(%rbp), %eax
cmpl -0x58(%rbp), %eax
jge 0x1b3d7
movl -0x80(%rbp), %edi
movl -0x54(%rbp), %esi
movl -0x50(%rbp), %edx
movl -0x40(%rbp), %ecx
callq 0xa1b0
movl %eax, -0x1dc(%rbp)
jmp 0x1b297
movq -0x1b8(%rbp), %rax
movl -0x1dc(%rbp), %ecx
movl %ecx, -0x84(%rbp)
movl -0x60(%rbp), %ecx
movl -0x84(%rbp), %edx
xorl %edx, %ecx
movl %ecx, -0x88(%rbp)
movq 0x78(%rax), %rdi
movl -0x88(%rbp), %esi
movq (%rdi), %rax
movq 0x28(%rax), %rax
callq *%rax
movsd %xmm1, -0x1f0(%rbp)
movsd %xmm0, -0x1e8(%rbp)
jmp 0x1b2e0
movsd -0x1f0(%rbp), %xmm0
movsd -0x1e8(%rbp), %xmm1
movsd %xmm1, -0x98(%rbp)
movsd %xmm0, -0x90(%rbp)
movslq -0x80(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x1bba0
movq %rax, %rcx
movq -0x1b8(%rbp), %rax
movq -0x98(%rbp), %rdx
movq %rdx, (%rcx)
movq -0x90(%rbp), %rdx
movq %rdx, 0x8(%rcx)
testb $0x1, 0x5c(%rax)
jne 0x1b3c7
movq -0x1b8(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0xec70
movb %al, -0x1f1(%rbp)
jmp 0x1b34e
movb -0x1f1(%rbp), %al
testb $0x1, %al
jne 0x1b35a
jmp 0x1b3c7
movq -0x1b8(%rbp), %rdi
subq $-0x80, %rdi
leaq -0x88(%rbp), %rsi
callq 0x11fe0
movb %dl, -0x201(%rbp)
movq %rax, -0x200(%rbp)
jmp 0x1b380
movb -0x201(%rbp), %al
movq -0x200(%rbp), %rcx
movq %rcx, -0xa8(%rbp)
movb %al, -0xa0(%rbp)
jmp 0x1b3c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x79(%rbp), %rdi
callq 0x121b0
jmp 0x1baf2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1b7e6
jmp 0x1b3c9
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x1b272
leaq -0xc0(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x1bbc0
jmp 0x1b3e9
movslq -0x58(%rbp), %rax
movq %rax, -0x218(%rbp)
leaq -0xd9(%rbp), %rdi
movq %rdi, -0x210(%rbp)
callq 0x12120
movq -0x218(%rbp), %rsi
movq -0x210(%rbp), %rdx
leaq -0xd8(%rbp), %rdi
callq 0x12140
jmp 0x1b423
leaq -0xd9(%rbp), %rdi
callq 0x121b0
movslq -0x58(%rbp), %rax
movq %rax, -0x228(%rbp)
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0x12120
movq -0x228(%rbp), %rsi
movq -0x220(%rbp), %rdx
leaq -0xf8(%rbp), %rdi
callq 0x12140
jmp 0x1b469
leaq -0xf9(%rbp), %rdi
callq 0x121b0
movl -0x58(%rbp), %eax
sarl %eax
movl %eax, -0x100(%rbp)
cmpl $0x0, -0x100(%rbp)
jle 0x1b6a2
movl $0x0, -0x104(%rbp)
movl -0x104(%rbp), %eax
cmpl -0x58(%rbp), %eax
jge 0x1b64e
movl -0x104(%rbp), %eax
cltd
idivl -0x100(%rbp)
movl $0x2, %ecx
cltd
idivl %ecx
movl %edx, -0x108(%rbp)
cmpl $0x0, -0x108(%rbp)
je 0x1b4da
xorl %eax, %eax
subl -0x100(%rbp), %eax
movl %eax, -0x22c(%rbp)
jmp 0x1b4e4
xorl %eax, %eax
movl %eax, -0x22c(%rbp)
jmp 0x1b4e4
movl -0x22c(%rbp), %eax
movl -0x104(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
leaq -0xc0(%rbp), %rdi
callq 0x1bba0
movq %rax, -0x238(%rbp)
movslq -0x104(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x1bba0
movq -0x238(%rbp), %rcx
movups (%rcx), %xmm0
movups %xmm0, (%rax)
movl -0x108(%rbp), %ecx
xorl %eax, %eax
negl %ecx
sbbl %eax, %eax
orl $0x1, %eax
cvtsi2sd %eax, %xmm0
leaq -0x128(%rbp), %rdi
xorps %xmm1, %xmm1
callq 0x7dd0
jmp 0x1b54c
cmpl $0x0, -0x108(%rbp)
je 0x1b55f
xorl %eax, %eax
movl %eax, -0x23c(%rbp)
jmp 0x1b56b
movl -0x100(%rbp), %eax
movl %eax, -0x23c(%rbp)
movl -0x23c(%rbp), %eax
movl -0x104(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
leaq -0xc0(%rbp), %rdi
callq 0x1bba0
movq %rax, %rsi
leaq -0x128(%rbp), %rdi
callq 0xa330
movsd %xmm1, -0x250(%rbp)
movsd %xmm0, -0x248(%rbp)
jmp 0x1b5a9
movsd -0x250(%rbp), %xmm0
movsd -0x248(%rbp), %xmm1
movsd %xmm1, -0x118(%rbp)
movsd %xmm0, -0x110(%rbp)
movslq -0x104(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x1bba0
movq %rax, %rdi
leaq -0x118(%rbp), %rsi
callq 0xa370
jmp 0x1b5ed
jmp 0x1b5ef
movl -0x104(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x104(%rbp)
jmp 0x1b497
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xd9(%rbp), %rdi
callq 0x121b0
jmp 0x1b7da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0xf9(%rbp), %rdi
callq 0x121b0
jmp 0x1b7ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1b7c2
leaq -0xf8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x1bcb0
jmp 0x1b663
leaq -0xc0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x1bcb0
jmp 0x1b678
leaq -0xd8(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x1bcb0
jmp 0x1b68d
jmp 0x1b68f
movl -0x100(%rbp), %eax
sarl %eax
movl %eax, -0x100(%rbp)
jmp 0x1b480
leaq -0x140(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x1bbc0
jmp 0x1b6b7
movl $0x0, -0x144(%rbp)
movl -0x144(%rbp), %eax
cmpl -0x58(%rbp), %eax
jge 0x1b77b
movslq -0x144(%rbp), %rsi
leaq -0x140(%rbp), %rdi
callq 0x1bba0
movq %rax, %rcx
movq -0x1b8(%rbp), %rax
movq %rcx, -0x268(%rbp)
movq 0x10(%rax), %rdi
movq 0x50(%rax), %rax
movq %rax, -0x260(%rbp)
movl -0x4c(%rbp), %esi
callq 0xeac0
movl %eax, -0x254(%rbp)
jmp 0x1b713
movq -0x268(%rbp), %rcx
movq -0x260(%rbp), %rax
movl -0x254(%rbp), %edx
addl -0x144(%rbp), %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movslq -0x5c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
movl -0x144(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x144(%rbp)
jmp 0x1b6c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x140(%rbp), %rdi
callq 0x121d0
jmp 0x1b7c2
leaq -0x140(%rbp), %rdi
callq 0x121d0
leaq -0xf8(%rbp), %rdi
callq 0x121d0
leaq -0xd8(%rbp), %rdi
callq 0x121d0
leaq -0xc0(%rbp), %rdi
callq 0x121d0
leaq -0x78(%rbp), %rdi
callq 0x121d0
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x1b1ec
leaq -0xf8(%rbp), %rdi
callq 0x121d0
leaq -0xd8(%rbp), %rdi
callq 0x121d0
leaq -0xc0(%rbp), %rdi
callq 0x121d0
leaq -0x78(%rbp), %rdi
callq 0x121d0
jmp 0x1baf2
jmp 0x1b7f6
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1b17a
movl $0x0, -0x148(%rbp)
movq -0x1b8(%rbp), %rax
movl -0x148(%rbp), %ecx
movl %ecx, -0x26c(%rbp)
movq 0x10(%rax), %rdi
callq 0xeb10
movl %eax, %ecx
movl -0x26c(%rbp), %eax
cmpl %ecx, %eax
jge 0x1ba45
movl $0x0, -0x14c(%rbp)
movq -0x1b8(%rbp), %rax
movl -0x14c(%rbp), %ecx
movl %ecx, -0x270(%rbp)
movq 0x10(%rax), %rdi
movl -0x148(%rbp), %esi
callq 0xea50
movl %eax, %ecx
movl -0x270(%rbp), %eax
cmpl %ecx, %eax
jge 0x1ba2f
movl $0x0, -0x150(%rbp)
movq -0x1b8(%rbp), %rax
movl -0x150(%rbp), %ecx
movl %ecx, -0x274(%rbp)
movq 0x10(%rax), %rdi
callq 0xeb30
movl %eax, %ecx
movl -0x274(%rbp), %eax
cmpl %ecx, %eax
jge 0x1ba19
movq -0x1b8(%rbp), %rax
movq 0x50(%rax), %rcx
movq %rcx, -0x298(%rbp)
movl -0x14c(%rbp), %ecx
movl %ecx, -0x29c(%rbp)
movq 0x10(%rax), %rdi
movl -0x148(%rbp), %esi
callq 0xeac0
movl -0x29c(%rbp), %edx
movq -0x298(%rbp), %rcx
movl %eax, %esi
movq -0x1b8(%rbp), %rax
addl %esi, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
movslq -0x150(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, -0x160(%rbp)
movq 0x8(%rcx), %rcx
movq %rcx, -0x158(%rbp)
movq 0x10(%rax), %rdi
movl -0x148(%rbp), %esi
callq 0xea50
movl %eax, %ecx
movq -0x1b8(%rbp), %rax
cvtsi2sd %ecx, %xmm1
movsd 0x4791(%rip), %xmm0     # 0x200d0
divsd %xmm1, %xmm0
movsd %xmm0, -0x290(%rbp)
movq 0x10(%rax), %rdi
callq 0xe9a0
movl %eax, %edi
movsd 0x559a(%rip), %xmm0     # 0x20ef8
callq 0x1bf00
movaps %xmm0, %xmm1
movsd -0x290(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x168(%rbp)
leaq -0x160(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x5d80
movq -0x1b8(%rbp), %rax
movsd %xmm0, -0x178(%rbp)
movsd %xmm1, -0x170(%rbp)
movq 0x50(%rax), %rcx
movq %rcx, -0x280(%rbp)
movl -0x14c(%rbp), %ecx
movl %ecx, -0x284(%rbp)
movq 0x10(%rax), %rdi
movl -0x148(%rbp), %esi
callq 0xeac0
movl -0x284(%rbp), %ecx
movl %eax, %edx
movq -0x280(%rbp), %rax
addl %edx, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movslq -0x150(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x178(%rbp), %rcx
movq %rcx, (%rax)
movq -0x170(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl -0x150(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x150(%rbp)
jmp 0x1b880
jmp 0x1ba1b
movl -0x14c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14c(%rbp)
jmp 0x1b844
jmp 0x1ba31
movl -0x148(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x148(%rbp)
jmp 0x1b80e
movq -0x1b8(%rbp), %rax
movb $0x1, 0x5c(%rax)
movq 0x8(%rax), %rax
movq %rax, -0x2b0(%rbp)
leaq -0x199(%rbp), %rdi
movq %rdi, -0x2a8(%rbp)
callq 0x4550
movq -0x2a8(%rbp), %rdx
leaq 0x5484(%rip), %rsi      # 0x20f00
leaq -0x198(%rbp), %rdi
callq 0x5a20
jmp 0x1ba8a
movq -0x2b0(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0xc340
jmp 0x1ba9f
leaq -0x198(%rbp), %rdi
callq 0x4180
leaq -0x199(%rbp), %rdi
callq 0x4310
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
jmp 0x1bae6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x4180
leaq -0x199(%rbp), %rdi
callq 0x4310
movq -0x38(%rbp), %rdi
callq 0x4540
nopl (%rax,%rax)