// File: /workspace/github_cpp_makefile_star2_O1/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
movl $0x0, 0x20(%rsp)
movslq (%rdi), %rax
leaq (,%rax,4), %rcx
testq %rax, %rax
movl %eax, (%rsp)
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0x2030
movq %rax, %r14
pxor %xmm0, %xmm0
movdqu %xmm0, 0x8(%rsp)
movq $0x0, 0x18(%rsp)
movl (%rbx), %ecx
cmpl %ecx, 0x1c(%rsp)
jge 0x405b
leaq 0x136d(%rip), %rbp      # 0x51d0
leaq 0x28(%rsp), %r15
leaq 0x142c(%rip), %r12      # 0x529b
movdqa 0x1319(%rip), %xmm5     # 0x5190
movdqa 0x1321(%rip), %xmm6     # 0x51a0
movdqa 0x1329(%rip), %xmm7     # 0x51b0
pcmpeqd %xmm8, %xmm8
movl 0x4(%rsp), %eax
cmpl %ecx, %eax
jge 0x3e9f
incl %eax
movl %eax, 0x4(%rsp)
jmp 0x3f96
movl $0x1, %r8d
movl $0x4, %r9d
leaq 0x4(%rsp), %r10
movq %r8, %rdi
movq %r9, %rax
movq %r10, %rdx
movl (%rsp,%r8,4), %esi
incq %r8
incq %r9
addq $0x4, %r10
cmpl %ecx, %esi
je 0x3eb0
incl %esi
decq %rdi
movq %rdi, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
andq $-0x4, %rax
pxor %xmm7, %xmm0
xorl %edi, %edi
movq %rdi, %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
movdqa %xmm1, %xmm2
por %xmm6, %xmm2
pxor %xmm7, %xmm2
movdqa %xmm2, %xmm3
pcmpgtd %xmm0, %xmm3
pcmpeqd %xmm0, %xmm2
pshufd $0xf5, %xmm2, %xmm4     # xmm4 = xmm2[1,1,3,3]
pand %xmm3, %xmm4
pshufd $0xf5, %xmm3, %xmm2     # xmm2 = xmm3[1,1,3,3]
por %xmm4, %xmm2
movd %xmm2, %r8d
notl %r8d
testb $0x1, %r8b
je 0x3f28
movl %esi, (%rdx)
pxor %xmm8, %xmm2
pextrw $0x4, %xmm2, %r8d
testb $0x1, %r8b
je 0x3f3c
movl %esi, -0x4(%rdx)
por %xmm5, %xmm1
pxor %xmm7, %xmm1
movdqa %xmm1, %xmm2
pcmpgtd %xmm0, %xmm2
pcmpeqd %xmm0, %xmm1
pshufd $0xf5, %xmm1, %xmm3     # xmm3 = xmm1[1,1,3,3]
pand %xmm2, %xmm3
pshufd $0xf5, %xmm2, %xmm1     # xmm1 = xmm2[1,1,3,3]
por %xmm3, %xmm1
pxor %xmm8, %xmm1
pextrw $0x0, %xmm1, %r8d
testb $0x1, %r8b
je 0x3f76
movl %esi, -0x8(%rdx)
pextrw $0x4, %xmm1, %r8d
testb $0x1, %r8b
je 0x3f85
movl %esi, -0xc(%rdx)
addq $0x4, %rdi
addq $-0x10, %rdx
cmpq %rdi, %rax
jne 0x3ee4
movslq %ecx, %rax
movq (%rbp,%rax,8), %r13
xorl %esi, %esi
movl $0x1, %edi
movslq -0x4(%rsp,%rdi,4), %r8
movslq (%rsp,%rdi,4), %rax
subq %rax, %r8
movq %r13, %rax
cqto
idivq (%rbp,%r8,8)
movq %rax, %r13
testl %r8d, %r8d
jle 0x3fdf
movslq %esi, %rax
leaq (%r14,%rax,4), %rax
movl %r8d, %edx
xorl %r8d, %r8d
movl %edi, (%rax,%r8,4)
incq %r8
cmpl %r8d, %edx
jne 0x3fd0
addl %r8d, %esi
incq %rdi
cmpq $0x9, %rdi
jne 0x3fa5
movl 0x4(%rbx), %esi
movq %r15, %rdi
movq %r14, %rdx
callq 0x385f
movq %r15, %rdi
movq %r12, %rsi
callq 0x2070
testl %eax, %eax
je 0x401e
addq %r13, 0x10(%rbx)
incl 0x8(%rbx)
movslq (%rbx), %rax
cmpl $0x6, -0x4(%r14,%rax,4)
jg 0x401e
addq %r13, 0x18(%rbx)
incl 0xc(%rbx)
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x4032
callq 0x2120
movl (%rbx), %ecx
cmpl %ecx, 0x1c(%rsp)
movdqa 0x1150(%rip), %xmm5     # 0x5190
movdqa 0x1158(%rip), %xmm6     # 0x51a0
movdqa 0x1160(%rip), %xmm7     # 0x51b0
pcmpeqd %xmm8, %xmm8
jl 0x3e8c
movq %r14, %rdi
callq 0x21a0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq