// File: /workspace/github_cpp_makefile_star2_O3/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, %rbp
movq 0x8(%rdi), %r14
leaq 0x30(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x2af1(%rip), %rsi      # 0xef47
leaq 0x2af2(%rip), %rdx      # 0xef4f
leaq 0x20(%rsp), %rdi
callq 0x4430
leaq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x5940
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0xc48b
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3270
movq 0x10(%rbp), %rdi
callq 0x6c18
movl %eax, 0x4(%rsp)
movq 0x10(%rbp), %rdi
callq 0x6cde
testl %eax, %eax
jle 0xc4fa
xorl %ebx, %ebx
movq 0x10(%rbp), %rdi
callq 0x6cf0
testl %eax, %eax
xorpd %xmm0, %xmm0
jle 0xc4e7
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x50(%rbp), %rax
movq (%rax,%rbx,8), %rax
incq %r15
movupd %xmm0, (%rax,%r14)
movq 0x10(%rbp), %rdi
callq 0x6cf0
xorpd %xmm0, %xmm0
cltq
addq $0x10, %r14
cmpq %rax, %r15
jl 0xc4be
incq %rbx
movq 0x10(%rbp), %rdi
callq 0x6cde
cltq
cmpq %rax, %rbx
jl 0xc4a7
movq 0x10(%rbp), %rdi
callq 0x6ce2
testl %eax, %eax
movq %rbp, 0x88(%rsp)
movl 0x4(%rsp), %ebx
jle 0xc8bc
leaq 0x80(%rbp), %rax
movq %rax, 0xa8(%rsp)
xorl %r15d, %r15d
movq 0x10(%rbp), %rdi
movl %r15d, %esi
callq 0x6c3c
movl %eax, %r13d
movq 0x10(%rbp), %rdi
movl %r15d, 0xc(%rsp)
movl %r15d, %esi
callq 0x6c94
movsd 0x1b97(%rip), %xmm0     # 0xe0e8
movl %eax, %edi
callq 0x33c0
movsd %xmm0, 0x10(%rsp)
movq 0x10(%rbp), %rdi
callq 0x6cf0
testl %eax, %eax
jle 0xc8a2
cvttsd2si 0x10(%rsp), %r12d
movslq %r12d, %r15
movl %r15d, %eax
sarl %eax
movl %eax, 0x8(%rsp)
movq %r12, 0x10(%rsp)
shlq $0x4, %r12
xorl %r14d, %r14d
movq %r15, 0x78(%rsp)
movq 0x60(%rbp), %rax
movq %r14, 0x80(%rsp)
movl (%rax,%r14,4), %eax
movl %eax, 0x5c(%rsp)
leaq 0x20(%rsp), %rdi
movq %r15, %rsi
leaq 0x40(%rsp), %rdx
callq 0x8c96
cmpl $0x0, 0x10(%rsp)
movq 0xa8(%rsp), %r14
jle 0xc658
xorl %r15d, %r15d
testl %ebx, %ebx
jle 0xc5ff
xorl %ecx, %ecx
xorl %esi, %esi
xorl %eax, %eax
movl $0x1, %edx
shll %cl, %edx
btl %ecx, %r13d
jae 0xc5f7
btl %eax, %r15d
leal 0x1(%rax), %eax
movl $0x0, %edi
cmovael %edi, %edx
addl %edx, %esi
incl %ecx
cmpl %ecx, %ebx
jne 0xc5d9
jmp 0xc601
xorl %esi, %esi
xorl 0x5c(%rsp), %esi
movl %esi, 0x40(%rsp)
movq 0x78(%rbp), %rdi
movq (%rdi), %rax
callq *0x28(%rax)
movq 0x20(%rsp), %rax
movq %r15, %rcx
shlq $0x4, %rcx
movsd %xmm0, (%rax,%rcx)
movsd %xmm1, 0x8(%rax,%rcx)
cmpb $0x0, 0x5c(%rbp)
jne 0xc64a
movq 0x10(%rbp), %rdi
callq 0x6d20
testb %al, %al
je 0xc64a
movq %r14, %rdi
leaq 0x40(%rsp), %rsi
callq 0x8d0c
incq %r15
cmpq 0x10(%rsp), %r15
jne 0xc5cf
leaq 0x40(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0xcb68
leaq 0x90(%rsp), %rdi
movq 0x78(%rsp), %r15
movq %r15, %rsi
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdx
callq 0x8c96
movq %rbx, %rdi
movq %r15, %rsi
leaq 0x60(%rsp), %rdx
callq 0x8c96
cmpl $0x0, 0x8(%rsp)
jle 0xc795
movl 0x8(%rsp), %ebx
cmpl $0x0, 0x10(%rsp)
jle 0xc74f
xorl %r15d, %r15d
xorl %r14d, %r14d
movl %r15d, %eax
xorl %edx, %edx
divl %ebx
andl $0x1, %eax
movl %eax, %ecx
negl %ecx
movl %ecx, %edx
andl %ebx, %edx
movq 0x40(%rsp), %rsi
movslq %edx, %rdx
shlq $0x4, %rdx
subq %rdx, %rsi
orl $0x1, %ecx
testl %eax, %eax
movq 0x90(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2sd %ecx, %xmm0
movupd (%r14,%rsi), %xmm1
movl $0x0, %esi
cmovel %ebx, %esi
movupd %xmm1, (%rax,%r14)
shlq $0x4, %rsi
addq 0x40(%rsp), %rsi
addq %r14, %rsi
movsd %xmm0, 0x60(%rsp)
movq $0x0, 0x68(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x5438
movq 0x90(%rsp), %rax
movupd (%rax,%r14), %xmm0
addpd 0x60(%rsp), %xmm0
movupd %xmm0, (%rax,%r14)
addq $0x10, %r14
incl %r15d
cmpq %r14, %r12
jne 0xc6b7
leaq 0xb0(%rsp), %r14
movq %r14, %rdi
leaq 0x40(%rsp), %rsi
callq 0xcbe0
leaq 0x40(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0xcbe0
leaq 0x90(%rsp), %rdi
movq %r14, %rsi
callq 0xcbe0
movl %ebx, %eax
shrl %eax
cmpl $0x2, %ebx
movl %eax, %ebx
jae 0xc6a6
leaq 0x60(%rsp), %rdi
leaq 0x40(%rsp), %rsi
callq 0xcb68
cmpl $0x0, 0x10(%rsp)
jle 0xc7fb
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x60(%rsp), %r15
movq 0x10(%rbp), %rdi
movq 0x50(%rbp), %rbp
movl 0xc(%rsp), %esi
callq 0x6cd2
addl %r14d, %eax
cltq
movq (%rbp,%rax,8), %rax
movq 0x80(%rsp), %rcx
shlq $0x4, %rcx
movupd (%r15,%rbx), %xmm0
movupd %xmm0, (%rax,%rcx)
incl %r14d
addq $0x10, %rbx
cmpq %rbx, %r12
movq 0x88(%rsp), %rbp
jne 0xc7b0
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0xc812
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
movl 0x4(%rsp), %ebx
je 0xc833
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
movq 0x78(%rsp), %r15
je 0xc855
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0xc86c
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xc883
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq 0x80(%rsp), %r14
incq %r14
movq 0x10(%rbp), %rdi
callq 0x6cf0
cltq
cmpq %rax, %r14
jl 0xc593
movl 0xc(%rsp), %r15d
incl %r15d
movq 0x10(%rbp), %rdi
callq 0x6ce2
cmpl %eax, %r15d
jl 0xc529
movq 0x10(%rbp), %rdi
callq 0x6ce2
testl %eax, %eax
jle 0xc9fe
xorl %r14d, %r14d
movq 0x10(%rbp), %rdi
movl %r14d, %esi
callq 0x6c48
testl %eax, %eax
jle 0xc9e9
xorl %r15d, %r15d
movq 0x10(%rbp), %rdi
callq 0x6cf0
testl %eax, %eax
jle 0xc9d1
xorl %ebx, %ebx
xorl %r12d, %r12d
movq 0x10(%rbp), %rdi
movq 0x50(%rbp), %r13
movl %r14d, %esi
callq 0x6cd2
addl %r15d, %eax
cltq
movq (%r13,%rax,8), %rax
movq 0x10(%rbp), %rdi
movups (%rax,%rbx), %xmm0
movaps %xmm0, 0x10(%rsp)
movl %r14d, %esi
callq 0x6c48
movq %rbp, %rcx
movl %eax, %ebp
movq 0x10(%rcx), %rdi
callq 0x6c28
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
ucomisd 0x23c7(%rip), %xmm0     # 0xed10
jb 0xc951
sqrtsd %xmm0, %xmm0
jmp 0xc956
callq 0x31c0
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
andpd 0x23eb(%rip), %xmm0     # 0xed50
movsd 0x177b(%rip), %xmm2     # 0xe0e8
divsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
movapd 0x10(%rsp), %xmm0
mulpd %xmm2, %xmm0
movapd %xmm0, 0x10(%rsp)
movq 0x88(%rsp), %rbp
movq 0x10(%rbp), %rdi
movq 0x50(%rbp), %r13
movl %r14d, %esi
callq 0x6cd2
addl %r15d, %eax
cltq
movq (%r13,%rax,8), %rax
movapd 0x10(%rsp), %xmm0
movupd %xmm0, (%rax,%rbx)
incq %r12
movq 0x10(%rbp), %rdi
callq 0x6cf0
cltq
addq $0x10, %rbx
cmpq %rax, %r12
jl 0xc8fd
incl %r15d
movq 0x10(%rbp), %rdi
movl %r14d, %esi
callq 0x6c48
cmpl %eax, %r15d
jl 0xc8e7
incl %r14d
movq 0x10(%rbp), %rdi
callq 0x6ce2
cmpl %eax, %r14d
jl 0xc8d0
movb $0x1, 0x5c(%rbp)
movq 0x8(%rbp), %rbx
leaq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %r14
movq %r14, (%rdi)
leaq 0x252d(%rip), %rsi      # 0xef47
leaq 0x252e(%rip), %rdx      # 0xef4f
callq 0x4430
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x59dc
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xca4a
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3270
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
jne 0xca81
jmp 0xcb36
jmp 0xca9e
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0xcb36
movq 0x30(%rsp), %rsi
incq %rsi
jmp 0xcb31
jmp 0xca9e
jmp 0xcacb
movq %rax, %rbx
jmp 0xcb08
jmp 0xcac4
movq %rax, %rbx
jmp 0xcaeb
movq %rax, %rbx
jmp 0xcb36
jmp 0xcac4
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0xcace
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
jmp 0xcace
movq %rax, %rbx
jmp 0xcb1f
jmp 0xcacb
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0xcaeb
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0xcb08
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0xcb1f
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0xcb36
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq %rbx, %rdi
callq 0x3490