// File: /workspace/github_cpp_makefile_star2_O2/Merulo[P]CompilerJFTT/src/IRs/SecondIR.cpp
// Function: SecondIR::checkIfThisCanBeRemoved(std::vector<Line, std::allocator<Line>>&, __gnu_cxx::__normal_iterator<Line*, std::vector<Line, std::allocator<Line>>>&)
void SecondIR::checkIfThisCanBeRemoved(std::vector<Line>& lines, std::vector<Line>::iterator& iterator)
{
    if (iterator->operation != "ADD" && iterator->operation != "SUB")
    {
        return;
    }
    std::string operation = iterator->operation;
    std::string arg = iterator->one;
    if (!_symbolTable->isConst(iterator->two))
    {
        return;
    }
    auto constString = _symbolTable->getConstValue(iterator->two);
    if (constString == "NAN")
    {
        return;
    }
    unsigned long long value = std::stoull(constString);
    if (value > 15)
    {
        return;
    }
    if ((iterator-1)->operation == "CONST")
    {
        iterator = lines.erase(iterator - 1);
    }
    else
    {
        iterator = lines.erase(iterator - 2);
        iterator++;
    }

    iterator = lines.erase(iterator);
    iterator--;

    Line l;
    l.operation = "DEC";
    if (operation == "ADD")
    {
        l.operation = "INC";
    }
    l.one = arg;
    for(unsigned long long i = 0; i < value; i++)
    {
        iterator++;
        iterator = lines.insert(iterator, l);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x110, %rsp            # imm = 0x110
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq (%rdx), %rdi
leaq 0xdb5e(%rip), %rsi      # 0x230a2
callq 0x16742
testb %al, %al
je 0x15564
movq (%rbx), %rdi
leaq 0xdb3f(%rip), %rsi      # 0x23096
callq 0x16742
testb %al, %al
jne 0x15753
movq (%rbx), %rsi
leaq 0x88(%rsp), %rdi
callq 0x4390
movq (%rbx), %rsi
addq $0x20, %rsi
leaq 0x68(%rsp), %rdi
callq 0x4390
movq (%r15), %r12
movq (%rbx), %rsi
addq $0x40, %rsi
leaq 0x48(%rsp), %rdi
callq 0x4390
leaq 0x48(%rsp), %rsi
movq %r12, %rdi
callq 0x10282
movl %eax, %ebp
leaq 0x48(%rsp), %rdi
callq 0x4548
testb %bpl, %bpl
je 0x1573c
movq (%r15), %r15
movq (%rbx), %rsi
addq $0x40, %rsi
leaq 0x28(%rsp), %rdi
callq 0x4390
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
movq %r15, %rsi
callq 0x107fa
leaq 0x28(%rsp), %rdi
callq 0x4548
leaq 0xde92(%rip), %rsi      # 0x23484
leaq 0x8(%rsp), %rdi
callq 0x8453
testb %al, %al
jne 0x15732
leaq 0x8(%rsp), %rdi
pushq $0xa
popq %rdx
xorl %esi, %esi
callq 0x8476
movq %rax, %r15
cmpq $0xf, %rax
ja 0x15732
movq (%rbx), %rdi
addq $-0x68, %rdi
leaq 0xdef3(%rip), %rsi      # 0x23521
callq 0x8453
movq (%rbx), %rsi
testb %al, %al
je 0x15648
addq $-0x68, %rsi
movq %r14, %rdi
callq 0x166a4
jmp 0x1565b
addq $-0xd0, %rsi
movq %r14, %rdi
callq 0x166a4
addq $0x68, %rax
movq %rax, (%rbx)
movq %r14, %rdi
movq %rax, %rsi
callq 0x166a4
addq $-0x68, %rax
movq %rax, (%rbx)
leaq 0xb8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0xd8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0xf8(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0xd9e8(%rip), %rsi      # 0x2309a
leaq 0xa8(%rsp), %rdi
callq 0x44e0
leaq 0xd9dc(%rip), %rsi      # 0x230a2
leaq 0x88(%rsp), %rdi
callq 0x8453
testb %al, %al
je 0x156eb
leaq 0xd9c0(%rip), %rsi      # 0x2309e
leaq 0xa8(%rsp), %rdi
callq 0x44e0
leaq 0xc8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x4180
leaq 0xa8(%rsp), %r12
subq $0x1, %r15
jb 0x15725
movq (%rbx), %rsi
addq $0x68, %rsi
movq %rsi, (%rbx)
movq %r14, %rdi
movq %r12, %rdx
callq 0x166aa
movq %rax, (%rbx)
jmp 0x15705
leaq 0xa8(%rsp), %rdi
callq 0x81fe
leaq 0x8(%rsp), %rdi
callq 0x4548
leaq 0x68(%rsp), %rdi
callq 0x4548
leaq 0x88(%rsp), %rdi
callq 0x4548
addq $0x110, %rsp            # imm = 0x110
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x15769
jmp 0x15769
jmp 0x15769
movq %rax, %rbx
jmp 0x157a0
jmp 0x15790
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x157a5
jmp 0x15786
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x157a5
movq %rax, %rbx
jmp 0x157aa
movq %rax, %rbx
jmp 0x157b4
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x81fe
leaq 0x8(%rsp), %rdi
callq 0x4548
leaq 0x68(%rsp), %rdi
callq 0x4548
leaq 0x88(%rsp), %rdi
callq 0x4548
movq %rbx, %rdi
callq 0x4490
nop