// File: /workspace/github_cpp_makefile_star2_O2/demon386[P]git-store/./command.hpp
// Function: command::parse_args(int, char**)
po::variables_map parse_args(int argc, char* argv[]) {
    // Inspired by
    // http://www.hitmaroc.net/553491-4141-how-implement-subcommands-using-boost-program-options.html
    po::options_description commands("Subcommands: init,read,write");

    commands.add_options()
        ("help,h", "Help screen")
        ("command", po::value<std::string>(), "subcommand")
        ("subargs", po::value<std::vector<std::string>>(),
         "Positional arguments for subcommands");

    po::positional_options_description pos;
    pos.add("command", 1).
        add("subargs", -1);

    po::variables_map vm;

    po::parsed_options parsed = po::command_line_parser(argc, argv).
        options(commands).
        positional(pos).
        allow_unregistered().
        run();

    po::store(parsed, vm);

    // @todo should exists a better way to judge whether the first positional
    // cmd is given.
    try {
        std::string cmd = vm["command"].as<std::string>();
    } catch(...) {
        std::cout << commands << std::endl;
        std::exit(1);
    }
    std::string cmd = vm["command"].as<std::string>();

    if (!global_command_map().count(cmd)) {
        std::cout << "Unrecognized command: " << cmd << std::endl;
        std::cout << commands << std::endl;
        std::exit(-1);
    } else {
        const auto& callback = std::get<1>(global_command_map().at(cmd));
        po::options_description sub_opts("sub-options for `" + cmd + "`");
        callback(sub_opts);
        sub_opts.add_options()
            ("help,h", "Help screen");

        std::vector<std::string> opts = po::collect_unrecognized(parsed.options, po::include_positional);
        opts.erase(opts.begin());

        try {
            po::store(po::command_line_parser(opts).options(sub_opts).run(), vm);
        } catch (boost::program_options::unknown_option& e) {
            std::cout << "Unknown options!" << std::endl;
            std::cout << sub_opts << std::endl;
            std::exit(1);
        }
        if (vm.count("help")) {
            std::cout << sub_opts << std::endl;
            std::exit(0);
        }
    }
    return vm;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movq %rdx, %r12
movl %esi, %r13d
movq %rdi, -0x30(%rbp)
leaq 0x95d1(%rip), %rsi      # 0x30ef0
leaq -0x110(%rbp), %rdi
leaq -0x188(%rbp), %rdx
callq 0xc1b0
leaq 0x61ff(%rip), %rax      # 0x2db38
movl (%rax), %r14d
movl %r14d, %r15d
shrl %r15d
leaq -0x268(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movl %r14d, %edx
movl %r15d, %ecx
callq 0x150ca
leaq -0x110(%rbp), %rdi
callq 0xc9a0
leaq -0x268(%rbp), %rdi
callq 0x1523a
leaq -0x110(%rbp), %rdi
movq %rax, (%rdi)
leaq 0x9589(%rip), %rsi      # 0x30f0d
leaq 0x9589(%rip), %rdx      # 0x30f14
callq 0x14e00
movq %rax, %rbx
callq 0x28a95
leaq 0x9584(%rip), %rsi      # 0x30f23
leaq 0x957a(%rip), %rcx      # 0x30f20
movq %rbx, %rdi
movq %rax, %rdx
callq 0x14fac
movq %rax, %rbx
callq 0x28aa1
leaq 0x956b(%rip), %rsi      # 0x30f2b
leaq 0x956c(%rip), %rcx      # 0x30f33
movq %rbx, %rdi
movq %rax, %rdx
callq 0x14fac
leaq -0x1e8(%rbp), %rdi
callq 0x1a594
leaq 0x953e(%rip), %rsi      # 0x30f23
leaq -0x1e8(%rbp), %rdi
pushq $0x1
popq %rdx
callq 0x1a5b6
leaq 0x9530(%rip), %rsi      # 0x30f2b
pushq $-0x1
popq %rdx
movq %rax, %rdi
callq 0x1a5b6
movq -0x30(%rbp), %rdi
callq 0x20d58
leaq -0x110(%rbp), %rdi
movl %r13d, %esi
movq %r12, %rdx
callq 0x28aae
leaq -0x110(%rbp), %rdi
leaq -0x268(%rbp), %rsi
callq 0x28b38
movq %rax, %r12
leaq -0x1e8(%rbp), %rsi
movq %rax, %rdi
callq 0xcf3e
movq %r12, %rdi
callq 0xcf1e
leaq -0x1b0(%rbp), %rdi
movq %r12, %rsi
callq 0x28b56
leaq -0x110(%rbp), %rdi
callq 0x28be8
leaq -0x1b0(%rbp), %rdi
movq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0x205f0
leaq 0x94a1(%rip), %rsi      # 0x30f23
leaq -0x188(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0xc1b0
leaq -0x188(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x20cf2
movq %rax, %rdi
callq 0x2abee
leaq -0x110(%rbp), %rdi
movq %rax, %rsi
callq 0xc660
leaq -0x188(%rbp), %rdi
callq 0xc9a0
leaq -0x110(%rbp), %rdi
callq 0xc9a0
leaq 0x944b(%rip), %rsi      # 0x30f23
leaq -0x110(%rbp), %rdi
leaq -0x188(%rbp), %rdx
callq 0xc1b0
leaq -0x110(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x20cf2
movq %rax, %rdi
callq 0x2abee
leaq -0x78(%rbp), %rdi
movq %rax, %rsi
callq 0xc660
leaq -0x110(%rbp), %rdi
callq 0xc9a0
callq 0x28951
leaq -0x78(%rbp), %rsi
movq %rax, %rdi
callq 0x28c12
testq %rax, %rax
je 0x27cf2
callq 0x28951
leaq -0x78(%rbp), %rsi
movq %rax, %rdi
callq 0x28c36
movq %rax, %r12
leaq 0x941f(%rip), %rsi      # 0x30f6f
leaq -0x58(%rbp), %rdi
leaq -0x78(%rbp), %rdx
callq 0x15d84
leaq 0x941b(%rip), %rdx      # 0x30f7f
leaq -0x188(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x12ae9
leaq -0x110(%rbp), %rdi
leaq -0x188(%rbp), %rsi
movl %r14d, %edx
movl %r15d, %ecx
callq 0x150ca
leaq -0x188(%rbp), %rdi
callq 0xc9a0
leaq -0x58(%rbp), %rdi
callq 0xc9a0
leaq -0x110(%rbp), %rsi
movq %r12, %rdi
callq 0x28c86
leaq -0x110(%rbp), %rdi
callq 0x1523a
leaq -0x188(%rbp), %rdi
movq %rax, (%rdi)
leaq 0x933f(%rip), %rsi      # 0x30f0d
leaq 0x933f(%rip), %rdx      # 0x30f14
callq 0x14e00
leaq -0x90(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
xorl %edx, %edx
callq 0x28c9c
leaq -0x90(%rbp), %rdi
movq (%rdi), %rsi
callq 0xeb30
leaq -0x188(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x28d34
leaq -0x188(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x28b38
leaq -0x58(%rbp), %rdi
movq %rax, %rsi
callq 0x28b56
leaq -0x58(%rbp), %rdi
movq -0x30(%rbp), %rsi
xorl %edx, %edx
callq 0x205f0
leaq -0x58(%rbp), %rdi
callq 0xeac8
leaq -0x188(%rbp), %rdi
callq 0x28be8
leaq 0x9337(%rip), %rsi      # 0x30f92
leaq -0x188(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0xc1b0
movq -0x30(%rbp), %rax
leaq 0x10(%rax), %rdi
leaq -0x188(%rbp), %rsi
callq 0x2101c
movq %rax, %rbx
leaq -0x188(%rbp), %rdi
callq 0xc9a0
testq %rbx, %rbx
jne 0x27d3b
leaq -0x90(%rbp), %rdi
callq 0xe840
leaq -0x110(%rbp), %rdi
callq 0x176fa
leaq -0x78(%rbp), %rdi
callq 0xc9a0
leaq -0x1b0(%rbp), %rdi
callq 0xeac8
leaq -0x1e8(%rbp), %rdi
callq 0x28d80
leaq -0x268(%rbp), %rdi
callq 0x176fa
movq -0x30(%rbp), %rax
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x212bf(%rip), %rdi     # 0x48fb8
leaq 0x9258(%rip), %rsi      # 0x30f58
callq 0xc4c0
leaq -0x78(%rbp), %rsi
movq %rax, %rdi
callq 0xc460
movq %rax, %rdi
callq 0xc230
movq 0x21298(%rip), %rdi     # 0x48fb8
leaq -0x268(%rbp), %rsi
callq 0x154a6
movq %rax, %rdi
callq 0xc230
pushq $-0x1
jmp 0x27f0d
movq 0x21276(%rip), %rdi     # 0x48fb8
leaq -0x110(%rbp), %rsi
callq 0x154a6
movq %rax, %rdi
callq 0xc230
xorl %edi, %edi
callq 0xc580
jmp 0x27d94
movq %rax, %r14
leaq -0x188(%rbp), %rdi
callq 0xc9a0
jmp 0x27e72
jmp 0x27d94
movq %rdx, %r15
movq %rax, %r14
leaq -0x58(%rbp), %rdi
callq 0xeac8
jmp 0x27e15
movq %rdx, %r15
movq %rax, %r14
jmp 0x27e21
movq %rax, %r14
jmp 0x27e72
jmp 0x27e80
jmp 0x27e80
movq %rax, %r14
leaq -0x188(%rbp), %rdi
callq 0xc9a0
jmp 0x27dba
movq %rax, %r14
leaq -0x58(%rbp), %rdi
callq 0xc9a0
jmp 0x27e8f
jmp 0x27e07
jmp 0x27e07
jmp 0x27dd6
movq %rax, %rbx
jmp 0x27ee8
movq %rax, %r14
jmp 0x27e98
movq %rax, %r14
jmp 0x27ea4
jmp 0x27f41
movq %rax, %r14
leaq -0x110(%rbp), %rdi
callq 0xc9a0
jmp 0x27ec5
movq %rax, %r14
jmp 0x27ec5
movq %rax, %r14
jmp 0x27e8f
movq %rdx, %r15
movq %rax, %r14
leaq -0x188(%rbp), %rdi
callq 0x28be8
cmpl $0x2, %r15d
jne 0x27e72
movq %r14, %rdi
callq 0xc1d0
movq 0x21182(%rip), %rdi     # 0x48fb8
leaq 0x9144(%rip), %rsi      # 0x30f81
callq 0xc4c0
movq %rax, %rdi
callq 0xc230
movq 0x21167(%rip), %rdi     # 0x48fb8
leaq -0x110(%rbp), %rsi
callq 0x154a6
movq %rax, %rdi
callq 0xc230
jmp 0x27f0b
movq %rax, %r14
callq 0xc7e0
leaq -0x90(%rbp), %rdi
callq 0xe840
jmp 0x27e83
movq %rax, %r14
leaq -0x110(%rbp), %rdi
callq 0x176fa
leaq -0x78(%rbp), %rdi
callq 0xc9a0
leaq -0x1b0(%rbp), %rdi
callq 0xeac8
movq -0x30(%rbp), %rdi
callq 0x2115a
leaq -0x1e8(%rbp), %rdi
callq 0x28d80
leaq -0x268(%rbp), %rdi
callq 0x176fa
movq %r14, %rdi
callq 0xc850
movq %rax, %r14
leaq -0x110(%rbp), %rdi
jmp 0x27e93
movq %rax, %rbx
leaq -0x188(%rbp), %rdi
callq 0xc9a0
movq %rbx, %rdi
callq 0xc1d0
movq 0x210c1(%rip), %rdi     # 0x48fb8
leaq -0x268(%rbp), %rsi
callq 0x154a6
movq %rax, %rdi
callq 0xc230
pushq $0x1
popq %rdi
callq 0xc580
movq %rax, %r14
callq 0xc7e0
jmp 0x27e98
movq %rax, %rdi
callq 0xeb96
movq %rax, %r14
jmp 0x27ead
movq %rax, %r14
leaq -0x110(%rbp), %rdi
callq 0x28be8
jmp 0x27ea4
movq %rax, %r14
jmp 0x27eb9