// File: /workspace/github_cpp_makefile_star2_O2/pokorj54[P]Pathfinder-utilities/src/SGsearch.cpp
// Function: SGCategory::TryAllCombinations()
void SGCategory::TryAllCombinations()
{
    int diceDelimiters[maxDiceValue+1];
    diceDelimiters[maxDiceValue] = 0;
    diceDelimiters[0] = noDices;
    diceDelimiters[1] = -1;
    int * dices = new int[noDices];
    for(int k = 2; k < maxDiceValue; ++k)
    {
        diceDelimiters[k] = 0;
    }
    while(diceDelimiters[maxDiceValue-1] < noDices)
    {
        int64_t permutations = factorial(noDices);
        if(diceDelimiters[1] < noDices)
        {
            diceDelimiters[1] += 1;
        }
        else
        {
            int l = 1;
            while(diceDelimiters[l] == noDices)
                ++l;
            int m = diceDelimiters[l] + 1;
            for(;l >= 1; --l)
                diceDelimiters[l] = m;
        }
        int currentPosition = 0;
        for(int n = 1; n <= maxDiceValue; ++n)
        {
            int difference = diceDelimiters[n-1] - diceDelimiters[n];
            permutations /= factorial(difference);
            for(int o = 0; o < difference; ++o)
            {
                dices[currentPosition] = n;
                ++currentPosition;
            }
        }
        string tmp = GetDesiredExpression(spellLevel, dices, noDices);
        if(showIntermedietResults)
        {
            cout << spellLevel << '\t';
            for(int p = 0; p < noDices; ++p)
            {
                cout << dices[p] << " ";
            }
            
            cout << '\t' << tmp << endl;
        }
        if(tmp != "")
        {
            successfulVariations += permutations;
            ++successfulCombinations;
            if(dices[noDices-1] <= limitedDiceValue)
            {
                successfulLimitedVariations += permutations;
                ++successfulLimitedCombinations;
            }
        }
    }
    delete [] dices;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
andl $0x0, 0x20(%rsp)
movslq (%rdi), %r13
orl $-0x1, 0x4(%rsp)
leaq (,%r13,4), %rax
testq %r13, %r13
movl %r13d, (%rsp)
pushq $-0x1
popq %rdi
cmovnsq %rax, %rdi
callq 0x2030
movq %rax, %r14
pushq $0x2
popq %rax
cmpq $0x8, %rax
je 0x340e
andl $0x0, (%rsp,%rax,4)
incq %rax
jmp 0x33ff
leaq 0xd5b(%rip), %r12       # 0x4170
leaq 0x28(%rsp), %r15
cmpl %r13d, 0x1c(%rsp)
jge 0x34f8
movl 0x4(%rsp), %eax
cmpl %r13d, %eax
jge 0x34d7
incl %eax
movl %eax, 0x4(%rsp)
movslq %r13d, %rax
movq (%r12,%rax,8), %rbp
xorl %esi, %esi
pushq $0x1
popq %rcx
cmpq $0x9, %rcx
je 0x348a
movslq -0x4(%rsp,%rcx,4), %rdx
movslq (%rsp,%rcx,4), %rax
subq %rax, %rdx
movq (%r12,%rdx,8), %rdi
movslq %esi, %rax
testl %edx, %edx
movl $0x0, %esi
cmovgl %edx, %esi
addl %eax, %esi
movslq %esi, %rdx
cmpq %rax, %rdx
je 0x347a
movl %ecx, (%r14,%rax,4)
incq %rax
jmp 0x346c
movq %rbp, %rax
cqto
idivq %rdi
incq %rcx
movq %rax, %rbp
jmp 0x3444
movl 0x4(%rbx), %esi
movq %r15, %rdi
movq %r14, %rdx
movl %r13d, %ecx
callq 0x2fa8
movq %r15, %rdi
leaq 0xd96(%rip), %rsi       # 0x423b
callq 0x32ba
testb %al, %al
je 0x34c7
addq %rbp, 0x10(%rbx)
incl 0x8(%rbx)
movslq (%rbx), %rax
cmpl $0x6, -0x4(%r14,%rax,4)
jg 0x34c7
addq %rbp, 0x18(%rbx)
incl 0xc(%rbx)
movq %r15, %rdi
callq 0x2090
movl (%rbx), %r13d
jmp 0x341a
xorl %eax, %eax
movl 0x4(%rsp,%rax,4), %ecx
incq %rax
cmpl %r13d, %ecx
je 0x34d9
incl %ecx
testq %rax, %rax
jle 0x3438
movl %ecx, (%rsp,%rax,4)
decq %rax
jmp 0x34e7
movq %r14, %rdi
callq 0x2160
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x2090
movq %rbx, %rdi
callq 0x2210