// File: /workspace/github_cpp_makefile_star2_O2/pokorj54[P]Pathfinder-utilities/src/sacredGeometry.cpp
// Function: CombineExpressions[abi:cxx11](int, ExprAndValue*, int, int)
string CombineExpressions(int spellLevel, ExprAndValue * exprs, int size, int originalSize)
{
    if(size == 1)
    {
        for(int i : PRIMECONSTANTS[spellLevel - 1])
        {
            if((double)i == exprs[0].value.ToDouble())
            {
                return exprs[0].expression;
            }
        }
    }
    for(int i = 0; i < size; ++i)
    {
        ExprAndValue e1 = exprs[i];
        exprs[i] = exprs[size-1];
        for(int j = 0; j < size - 1; ++j)
        {
            ExprAndValue e2 = exprs[j];
            exprs[j] = exprs[size-2];
            string tmp;
            if(e1.pHighIndex < e2.pLowIndex && (e1.canSubstract || e2.canSubstract))
            {
                exprs[size-2] = e1.Combine(e2, Add, "+",e1.canSubstract && e2.canSubstract, true, 2*originalSize-size);
                exprs[size-2].pLowIndex = e1.pLowIndex;
                exprs[size-2].pHighIndex = e1.pHighIndex;
                tmp = CombineExpressions(spellLevel, exprs, size-1, originalSize);
                if(tmp != "")
                {
                    return tmp;
                }
            }
            if(e1.mHighIndex < e2.mLowIndex && (e1.canDivide || e2.canDivide) && (e1.value != Fraction(2) || e2.value != Fraction(2)) && (e1.value != Fraction(0) || e2.value != Fraction(0))) //2*2 == 2+2, 0*0=0+0
            {
                exprs[size-2] = e1.Combine(e2, Multiply, "*", true, e1.canDivide && e2.canDivide, 2*originalSize-size);
                exprs[size-2].mLowIndex = e1.mLowIndex;
                exprs[size-2].mHighIndex = e1.mHighIndex;
                tmp = CombineExpressions(spellLevel, exprs, size-1, originalSize);
                if(tmp != "")
                {
                    return tmp;
                }
            }
            exprs[size-2] = e1.Combine(e2, Subtract, "-", false, true, 2*originalSize-size);
            if(e2.canSubstract && exprs[size-2].value >= Fraction(0) && e1.value != exprs[size-2].value)//no point of using negative numbers, we already added 0
            {
                tmp = CombineExpressions(spellLevel, exprs, size-1, originalSize);
                if(tmp != "")
                {
                    return tmp;
                }
            }
            if(e2.canDivide && e2.value != Fraction(1) && e2.value != Fraction(0) && e1.value != Fraction(0) && (e1.value != Fraction(4) || e2.value != Fraction(2))) //we already multiplied by zero and substracted 2 from 4
            {
                exprs[size-2] = e1.Combine(e2, Divide, "/", true, false, 2*originalSize-size);
                tmp = CombineExpressions(spellLevel, exprs, size-1, originalSize);
                if(tmp != "")
                {
                    return tmp;
                }
            }
            exprs[size-2] = exprs[j];
            exprs[j] = e2;
        }
        exprs[size-1] = exprs[i];
        exprs[i] = e1;
    }
    return "";
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %r8, 0x28(%rsp)
movq %rdx, 0x8(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, %rbx
movq %rcx, %r12
cmpl $0x1, %ecx
jne 0x2891
movq 0x20(%rsp), %rax
decl %eax
cltq
imulq $0xc, %rax, %rax
leaq 0x18a5(%rip), %r14      # 0x40f0
addq %rax, %r14
xorl %r15d, %r15d
cmpq $0xc, %r15
je 0x2891
cvtsi2sdl (%r14,%r15), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x8(%rsp), %rdi
callq 0x2490
addq $0x4, %r15
ucomisd 0x18(%rsp), %xmm0
jne 0x2851
jp 0x2851
movq 0x8(%rsp), %rsi
addq $0x8, %rsi
movq %rbx, %rdi
callq 0x2180
jmp 0x2f21
leal -0x1(%r12), %edx
movslq %edx, %rsi
movq %rsi, %rax
shlq $0x6, %rax
movq 0x8(%rsp), %rcx
addq %rcx, %rax
movq %rax, 0x38(%rsp)
movslq %r12d, %rax
shlq $0x6, %rax
leaq (%rcx,%rax), %rdi
movq %rdi, 0x40(%rsp)
leaq (%rcx,%rax), %r15
addq $-0x80, %r15
leaq 0x10(%rbx), %rax
movq %rax, 0x108(%rsp)
movq 0x28(%rsp), %rax
addl %eax, %eax
subl %r12d, %eax
movq %rax, 0x18(%rsp)
xorl %eax, %eax
movq %rsi, 0xe8(%rsp)
testl %esi, %esi
movl $0x0, %ecx
movl %edx, 0x14(%rsp)
cmovgl %edx, %ecx
movq %rcx, 0x110(%rsp)
testl %r12d, %r12d
cmovlel %eax, %r12d
movq %r12, 0xf0(%rsp)
leaq 0x128(%rsp), %r12
cmpq 0xf0(%rsp), %rax
je 0x2f0a
movq %rax, 0x100(%rsp)
movq %rax, %r14
shlq $0x6, %r14
addq 0x8(%rsp), %r14
leaq 0x88(%rsp), %rdi
movq %r14, %rsi
callq 0x30e2
movq %r14, %rdi
movq 0x38(%rsp), %rsi
callq 0x3118
movq %r14, 0xf8(%rsp)
movq 0x8(%rsp), %r13
xorl %r14d, %r14d
cmpq %r14, 0x110(%rsp)
je 0x2eb1
leaq 0x48(%rsp), %rdi
movq %r13, %rsi
callq 0x30e2
movq %r13, %rdi
movq %r15, %rsi
callq 0x3118
movq 0x108(%rsp), %rax
movq %rax, (%rbx)
andq $0x0, 0x8(%rbx)
movb $0x0, 0x10(%rbx)
movl 0xb8(%rsp), %eax
cmpl 0x74(%rsp), %eax
jge 0x2a8e
cmpb $0x0, 0xb0(%rsp)
jne 0x29c6
cmpb $0x1, 0x70(%rsp)
jne 0x2a8e
leaq 0xc8(%rsp), %rbp
movq %rbp, %rdi
leaq 0x1784(%rip), %rsi      # 0x415c
leaq 0x30(%rsp), %rdx
callq 0x2070
movb 0x70(%rsp), %al
andb 0xb0(%rsp), %al
movzbl %al, %r9d
movq %r12, %rdi
leaq 0x88(%rsp), %rsi
leaq 0x48(%rsp), %rdx
leaq -0x4b8(%rip), %rcx      # 0x2550
movq %rbp, %r8
pushq 0x18(%rsp)
pushq $0x1
callq 0x3150
popq %rax
popq %rcx
movq %r15, %rdi
movq %r12, %rsi
callq 0x3282
leaq 0x130(%rsp), %rdi
callq 0x2090
movq %rbp, %rdi
callq 0x2090
movq 0xb4(%rsp), %rax
movq 0x40(%rsp), %rcx
movq %rax, -0x54(%rcx)
movq %r12, %rdi
movq 0x20(%rsp), %rsi
movq 0x8(%rsp), %rdx
movl 0x14(%rsp), %ecx
movq 0x28(%rsp), %r8
callq 0x280c
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2150
movq %r12, %rdi
callq 0x2090
movq %rbx, %rdi
leaq 0x17ba(%rip), %rsi      # 0x423b
callq 0x32ba
testb %al, %al
jne 0x2ed8
movl 0xc0(%rsp), %eax
cmpl 0x7c(%rsp), %eax
jge 0x2c1b
cmpb $0x0, 0xb1(%rsp)
jne 0x2ab4
cmpb $0x1, 0x71(%rsp)
jne 0x2c1b
movq %r12, %rdi
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x237c
leaq 0x88(%rsp), %rdi
movq %r12, %rsi
callq 0x2516
testb %al, %al
jne 0x2b01
leaq 0xc8(%rsp), %rbp
movq %rbp, %rdi
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x237c
leaq 0x48(%rsp), %rdi
movq %rbp, %rsi
callq 0x2516
testb %al, %al
je 0x2c1b
leaq 0x30(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
callq 0x237c
leaq 0x88(%rsp), %rdi
movq %rbp, %rsi
callq 0x2516
testb %al, %al
jne 0x2b51
leaq 0x118(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
callq 0x237c
leaq 0x48(%rsp), %rdi
movq %rbp, %rsi
callq 0x2516
testb %al, %al
je 0x2c1b
leaq 0xc8(%rsp), %rbp
movq %rbp, %rdi
leaq 0x15fb(%rip), %rsi      # 0x415e
leaq 0x30(%rsp), %rdx
callq 0x2070
movb 0x71(%rsp), %al
andb 0xb1(%rsp), %al
movzbl %al, %eax
movq %r12, %rdi
leaq 0x88(%rsp), %rsi
leaq 0x48(%rsp), %rdx
leaq -0x5d5(%rip), %rcx      # 0x25bd
movq %rbp, %r8
pushq $0x1
popq %r9
pushq 0x18(%rsp)
pushq %rax
callq 0x3150
popq %rax
popq %rcx
movq %r15, %rdi
movq %r12, %rsi
callq 0x3282
leaq 0x130(%rsp), %rdi
callq 0x2090
movq %rbp, %rdi
callq 0x2090
movq 0xbc(%rsp), %rax
movq 0x40(%rsp), %rcx
movq %rax, -0x4c(%rcx)
movq %r12, %rdi
movq 0x20(%rsp), %rsi
movq 0x8(%rsp), %rdx
movl 0x14(%rsp), %ecx
movq 0x28(%rsp), %r8
callq 0x280c
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2150
movq %r12, %rdi
callq 0x2090
movq %rbx, %rdi
leaq 0x162d(%rip), %rsi      # 0x423b
callq 0x32ba
testb %al, %al
jne 0x2ed8
leaq 0xc8(%rsp), %rbp
movq %rbp, %rdi
leaq 0x1533(%rip), %rsi      # 0x4160
leaq 0x30(%rsp), %rdx
callq 0x2070
movq %r12, %rdi
leaq 0x88(%rsp), %rsi
leaq 0x48(%rsp), %rdx
leaq -0x6c4(%rip), %rcx      # 0x258a
movq %rbp, %r8
xorl %r9d, %r9d
pushq 0x18(%rsp)
pushq $0x1
callq 0x3150
popq %rax
popq %rcx
movq %r15, %rdi
movq %r12, %rsi
callq 0x3282
leaq 0x130(%rsp), %rdi
callq 0x2090
movq %rbp, %rdi
callq 0x2090
cmpb $0x1, 0x70(%rsp)
jne 0x2cfd
movq %r12, %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
callq 0x237c
movq %r15, %rdi
movq %r12, %rsi
callq 0x250c
testb %al, %al
je 0x2cfd
leaq 0x88(%rsp), %rdi
movq %r15, %rsi
callq 0x2516
testb %al, %al
je 0x2cfd
movq %r12, %rdi
movq 0x20(%rsp), %rsi
movq 0x8(%rsp), %rdx
movl 0x14(%rsp), %ecx
movq 0x28(%rsp), %r8
callq 0x280c
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2150
movq %r12, %rdi
callq 0x2090
movq %rbx, %rdi
leaq 0x154b(%rip), %rsi      # 0x423b
callq 0x32ba
testb %al, %al
jne 0x2ed8
cmpb $0x1, 0x71(%rsp)
jne 0x2e7b
movq %r12, %rdi
pushq $0x1
popq %rdx
movl %edx, %esi
callq 0x237c
leaq 0x48(%rsp), %rdi
movq %r12, %rsi
callq 0x2516
testb %al, %al
je 0x2e7b
leaq 0xc8(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
callq 0x237c
leaq 0x48(%rsp), %rdi
movq %rbp, %rsi
callq 0x2516
testb %al, %al
je 0x2e7b
leaq 0x30(%rsp), %rbp
movq %rbp, %rdi
xorl %esi, %esi
pushq $0x1
popq %rdx
callq 0x237c
leaq 0x88(%rsp), %rdi
movq %rbp, %rsi
callq 0x2516
testb %al, %al
je 0x2e7b
leaq 0x118(%rsp), %rbp
movq %rbp, %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
callq 0x237c
leaq 0x88(%rsp), %rdi
movq %rbp, %rsi
callq 0x2516
testb %al, %al
jne 0x2dd3
leaq 0x120(%rsp), %rbp
movq %rbp, %rdi
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x237c
leaq 0x48(%rsp), %rdi
movq %rbp, %rsi
callq 0x2516
testb %al, %al
je 0x2e7b
leaq 0xc8(%rsp), %rbp
movq %rbp, %rdi
leaq 0x121f(%rip), %rsi      # 0x4004
leaq 0x30(%rsp), %rdx
callq 0x2070
movq %r12, %rdi
leaq 0x88(%rsp), %rsi
leaq 0x48(%rsp), %rdx
leaq -0x950(%rip), %rcx      # 0x24b6
movq %rbp, %r8
pushq $0x1
popq %r9
pushq 0x18(%rsp)
pushq $0x0
callq 0x3150
popq %rax
popq %rcx
movq %r15, %rdi
movq %r12, %rsi
callq 0x3282
leaq 0x130(%rsp), %rdi
callq 0x2090
movq %rbp, %rdi
callq 0x2090
movq %r12, %rdi
movq 0x20(%rsp), %rsi
movq 0x8(%rsp), %rdx
movl 0x14(%rsp), %ecx
movq 0x28(%rsp), %r8
callq 0x280c
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2150
movq %r12, %rdi
callq 0x2090
movq %rbx, %rdi
leaq 0x13c9(%rip), %rsi      # 0x423b
callq 0x32ba
testb %al, %al
jne 0x2ed8
movq %r15, %rdi
movq %r13, %rsi
callq 0x3118
movq %r13, %rdi
leaq 0x48(%rsp), %rsi
callq 0x3118
movq %rbx, %rdi
callq 0x2090
leaq 0x50(%rsp), %rdi
callq 0x2090
incq %r14
addq $0x40, %r13
jmp 0x2966
movq 0x38(%rsp), %rdi
movq 0xf8(%rsp), %r13
movq %r13, %rsi
callq 0x3118
movq %r13, %rdi
leaq 0x88(%rsp), %rsi
callq 0x3118
jmp 0x2ee2
leaq 0x50(%rsp), %rdi
callq 0x2090
leaq 0x90(%rsp), %rdi
callq 0x2090
movq 0x100(%rsp), %rax
incq %rax
cmpq 0xe8(%rsp), %r14
jge 0x2917
jmp 0x2f21
leaq 0x132a(%rip), %rsi      # 0x423b
leaq 0x88(%rsp), %rdx
movq %rbx, %rdi
callq 0x2070
movq %rbx, %rax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2f5e
jmp 0x2f7e
jmp 0x2f7e
jmp 0x2f7e
jmp 0x2f72
jmp 0x2f7e
jmp 0x2f7e
jmp 0x2f7e
jmp 0x2f7e
jmp 0x2f5e
jmp 0x2f7e
jmp 0x2f7e
jmp 0x2f7e
jmp 0x2f7e
jmp 0x2f5e
jmp 0x2f7e
jmp 0x2f7e
jmp 0x2f7e
jmp 0x2f7e
jmp 0x2f7e
movq %rax, %r14
leaq 0xc8(%rsp), %rdi
callq 0x2090
jmp 0x2f81
jmp 0x2f7e
movq %rax, %r14
jmp 0x2f93
movq %rax, %r14
jmp 0x2f89
jmp 0x2f7e
movq %rax, %r14
movq %rbx, %rdi
callq 0x2090
leaq 0x50(%rsp), %rdi
callq 0x2090
leaq 0x90(%rsp), %rdi
callq 0x2090
movq %r14, %rdi
callq 0x2210