// File: /workspace/github_cpp_makefile_star2_O1/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 0x6214
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 0x6d5a
testb %al, %al
movq %r15, %rbp
je 0xd092
movl $0xd8, %edi
callq 0x3260
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x9644
movl $0x160, %edi            # imm = 0x160
callq 0x3260
movq %rax, %r13
leaq 0x8b42(%rip), %rsi      # 0x15bb0
leaq 0x8bfb(%rip), %rdx      # 0x15c70
movq %r12, %rdi
xorl %ecx, %ecx
callq 0x32a0
movq %r13, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
movq %rax, %rcx
callq 0xa3bc
jmp 0xd0c8
movl $0x80, %edi
callq 0x3260
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x86b0
movl $0x20, %edi
callq 0x3260
movq %rax, %r13
movq %rax, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x9060
movl $0x38, %edi
callq 0x3260
movq %rax, 0x8(%rsp)
movq %rax, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r13, %rcx
callq 0xd7f8
movq %rbp, %rdi
callq 0x815e
testb %al, %al
jne 0xd2e1
movq %rbx, 0x10(%rsp)
movq %rbp, %rdi
callq 0x6d5e
movl %eax, %r14d
movq %rbp, %rdi
callq 0x6e6e
testl %r14d, %r14d
jle 0xd224
xorl %ebx, %ebx
movq %r13, 0x18(%rsp)
movq %rbp, %r15
leaq 0x40(%rsp), %rbp
movq %rbp, %rdi
movq 0x8(%rsp), %rsi
callq 0xdfae
movq (%r12), %rax
movq %r12, %rdi
movq %rbp, %rsi
callq *0x20(%rax)
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0xd159
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x3270
movq 0x8(%rsp), %rdi
callq 0xd9fa
movq %r15, %rbp
movq %r15, %rdi
callq 0x6e4e
testb %al, %al
je 0xd20f
movq 0x8e4b(%rip), %r15      # 0x15fc8
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 0x2dde(%rip), %rsi      # 0xff97
callq 0x32b0
movq %rbp, %rdi
movl %ebx, %esi
callq 0x3470
movq %rax, %rbp
movl $0xc, %edx
movq %rax, %rdi
leaq 0x2dcc(%rip), %rsi      # 0xffa6
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 0xd120
movq 0x8(%rsp), %rdi
callq 0xdad4
movq %rbp, %rdi
callq 0x6d5a
testb %al, %al
movq 0x10(%rsp), %rbx
je 0xd2e1
movq 0x8d7e(%rip), %rax      # 0x15fc8
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 0x29ca(%rip), %rsi      # 0xfc4b
leaq 0x29c8(%rip), %rdx      # 0xfc50
leaq 0x20(%rsp), %rdi
callq 0x44c2
leaq 0x20(%rsp), %rsi
movq %rbx, %rdi
callq 0x5c46
movq 0x8d22(%rip), %rdi      # 0x15fc8
callq 0x3400
movq %rax, %rbx
leaq 0x2cfe(%rip), %rsi      # 0xffb3
movl $0x1a, %edx
movq %rax, %rdi
callq 0x32b0
movq %rbx, %rdi
callq 0x3100
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xd2e1
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3270
movq 0x8ce0(%rip), %rdi      # 0x15fc8
callq 0x3100
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0xd904
movl $0x38, %esi
movq %rbx, %rdi
callq 0x3270
xorl %edi, %edi
callq 0x32f0
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0xd38e
movq 0x30(%rsp), %rsi
incq %rsi
jmp 0xd389
movq %rax, %rbx
jmp 0xd38e
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0xd38e
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
jmp 0xd389
movq %rax, %rbx
movl $0x38, %esi
movq 0x8(%rsp), %rdi
jmp 0xd389
movq %rax, %rbx
movl $0x20, %esi
jmp 0xd362
movq %rax, %rbx
movl $0x160, %esi            # imm = 0x160
movq %r13, %rdi
jmp 0xd389
movq %rax, %rbx
movl $0x80, %esi
jmp 0xd379
movq %rax, %rbx
movl $0xd8, %esi
movq %r12, %rdi
jmp 0xd389
movq %rax, %rbx
movl $0xd0, %esi
movq %r15, %rdi
callq 0x3270
movq %rbx, %rdi
callq 0x3490
nop