// File: /workspace/github_cpp_makefile_star2_O1/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 0x15e64(%rip), %rsi     # 0x380a2
callq 0x40d0
testl %eax, %eax
je 0x2225e
movq (%rbx), %rdi
leaq 0x15e45(%rip), %rsi     # 0x38096
callq 0x40d0
testl %eax, %eax
jne 0x225a5
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 0xca12
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 0xca12
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 0xca12
leaq 0x90(%rsp), %rsi
movq %r12, %rdi
callq 0x1a9b6
movl %eax, %ebp
movq 0x90(%rsp), %rdi
cmpq %r13, %rdi
je 0x222f8
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x42a0
testb %bpl, %bpl
je 0x2256d
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 0xca12
leaq 0x70(%rsp), %rdi
leaq 0x50(%rsp), %rdx
movq %r15, %rsi
callq 0x1b276
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0x2234f
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x1612e(%rip), %rsi     # 0x38484
leaq 0x70(%rsp), %rdi
callq 0x40d0
testl %eax, %eax
je 0x2254c
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 0x225b7
movq %rax, %r15
movl (%r12), %eax
testl %eax, %eax
je 0x223c1
cmpl $0x22, %eax
jne 0x223c9
leaq 0x15d66(%rip), %rdi     # 0x38122
callq 0x43f0
movl 0xc(%rsp), %eax
movl %eax, (%r12)
cmpq $0xf, %r15
ja 0x2254c
movq (%rbx), %rdi
addq $-0x68, %rdi
leaq 0x16140(%rip), %rsi     # 0x38521
callq 0x40d0
movq (%rbx), %rsi
testl %eax, %eax
je 0x22402
addq $-0xd0, %rsi
movq %r14, %rdi
callq 0x242a4
addq $0x68, %rax
jmp 0x2240e
addq $-0x68, %rsi
movq %r14, %rdi
callq 0x242a4
movq %rax, (%rbx)
movq %r14, %rdi
movq %rax, %rsi
callq 0x242a4
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 0x15c35(%rip), %rcx     # 0x3809a
leaq 0xb0(%rsp), %rdi
movl $0x3, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x4440
leaq 0x15c1f(%rip), %rsi     # 0x380a2
leaq 0x30(%rsp), %rdi
callq 0x40d0
testl %eax, %eax
jne 0x224b1
leaq 0xb0(%rsp), %rdi
movq 0x8(%rdi), %rdx
leaq 0x15bfa(%rip), %rcx     # 0x3809e
movl $0x3, %r8d
xorl %esi, %esi
callq 0x4440
leaq 0xd0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x4170
testq %r15, %r15
je 0x224ed
leaq 0xb0(%rsp), %r12
movq (%rbx), %rsi
addq $0x68, %rsi
movq %rsi, (%rbx)
movq %r14, %rdi
movq %r12, %rdx
callq 0x24010
movq %rax, (%rbx)
decq %r15
jne 0x224d0
movq 0xf0(%rsp), %rdi
cmpq %r13, %rdi
je 0x2250a
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0xd0(%rsp), %rdi
cmpq %rbp, %rdi
je 0x22527
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x2254c
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2256d
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x22589
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x225a5
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 0x15b64(%rip), %rdi     # 0x38122
callq 0x41a0
jmp 0x225c7
jmp 0x225c7
movq %rax, %rbx
jmp 0x2262c
jmp 0x2261c
movq %rax, %rbx
cmpl $0x0, (%r12)
jne 0x2262c
movl 0xc(%rsp), %eax
movl %eax, (%r12)
jmp 0x2262c
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r12, %rdi
je 0x2264d
movq 0x60(%rsp), %rsi
jmp 0x22645
jmp 0x22612
movq %rax, %rbx
movq 0x90(%rsp), %rdi
cmpq %r13, %rdi
je 0x2264d
movq 0xa0(%rsp), %rsi
jmp 0x22645
movq %rax, %rbx
jmp 0x2264d
movq %rax, %rbx
jmp 0x22669
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0xbf10
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2264d
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0x22669
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x22685
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x42a0
movq %rbx, %rdi
callq 0x44c0
nop