// File: /workspace/github_cpp_makefile_star2_O3/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), %r12
leaq (,%r12,4), %rax
testq %r12, %r12
movl %r12d, (%rsp)
movl $0xffffffff, 0x4(%rsp)  # imm = 0xFFFFFFFF
movq $-0x1, %rdi
cmovnsq %rax, %rdi
callq 0x2030
movq %rax, %r14
pxor %xmm0, %xmm0
movdqu %xmm0, 0x8(%rsp)
movq $0x0, 0x18(%rsp)
testq %r12, %r12
jle 0x3f4d
leaq 0x1483(%rip), %rbp      # 0x51d0
leaq 0x28(%rsp), %r15
movdqa 0x1436(%rip), %xmm5     # 0x5190
movdqa 0x143e(%rip), %xmm6     # 0x51a0
movdqa 0x1446(%rip), %xmm7     # 0x51b0
pcmpeqd %xmm8, %xmm8
movl %r12d, %ecx
movl 0x4(%rsp), %eax
cmpl %ecx, %eax
jge 0x3d85
incl %eax
movl %eax, 0x4(%rsp)
jmp 0x3e80
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 0x3d96
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 0x3e0e
movl %esi, (%rdx)
pxor %xmm8, %xmm2
pextrw $0x4, %xmm2, %r8d
testb $0x1, %r8b
je 0x3e22
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 0x3e5c
movl %esi, -0x8(%rdx)
pextrw $0x4, %xmm1, %r8d
testb $0x1, %r8b
je 0x3e6b
movl %esi, -0xc(%rdx)
addq $0x4, %rdi
addq $-0x10, %rdx
cmpq %rdi, %rax
jne 0x3dca
movl (%rsp), %r12d
movslq %ecx, %rax
movq (%rbp,%rax,8), %r13
xorl %esi, %esi
movl $0x1, %edi
movl %r12d, %r8d
movl %r8d, %r9d
movl (%rsp,%rdi,4), %r8d
subl %r8d, %r9d
movslq %r9d, %r10
movq %r13, %rax
cqto
idivq (%rbp,%r10,8)
movq %rax, %r13
testl %r10d, %r10d
jle 0x3ecd
movslq %esi, %rax
leaq (%r14,%rax,4), %rax
movl %r9d, %edx
xorl %r9d, %r9d
movl %edi, (%rax,%r9,4)
incq %r9
cmpl %r9d, %edx
jne 0x3ebe
addl %r9d, %esi
incq %rdi
cmpq $0x9, %rdi
jne 0x3e92
movl 0x4(%rbx), %esi
movq %r15, %rdi
movq %r14, %rdx
callq 0x3740
movq %r15, %rdi
leaq 0x13ad(%rip), %rsi      # 0x529b
callq 0x2070
testl %eax, %eax
je 0x3f10
addq %r13, 0x10(%rbx)
incl 0x8(%rbx)
movslq (%rbx), %rax
cmpl $0x6, -0x4(%r14,%rax,4)
jg 0x3f10
addq %r13, 0x18(%rbx)
incl 0xc(%rbx)
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x3f24
callq 0x2120
movl (%rbx), %ecx
cmpl %ecx, 0x1c(%rsp)
movdqa 0x125e(%rip), %xmm5     # 0x5190
movdqa 0x1266(%rip), %xmm6     # 0x51a0
movdqa 0x126e(%rip), %xmm7     # 0x51b0
pcmpeqd %xmm8, %xmm8
jl 0x3d72
movq %r14, %rdi
callq 0x21a0
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq