// File: /workspace/github_cpp_makefile_star2_O3/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, 0xb7af(%rip)      # 0x12650
xorl %eax, %eax
movb %al, 0xb7c7(%rip)       # 0x12670
movb %al, 0xb7c2(%rip)       # 0x12671
movq $0x0, 0x68(%rsp)
movb %al, 0xb7b4(%rip)       # 0x12672
movq $0x1, 0xb77f(%rip) # 0x12648
movq $0x0, 0xb78c(%rip) # 0x12660
callq 0x43c0
movl %eax, 0xb789(%rip)      # 0x12668
movq 0xb0da(%rip), %rax      # 0x11fc0
movl $0x0, (%rax)
leaq 0x549d(%rip), %rbx      # 0xc390
leaq 0xb4d6(%rip), %r14      # 0x123d0
leaq 0x53e7(%rip), %r13      # 0xc2e8
movq 0xb070(%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 0x715f
movb $0x1, %al
movslq (%r13,%rcx,4), %rcx
addq %r13, %rcx
jmpq *%rcx
movq (%r12), %rax
movq %rax, 0x78(%rsp)
movl %r15d, %eax
jmp 0x6f37
movq (%r12), %rax
movq %rax, 0x58(%rsp)
movb $0x1, %al
movq %rax, 0x60(%rsp)
movl %r15d, %eax
jmp 0x6f37
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 0x6f37
movb $0x1, 0xb6be(%rip)      # 0x12670
movl %r15d, %eax
jmp 0x6f37
movq (%r12), %rdi
callq 0x7a0a
movl %r15d, %eax
jmp 0x6f37
callq 0x77b0
movl %r15d, %eax
jmp 0x6f37
movq (%r12), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x4070
movq %rax, 0xb664(%rip)      # 0x12650
movl %r15d, %eax
jmp 0x6f37
movb $0x1, %al
movb $0x1, %cl
movq %rcx, 0x50(%rsp)
jmp 0x6f37
movb $0x1, 0xb669(%rip)      # 0x12672
movq (%r12), %rsi
movq %rsp, %rdi
leaq 0x80(%rsp), %rdx
callq 0x91f6
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 0x761a
movl (%r14), %ecx
testl %ecx, %ecx
je 0x710c
cmpl $0x22, %ecx
movq 0xaf15(%rip), %r12      # 0x11f78
jne 0x7116
jmp 0x7632
movq (%r12), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x4070
movq %rax, 0xb5db(%rip)      # 0x12660
movl %r15d, %eax
jmp 0x6f37
movq (%r12), %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x4070
incq %rax
movq %rax, 0xb5a1(%rip)      # 0x12648
movl %r15d, %eax
jmp 0x6f37
movq (%r12), %rsi
movq %rsp, %rdi
leaq 0x80(%rsp), %rdx
callq 0x91f6
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 0x7626
movl (%r14), %ecx
testl %ecx, %ecx
je 0x711e
cmpl $0x22, %ecx
movq 0xae73(%rip), %r12      # 0x11f78
jne 0x7128
jmp 0x763e
movl %ebx, (%r14)
movq 0xae62(%rip), %r12      # 0x11f78
movl %eax, 0xb550(%rip)      # 0x1266c
jmp 0x712e
movl %ebx, (%r14)
movq 0xae50(%rip), %r12      # 0x11f78
movl %eax, 0xb53a(%rip)      # 0x12668
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x7149
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42f0
movl %r15d, %eax
leaq 0x523d(%rip), %rbx      # 0xc390
leaq 0xb276(%rip), %r14      # 0x123d0
jmp 0x6f37
cmpl $-0x1, %eax
jne 0x7265
cmpq $0x0, 0xb4d8(%rip)      # 0x12648
jne 0x717d
movq $0x1, 0xb4cb(%rip) # 0x12648
movl 0xb4e5(%rip), %eax      # 0x12668
testl %eax, %eax
movq 0x78(%rsp), %rbx
jne 0x719b
movl $0x1, 0xb4d2(%rip)      # 0x12668
movl $0x1, %eax
movl %eax, %esi
leaq 0x80(%rsp), %rdi
movq %rsp, %rdx
callq 0x923e
leaq 0xb4c4(%rip), %rdi      # 0x12678
callq 0x4f0e
testq %rbx, %rbx
je 0x71cd
leaq 0xb4b3(%rip), %rdi      # 0x12678
movq %rbx, %rsi
callq 0x4a80
testb $0x1, 0x70(%rsp)
je 0x7277
leaq 0xb499(%rip), %rsi      # 0x12678
movq %rsp, %rdi
callq 0x49e2
movq %rsp, %rdi
movq 0x68(%rsp), %rsi
callq 0x4cfe
leaq 0x30(%rsp), %rdi
movq %rsp, %rsi
callq 0x4f56
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0xad9e(%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 0x72f3
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x42f0
jmp 0x72f3
movq 0x28(%rsp), %rax
movq (%rax), %rdi
callq 0x7d84
jmp 0x7606
testb $0x1, 0x60(%rsp)
je 0x7312
movq %rsp, %rdi
movq 0x58(%rsp), %rsi
callq 0x4a3a
leaq 0xb3e2(%rip), %rdi      # 0x12678
movq %rsp, %rsi
callq 0x4d86
leaq 0x5103(%rip), %rcx      # 0xc3a8
leaq 0x5101(%rip), %rsi      # 0xc3ad
testb %al, %al
cmovneq %rcx, %rsi
movzbl %al, %edx
xorq $0x5, %rdx
movq 0xacf0(%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 0xacca(%rip), %rdi      # 0x11fb0
callq 0x4040
movq %rax, %rdi
callq 0x41f0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x75f9
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x42f0
jmp 0x75f9
testb $0x1, %r15b
je 0x737e
movq 0xacd1(%rip), %rdi      # 0x11ff0
leaq 0x508d(%rip), %rsi      # 0xc3b3
movl $0x9, %edx
callq 0x4340
movl 0xb332(%rip), %esi      # 0x12668
movq 0xacb3(%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 0x8427
jmp 0x75f9
movq 0xac6b(%rip), %rdi      # 0x11ff0
leaq 0x5031(%rip), %rsi      # 0xc3bd
movl $0x11, %edx
callq 0x4340
movq 0xb2b3(%rip), %rsi      # 0x12650
movq 0xac4c(%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 0xac16(%rip), %rdi      # 0x11ff0
leaq 0x4fee(%rip), %rsi      # 0xc3cf
movl $0x11, %edx
callq 0x4340
leaq 0xb286(%rip), %rsi      # 0x12678
movq %rsp, %rdi
callq 0x4f56
movq (%rsp), %rsi
movq 0x8(%rsp), %rdx
movq 0xabe6(%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 0x7454
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42f0
cmpb $0x1, 0xb216(%rip)      # 0x12671
jne 0x74b9
movq 0xab8c(%rip), %rdi      # 0x11ff0
leaq 0x4f76(%rip), %rsi      # 0xc3e1
movl $0x10, %edx
callq 0x4340
movq 0xb184(%rip), %rsi      # 0x12600
movq 0xb185(%rip), %rdx      # 0x12608
movq 0xab66(%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 0xab30(%rip), %rdi      # 0x11ff0
leaq 0x4eec(%rip), %rsi      # 0xc3b3
movl $0x9, %edx
callq 0x4340
movl 0xb191(%rip), %esi      # 0x12668
movq 0xab12(%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, 0xb14c(%rip)      # 0x12668
je 0x7586
leaq 0x15b2(%rip), %rbx      # 0x8ad7
movq %rsp, %r14
leaq 0x30(%rsp), %r15
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x92ac
movl 0x30(%rsp), %esi
movq 0x80(%rsp), %rax
movq 0x88(%rsp), %r12
movq %r12, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
cmpq %rsi, %rdx
jbe 0x764a
cmpq $0x0, (%rax,%rsi,8)
jne 0x76c1
movq (%rsp), %rcx
movq %rcx, (%rax,%rsi,8)
leal 0x1(%rsi), %eax
movl %eax, 0x30(%rsp)
cmpl 0xb0e6(%rip), %eax      # 0x12668
jb 0x752d
jmp 0x758e
movq 0x88(%rsp), %r12
movq 0x80(%rsp), %rbx
cmpq %r12, %rbx
je 0x75a9
movq %rbx, %rdi
callq 0x4518
addq $0x8, %rbx
jmp 0x7596
cmpq $0x0, 0xb0af(%rip)      # 0x12660
je 0x75f9
movq 0xa9f6(%rip), %rbx      # 0x11fb0
leaq 0x4e31(%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 0xa9c4(%rip), %rdi      # 0x11fb0
callq 0x4040
movq %rax, %rdi
callq 0x41f0
leaq 0x80(%rsp), %rdi
callq 0x932a
xorl %eax, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5518(%rip), %rdi      # 0xcb39
callq 0x41b0
leaq 0x550c(%rip), %rdi      # 0xcb39
callq 0x41b0
leaq 0x5500(%rip), %rdi      # 0xcb39
callq 0x43e0
leaq 0x54f4(%rip), %rdi      # 0xcb39
callq 0x43e0
leaq 0x4bb7(%rip), %rdi      # 0xc208
xorl %eax, %eax
callq 0x4410
jmp 0x76ca
jmp 0x76ca
movq %rax, %r15
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x76cd
movq 0x10(%rsp), %rsi
incq %rsi
jmp 0x76b3
jmp 0x767f
jmp 0x767f
jmp 0x76ca
jmp 0x76e4
movq %rax, %r15
jmp 0x76a2
movq %rax, %r15
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x76a2
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x42f0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x76cd
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x42f0
jmp 0x76cd
cmpq $0x0, (%rsp)
je 0x76ca
callq 0x40a0
jmp 0x76ca
jmp 0x76ca
movq %rax, %r15
leaq 0x80(%rsp), %rdi
callq 0x932a
jmp 0x7710
movq %rdx, %r12
movq %rax, %r15
jmp 0x7742
movq %rax, %r15
jmp 0x7710
movq %rax, %r15
cmpl $0x0, (%r14)
jne 0x76f5
movl %ebx, (%r14)
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x7710
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42f0
movq %r15, %rdi
callq 0x44c0
movq %rdx, %r12
movq %rax, %r15
cmpl $0x0, (%r14)
jne 0x7727
movl %ebx, (%r14)
movq (%rsp), %rdi
leaq 0x10(%rsp), %rax
cmpq %rax, %rdi
je 0x7742
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x42f0
cmpl $0x1, %r12d
jne 0x7710
movq %r15, %rdi
callq 0x4380
movq %rsp, %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x4490
movq 0xa833(%rip), %rax      # 0x11f98
addq $0x10, %rax
movq %rax, (%r14)
movq %r15, %rdi
callq 0x4100
movq 0x28(%rsp), %rax
movq (%rax), %rdi
callq 0x7d84
movq %rsp, %rdi
callq 0x4480
callq 0x4460
jmp 0x7606
movq %rax, %r15
movq %rsp, %rdi
callq 0x4480
callq 0x4460
jmp 0x7710
movq %rax, %rdi
callq 0x9233