// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
movq (%rdx), %rdi
leaq 0x150fe(%rip), %rsi     # 0x370a2
callq 0x40d0
testl %eax, %eax
je 0x21fc4
movq (%rbx), %rdi
leaq 0x150df(%rip), %rsi     # 0x37096
callq 0x40d0
testl %eax, %eax
jne 0x2230e
movq (%rbx), %rax
leaq 0x40(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x30(%rsp), %rdi
callq 0xc7aa
movq (%rbx), %rax
leaq 0x20(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq 0x20(%rax), %rsi
movq 0x28(%rax), %rdx
addq %rsi, %rdx
leaq 0x10(%rsp), %rdi
callq 0xc7aa
movq (%r15), %r12
movq (%rbx), %rax
leaq 0xa0(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
addq %rsi, %rdx
leaq 0x90(%rsp), %rdi
callq 0xc7aa
leaq 0x90(%rsp), %rsi
movq %r12, %rdi
callq 0x1a6f8
movl %eax, %ebp
movq 0x90(%rsp), %rdi
cmpq %r13, %rdi
je 0x2205e
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x42a0
testb %bpl, %bpl
je 0x222d6
movq (%r15), %r15
movq (%rbx), %rax
leaq 0x60(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x40(%rax), %rsi
movq 0x48(%rax), %rdx
addq %rsi, %rdx
leaq 0x50(%rsp), %rdi
callq 0xc7aa
leaq 0x70(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movq %r15, %rsi
callq 0x1afb8
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0x220b5
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x153c8(%rip), %rsi     # 0x37484
leaq 0x70(%rsp), %rdi
callq 0x40d0
testl %eax, %eax
je 0x222b5
movq 0x70(%rsp), %r13
callq 0x4050
movq %rax, %r12
movl (%rax), %eax
movl %eax, 0xc(%rsp)
movl $0x0, (%r12)
leaq 0xb0(%rsp), %rbp
movq %r13, %rdi
movq %rbp, %rsi
movl $0xa, %edx
callq 0x43c0
cmpq %r13, (%rbp)
je 0x22320
movq %rax, %r15
movl (%r12), %eax
testl %eax, %eax
je 0x22127
cmpl $0x22, %eax
jne 0x2212f
leaq 0x15000(%rip), %rdi     # 0x37122
callq 0x43f0
movl 0xc(%rsp), %eax
movl %eax, (%r12)
cmpq $0xf, %r15
ja 0x222b5
movq (%rbx), %rdi
addq $-0x68, %rdi
leaq 0x153da(%rip), %rsi     # 0x37521
callq 0x40d0
movq (%rbx), %rsi
testl %eax, %eax
je 0x22168
addq $-0xd0, %rsi
movq %r14, %rdi
callq 0x24050
addq $0x68, %rax
jmp 0x22174
addq $-0x68, %rsi
movq %r14, %rdi
callq 0x24050
movq %rax, (%rbx)
movq %r14, %rdi
movq %rax, %rsi
callq 0x24050
addq $-0x68, %rax
movq %rax, (%rbx)
leaq 0xc0(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0xe0(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq %rax, -0x8(%rbp)
movb %al, (%rbp)
leaq 0x100(%rsp), %r13
movq %r13, -0x10(%r13)
movq %rax, -0x8(%r13)
movb %al, (%r13)
leaq 0x14ecf(%rip), %rcx     # 0x3709a
leaq 0xb0(%rsp), %rdi
movl $0x3, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x4440
leaq 0x14eb9(%rip), %rsi     # 0x370a2
leaq 0x30(%rsp), %rdi
callq 0x40d0
testl %eax, %eax
jne 0x22217
leaq 0xb0(%rsp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x14e94(%rip), %rcx     # 0x3709e
movl $0x3, %r8d
xorl %esi, %esi
callq 0x4440
leaq 0xd0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x4170
testq %r15, %r15
je 0x22256
movq (%rbx), %rax
leaq 0xb0(%rsp), %r12
addq $0x68, %rax
movq %rax, (%rbx)
movq %r14, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x23d72
movq %rax, (%rbx)
decq %r15
jne 0x22239
movq 0xf0(%rsp), %rdi
cmpq %r13, %rdi
je 0x22273
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0xd0(%rsp), %rdi
cmpq %rbp, %rdi
je 0x22290
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x222b5
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x222d6
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x222f2
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x2230e
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x42a0
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x14dfb(%rip), %rdi     # 0x37122
callq 0x41a0
jmp 0x22330
jmp 0x22330
movq %rax, %rbx
jmp 0x22395
jmp 0x22385
movq %rax, %rbx
cmpl $0x0, (%r12)
jne 0x22395
movl 0xc(%rsp), %eax
movl %eax, (%r12)
jmp 0x22395
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0x223b6
movq 0x60(%rsp), %rsi
jmp 0x223ae
jmp 0x2237b
movq %rax, %rbx
movq 0x90(%rsp), %rdi
cmpq %r13, %rdi
je 0x223b6
movq 0xa0(%rsp), %rsi
jmp 0x223ae
movq %rax, %rbx
jmp 0x223b6
movq %rax, %rbx
jmp 0x223d2
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0xbca2
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x223b6
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x223d2
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x223ee
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x42a0
movq %rbx, %rdi
callq 0x44c0