// File: chuckwolber[P]Cube/order/cli.cpp
// Function: calculateOrder(unsigned int)
void calculateOrder(const unsigned int threadNum) {
    Algorithm algorithm(initialAlgorithm);
    std::vector<Turn> turnSet;
    Cube c(CubieColor::RED, 3);
    unsigned int order;
    unsigned long long int algorithmCount = threadNum;

    algorithm += threadNum;
    while (algorithmCount < algorithmCountMax) {
        if (algorithmCount % skip_nth != 0)
            goto bypass;
        if (keepDuplicates || !algorithm.isRedundant()) {
            order = 0;
            turnSet = algorithm.getAlgorithm();
            do {
                ++order;
                c.performAlgorithm(turnSet);
            } while (!c.isSolved());

            printResult(threadNum, algorithmCount, turnSet, order);
            if (skipFoundOrders && !numSkipFoundOrders)
                return;
        }
        
        bypass:
        algorithmCount += numThreads;
        algorithm += numThreads;

        if (heartbeat > 0 && algorithmCount % heartbeat == 0) {
            coutMutex.lock();
            std::cout << "HB:" << algorithmCount << std::endl;
            coutMutex.unlock();
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movl %edi, -0x4(%rbp)
leaq 0x1d573(%rip), %rsi     # 0x2b728
leaq -0x30(%rbp), %rdi
callq 0x4bb0
leaq -0x48(%rbp), %rdi
callq 0x74e0
leaq -0xc0(%rbp), %rdi
movl $0x72, %esi
movl $0x3, %edx
callq 0xa170
jmp 0xe1df
movl -0x4(%rbp), %eax
movq %rax, -0xd8(%rbp)
movl -0x4(%rbp), %eax
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x5010
jmp 0xe1f9
jmp 0xe1fb
movq -0xd8(%rbp), %rax
cmpq 0x1d4f7(%rip), %rax     # 0x2b700
jae 0xe40d
movq -0xd8(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq 0x1d4d7(%rip)           # 0x2b6f8
cmpq $0x0, %rdx
je 0xe266
jmp 0xe34b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
jmp 0xe43e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xc8(%rbp)
movl %eax, -0xcc(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xa6a0
jmp 0xe43e
testb $0x1, 0x1d4b3(%rip)     # 0x2b720
jne 0xe290
leaq -0x30(%rbp), %rdi
callq 0x58f0
movb %al, -0xf5(%rbp)
jmp 0xe280
movb -0xf5(%rbp), %al
testb $0x1, %al
jne 0xe349
jmp 0xe290
movl $0x0, -0xd0(%rbp)
leaq -0xf0(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x5820
jmp 0xe2ac
leaq -0x48(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0xfba0
leaq -0xf0(%rbp), %rdi
callq 0x6d60
movl -0xd0(%rbp), %eax
incl %eax
movl %eax, -0xd0(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0xa9a0
jmp 0xe2e8
jmp 0xe2ea
leaq -0xc0(%rbp), %rdi
callq 0xa830
movb %al, -0xf6(%rbp)
jmp 0xe2fe
movb -0xf6(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0xe2c8
movl -0x4(%rbp), %edi
movq -0xd8(%rbp), %rsi
movl -0xd0(%rbp), %ecx
leaq -0x48(%rbp), %rdx
callq 0xe8d0
jmp 0xe325
testb $0x1, 0x1d3f5(%rip)     # 0x2b721
je 0xe347
cmpq $0x0, 0x1d3d2(%rip)     # 0x2b708
jne 0xe347
movl $0x1, -0xf4(%rbp)
jmp 0xe417
jmp 0xe349
jmp 0xe34b
movl 0x1d3c7(%rip), %eax     # 0x2b718
movl %eax, %ecx
movq -0xd8(%rbp), %rax
addq %rcx, %rax
movq %rax, -0xd8(%rbp)
movl 0x1d3ae(%rip), %eax     # 0x2b718
movl %eax, %esi
leaq -0x30(%rbp), %rdi
callq 0x5010
jmp 0xe377
cmpq $0x0, 0x1d391(%rip)     # 0x2b710
jbe 0xe408
movq -0xd8(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %edx
divq 0x1d379(%rip)           # 0x2b710
cmpq $0x0, %rdx
jne 0xe408
leaq 0x1d2e4(%rip), %rdi     # 0x2b688
callq 0xfbd0
jmp 0xe3ab
movq 0x1cbfe(%rip), %rdi     # 0x2afb0
leaq 0xe6ea(%rip), %rsi      # 0x1caa3
callq 0x4370
movq %rax, -0x100(%rbp)
jmp 0xe3c7
movq -0x100(%rbp), %rdi
movq -0xd8(%rbp), %rsi
callq 0x4340
movq %rax, -0x108(%rbp)
jmp 0xe3e3
movq -0x108(%rbp), %rdi
movq 0x1cb6f(%rip), %rsi     # 0x2af60
callq 0x43b0
jmp 0xe3f8
leaq 0x1d289(%rip), %rdi     # 0x2b688
callq 0xfc00
jmp 0xe406
jmp 0xe408
jmp 0xe1fb
movl $0x0, -0xf4(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xa6a0
leaq -0x48(%rbp), %rdi
callq 0x6d60
leaq -0x30(%rbp), %rdi
callq 0x7010
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0x6d60
leaq -0x30(%rbp), %rdi
callq 0x7010
movq -0xc8(%rbp), %rdi
callq 0x45e0
nopl (%rax)