// File: /workspace/github_cpp_makefile_star2_O2/bonetblai[P]mdp-engine/puzzle/main.cc
// Function: main
int main(int argc, const char **argv) {
    unsigned rows = 0;
    unsigned cols = 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 >= 3 ) {
        rows = strtoul(argv[0], 0, 0);
        cols = strtoul(argv[1], 0, 0);
        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);
    state_t init;
    init.set_goal(rows, cols);
    init.random_moves(rows, cols, 500);
    problem_t problem(rows, cols, init, 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;
    dispatcher.insert_heuristic("manhattan()", new manhattan_t(problem));
    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 $0x208, %rsp            # imm = 0x208
movq %rsi, %r15
movl %edi, %ebp
xorps %xmm0, %xmm0
leaq 0x100(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
callq 0x5e02
movss %xmm0, 0xc(%rsp)
movq 0x28a7b(%rip), %rax     # 0x2dfd8
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 0x130(%rsp), %r12
leaq 0x10(%rsp), %r13
cmpl $0x3, %ebp
jl 0x5ce6
leaq 0x8(%r15), %r14
movq (%r14), %rsi
cmpb $0x2d, (%rsi)
jne 0x56e5
movq %r12, %rdi
movq %r13, %rdx
callq 0x50a0
movq %r12, %rdi
leaq 0x16ba5(%rip), %rsi     # 0x1c15c
callq 0x5e67
movl %eax, %ebx
movq %r12, %rdi
callq 0x50e0
testb %bl, %bl
je 0x55d8
decl %ebp
movb $0x0, 0x28c25(%rip)     # 0x2e1f8
movq %r14, %r15
jmp 0x5589
movq (%r14), %rsi
cmpb $0x72, 0x1(%rsi)
je 0x5609
movq %r12, %rdi
movq %r13, %rdx
callq 0x50a0
movq %r12, %rdi
leaq 0x16b72(%rip), %rsi     # 0x1c168
callq 0x5e67
movl %eax, %ebx
movq %r12, %rdi
callq 0x50e0
testb %bl, %bl
je 0x563c
movq 0x10(%r15), %rsi
movq %r12, %rdi
movq %r13, %rdx
callq 0x50a0
leaq 0x100(%rsp), %rdi
movq %r12, %rsi
callq 0x8166
addq $0x10, %r15
movq %r12, %rdi
callq 0x50e0
addl $-0x2, %ebp
jmp 0x5589
movq (%r14), %rsi
cmpb $0x73, 0x1(%rsi)
je 0x566d
movq %r12, %rdi
movq %r13, %rdx
callq 0x50a0
movq %r12, %rdi
leaq 0x16b18(%rip), %rsi     # 0x1c172
callq 0x5e67
movl %eax, %ebx
movq %r12, %rdi
callq 0x50e0
testb %bl, %bl
je 0x5692
movq 0x10(%r15), %rdi
addq $0x10, %r15
xorl %esi, %esi
xorl %edx, %edx
callq 0x5080
movl %eax, 0x28b8c(%rip)     # 0x2e210
movl %eax, 0x28b8a(%rip)     # 0x2e214
addl $-0x2, %ebp
jmp 0x5589
movq (%r14), %rsi
cmpb $0x74, 0x1(%rsi)
je 0x56c7
movq %r12, %rdi
movq %r13, %rdx
callq 0x50a0
movq %r12, %rdi
leaq 0x16ac9(%rip), %rsi     # 0x1c179
callq 0x5e67
movl %eax, %ebx
movq %r12, %rdi
callq 0x50e0
testb %bl, %bl
je 0x5cfa
movq 0x10(%r15), %rdi
addq $0x10, %r15
xorl %esi, %esi
xorl %edx, %edx
callq 0x5080
movq %rax, 0x68(%rsp)
addl $-0x2, %ebp
jmp 0x5589
cmpl $0x3, %ebp
je 0x5ce6
movq %rsi, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5080
movq %rax, %rbx
movq 0x10(%r15), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5080
movq %rax, %r12
movq 0x18(%r15), %rdi
xorl %esi, %esi
callq 0x51b0
movsd %xmm0, (%rsp)
movq 0x288b4(%rip), %rdi     # 0x2dfd8
leaq 0x16a57(%rip), %rsi     # 0x1c182
callq 0x5230
movl 0x28ada(%rip), %esi     # 0x2e210
movq %rax, %rdi
callq 0x5160
movq %rax, %rdi
callq 0x50f0
movl 0x28ac4(%rip), %edi     # 0x2e210
callq 0x5e74
leaq 0x124(%rsp), %rdi
andq $0x0, (%rdi)
andl $0x0, 0x8(%rdi)
movl %ebx, %esi
movl %r12d, %edx
callq 0x5ea0
leaq 0x124(%rsp), %rdi
movl %ebx, %esi
movl %r12d, %edx
movl $0x1f4, %ecx            # imm = 0x1F4
callq 0x5ef8
cvtsd2ss (%rsp), %xmm0
leaq 0x1c8(%rsp), %r14
leaq 0x124(%rsp), %rcx
movq %r14, %rdi
movl %ebx, %esi
movl %r12d, %edx
callq 0x5f6c
andq $0x0, 0xf0(%rsp)
xorps %xmm0, %xmm0
andq $0x0, 0xd0(%rsp)
movaps %xmm0, 0xe0(%rsp)
movaps %xmm0, 0xc0(%rsp)
leaq 0x278a0(%rip), %rax     # 0x2d070
leaq 0x140(%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 0x170(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x1a0(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x1695c(%rip), %rsi     # 0x1c18e
leaq 0x10(%rsp), %rdi
leaq 0x70(%rsp), %rdx
callq 0x50a0
pushq $0x20
popq %rdi
callq 0x5240
movq %r14, 0x8(%rax)
andq $0x0, 0x10(%rax)
andl $0x0, 0x18(%rax)
leaq 0x27783(%rip), %rcx     # 0x2cfe0
movq %rcx, (%rax)
leaq 0x130(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movq %rax, %rdx
callq 0x5fb2
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x50e0
leaq 0x18(%rsp), %r13
xorl %ecx, %ecx
leaq 0x130(%rsp), %r15
leaq 0x70(%rsp), %rbx
movq 0x100(%rsp), %rdi
movq 0x108(%rsp), %rax
subq %rdi, %rax
shrq $0x5, %rax
cltq
cmpq %rax, %rcx
jge 0x59dd
movq %rcx, (%rsp)
movq %rcx, %rax
shlq $0x5, %rax
addq %rax, %rdi
andl $0x0, 0x18(%rsp)
andq $0x0, 0x20(%rsp)
movq %r13, 0x28(%rsp)
movq %r13, 0x30(%rsp)
andq $0x0, 0x38(%rsp)
movq %r14, %rsi
pushq $0x2c
popq %rdx
callq 0x600a
movq 0x28(%rsp), %rbp
cmpq %r13, %rbp
je 0x59c4
leaq 0x20(%rbp), %r12
leaq 0x40(%rbp), %r14
movq %r15, %rdi
leaq 0x1c8(%rsp), %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x61da
movq %r12, %rdi
leaq 0x16878(%rip), %rsi     # 0x1c19a
callq 0x5e67
testb %al, %al
je 0x5963
movq %r15, %rdi
movq %r14, %rsi
callq 0x6b3a
movq %rax, %r12
testq %rax, %rax
je 0x59b4
movq %rbx, %rdi
movq %r14, %rsi
callq 0x52e0
movq %r12, 0x90(%rsp)
leaq 0xc0(%rsp), %rdi
movq %rbx, %rsi
callq 0x1a6e4
jmp 0x59ac
movq %r12, %rdi
leaq 0x16837(%rip), %rsi     # 0x1c1a4
callq 0x5e67
testb %al, %al
je 0x59b4
movq %r15, %rdi
movq %r14, %rsi
callq 0x6b5a
movq %rax, %r12
testq %rax, %rax
je 0x59b4
movq %rbx, %rdi
movq %r14, %rsi
callq 0x52e0
movq %r12, 0x90(%rsp)
leaq 0xe0(%rsp), %rdi
movq %rbx, %rsi
callq 0x1a940
movq %rbx, %rdi
callq 0x50e0
movq %rbp, %rdi
callq 0x5270
movq %rax, %rbp
jmp 0x58f1
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x80e8
movq (%rsp), %rcx
incq %rcx
jmp 0x5896
xorps %xmm0, %xmm0
leaq 0x70(%rsp), %rbx
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
leaq 0x30(%rsp), %r14
xorl %r15d, %r15d
leaq 0x130(%rsp), %r12
leaq 0x10(%rsp), %r13
xorl %ebp, %ebp
movq 0xc0(%rsp), %rsi
movq 0xc8(%rsp), %rax
subq %rsi, %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
cltq
cmpq %rax, %rbp
jge 0x5a7a
movq 0x20(%rsi,%r15), %rdx
addq %r15, %rsi
andq $0x0, 0x10(%rsp)
andl $0x0, 0x18(%rsp)
movq %r14, 0x20(%rsp)
andq $0x0, 0x28(%rsp)
movb $0x0, 0x30(%rsp)
movq %r12, %rdi
leaq 0x1ec(%rsp), %rcx
movq %r13, %r8
callq 0x6b7a
movq %rbx, %rdi
movq %r13, %rsi
callq 0x6c80
leaq 0x20(%rsp), %rdi
callq 0x50e0
incq %rbp
addq $0x28, %r15
jmp 0x5a04
leaq 0x10(%rsp), %rdi
callq 0x6cac
movq 0x2854d(%rip), %rdi     # 0x2dfd8
leaq 0x10(%rsp), %rsi
callq 0x51f0
movq 0x68(%rsp), %rbp
leaq 0x1670a(%rip), %rsi     # 0x1c1ab
movq %rax, %rdi
callq 0x5230
movq %rax, %rdi
callq 0x50f0
leaq 0x10(%rsp), %rdi
callq 0x50e0
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rax
cmpq %rax, %rcx
je 0x5b16
xorl %r14d, %r14d
pushq $0x58
popq %r15
movq 0x28500(%rip), %rbx     # 0x2dfd8
leaq 0x130(%rsp), %r12
xorl %r13d, %r13d
subq %rcx, %rax
cqto
idivq %r15
cltq
cmpq %rax, %r13
jge 0x5b16
addq %r14, %rcx
movq %r12, %rdi
movq %rbx, %rsi
movq %rcx, %rdx
callq 0x6ce0
incq %r13
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %rax
addq $0x58, %r14
jmp 0x5ae3
xorps %xmm0, %xmm0
leaq 0xa0(%rsp), %rbx
movaps %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
xorl %r14d, %r14d
leaq 0x130(%rsp), %r12
leaq 0x10(%rsp), %r13
xorl %r15d, %r15d
movq 0xe0(%rsp), %rsi
movq 0xe8(%rsp), %rax
subq %rsi, %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
cltq
cmpq %rax, %r15
jge 0x5bb3
movq 0x20(%rsi,%r14), %rdx
addq %r14, %rsi
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
andq $0x0, 0x18(%rsp)
movb $0x0, 0x20(%rsp)
movq %r12, %rdi
leaq 0x1ec(%rsp), %rcx
movq %r13, %r8
movl %ebp, %r9d
pushq $0x1
pushq $0x64
callq 0x723a
popq %rax
popq %rcx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x72fa
movq %r13, %rdi
callq 0x50e0
incq %r15
addq $0x28, %r14
jmp 0x5b3c
leaq 0x10(%rsp), %rdi
callq 0x6cac
movq 0x28414(%rip), %rdi     # 0x2dfd8
leaq 0x10(%rsp), %rsi
callq 0x51f0
leaq 0x1662a(%rip), %rsi     # 0x1c1ff
movq %rax, %rdi
callq 0x5230
movq %rax, %rdi
callq 0x50f0
leaq 0x10(%rsp), %rdi
callq 0x50e0
movq 0xa0(%rsp), %rcx
movq 0xa8(%rsp), %rax
cmpq %rax, %rcx
je 0x5c56
xorl %r15d, %r15d
pushq $0x48
popq %r12
movq 0x283c6(%rip), %rbx     # 0x2dfd8
leaq 0x130(%rsp), %r14
xorl %r13d, %r13d
subq %rcx, %rax
cqto
idivq %r12
cltq
cmpq %rax, %r13
jge 0x5c56
addq %r15, %rcx
movq %r14, %rdi
movq %rbx, %rsi
movq %rcx, %rdx
callq 0x7326
incq %r13
movq 0xa0(%rsp), %rcx
movq 0xa8(%rsp), %rax
addq $0x48, %r15
jmp 0x5c1d
movq 0x2837b(%rip), %rdi     # 0x2dfd8
leaq 0x165ed(%rip), %rsi     # 0x1c251
callq 0x5230
movq %rax, %rbx
callq 0x5e02
subss 0xc(%rsp), %xmm0
movq %rbx, %rdi
callq 0x5190
movq %rax, %rdi
callq 0x50f0
leaq 0xa0(%rsp), %rdi
callq 0x757a
leaq 0x70(%rsp), %rdi
callq 0x759c
leaq 0x130(%rsp), %rdi
callq 0x75be
leaq 0xc0(%rsp), %rdi
callq 0x7674
leaq 0xe0(%rsp), %rdi
callq 0x7696
leaq 0x100(%rsp), %rdi
callq 0x76ba
xorl %eax, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x282eb(%rip), %rdi     # 0x2dfd8
callq 0x550c
pushq $-0x1
popq %rdi
callq 0x5290
movq 0x282d7(%rip), %rdi     # 0x2dfd8
callq 0x550c
jmp 0x5cf2
jmp 0x5d63
jmp 0x5d55
jmp 0x5d5a
movq %rax, %rbx
jmp 0x5dc6
jmp 0x5d63
jmp 0x5d63
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x50e0
jmp 0x5dc6
jmp 0x5d63
jmp 0x5d55
jmp 0x5d6b
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
jmp 0x5d8f
jmp 0x5d63
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
callq 0x50e0
jmp 0x5ded
jmp 0x5d63
movq %rax, %rbx
jmp 0x5d78
movq %rax, %rbx
jmp 0x5d94
jmp 0x5d63
jmp 0x5db9
movq %rax, %rbx
jmp 0x5ded
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x50e0
leaq 0xa0(%rsp), %rdi
callq 0x757a
jmp 0x5d94
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x50e0
leaq 0x70(%rsp), %rdi
callq 0x759c
jmp 0x5dc6
jmp 0x5da6
jmp 0x5db9
jmp 0x5db9
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x50e0
jmp 0x5dbc
jmp 0x5db9
jmp 0x5db9
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x80e8
leaq 0x130(%rsp), %rdi
callq 0x75be
leaq 0xc0(%rsp), %rdi
callq 0x7674
leaq 0xe0(%rsp), %rdi
callq 0x7696
leaq 0x100(%rsp), %rdi
callq 0x76ba
movq %rbx, %rdi
callq 0x5380