// File: /workspace/github_cpp_makefile_star2_O1/chuckwolber[P]Cube/order/cli.cpp
// Function: main
int main(int argc, char *argv[]) {
    int ch;
    char* algorithmStart = nullptr;
    unsigned long long int algmathAddVal = 0;
    char* algmathLtVal = nullptr;
    bool algmathAdd = false;
    bool algmathLt = false;
    bool algBench = false;
    bool algBenchLite = false;
    algorithmCountMax = DEFAULT_ALG_MAX;
    keepDuplicates = false;
    skipFoundOrders = false;
    showFoundOrder = false;
    skip_nth = 1;
    heartbeat = 0;
    numThreads = std::thread::hardware_concurrency();

    opterr = 0;
    while((ch = getopt_long(argc, argv, "a:gep:l:c:b:ks:t:f:o:ih", longopts, NULL)) != -1) {
        switch(ch) {
            case 'a':
                algorithmStart = optarg;
                break;
            case 'g':
                algBench = true;
                break;
            case 'e':
                algBench = true;
                algBenchLite = true;
                break;
            case 'p':
                algmathAddVal = (unsigned long long int)(std::strtoll(optarg, nullptr, 10));
                algmathAdd = true;
                break;
            case 'l':
                algmathLtVal = optarg;
                algmathLt = true;
                break;
            case 'c':
                algorithmCountMax = (unsigned long long int)(std::strtoll(optarg, nullptr, 10));
                break;
            case 'b':
                heartbeat = (unsigned long long int)(std::strtoll(optarg, nullptr, 10));
                break;
            case 'k':
                keepDuplicates = true;
                break;
            case 's':
                skip_nth = (unsigned long long int)std::strtoll(optarg, nullptr, 10);
                ++skip_nth;
                break;
            case 't':
                numThreads = (unsigned int)std::stoul(optarg, nullptr, 10);
                break;
            case 'i':
                setFindAllOrders();
                break;
            case 'f':
                setFindOrders(optarg);
                break;
            case 'o':
                showFoundOrder = true;
                try {
                    foundOrder = (unsigned int)std::stoul(optarg, nullptr, 10);
                } catch (std::invalid_argument) {
                    usage(argv[0]);
                    return 0;
                }
                break;
            case 'h':
            default:
                usage(argv[0]);
                return 0;
                break;
        }
    }

    if (skip_nth == 0)
        skip_nth = 1;
    if (numThreads < 1)
        numThreads = 1;
    std::vector<std::thread> threads(numThreads);

    initialAlgorithm.reset();
    if (algorithmStart != nullptr)
        initialAlgorithm.setAlgorithm(algorithmStart);

    if (algmathAdd) {
        Algorithm endAlgorithm(initialAlgorithm);
        endAlgorithm += algmathAddVal;
        std::cout << endAlgorithm.getAlgorithmStr() << std::endl;
    } else if (algmathLt) {
        Algorithm ltAlgorithm(algmathLtVal);
        if (initialAlgorithm < ltAlgorithm)
            std::cout << "true" << std::endl;
        else
            std::cout << "false" << std::endl;
    } else if (algBench) {
        std::cerr << "Threads: " << numThreads << std::endl;
        doAlgBench(algBenchLite);
    } else {
        std::cerr << "Algorithm Count: " << algorithmCountMax << std::endl;
        std::cerr << "Algorithm Start: " << initialAlgorithm.getAlgorithmStr() << std::endl;

        if (skipFoundOrders)
            std::cerr << "Finding Orders: " << findOrders << std::endl;
        std::cerr << "Threads: " << numThreads << std::endl;
   
        for (unsigned int i=0; i<numThreads; i++)
            threads.at(i) = std::thread(calculateOrder, i);
        for (std::thread &t : threads)
            t.join();

        if (heartbeat > 0)
            std::cout << "HB:-1" << std::endl;
    }
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, 0x28(%rsp)
movl %edi, %ebp
movabsq $0x183870714, %rax      # imm = 0x183870714
movq %rax, 0xb54b(%rip)      # 0x12650
xorl %eax, %eax
movb %al, 0xb563(%rip)       # 0x12670
movb %al, 0xb55e(%rip)       # 0x12671
movq $0x0, 0x68(%rsp)
movb %al, 0xb550(%rip)       # 0x12672
movq $0x1, 0xb51b(%rip) # 0x12648
movq $0x0, 0xb528(%rip) # 0x12660
callq 0x43c0
movl %eax, 0xb525(%rip)      # 0x12668
movq 0xae76(%rip), %rax      # 0x11fc0
movl $0x0, (%rax)
leaq 0x5239(%rip), %rbx      # 0xc390
leaq 0xb272(%rip), %r14      # 0x123d0
leaq 0x5183(%rip), %r13      # 0xc2e8
movq 0xae0c(%rip), %r12      # 0x11f78
movq $0x0, 0x58(%rsp)
movq $0x0, 0x70(%rsp)
movq $0x0, 0x60(%rsp)
xorl %eax, %eax
movq $0x0, 0x50(%rsp)
movq $0x0, 0x78(%rsp)
movl %eax, %r15d
movl %ebp, %edi
movq 0x28(%rsp), %rsi
movq %rbx, %rdx
movq %r14, %rcx
xorl %r8d, %r8d
callq 0x4470
leal -0x61(%rax), %ecx
cmpl $0x13, %ecx
ja 0x73c3
movb $0x1, %al
movslq (%r13,%rcx,4), %rcx
addq %r13, %rcx
jmpq *%rcx
movq (%r12), %rax
movq %rax, 0x78(%rsp)
movl %r15d, %eax
jmp 0x719b
movq (%r12), %rax
movq %rax, 0x58(%rsp)
movb $0x1, %al
movq %rax, 0x60(%rsp)
movl %r15d, %eax
jmp 0x719b
movq (%r12), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x4070
movq %rax, 0x68(%rsp)
movb $0x1, %al
movq %rax, 0x70(%rsp)
movl %r15d, %eax
jmp 0x719b
movb $0x1, 0xb45a(%rip)      # 0x12670
movl %r15d, %eax
jmp 0x719b
movq (%r12), %rdi
callq 0x7c68
movl %r15d, %eax
jmp 0x719b
callq 0x7a0d
movl %r15d, %eax
jmp 0x719b
movq (%r12), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x4070
movq %rax, 0xb400(%rip)      # 0x12650
movl %r15d, %eax
jmp 0x719b
movb $0x1, %al
movb $0x1, %cl
movq %rcx, 0x50(%rsp)
jmp 0x719b
movb $0x1, 0xb405(%rip)      # 0x12672
movq (%r12), %rsi
movq %rsp, %rdi
leaq 0x80(%rsp), %rdx
callq 0x942a
movq (%rsp), %r12
callq 0x4060
movq %rax, %r14
movl (%rax), %ebx
movl $0x0, (%rax)
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
movl $0xa, %edx
callq 0x40d0
cmpq %r12, 0x30(%rsp)
je 0x7877
movl (%r14), %ecx
testl %ecx, %ecx
je 0x7370
cmpl $0x22, %ecx
movq 0xacb1(%rip), %r12      # 0x11f78
jne 0x737a
jmp 0x788f
movq (%r12), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x4070
movq %rax, 0xb377(%rip)      # 0x12660
movl %r15d, %eax
jmp 0x719b
movq (%r12), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x4070
incq %rax
movq %rax, 0xb33d(%rip)      # 0x12648
movl %r15d, %eax
jmp 0x719b
movq (%r12), %rsi
movq %rsp, %rdi
leaq 0x80(%rsp), %rdx
callq 0x942a
movq (%rsp), %r12
callq 0x4060
movq %rax, %r14
movl (%rax), %ebx
movl $0x0, (%rax)
movq %r12, %rdi
leaq 0x30(%rsp), %rsi
movl $0xa, %edx
callq 0x40d0
cmpq %r12, 0x30(%rsp)
je 0x7883
movl (%r14), %ecx
testl %ecx, %ecx
je 0x7382
cmpl $0x22, %ecx
movq 0xac0f(%rip), %r12      # 0x11f78
jne 0x738c
jmp 0x789b
movl %ebx, (%r14)
movq 0xabfe(%rip), %r12      # 0x11f78
movl %eax, 0xb2ec(%rip)      # 0x1266c
jmp 0x7392
movl %ebx, (%r14)
movq 0xabec(%rip), %r12      # 0x11f78
movl %eax, 0xb2d6(%rip)      # 0x12668
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x73ad
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42f0
movl %r15d, %eax
leaq 0x4fd9(%rip), %rbx      # 0xc390
leaq 0xb012(%rip), %r14      # 0x123d0
jmp 0x719b
cmpl $-0x1, %eax
jne 0x74c7
cmpq $0x0, 0xb274(%rip)      # 0x12648
jne 0x73e1
movq $0x1, 0xb267(%rip) # 0x12648
cmpl $0x0, 0xb280(%rip)      # 0x12668
movq 0x78(%rsp), %rbx
jne 0x73f9
movl $0x1, 0xb26f(%rip)      # 0x12668
movl 0xb269(%rip), %esi      # 0x12668
leaq 0x80(%rsp), %rdi
movq %rsp, %rdx
callq 0x9472
leaq 0xb262(%rip), %rdi      # 0x12678
callq 0x4f34
testq %rbx, %rbx
je 0x742f
leaq 0xb251(%rip), %rdi      # 0x12678
movq %rbx, %rsi
callq 0x4a90
testb $0x1, 0x70(%rsp)
je 0x74d9
leaq 0xb237(%rip), %rsi      # 0x12678
movq %rsp, %rdi
callq 0x49f2
movq %rsp, %rdi
movq 0x68(%rsp), %rsi
callq 0x4d08
leaq 0x30(%rsp), %rdi
movq %rsp, %rsi
callq 0x4f7c
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0xab3c(%rip), %rdi      # 0x11fb0
callq 0x4340
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x7555
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x42f0
jmp 0x7555
movq 0x28(%rsp), %rax
movq (%rax), %rdi
callq 0x7fd2
jmp 0x7863
testb $0x1, 0x60(%rsp)
je 0x7574
movq %rsp, %rdi
movq 0x58(%rsp), %rsi
callq 0x4a4a
leaq 0xb180(%rip), %rdi      # 0x12678
movq %rsp, %rsi
callq 0x4d90
leaq 0x4ea1(%rip), %rcx      # 0xc3a8
leaq 0x4e9f(%rip), %rsi      # 0xc3ad
testb %al, %al
cmovneq %rcx, %rsi
movzbl %al, %edx
xorq $0x5, %rdx
movq 0xaa8e(%rip), %rbx      # 0x11fb0
movq %rbx, %rdi
callq 0x4340
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x42d0
movsbl %al, %esi
movq 0xaa68(%rip), %rdi      # 0x11fb0
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x7856
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x42f0
jmp 0x7856
testb $0x1, %r15b
je 0x75e0
movq 0xaa6f(%rip), %rdi      # 0x11ff0
leaq 0x4e2b(%rip), %rsi      # 0xc3b3
movl $0x9, %edx
callq 0x4340
movl 0xb0d0(%rip), %esi      # 0x12668
movq 0xaa51(%rip), %rdi      # 0x11ff0
callq 0x41e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movzbl 0x50(%rsp), %edi
andl $0x1, %edi
callq 0x8675
jmp 0x7856
movq 0xaa09(%rip), %rdi      # 0x11ff0
leaq 0x4dcf(%rip), %rsi      # 0xc3bd
movl $0x11, %edx
callq 0x4340
movq 0xb051(%rip), %rsi      # 0x12650
movq 0xa9ea(%rip), %rdi      # 0x11ff0
callq 0x41d0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movq 0xa9b4(%rip), %rdi      # 0x11ff0
leaq 0x4d8c(%rip), %rsi      # 0xc3cf
movl $0x11, %edx
callq 0x4340
leaq 0xb024(%rip), %rsi      # 0x12678
movq %rsp, %rdi
callq 0x4f7c
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0xa984(%rip), %rdi      # 0x11ff0
callq 0x4340
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x76b6
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42f0
cmpb $0x1, 0xafb4(%rip)      # 0x12671
jne 0x771b
movq 0xa92a(%rip), %rdi      # 0x11ff0
leaq 0x4d14(%rip), %rsi      # 0xc3e1
movl $0x10, %edx
callq 0x4340
movq 0xaf22(%rip), %rsi      # 0x12600
movq 0xaf23(%rip), %rdx      # 0x12608
movq 0xa904(%rip), %rdi      # 0x11ff0
callq 0x4340
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movq 0xa8ce(%rip), %rdi      # 0x11ff0
leaq 0x4c8a(%rip), %rsi      # 0xc3b3
movl $0x9, %edx
callq 0x4340
movl 0xaf2f(%rip), %esi      # 0x12668
movq 0xa8b0(%rip), %rdi      # 0x11ff0
callq 0x41e0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x42d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movl $0x0, 0x30(%rsp)
cmpl $0x0, 0xaeea(%rip)      # 0x12668
je 0x77e3
leaq 0x1595(%rip), %rbx      # 0x8d1c
movq %rsp, %r14
leaq 0x30(%rsp), %r15
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x94ea
movl 0x30(%rsp), %esi
movq 0x80(%rsp), %rax
movq 0x88(%rsp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x78a7
cmpq $0x0, (%rax,%rsi,8)
jne 0x791e
movq (%rsp), %rcx
movq %rcx, (%rax,%rsi,8)
leal 0x1(%rsi), %eax
movl %eax, 0x30(%rsp)
cmpl 0xae87(%rip), %eax      # 0x12668
jb 0x778f
movq 0x80(%rsp), %rbx
movq 0x88(%rsp), %r14
cmpq %r14, %rbx
je 0x7806
movq %rbx, %rdi
callq 0x4518
addq $0x8, %rbx
jmp 0x77f3
cmpq $0x0, 0xae52(%rip)      # 0x12660
je 0x7856
movq 0xa799(%rip), %rbx      # 0x11fb0
leaq 0x4bd4(%rip), %rsi      # 0xc3f2
movl $0x5, %edx
movq %rbx, %rdi
callq 0x4340
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x42d0
movsbl %al, %esi
movq 0xa767(%rip), %rdi      # 0x11fb0
callq 0x4040
movq %rax, %rdi
callq 0x41f0
leaq 0x80(%rsp), %rdi
callq 0x957a
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x52bb(%rip), %rdi      # 0xcb39
callq 0x41b0
leaq 0x52af(%rip), %rdi      # 0xcb39
callq 0x41b0
leaq 0x52a3(%rip), %rdi      # 0xcb39
callq 0x43e0
leaq 0x5297(%rip), %rdi      # 0xcb39
callq 0x43e0
leaq 0x495a(%rip), %rdi      # 0xc208
xorl %eax, %eax
callq 0x4410
jmp 0x7927
jmp 0x7927
movq %rax, %r15
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x792a
movq 0x10(%rsp), %rsi
incq %rsi
jmp 0x7910
jmp 0x78dc
jmp 0x78dc
jmp 0x7927
jmp 0x7941
movq %rax, %r15
jmp 0x78ff
movq %rax, %r15
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x78ff
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x42f0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x792a
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x42f0
jmp 0x792a
cmpq $0x0, (%rsp)
je 0x7927
callq 0x40a0
jmp 0x7927
jmp 0x7927
movq %rax, %r15
leaq 0x80(%rsp), %rdi
callq 0x957a
jmp 0x796d
movq %rdx, %r12
movq %rax, %r15
jmp 0x799f
movq %rax, %r15
jmp 0x796d
movq %rax, %r15
cmpl $0x0, (%r14)
jne 0x7952
movl %ebx, (%r14)
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x796d
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42f0
movq %r15, %rdi
callq 0x44c0
movq %rdx, %r12
movq %rax, %r15
cmpl $0x0, (%r14)
jne 0x7984
movl %ebx, (%r14)
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x799f
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42f0
cmpl $0x1, %r12d
jne 0x796d
movq %r15, %rdi
callq 0x4380
movq %rsp, %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x4490
movq 0xa5d6(%rip), %rax      # 0x11f98
addq $0x10, %rax
movq %rax, (%r14)
movq %r15, %rdi
callq 0x4100
movq 0x28(%rsp), %rax
movq (%rax), %rdi
callq 0x7fd2
movq %rsp, %rdi
callq 0x4480
callq 0x4460
jmp 0x7863
movq %rax, %r15
movq %rsp, %rdi
callq 0x4480
callq 0x4460
jmp 0x796d
movq %rax, %rdi
callq 0x9467