// File: /workspace/github_cpp_makefile_star2_O3/UCBASiCS[P]SPRIGHT/src/main.cpp
// Function: main
int main(int argc, char** argv)
{
    // Sets a random seed for each run of SPRIGHT.
    srand48((long int) time (NULL));
    
    // Configurations are set through the command line arguments
    Config* configurations = new Config(argc, argv);
    // This is here measuring how long it takes to generate the input and output
    Chrono* mChrono = new Chrono();

    // Input object
    Input* input;
    // Output object
    Output* output;
     
    // In the experiment mode, program uses randomly generated input and
    // compare the SPRIGHT output to the input.
    // In the customized mode, program takes input from a file and outputs
    // the recovered signal to a file. 
    // Note that input and output to SPRIGHT is made modular and for using SPRIGHT
    // in other applications changing these objects would be enough.
    if ( configurations->isExperimentMode() )
    {
	   input  = new ExperimentInput(mChrono, configurations);
	   // output = new CustomizedOutput(mChrono, configurations);
	   output = new ExperimentOutput(mChrono, configurations, dynamic_cast<ExperimentInput*>(input));
    }
    else
    {
	   input  = new CustomizedInput(mChrono, configurations);    
	   output = new CustomizedOutput(mChrono, configurations);
    }

    SPRIGHT* spright = new SPRIGHT(configurations, input, output);
    
    if (!configurations->isHelpDisplayed())
    {
        // the number of iterations entered by the user
        int iterations = configurations->getIterations();

        configurations->display();

        // do the required number of iterations
        for (int iteration=0; iteration<iterations; iteration++)
        {
            input->process( spright->getDelays() );
            spright->process();

            if (configurations->isVerbose())
                std::cout << std::endl << "### Iteration "<< iteration << " results ###" << std::endl;
            output->process();
        }

        spright->displayResults();

        if ( configurations->isExperimentMode() )
        {
            std::cout << std::setprecision(3) << std::scientific << mChrono->average("Input") << " -> signal generation time"  << std::endl;
        }
    }

    std::cout << std::endl;
	
    delete spright;

    exit(EXIT_SUCCESS);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
movl %edi, %ebp
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x3240
movq %rax, %rdi
callq 0x3430
movl $0xd0, %edi
callq 0x3260
movq %rax, %r15
movq %rax, %rdi
movl %ebp, %esi
movq %rbx, %rdx
callq 0x6114
movl $0xa0, %edi
callq 0x3260
movq %rax, %rbx
addq $0x18, %rax
movl %r14d, 0x18(%rbx)
movq %r14, 0x20(%rbx)
movq %rax, 0x28(%rbx)
movq %rax, 0x30(%rbx)
movq %r14, 0x38(%rbx)
leaq 0x48(%rbx), %rax
movl %r14d, 0x48(%rbx)
movq %r14, 0x50(%rbx)
movq %rax, 0x58(%rbx)
movq %rax, 0x60(%rbx)
movq %r14, 0x68(%rbx)
leaq 0x78(%rbx), %rax
movl %r14d, 0x78(%rbx)
movq %r14, 0x80(%rbx)
movq %rax, 0x88(%rbx)
movq %rax, 0x90(%rbx)
movq %r14, 0x98(%rbx)
movq %r15, %rdi
callq 0x6c20
testb %al, %al
movq %r15, %rbp
je 0xcf2a
movl $0xd8, %edi
callq 0x3260
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x94e8
movl $0x160, %edi            # imm = 0x160
callq 0x3260
movq %rax, %r13
leaq 0x7caa(%rip), %rsi      # 0x14bb0
leaq 0x7d63(%rip), %rdx      # 0x14c70
movq %r12, %rdi
xorl %ecx, %ecx
callq 0x32a0
movq %r13, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %rax, %rcx
callq 0xa22c
jmp 0xcf60
movl $0x80, %edi
callq 0x3260
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x8584
movl $0x20, %edi
callq 0x3260
movq %rax, %r13
movq %rax, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x8ef4
movl $0x38, %edi
callq 0x3260
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0xd658
movq %rbp, %rdi
callq 0x8024
testb %al, %al
jne 0xd179
movq %rbx, 0x10(%rsp)
movq %rbp, %rdi
callq 0x6c24
movl %eax, %r14d
movq %rbp, %rdi
callq 0x6d34
testl %r14d, %r14d
jle 0xd0bc
xorl %ebx, %ebx
movq %r13, 0x18(%rsp)
movq %rbp, %r15
leaq 0x40(%rsp), %rbp
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
callq 0xde06
movq (%r12), %rax
movq %r12, %rdi
movq %rbp, %rsi
callq *0x20(%rax)
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0xcff1
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq 0x8(%rsp), %rdi
callq 0xd852
movq %r15, %rbp
movq %r15, %rdi
callq 0x6d14
testb %al, %al
je 0xd0a7
movq 0x7fb3(%rip), %r15      # 0x14fc8
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3250
movsbl %al, %esi
movq %r15, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq %rbp, %r15
movq %rax, %rbp
movl $0xe, %edx
movq %rax, %rdi
leaq 0x1f56(%rip), %rsi      # 0xefa7
callq 0x32b0
movq %rbp, %rdi
movl %ebx, %esi
callq 0x3470
movq %rax, %rbp
movl $0xc, %edx
movq %rax, %rdi
leaq 0x1f44(%rip), %rsi      # 0xefb6
callq 0x32b0
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3250
movsbl %al, %esi
movq %rbp, %rdi
movq %r15, %rbp
movq 0x18(%rsp), %r13
callq 0x3030
movq %rax, %rdi
callq 0x3170
movq (%r13), %rax
movq %r13, %rdi
callq *0x10(%rax)
incl %ebx
cmpl %ebx, %r14d
jne 0xcfb8
movq 0x8(%rsp), %rdi
callq 0xd92c
movq %rbp, %rdi
callq 0x6c20
testb %al, %al
movq 0x10(%rsp), %rbx
je 0xd179
movq 0x7ee6(%rip), %rax      # 0x14fc8
movq (%rax), %rcx
movq -0x18(%rcx), %rdx
movq $0x3, 0x8(%rax,%rdx)
movq -0x18(%rcx), %rcx
movl $0xfffffefb, %edx       # imm = 0xFFFFFEFB
andl 0x18(%rax,%rcx), %edx
orl $0x100, %edx            # imm = 0x100
movl %edx, 0x18(%rax,%rcx)
leaq 0x30(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1b32(%rip), %rsi      # 0xec4b
leaq 0x1b30(%rip), %rdx      # 0xec50
leaq 0x20(%rsp), %rdi
callq 0x4430
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x5b3e
movq 0x7e8a(%rip), %rdi      # 0x14fc8
callq 0x3400
movq %rax, %rbx
leaq 0x1e76(%rip), %rsi      # 0xefc3
movl $0x1a, %edx
movq %rax, %rdi
callq 0x32b0
movq %rbx, %rdi
callq 0x3100
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xd179
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3270
movq 0x7e48(%rip), %rdi      # 0x14fc8
callq 0x3100
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0xd764
movl $0x38, %esi
movq %rbx, %rdi
callq 0x3270
xorl %edi, %edi
callq 0x32f0
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xd226
movq 0x30(%rsp), %rsi
incq %rsi
jmp 0xd221
movq %rax, %rbx
jmp 0xd226
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0xd226
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
jmp 0xd221
movq %rax, %rbx
movl $0x38, %esi
movq 0x8(%rsp), %rdi
jmp 0xd221
movq %rax, %rbx
movl $0x20, %esi
jmp 0xd1fa
movq %rax, %rbx
movl $0x160, %esi            # imm = 0x160
movq %r13, %rdi
jmp 0xd221
movq %rax, %rbx
movl $0x80, %esi
jmp 0xd211
movq %rax, %rbx
movl $0xd8, %esi
movq %r12, %rdi
jmp 0xd221
movq %rax, %rbx
movl $0xd0, %esi
movq %r15, %rdi
callq 0x3270
movq %rbx, %rdi
callq 0x3490
nop