// File: /workspace/github_cpp_makefile_star2_O2/Merulo[P]CompilerJFTT/src/IRs/FirstIR.cpp
// Function: FirstIR::handleMathOperation(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void FirstIR::handleMathOperation(cStrRef resultName)
{
    if (_firstExtraParameter == _secondExtraParameter && _symbolTable->isItTable(_firstExtraParameter))
    {
        std::string res = _firstExtraParameter.substr(_firstExtraParameter.find("(") + 1, std::string::npos);
        res.pop_back();
        if (res == resultName)
        {
            std::string var = getVariable("NAN");
            addNewCode("COPY", var, _secondExtraParameter);
            _secondExtraParameter = var;
        }
    }
    if (_operation.empty())
    {
        addNewCode("CONST", resultName, _firstExtraParameter);
    }
    else if (_operation == "COPY")
    {
        addNewCode("COPY", resultName, _firstExtraParameter);      
    }
    else if (_secondExtraParameter == resultName)
    {
        if (_operation == "ADD" || _operation == "MUL")
        {
            addNewCode(_operation, resultName, _firstExtraParameter);
        }
        else if (_operation == "SUB" || _operation == "DIV" || _operation == "MOD")
        {
            handleNonCommutativeOperation(resultName, _operation);
        }
    }
    else
    {
        if (_firstExtraParameter == resultName)
        {
            addNewCode(_operation, resultName, _secondExtraParameter);
        }
        else
        {
            addNewCode("COPY", resultName, _firstExtraParameter);
            addNewCode(_operation, resultName, _secondExtraParameter);
        }  
    }
    reset();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xd8(%rdi), %r15
leaq 0xf8(%rdi), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x8141
testb %al, %al
je 0x1223c
movq (%rbx), %r13
leaq 0x88(%rsp), %rbp
movq %rbp, %rdi
movq %r15, %rsi
callq 0x4390
movq %r13, %rdi
movq %rbp, %rsi
callq 0x108c4
movl %eax, %ebp
leaq 0x88(%rsp), %rdi
callq 0x4548
testb %bpl, %bpl
je 0x1223c
leaq 0x12441(%rip), %rsi     # 0x245bd
movq %r15, %rdi
xorl %edx, %edx
callq 0x4520
leaq 0x1(%rax), %rdx
leaq 0x8(%rsp), %r13
pushq $-0x1
popq %rcx
movq %r13, %rdi
movq %r15, %rsi
callq 0x42a0
movq %r13, %rdi
callq 0x4330
movq %r13, %rdi
movq %r14, %rsi
callq 0x8141
testb %al, %al
je 0x12232
leaq 0x112c9(%rip), %rsi     # 0x23484
leaq 0x68(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x4a54
leaq 0x28(%rsp), %rdi
leaq 0x68(%rsp), %rdx
movq %rbx, %rsi
callq 0x1af90
leaq 0x68(%rsp), %rdi
callq 0x4548
leaq 0x10ed8(%rip), %rsi     # 0x230c5
leaq 0x48(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0x4a54
leaq 0x48(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movq %rbx, %rdi
movq %r12, %rcx
callq 0x12014
leaq 0x48(%rsp), %rdi
callq 0x4548
leaq 0x28(%rsp), %rsi
movq %r12, %rdi
callq 0x4180
leaq 0x28(%rsp), %rdi
callq 0x4548
leaq 0x8(%rsp), %rdi
callq 0x4548
cmpq $0x0, 0xc0(%rbx)
je 0x1228b
leaq 0xb8(%rbx), %r13
leaq 0x10e71(%rip), %rsi     # 0x230c5
movq %r13, %rdi
callq 0x8453
testb %al, %al
je 0x122c3
leaq 0x10e5e(%rip), %rsi     # 0x230c5
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x4a54
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
callq 0x12014
jmp 0x122b4
leaq 0x1128f(%rip), %rsi     # 0x23521
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x4a54
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
callq 0x12014
leaq 0x8(%rsp), %rdi
callq 0x4548
jmp 0x12359
movq %r12, %rdi
movq %r14, %rsi
callq 0x8141
testb %al, %al
je 0x12306
leaq 0x10dc9(%rip), %rsi     # 0x230a2
movq %r13, %rdi
callq 0x8453
testb %al, %al
jne 0x122f8
leaq 0x1119c(%rip), %rsi     # 0x23488
movq %r13, %rdi
callq 0x8453
testb %al, %al
je 0x12373
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r15, %rcx
jmp 0x12354
movq %r15, %rdi
movq %r14, %rsi
callq 0x8141
testb %al, %al
jne 0x12348
leaq 0x10da9(%rip), %rsi     # 0x230c5
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x4a54
leaq 0x8(%rsp), %rsi
movq %rbx, %rdi
movq %r14, %rdx
movq %r15, %rcx
callq 0x12014
leaq 0x8(%rsp), %rdi
callq 0x4548
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq %r12, %rcx
callq 0x12014
movq %rbx, %rdi
callq 0x12528
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10d1c(%rip), %rsi     # 0x23096
movq %r13, %rdi
callq 0x8453
testb %al, %al
jne 0x123ac
leaq 0x110ff(%rip), %rsi     # 0x2348c
movq %r13, %rdi
callq 0x8453
testb %al, %al
jne 0x123ac
leaq 0x110f0(%rip), %rsi     # 0x23490
movq %r13, %rdi
callq 0x8453
testb %al, %al
je 0x12359
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x12418
jmp 0x12359
jmp 0x123f0
jmp 0x123fa
jmp 0x123d1
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x4548
jmp 0x123d4
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x123e3
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x4548
jmp 0x123f3
jmp 0x123f0
jmp 0x123f0
jmp 0x123fa
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0x1240a
movq %rax, %rbx
jmp 0x1240f
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x4548
movq %rbx, %rdi
callq 0x4490
nop