// File: 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:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
movq %rax, 0x18(%rsp)
movl $0x0, 0xa0(%rsp)
movl (%rax), %ecx
movl %ecx, 0x80(%rsp)
movl $0xffffffff, 0x84(%rsp) # imm = 0xFFFFFFFF
movslq (%rax), %rax
movl $0x4, %ecx
mulq %rcx
movq %rax, %rdi
seto %cl
movq $-0x1, %rax
testb $0x1, %cl
cmovneq %rax, %rdi
callq 0x2030
movq %rax, 0x78(%rsp)
movl $0x2, 0x74(%rsp)
cmpl $0x8, 0x74(%rsp)
jge 0x4960
movslq 0x74(%rsp), %rax
movl $0x0, 0x80(%rsp,%rax,4)
movl 0x74(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x74(%rsp)
jmp 0x493c
jmp 0x4962
movq 0x18(%rsp), %rcx
movl 0x9c(%rsp), %eax
cmpl (%rcx), %eax
jge 0x4b65
movq 0x18(%rsp), %rax
movl (%rax), %edi
callq 0x4890
movq 0x18(%rsp), %rcx
movq %rax, 0x68(%rsp)
movl 0x84(%rsp), %eax
cmpl (%rcx), %eax
jge 0x49aa
movl 0x84(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x84(%rsp)
jmp 0x4a0d
movl $0x1, 0x64(%rsp)
movq 0x18(%rsp), %rcx
movslq 0x64(%rsp), %rax
movl 0x80(%rsp,%rax,4), %eax
cmpl (%rcx), %eax
jne 0x49d4
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x49b2
movslq 0x64(%rsp), %rax
movl 0x80(%rsp,%rax,4), %eax
addl $0x1, %eax
movl %eax, 0x60(%rsp)
cmpl $0x1, 0x64(%rsp)
jl 0x4a0b
movl 0x60(%rsp), %ecx
movslq 0x64(%rsp), %rax
movl %ecx, 0x80(%rsp,%rax,4)
movl 0x64(%rsp), %eax
addl $-0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x49e7
jmp 0x4a0d
movl $0x0, 0x5c(%rsp)
movl $0x1, 0x58(%rsp)
cmpl $0x8, 0x58(%rsp)
jg 0x4ab0
movl 0x58(%rsp), %eax
subl $0x1, %eax
cltq
movl 0x80(%rsp,%rax,4), %eax
movslq 0x58(%rsp), %rcx
subl 0x80(%rsp,%rcx,4), %eax
movl %eax, 0x54(%rsp)
movl 0x54(%rsp), %edi
callq 0x4890
movq %rax, %rcx
movq 0x68(%rsp), %rax
cqto
idivq %rcx
movq %rax, 0x68(%rsp)
movl $0x0, 0x50(%rsp)
movl 0x50(%rsp), %eax
cmpl 0x54(%rsp), %eax
jge 0x4a9e
movl 0x58(%rsp), %edx
movq 0x78(%rsp), %rax
movslq 0x5c(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
movl 0x5c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x5c(%rsp)
movl 0x50(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x50(%rsp)
jmp 0x4a6b
jmp 0x4aa0
movl 0x58(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x58(%rsp)
jmp 0x4a1d
movq 0x18(%rsp), %rax
movl (%rax), %ecx
movl 0x4(%rax), %esi
movq 0x78(%rsp), %rdx
leaq 0x30(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x3fb0
movq 0x8(%rsp), %rdi
leaq 0x1761(%rip), %rsi      # 0x623b
callq 0x45a0
movb %al, 0x17(%rsp)
jmp 0x4ae5
movb 0x17(%rsp), %al
testb $0x1, %al
jne 0x4aef
jmp 0x4b56
movq 0x18(%rsp), %rcx
movq 0x68(%rsp), %rax
addq 0x10(%rcx), %rax
movq %rax, 0x10(%rcx)
movl 0x8(%rcx), %eax
addl $0x1, %eax
movl %eax, 0x8(%rcx)
movq 0x78(%rsp), %rax
movl (%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
cmpl $0x6, (%rax,%rcx,4)
jg 0x4b54
movq 0x18(%rsp), %rax
movq 0x68(%rsp), %rcx
addq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
movl 0xc(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xc(%rax)
jmp 0x4b54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x28(%rsp)
movl %eax, 0x24(%rsp)
leaq 0x30(%rsp), %rdi
callq 0x2100
jmp 0x4b85
jmp 0x4b56
leaq 0x30(%rsp), %rdi
callq 0x2100
jmp 0x4962
movq 0x78(%rsp), %rax
movq %rax, (%rsp)
cmpq $0x0, %rax
je 0x4b7d
movq (%rsp), %rdi
callq 0x21c0
addq $0xb8, %rsp
retq
movq 0x28(%rsp), %rdi
callq 0x2270
nop