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

    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 if( ((*argv)[1] == 'd') || (string(*argv) == "--dead-end-value") ) {
            dead_end_value = strtod(argv[1], 0);
            ++argv;
            --argc;
        } else {
            usage(cout);
            exit(-1);
        }
    }

    // read problem parameters
    if( argc >= 1 ) {
        is = fopen(argv[0], "r");
        if( argc >= 2 ) p = strtod(argv[1], 0);
    } else {
        usage(cout);
        exit(-1);
    }

    // build problem instances
    cout << "main: seed=" << Algorithm::g_seed << endl;
    Random::set_seed(Algorithm::g_seed);

    grid_t grid;
    grid.parse(cout, is);
    problem_t problem(grid, p, dead_end_value);
    fclose(is);

    // 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 $0x2b8, %rsp            # imm = 0x2B8
movq %rsi, %r15
movl %edi, %ebp
xorps %xmm0, %xmm0
leaq 0x100(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
callq 0x5f23
movq 0x2a9a1(%rip), %rax     # 0x2ffd8
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl $0xfffffefb, %edx       # imm = 0xFFFFFEFB
andl 0x18(%rax,%rcx), %edx
movss %xmm0, 0x14(%rsp)
orl $0x4, %edx
movl %edx, 0x18(%rax,%rcx)
pushq $0x1
popq %rax
movq %rax, 0x68(%rsp)
movss 0x179a0(%rip), %xmm0    # 0x1d004
movss %xmm0, 0x8(%rsp)
leaq 0x200(%rsp), %r12
leaq 0x120(%rsp), %r13
leaq 0x8(%r15), %r14
cmpl $0x3, %ebp
jl 0x5828
movq (%r14), %rsi
cmpb $0x2d, (%rsi)
jne 0x5834
movq %r12, %rdi
movq %r13, %rdx
callq 0x50c0
movq %r12, %rdi
leaq 0x17aad(%rip), %rsi     # 0x1d155
callq 0x5f88
movl %eax, %ebx
movq %r12, %rdi
callq 0x50f0
testb %bl, %bl
je 0x56c9
decl %ebp
movb $0x0, 0x2ab8c(%rip)     # 0x30250
movq %r14, %r15
jmp 0x567a
movq (%r14), %rsi
cmpb $0x72, 0x1(%rsi)
je 0x56fa
movq %r12, %rdi
movq %r13, %rdx
callq 0x50c0
movq %r12, %rdi
leaq 0x17a7a(%rip), %rsi     # 0x1d161
callq 0x5f88
movl %eax, %ebx
movq %r12, %rdi
callq 0x50f0
testb %bl, %bl
je 0x572d
movq 0x10(%r15), %rsi
movq %r12, %rdi
movq %r13, %rdx
callq 0x50c0
leaq 0x100(%rsp), %rdi
movq %r12, %rsi
callq 0x8ed6
addq $0x10, %r15
movq %r12, %rdi
callq 0x50f0
addl $-0x2, %ebp
jmp 0x567a
movq (%r14), %rsi
cmpb $0x73, 0x1(%rsi)
je 0x575e
movq %r12, %rdi
movq %r13, %rdx
callq 0x50c0
movq %r12, %rdi
leaq 0x17a20(%rip), %rsi     # 0x1d16b
callq 0x5f88
movl %eax, %ebx
movq %r12, %rdi
callq 0x50f0
testb %bl, %bl
je 0x5783
movq 0x10(%r15), %rdi
addq $0x10, %r15
xorl %esi, %esi
xorl %edx, %edx
callq 0x50a0
movl %eax, 0x2aaf3(%rip)     # 0x30268
movl %eax, 0x2aaf1(%rip)     # 0x3026c
addl $-0x2, %ebp
jmp 0x567a
movq (%r14), %rsi
cmpb $0x74, 0x1(%rsi)
je 0x57b4
movq %r12, %rdi
movq %r13, %rdx
callq 0x50c0
movq %r12, %rdi
leaq 0x179d1(%rip), %rsi     # 0x1d172
callq 0x5f88
movl %eax, %ebx
movq %r12, %rdi
callq 0x50f0
testb %bl, %bl
je 0x57d2
movq 0x10(%r15), %rdi
addq $0x10, %r15
xorl %esi, %esi
xorl %edx, %edx
callq 0x50a0
movq %rax, 0x68(%rsp)
addl $-0x2, %ebp
jmp 0x567a
movq (%r14), %rsi
cmpb $0x64, 0x1(%rsi)
je 0x5807
movq %r12, %rdi
movq %r13, %rdx
callq 0x50c0
movq %r12, %rdi
leaq 0x1798b(%rip), %rsi     # 0x1d17b
callq 0x5f88
movl %eax, %ebx
movq %r12, %rdi
callq 0x50f0
testb %bl, %bl
je 0x5e13
movq 0x10(%r15), %rdi
addq $0x10, %r15
xorl %esi, %esi
callq 0x51d0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
addl $-0x2, %ebp
jmp 0x567a
cmpl $0x2, %ebp
jne 0x5dff
movq (%r14), %rsi
leaq 0x18161(%rip), %rax     # 0x1d99c
movq %rsi, %rdi
movq %rax, %rsi
callq 0x52f0
movq %rax, %rbx
cmpl $0x3, %ebp
jge 0x5858
movss 0x177b2(%rip), %xmm0    # 0x1d008
jmp 0x5867
movq 0x10(%r15), %rdi
xorl %esi, %esi
callq 0x51d0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, 0x4(%rsp)
movq 0x2a764(%rip), %rdi     # 0x2ffd8
leaq 0x17911(%rip), %rsi     # 0x1d18c
callq 0x5270
movl 0x2a9e2(%rip), %esi     # 0x30268
movq %rax, %rdi
callq 0x5180
movq %rax, %rdi
callq 0x5100
movl 0x2a9cc(%rip), %edi     # 0x30268
callq 0x5f95
leaq 0x296d8(%rip), %rax     # 0x2ef80
leaq 0x1b8(%rsp), %rdi
movq %rax, (%rdi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rdi)
movups %xmm0, 0x18(%rdi)
movups %xmm0, 0x28(%rdi)
movups %xmm0, 0x38(%rdi)
movq 0x2a70b(%rip), %rsi     # 0x2ffd8
movq %rbx, %rdx
callq 0x1c952
leaq 0x200(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
movss 0x4(%rsp), %xmm0
movss 0x8(%rsp), %xmm1
callq 0x5fc0
movq %rbx, %rdi
callq 0x5280
leaq 0xe0(%rsp), %rdx
andq $0x0, 0x10(%rdx)
leaq 0xc0(%rsp), %rsi
andq $0x0, 0x10(%rsi)
leaq 0x29739(%rip), %rax     # 0x2f058
leaq 0x130(%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 0x160(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x190(%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), %rbx
leaq 0x120(%rsp), %r13
leaq 0x70(%rsp), %r12
movq 0x100(%rsp), %rdi
movq 0x108(%rsp), %rax
subq %rdi, %rax
shrq $0x5, %rax
cltq
cmpq %rax, %rcx
jge 0x5ae5
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 %rbx, %rsi
pushq $0x2c
popq %rdx
callq 0x61b3
movq 0x30(%rsp), %r15
cmpq %rbp, %r15
je 0x5acb
leaq 0x20(%r15), %rbx
leaq 0x40(%r15), %r14
movq %r13, %rdi
leaq 0x200(%rsp), %rsi
movq %rbx, %rdx
movq %r14, %rcx
callq 0x6382
movq %rbx, %rdi
leaq 0x1776f(%rip), %rsi     # 0x1d198
callq 0x5f88
testb %al, %al
je 0x5a6a
movq %r13, %rdi
movq %r14, %rsi
callq 0x6ce2
movq %rax, %rbx
testq %rax, %rax
je 0x5abb
movq %r12, %rdi
movq %r14, %rsi
callq 0x5360
movq %rbx, 0x90(%rsp)
leaq 0xc0(%rsp), %rdi
movq %r12, %rsi
callq 0x1b352
jmp 0x5ab3
movq %rbx, %rdi
leaq 0x1772e(%rip), %rsi     # 0x1d1a2
callq 0x5f88
testb %al, %al
je 0x5abb
movq %r13, %rdi
movq %r14, %rsi
callq 0x6d02
movq %rax, %rbx
testq %rax, %rax
je 0x5abb
movq %r12, %rdi
movq %r14, %rsi
callq 0x5360
movq %rbx, 0x90(%rsp)
leaq 0xe0(%rsp), %rdi
movq %r12, %rsi
callq 0x1b5ae
movq %r12, %rdi
callq 0x50f0
movq %r15, %rdi
callq 0x52c0
movq %rax, %r15
jmp 0x59f8
leaq 0x18(%rsp), %rbx
movq %rbx, %rdi
callq 0x8de6
movq 0x8(%rsp), %rcx
incq %rcx
jmp 0x599c
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rbx
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
leaq 0x30(%rsp), %r14
xorl %ebp, %ebp
leaq 0x120(%rsp), %r12
leaq 0x18(%rsp), %r13
xorl %r15d, %r15d
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rax
subq %rsi, %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
cltq
cmpq %rax, %r15
jge 0x5b7d
movq 0x20(%rsi,%rbp), %rdx
addq %rbp, %rsi
andq $0x0, 0x18(%rsp)
movq %r14, 0x20(%rsp)
andq $0x0, 0x28(%rsp)
movb $0x0, 0x30(%rsp)
movq %r12, %rdi
leaq 0x238(%rsp), %rcx
movq %r13, %r8
callq 0x6d22
movq %rbx, %rdi
movq %r13, %rsi
callq 0x6e22
leaq 0x20(%rsp), %rdi
callq 0x50f0
incq %r15
addq $0x28, %rbp
jmp 0x5b0c
leaq 0x18(%rsp), %rdi
callq 0x6e4e
movq 0x2a44a(%rip), %rdi     # 0x2ffd8
leaq 0x18(%rsp), %rsi
callq 0x5210
leaq 0x1760a(%rip), %rsi     # 0x1d1a9
movq %rax, %rdi
callq 0x5270
movq %rax, %rdi
callq 0x5100
leaq 0x18(%rsp), %rdi
callq 0x50f0
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rax
cmpq %rax, %rcx
je 0x5c14
xorl %r14d, %r14d
pushq $0x50
popq %r12
movq 0x2a402(%rip), %rbx     # 0x2ffd8
leaq 0x120(%rsp), %r15
xorl %r13d, %r13d
subq %rcx, %rax
cqto
idivq %r12
cltq
cmpq %rax, %r13
jge 0x5c14
addq %r14, %rcx
movq %r15, %rdi
movq %rbx, %rsi
movq %rcx, %rdx
callq 0x6e82
incq %r13
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rax
addq $0x50, %r14
jmp 0x5be1
xorps %xmm0, %xmm0
leaq 0xa0(%rsp), %rbx
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
leaq 0x28(%rsp), %r13
xorl %r14d, %r14d
leaq 0x120(%rsp), %r15
leaq 0x18(%rsp), %r12
xorl %ebp, %ebp
movq 0xe0(%rsp), %rsi
movq 0xe8(%rsp), %rax
subq %rsi, %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
cltq
cmpq %rax, %rbp
jge 0x5cb2
movq 0x20(%rsi,%r14), %rdx
addq %r14, %rsi
movq %r13, 0x18(%rsp)
andq $0x0, 0x20(%rsp)
movb $0x0, 0x28(%rsp)
movq %r15, %rdi
leaq 0x238(%rsp), %rcx
movq %r12, %r8
movq 0x68(%rsp), %r9
pushq $0x1
pushq $0x64
callq 0x73dc
popq %rax
popq %rcx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x749c
movq %r12, %rdi
callq 0x50f0
incq %rbp
addq $0x28, %r14
jmp 0x5c3e
leaq 0x18(%rsp), %rdi
callq 0x6e4e
movq 0x2a315(%rip), %rdi     # 0x2ffd8
leaq 0x18(%rsp), %rsi
callq 0x5210
leaq 0x17529(%rip), %rsi     # 0x1d1fd
movq %rax, %rdi
callq 0x5270
movq %rax, %rdi
callq 0x5100
leaq 0x18(%rsp), %rdi
callq 0x50f0
movq 0xa0(%rsp), %rcx
movq 0xa8(%rsp), %rax
cmpq %rax, %rcx
je 0x5d55
xorl %r15d, %r15d
pushq $0x48
popq %r12
movq 0x2a2c7(%rip), %rbx     # 0x2ffd8
leaq 0x120(%rsp), %r14
xorl %r13d, %r13d
subq %rcx, %rax
cqto
idivq %r12
cltq
cmpq %rax, %r13
jge 0x5d55
addq %r15, %rcx
movq %r14, %rdi
movq %rbx, %rsi
movq %rcx, %rdx
callq 0x74c8
incq %r13
movq 0xa0(%rsp), %rcx
movq 0xa8(%rsp), %rax
addq $0x48, %r15
jmp 0x5d1c
movq 0x2a27c(%rip), %rdi     # 0x2ffd8
leaq 0x174ec(%rip), %rsi     # 0x1d24f
callq 0x5270
movq %rax, %rbx
callq 0x5f23
subss 0x14(%rsp), %xmm0
movq %rbx, %rdi
callq 0x51b0
movq %rax, %rdi
callq 0x5100
leaq 0xa0(%rsp), %rdi
callq 0x771c
leaq 0x70(%rsp), %rdi
callq 0x773e
leaq 0x120(%rsp), %rdi
callq 0x7760
leaq 0xc0(%rsp), %rdi
callq 0x7816
leaq 0xe0(%rsp), %rdi
callq 0x7838
leaq 0x200(%rsp), %rdi
callq 0x785a
leaq 0x1b8(%rsp), %rdi
callq 0x78d2
leaq 0x100(%rsp), %rdi
callq 0x7904
xorl %eax, %eax
addq $0x2b8, %rsp            # imm = 0x2B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2a1d2(%rip), %rdi     # 0x2ffd8
callq 0x55ec
pushq $-0x1
popq %rdi
callq 0x5300
movq 0x2a1be(%rip), %rdi     # 0x2ffd8
callq 0x55ec
jmp 0x5e0b
jmp 0x5e5e
jmp 0x5e5e
jmp 0x5e5e
jmp 0x5e66
jmp 0x5e6b
jmp 0x5e2d
movq %rax, %rbx
jmp 0x5f01
jmp 0x5e66
jmp 0x5e72
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
jmp 0x5e96
jmp 0x5e5e
jmp 0x5e5e
movq %rax, %rbx
leaq 0x200(%rsp), %rdi
callq 0x50f0
jmp 0x5f0e
jmp 0x5e5e
movq %rax, %rbx
jmp 0x5f0e
movq %rax, %rbx
jmp 0x5e7f
movq %rax, %rbx
jmp 0x5e9b
jmp 0x5ec0
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x50f0
leaq 0xa0(%rsp), %rdi
callq 0x771c
jmp 0x5e9b
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x50f0
leaq 0x70(%rsp), %rdi
callq 0x773e
jmp 0x5ecd
jmp 0x5ead
jmp 0x5ec0
jmp 0x5ec0
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x50f0
jmp 0x5ec3
jmp 0x5ec0
jmp 0x5ec0
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x8de6
leaq 0x120(%rsp), %rdi
callq 0x7760
leaq 0xc0(%rsp), %rdi
callq 0x7816
leaq 0xe0(%rsp), %rdi
callq 0x7838
leaq 0x200(%rsp), %rdi
callq 0x785a
leaq 0x1b8(%rsp), %rdi
callq 0x78d2
leaq 0x100(%rsp), %rdi
callq 0x7904
movq %rbx, %rdi
callq 0x5430