// File: /workspace/github_cpp_makefile_star2_O2/bonetblai[P]mdp-engine/rect/main.cc
// Function: main
int main(int argc, const char **argv) {
    unsigned xdim = 0;
    unsigned ydim = 0;
    float p = 1.0;
    unsigned num_trials = 1;

    vector<string> requests;

    float start_time = Utils::read_time_in_seconds();
    cout << fixed;

    // parse arguments
    for( ++argv, --argc; (argc > 1) && (**argv == '-'); ++argv, --argc ) {
        if( string(*argv) == "--no-colors" ) {
            Utils::g_use_colors = false;
        } else if( ((*argv)[1] == 'r') || (string(*argv) == "--request") ) {
            requests.push_back(argv[1]);
            ++argv;
            --argc;
        } else if( ((*argv)[1] == 's') || (string(*argv) == "--seed") ) {
            Algorithm::g_seed = strtoul(argv[1], 0, 0);
            Online::g_seed = Algorithm::g_seed;
            ++argv;
            --argc;
        } else if( ((*argv)[1] == 't') || (string(*argv) == "--trials") ) {
            num_trials = strtoul(argv[1], 0, 0);
            ++argv;
            --argc;
        } else {
            usage(cout);
            exit(-1);
        }
    }

    // read problem parameters
    if( argc >= 2 ) {
        xdim = strtoul(argv[0], 0, 0);
        ydim = strtoul(argv[1], 0, 0);
        if( argc >= 3 ) p = strtod(argv[2], 0);
    } else {
        usage(cout);
        exit(-1);
    }

    // build problem instances
    cout << "main: seed=" << Algorithm::g_seed << endl;
    Random::set_seed(Algorithm::g_seed);
    problem_t problem(xdim, ydim, p);

    // build requests
    vector<pair<string, Online::Policy::policy_t<state_t>*> > policies;
    vector<pair<string, Algorithm::algorithm_t<state_t>*> > algorithms;
    Dispatcher::dispatcher_t<state_t> dispatcher;
    for( int i = 0; i < int(requests.size()); ++i ) {
        const string &request_str = requests[i];
        std::multimap<std::string, std::string> request;
        Utils::tokenize(request_str, request);
        for( std::multimap<std::string, std::string>::const_iterator it = request.begin(); it != request.end(); ++it ) {
            dispatcher.create_request(problem, it->first, it->second);
            if( it->first == "algorithm" ) {
                Algorithm::algorithm_t<state_t> *algorithm = dispatcher.fetch_algorithm(it->second);
                if( algorithm != 0 ) algorithms.push_back(make_pair(it->second, algorithm));
            } else if( it->first == "policy" ) {
                Online::Policy::policy_t<state_t> *policy = dispatcher.fetch_policy(it->second);
                if( policy != 0 ) policies.push_back(make_pair(it->second, policy));
            }
        }
    }

    // solve problems with requested algorithms
    vector<Dispatcher::dispatcher_t<state_t>::solve_result_t> solve_results;
    for( int i = 0; i < int(algorithms.size()); ++i ) {
        const string &request = algorithms[i].first;
        const Algorithm::algorithm_t<state_t> &algorithm = *algorithms[i].second;
        Dispatcher::dispatcher_t<state_t>::solve_result_t result;
        dispatcher.solve(request, algorithm, problem.init(), result);
        solve_results.push_back(result);
    }

    cout << Utils::warning() << "the following stats may aggregate figures when elements are shared among algorithms" << endl;
    if( !solve_results.empty() ) {
        for( int i = 0; i < int(solve_results.size()); ++i ) {
            dispatcher.print_stats(cout, solve_results[i]);
        }
    }

    // evaluate requested policies
    vector<Dispatcher::dispatcher_t<state_t>::evaluate_result_t> evaluate_results;
    for( int i = 0; i < int(policies.size()); ++i ) {
        const string &request = policies[i].first;
        const Online::Policy::policy_t<state_t> &policy = *policies[i].second;
        Dispatcher::dispatcher_t<state_t>::evaluate_result_t result;
        dispatcher.evaluate(request, policy, problem.init(), result, num_trials, 100, true);
        evaluate_results.push_back(result);
    }

    cout << Utils::warning() << "the following stats may aggregate figures when elements are shared among policies" << endl;
    if( !evaluate_results.empty() ) {
        for( int i = 0; i < int(evaluate_results.size()); ++i ) {
            dispatcher.print_stats(cout, evaluate_results[i]);
        }
    }

    cout << "main: total-time=" << Utils::read_time_in_seconds() - start_time << endl;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rsi, %r15
movl %edi, %ebp
xorps %xmm0, %xmm0
leaq 0x100(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
callq 0x5d74
movss %xmm0, 0x14(%rsp)
movq 0x26a8b(%rip), %rax     # 0x2bfd8
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl $0xfffffefb, %edx       # imm = 0xFFFFFEFB
andl 0x18(%rax,%rcx), %edx
orl $0x4, %edx
movl %edx, 0x18(%rax,%rcx)
pushq $0x1
popq %rax
movq %rax, 0x68(%rsp)
leaq 0x140(%rsp), %r12
leaq 0x18(%rsp), %r13
cmpl $0x3, %ebp
jl 0x5c76
leaq 0x8(%r15), %r14
movq (%r14), %rsi
cmpb $0x2d, (%rsi)
jne 0x56d5
movq %r12, %rdi
movq %r13, %rdx
callq 0x50a0
movq %r12, %rdi
leaq 0x15b95(%rip), %rsi     # 0x1b13c
callq 0x5dd9
movl %eax, %ebx
movq %r12, %rdi
callq 0x50d0
testb %bl, %bl
je 0x55c8
decl %ebp
movb $0x0, 0x26c2d(%rip)     # 0x2c1f0
movq %r14, %r15
jmp 0x5579
movq (%r14), %rsi
cmpb $0x72, 0x1(%rsi)
je 0x55f9
movq %r12, %rdi
movq %r13, %rdx
callq 0x50a0
movq %r12, %rdi
leaq 0x15b62(%rip), %rsi     # 0x1b148
callq 0x5dd9
movl %eax, %ebx
movq %r12, %rdi
callq 0x50d0
testb %bl, %bl
je 0x562c
movq 0x10(%r15), %rsi
movq %r12, %rdi
movq %r13, %rdx
callq 0x50a0
leaq 0x100(%rsp), %rdi
movq %r12, %rsi
callq 0x7c30
addq $0x10, %r15
movq %r12, %rdi
callq 0x50d0
addl $-0x2, %ebp
jmp 0x5579
movq (%r14), %rsi
cmpb $0x73, 0x1(%rsi)
je 0x565d
movq %r12, %rdi
movq %r13, %rdx
callq 0x50a0
movq %r12, %rdi
leaq 0x15b08(%rip), %rsi     # 0x1b152
callq 0x5dd9
movl %eax, %ebx
movq %r12, %rdi
callq 0x50d0
testb %bl, %bl
je 0x5682
movq 0x10(%r15), %rdi
addq $0x10, %r15
xorl %esi, %esi
xorl %edx, %edx
callq 0x5080
movl %eax, 0x26b94(%rip)     # 0x2c208
movl %eax, 0x26b92(%rip)     # 0x2c20c
addl $-0x2, %ebp
jmp 0x5579
movq (%r14), %rsi
cmpb $0x74, 0x1(%rsi)
je 0x56b7
movq %r12, %rdi
movq %r13, %rdx
callq 0x50a0
movq %r12, %rdi
leaq 0x15ab9(%rip), %rsi     # 0x1b159
callq 0x5dd9
movl %eax, %ebx
movq %r12, %rdi
callq 0x50d0
testb %bl, %bl
je 0x5c8a
movq 0x10(%r15), %rdi
addq $0x10, %r15
xorl %esi, %esi
xorl %edx, %edx
callq 0x5080
movq %rax, 0x68(%rsp)
addl $-0x2, %ebp
jmp 0x5579
movq %rsi, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5080
movq %rax, %r14
movq 0x10(%r15), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5080
movq %rax, %rbx
cmpl $0x3, %ebp
jne 0x5703
movss 0x15903(%rip), %xmm0    # 0x1b004
jmp 0x5712
movq 0x18(%r15), %rdi
xorl %esi, %esi
callq 0x51a0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
movq 0x268b9(%rip), %rdi     # 0x2bfd8
leaq 0x15a3c(%rip), %rsi     # 0x1b162
callq 0x5220
movl 0x26ad7(%rip), %esi     # 0x2c208
movq %rax, %rdi
callq 0x5150
movq %rax, %rdi
callq 0x50e0
movl 0x26ac1(%rip), %edi     # 0x2c208
callq 0x5de6
movsd 0x158cc(%rip), %xmm0    # 0x1b020
leaq 0x13c(%rsp), %rcx
movsd %xmm0, -0x1c(%rcx)
andq $0x0, -0x14(%rcx)
leaq 0x2584b(%rip), %rax     # 0x2afb8
movq %rax, -0x24(%rcx)
movl %r14d, -0xc(%rcx)
movl %ebx, -0x8(%rcx)
movss 0x8(%rsp), %xmm0
movss %xmm0, -0x4(%rcx)
andw $0x0, (%rcx)
leaq 0xe0(%rsp), %rdx
andq $0x0, 0x10(%rdx)
leaq 0xc0(%rsp), %rsi
andq $0x0, 0x10(%rsi)
shrl %ebx
movw %bx, 0x2(%rcx)
leaq 0x258b2(%rip), %rax     # 0x2b060
leaq 0x150(%rsp), %rcx
movq %rax, -0x10(%rcx)
andl $0x0, (%rcx)
andq $0x0, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
andq $0x0, 0x20(%rcx)
leaq 0x180(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x1b0(%rsp), %rax
andl $0x0, (%rax)
xorps %xmm0, %xmm0
andq $0x0, 0x8(%rax)
movaps %xmm0, (%rdx)
movaps %xmm0, (%rsi)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x20(%rsp), %rbp
xorl %ecx, %ecx
leaq 0x18(%rsp), %r14
leaq 0x140(%rsp), %rbx
leaq 0x70(%rsp), %r13
movq 0x100(%rsp), %rdi
movq 0x108(%rsp), %rax
subq %rdi, %rax
shrq $0x5, %rax
cltq
cmpq %rax, %rcx
jge 0x5976
movq %rcx, 0x8(%rsp)
movq %rcx, %rax
shlq $0x5, %rax
addq %rax, %rdi
andl $0x0, 0x20(%rsp)
andq $0x0, 0x28(%rsp)
movq %rbp, 0x30(%rsp)
movq %rbp, 0x38(%rsp)
andq $0x0, 0x40(%rsp)
movq %r14, %rsi
pushq $0x2c
popq %rdx
callq 0x5e11
movq 0x30(%rsp), %r12
cmpq %rbp, %r12
je 0x595c
leaq 0x20(%r12), %r14
leaq 0x40(%r12), %r15
movq %rbx, %rdi
leaq 0x118(%rsp), %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x5fe0
movq %r14, %rdi
leaq 0x158b4(%rip), %rsi     # 0x1b16e
callq 0x5dd9
testb %al, %al
je 0x58fb
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6940
movq %rax, %r14
testq %rax, %rax
je 0x594c
movq %r13, %rdi
movq %r15, %rsi
callq 0x52d0
movq %r14, 0x90(%rsp)
leaq 0xc0(%rsp), %rdi
movq %r13, %rsi
callq 0x19e80
jmp 0x5944
movq %r14, %rdi
leaq 0x15873(%rip), %rsi     # 0x1b178
callq 0x5dd9
testb %al, %al
je 0x594c
movq %rbx, %rdi
movq %r15, %rsi
callq 0x6960
movq %rax, %r14
testq %rax, %rax
je 0x594c
movq %r13, %rdi
movq %r15, %rsi
callq 0x52d0
movq %r14, 0x90(%rsp)
leaq 0xe0(%rsp), %rdi
movq %r13, %rsi
callq 0x1a0dc
movq %r13, %rdi
callq 0x50d0
movq %r12, %rdi
callq 0x5260
movq %rax, %r12
jmp 0x5887
leaq 0x18(%rsp), %r14
movq %r14, %rdi
callq 0x7bb2
movq 0x8(%rsp), %rcx
incq %rcx
jmp 0x582b
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rbx
andq $0x0, 0x10(%rbx)
movaps %xmm0, (%rbx)
leaq 0x30(%rsp), %rbp
xorl %r13d, %r13d
leaq 0x140(%rsp), %r15
leaq 0x18(%rsp), %r12
xorl %r14d, %r14d
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rax
subq %rsi, %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
cltq
cmpq %rax, %r14
jge 0x5a0e
movq 0x20(%rsi,%r13), %rdx
addq %r13, %rsi
andl $0x0, 0x18(%rsp)
movq %rbp, 0x20(%rsp)
andq $0x0, 0x28(%rsp)
movb $0x0, 0x30(%rsp)
movq %r15, %rdi
leaq 0x13c(%rsp), %rcx
movq %r12, %r8
callq 0x6980
movq %rbx, %rdi
movq %r12, %rsi
callq 0x6a7e
leaq 0x20(%rsp), %rdi
callq 0x50d0
incq %r14
addq $0x28, %r13
jmp 0x599e
leaq 0x18(%rsp), %rdi
callq 0x6aaa
movq 0x265b9(%rip), %rdi     # 0x2bfd8
leaq 0x18(%rsp), %rsi
callq 0x51e0
leaq 0x1574f(%rip), %rsi     # 0x1b17f
movq %rax, %rdi
callq 0x5220
movq %rax, %rdi
callq 0x50e0
leaq 0x18(%rsp), %rdi
callq 0x50d0
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rax
cmpq %rax, %rcx
je 0x5aa5
xorl %r15d, %r15d
pushq $0x50
popq %r12
movq 0x26571(%rip), %rbx     # 0x2bfd8
leaq 0x140(%rsp), %r14
xorl %r13d, %r13d
subq %rcx, %rax
cqto
idivq %r12
cltq
cmpq %rax, %r13
jge 0x5aa5
addq %r15, %rcx
movq %r14, %rdi
movq %rbx, %rsi
movq %rcx, %rdx
callq 0x6ade
incq %r13
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rax
addq $0x50, %r15
jmp 0x5a72
xorps %xmm0, %xmm0
leaq 0xa0(%rsp), %rbx
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
leaq 0x28(%rsp), %r12
xorl %ebp, %ebp
leaq 0x140(%rsp), %r14
leaq 0x18(%rsp), %r15
xorl %r13d, %r13d
movq 0xe0(%rsp), %rsi
movq 0xe8(%rsp), %rax
subq %rsi, %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
cltq
cmpq %rax, %r13
jge 0x5b43
movq 0x20(%rsi,%rbp), %rdx
addq %rbp, %rsi
movq %r12, 0x18(%rsp)
andq $0x0, 0x20(%rsp)
movb $0x0, 0x28(%rsp)
movq %r14, %rdi
leaq 0x13c(%rsp), %rcx
movq %r15, %r8
movq 0x68(%rsp), %r9
pushq $0x1
pushq $0x64
callq 0x7038
popq %rax
popq %rcx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x70f8
movq %r15, %rdi
callq 0x50d0
incq %r13
addq $0x28, %rbp
jmp 0x5acf
leaq 0x18(%rsp), %rdi
callq 0x6aaa
movq 0x26484(%rip), %rdi     # 0x2bfd8
leaq 0x18(%rsp), %rsi
callq 0x51e0
leaq 0x1566e(%rip), %rsi     # 0x1b1d3
movq %rax, %rdi
callq 0x5220
movq %rax, %rdi
callq 0x50e0
leaq 0x18(%rsp), %rdi
callq 0x50d0
movq 0xa0(%rsp), %rcx
movq 0xa8(%rsp), %rax
cmpq %rax, %rcx
je 0x5be6
xorl %r15d, %r15d
pushq $0x48
popq %r12
movq 0x26436(%rip), %rbx     # 0x2bfd8
leaq 0x140(%rsp), %r14
xorl %r13d, %r13d
subq %rcx, %rax
cqto
idivq %r12
cltq
cmpq %rax, %r13
jge 0x5be6
addq %r15, %rcx
movq %r14, %rdi
movq %rbx, %rsi
movq %rcx, %rdx
callq 0x7124
incq %r13
movq 0xa0(%rsp), %rcx
movq 0xa8(%rsp), %rax
addq $0x48, %r15
jmp 0x5bad
movq 0x263eb(%rip), %rdi     # 0x2bfd8
leaq 0x15631(%rip), %rsi     # 0x1b225
callq 0x5220
movq %rax, %rbx
callq 0x5d74
subss 0x14(%rsp), %xmm0
movq %rbx, %rdi
callq 0x5180
movq %rax, %rdi
callq 0x50e0
leaq 0xa0(%rsp), %rdi
callq 0x7378
leaq 0x70(%rsp), %rdi
callq 0x739a
leaq 0x140(%rsp), %rdi
callq 0x73bc
leaq 0xc0(%rsp), %rdi
callq 0x7472
leaq 0xe0(%rsp), %rdi
callq 0x7494
leaq 0x100(%rsp), %rdi
callq 0x74b8
xorl %eax, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2635b(%rip), %rdi     # 0x2bfd8
callq 0x54fc
pushq $-0x1
popq %rdi
callq 0x5280
movq 0x26347(%rip), %rdi     # 0x2bfd8
callq 0x54fc
jmp 0x5c82
jmp 0x5cd5
jmp 0x5cc9
jmp 0x5cce
jmp 0x5cd5
jmp 0x5cc9
jmp 0x5cdd
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
jmp 0x5d01
jmp 0x5cd5
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x50d0
jmp 0x5d5f
jmp 0x5cd5
jmp 0x5cd5
movq %rax, %rbx
jmp 0x5cea
movq %rax, %rbx
jmp 0x5d06
jmp 0x5d2b
movq %rax, %rbx
jmp 0x5d5f
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x50d0
leaq 0xa0(%rsp), %rdi
callq 0x7378
jmp 0x5d06
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x50d0
leaq 0x70(%rsp), %rdi
callq 0x739a
jmp 0x5d38
jmp 0x5d18
jmp 0x5d2b
jmp 0x5d2b
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x50d0
jmp 0x5d2e
jmp 0x5d2b
jmp 0x5d2b
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x7bb2
leaq 0x140(%rsp), %rdi
callq 0x73bc
leaq 0xc0(%rsp), %rdi
callq 0x7472
leaq 0xe0(%rsp), %rdi
callq 0x7494
leaq 0x100(%rsp), %rdi
callq 0x74b8
movq %rbx, %rdi
callq 0x5370