// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rdi, %rbx
movq 0x8(%rdi), %r14
leaq 0x2444(%rip), %rsi      # 0xcf0f
leaq 0x40(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x3fb6
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq 0x56f4
leaq 0x40(%rsp), %rdi
callq 0x30f0
movq 0x10(%rbx), %rdi
callq 0x6700
movl %eax, 0x24(%rsp)
xorl %r14d, %r14d
movq 0x10(%rbx), %rdi
callq 0x67c6
cltq
cmpq %rax, %r14
jge 0xab45
xorl %r15d, %r15d
xorl %r12d, %r12d
movq 0x10(%rbx), %rdi
callq 0x67d8
cltq
cmpq %rax, %r12
jge 0xab40
movq 0x50(%rbx), %rax
movq (%rax,%r14,8), %rax
incq %r12
xorps %xmm0, %xmm0
movups %xmm0, (%rax,%r15)
addq $0x10, %r15
jmp 0xab17
incq %r14
jmp 0xab01
leaq 0x80(%rbx), %rax
movq %rax, 0x90(%rsp)
xorl %r14d, %r14d
leaq 0x98(%rsp), %rbp
movq %rbx, (%rsp)
movq 0x10(%rbx), %rdi
callq 0x67ca
cmpl %eax, %r14d
jge 0xae4f
movq 0x10(%rbx), %rdi
movl %r14d, %esi
callq 0x6724
movl %eax, 0x2c(%rsp)
movq 0x10(%rbx), %rdi
movq %r14, 0x68(%rsp)
movl %r14d, %esi
callq 0x677c
movsd 0x154a(%rip), %xmm0     # 0xc0e8
movl %eax, 0x28(%rsp)
movl %eax, %edi
callq 0x33c0
cvttsd2si %xmm0, %eax
movslq %eax, %r14
movl %r14d, %eax
sarl %eax
movl %eax, 0x20(%rsp)
testl %r14d, %r14d
movl $0x0, %r15d
cmovgl %r14d, %r15d
movq %r15, 0x30(%rsp)
shlq $0x4, %r15
xorl %r12d, %r12d
movq %r14, 0x60(%rsp)
movq 0x10(%rbx), %rdi
callq 0x67d8
cltq
cmpq %rax, %r12
jge 0xae42
movq 0x60(%rbx), %rax
movq %r14, %rsi
movl (%rax,%r12,4), %r13d
leaq 0x40(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x7aaa
movq %r12, 0x70(%rsp)
pushq $0x8
popq %r12
xorl %r14d, %r14d
cmpq %r14, 0x30(%rsp)
je 0xac7f
movl %r14d, %edi
movl 0x28(%rsp), %esi
movl 0x2c(%rsp), %edx
movl 0x24(%rsp), %ecx
callq 0x5071
xorl %r13d, %eax
movl %eax, 0x8(%rsp)
movq 0x78(%rbx), %rdi
movq (%rdi), %rcx
movl %eax, %esi
callq *0x28(%rcx)
movq 0x40(%rsp), %rax
movsd %xmm0, -0x8(%rax,%r12)
movsd %xmm1, (%rax,%r12)
cmpb $0x0, 0x5c(%rbx)
jne 0xac76
movq 0x10(%rbx), %rdi
callq 0x6808
testb %al, %al
je 0xac76
movq 0x90(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x7afc
incq %r14
addq $0x10, %r12
jmp 0xac11
leaq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0xb054
leaq 0x78(%rsp), %rdi
movq 0x60(%rsp), %r12
movq %r12, %rsi
leaq 0xb0(%rsp), %r14
movq %r14, %rdx
callq 0x7aaa
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x7aaa
movl 0x20(%rsp), %r13d
testl %r13d, %r13d
jle 0xad9e
xorl %r14d, %r14d
xorl %r12d, %r12d
cmpq %r12, %r15
je 0xad65
movl %r14d, %eax
xorl %edx, %edx
divl %r13d
andl $0x1, %eax
movl %eax, %ecx
negl %ecx
movl %ecx, %edx
andl %r13d, %edx
movq 0x8(%rsp), %rsi
movslq %edx, %rdx
shlq $0x4, %rdx
subq %rdx, %rsi
movq 0x78(%rsp), %rdx
movups (%r12,%rsi), %xmm0
movups %xmm0, (%rdx,%r12)
andq $0x0, 0xa0(%rsp)
orl $0x1, %ecx
testl %eax, %eax
cvtsi2sd %ecx, %xmm0
movsd %xmm0, 0x98(%rsp)
movl $0x0, %esi
cmovel %r13d, %esi
shlq $0x4, %rsi
addq 0x8(%rsp), %rsi
addq %r12, %rsi
movq %rbp, %rdi
callq 0x50aa
movq 0x78(%rsp), %rax
movupd (%rax,%r12), %xmm2
unpcklpd %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0]
addpd %xmm2, %xmm0
movupd %xmm0, (%rax,%r12)
addq $0x10, %r12
incl %r14d
jmp 0xaccd
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
callq 0xb0a4
leaq 0x8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0xb0a4
leaq 0x78(%rsp), %rdi
movq %r14, %rsi
callq 0xb0a4
shrl %r13d
jmp 0xacbe
movq %rbp, %rdi
leaq 0x8(%rsp), %rsi
callq 0xb054
xorl %r14d, %r14d
xorl %r12d, %r12d
cmpq %r12, 0x30(%rsp)
je 0xadfd
movq 0x98(%rsp), %r13
movq 0x10(%rbx), %rdi
movq 0x50(%rbx), %rbx
movq 0x68(%rsp), %rsi
callq 0x67ba
addl %r12d, %eax
cltq
movq (%rbx,%rax,8), %rax
movq 0x70(%rsp), %rcx
shlq $0x4, %rcx
movupd (%r13,%r14), %xmm0
movupd %xmm0, (%rax,%rcx)
incq %r12
addq $0x10, %r14
movq (%rsp), %rbx
jmp 0xadb1
movq %rbp, %rdi
callq 0x7dbc
leaq 0xb0(%rsp), %rdi
callq 0x7dbc
leaq 0x78(%rsp), %rdi
callq 0x7dbc
leaq 0x8(%rsp), %rdi
callq 0x7dbc
leaq 0x40(%rsp), %rdi
callq 0x7dbc
movq 0x70(%rsp), %r12
incq %r12
movq 0x60(%rsp), %r14
jmp 0xabd7
movq 0x68(%rsp), %r14
incl %r14d
jmp 0xab63
xorl %r14d, %r14d
movq 0x10(%rbx), %rdi
callq 0x67ca
cmpl %eax, %r14d
jge 0xaf6a
xorl %r15d, %r15d
movq 0x10(%rbx), %rdi
movl %r14d, %esi
callq 0x6730
cmpl %eax, %r15d
jge 0xaf62
xorl %r12d, %r12d
xorl %r13d, %r13d
movq 0x10(%rbx), %rdi
callq 0x67d8
cltq
cmpq %rax, %r13
jge 0xaf5a
movq 0x10(%rbx), %rdi
movq (%rsp), %rax
movq 0x50(%rax), %rbx
movl %r14d, %esi
callq 0x67ba
addl %r15d, %eax
cltq
movq (%rbx,%rax,8), %rax
movq (%rsp), %rbx
movq 0x10(%rbx), %rdi
movups (%rax,%r12), %xmm0
movaps %xmm0, 0x30(%rsp)
movl %r14d, %esi
callq 0x6730
movl %eax, %ebp
movq 0x10(%rbx), %rdi
callq 0x6710
cvtsi2sd %eax, %xmm0
ucomisd 0x1e2c(%rip), %xmm0     # 0xcd10
jb 0xaeec
sqrtsd %xmm0, %xmm0
jmp 0xaef1
callq 0x31d0
cvtsi2sd %ebp, %xmm1
andpd 0x1e43(%rip), %xmm0     # 0xcd40
movsd 0x11e3(%rip), %xmm2     # 0xc0e8
divsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
movapd 0x30(%rsp), %xmm0
mulpd %xmm2, %xmm0
movapd %xmm0, 0x30(%rsp)
movq 0x10(%rbx), %rdi
movq (%rsp), %rax
movq 0x50(%rax), %rbx
movl %r14d, %esi
callq 0x67ba
addl %r15d, %eax
cltq
movq (%rbx,%rax,8), %rax
movq (%rsp), %rbx
movapd 0x30(%rsp), %xmm0
movupd %xmm0, (%rax,%r12)
incq %r13
addq $0x10, %r12
jmp 0xae82
incl %r15d
jmp 0xae67
incl %r14d
jmp 0xae52
movb $0x1, 0x5c(%rbx)
movq 0x8(%rbx), %rbx
leaq 0x1f96(%rip), %rsi      # 0xcf0f
leaq 0x40(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x3fb6
leaq 0x40(%rsp), %rsi
movq %rbx, %rdi
callq 0x5758
leaq 0x40(%rsp), %rdi
callq 0x30f0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xafb5
jmp 0xafd4
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x30f0
jmp 0xb022
jmp 0xafd4
jmp 0xaff4
movq %rax, %rbx
jmp 0xb00e
jmp 0xafed
movq %rax, %rbx
jmp 0xb004
movq %rax, %rbx
jmp 0xb022
jmp 0xafed
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x7dbc
jmp 0xaff7
movq %rax, %rbx
jmp 0xb018
jmp 0xaff4
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x7dbc
leaq 0x78(%rsp), %rdi
callq 0x7dbc
leaq 0x8(%rsp), %rdi
callq 0x7dbc
leaq 0x40(%rsp), %rdi
callq 0x7dbc
movq %rbx, %rdi
callq 0x3490