// File: Merulo[P]CompilerJFTT/src/IRs/SecondIR.cpp
// Function: SecondIR::removeDivAndMod()
void SecondIR::removeDivAndMod()
{
    for(auto& b : _blocks)
    {
        for(auto l = b.lines.begin(); l != b.lines.end(); l++)
        {
            if (l->operation == "DIV" || l->operation == "MOD")
            {
                std::string arg1 = l->one;
                std::string arg2 = l->two;
                std::string operation = l->operation;
                auto prev = l - 1;
                if (prev->operation == "COPY" && prev->one == arg1 && prev->two == arg1)
                {
                    auto prevprev = prev - 1;
                    if (prevprev == b.lines.begin())
                    {
                        continue;
                    }
                    if (prevprev->operation == "COPY" && prevprev->one == arg2 && prevprev->two == arg1)
                    {
                        l = b.lines.erase(l);
                        l--;
                        l = b.lines.erase(l);
                        l--;
                        l = b.lines.erase(l);
                        Line line{"CONST", arg1, "1"};
                        if (operation == "MOD")
                        {
                            line.two = "0";
                        }
                        b.lines.insert(l, line);
                    }
                }
            }
        }
    }
}

// Assembly:
subq $0x278, %rsp            # imm = 0x278
movq %rdi, 0x270(%rsp)
movq 0x270(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x268(%rsp)
movq 0x268(%rsp), %rdi
callq 0x29fd0
movq %rax, 0x260(%rsp)
movq 0x268(%rsp), %rdi
callq 0x2a870
movq %rax, 0x258(%rsp)
leaq 0x260(%rsp), %rdi
leaq 0x258(%rsp), %rsi
callq 0x30be0
testb $0x1, %al
jne 0x2c9cb
jmp 0x2d0c7
leaq 0x260(%rsp), %rdi
callq 0x2bda0
movq %rax, 0x250(%rsp)
movq 0x250(%rsp), %rdi
addq $0x20, %rdi
callq 0xe3f0
movq %rax, 0x248(%rsp)
movq 0x250(%rsp), %rdi
addq $0x20, %rdi
callq 0xe380
movq %rax, 0x240(%rsp)
leaq 0x248(%rsp), %rdi
leaq 0x240(%rsp), %rsi
callq 0xec10
testb $0x1, %al
jne 0x2ca30
jmp 0x2d0b3
leaq 0x248(%rsp), %rdi
callq 0x30d40
movq %rax, %rdi
leaq 0x24a75(%rip), %rsi     # 0x514bc
callq 0xdd10
testb $0x1, %al
jne 0x2ca75
leaq 0x248(%rsp), %rdi
callq 0x30d40
movq %rax, %rdi
leaq 0x24a59(%rip), %rsi     # 0x514c0
callq 0xdd10
testb $0x1, %al
jne 0x2ca75
jmp 0x2d095
leaq 0x248(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x30d40
movq %rax, %rsi
addq $0x20, %rsi
leaq 0x220(%rsp), %rdi
callq 0x4180
movq 0x78(%rsp), %rdi
callq 0x30d40
movq %rax, %rsi
addq $0x40, %rsi
leaq 0x200(%rsp), %rdi
callq 0x4180
jmp 0x2cabb
leaq 0x248(%rsp), %rdi
callq 0x30d40
movq %rax, %rsi
leaq 0x1d0(%rsp), %rdi
callq 0x4180
jmp 0x2cada
leaq 0x248(%rsp), %rdi
movl $0x1, %esi
callq 0x118b0
movq %rax, 0x1c8(%rsp)
leaq 0x1c8(%rsp), %rdi
callq 0x30d40
movq %rax, %rdi
leaq 0x245f2(%rip), %rsi     # 0x510fd
callq 0xdd10
movb %al, 0x77(%rsp)
jmp 0x2cb16
movb 0x77(%rsp), %al
testb $0x1, %al
jne 0x2cb23
jmp 0x2d029
leaq 0x1c8(%rsp), %rdi
callq 0x30d40
movq %rax, %rdi
addq $0x20, %rdi
leaq 0x220(%rsp), %rsi
callq 0xd2c0
testb $0x1, %al
jne 0x2cb4d
jmp 0x2d029
leaq 0x1c8(%rsp), %rdi
callq 0x30d40
movq %rax, %rdi
addq $0x40, %rdi
leaq 0x220(%rsp), %rsi
callq 0xd2c0
testb $0x1, %al
jne 0x2cb77
jmp 0x2d029
leaq 0x1c8(%rsp), %rdi
movl $0x1, %esi
callq 0x118b0
movq %rax, 0x1c0(%rsp)
movq 0x250(%rsp), %rdi
addq $0x20, %rdi
callq 0xe3f0
movq %rax, 0x1b8(%rsp)
leaq 0x1c0(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0x1fba0
testb $0x1, %al
jne 0x2cbc5
jmp 0x2cc20
movl $0x6, 0x1b4(%rsp)
jmp 0x2d034
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
jmp 0x2d086
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
jmp 0x2d079
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
jmp 0x2d06c
leaq 0x1c0(%rsp), %rdi
callq 0x30d40
movq %rax, %rdi
leaq 0x244c6(%rip), %rsi     # 0x510fd
callq 0xdd10
movb %al, 0x76(%rsp)
jmp 0x2cc42
movb 0x76(%rsp), %al
testb $0x1, %al
jne 0x2cc4f
jmp 0x2d027
leaq 0x1c0(%rsp), %rdi
callq 0x30d40
movq %rax, %rdi
addq $0x20, %rdi
leaq 0x200(%rsp), %rsi
callq 0xd2c0
testb $0x1, %al
jne 0x2cc79
jmp 0x2d027
leaq 0x1c0(%rsp), %rdi
callq 0x30d40
movq %rax, %rdi
addq $0x40, %rdi
leaq 0x220(%rsp), %rsi
callq 0xd2c0
testb $0x1, %al
jne 0x2cca3
jmp 0x2d027
movq 0x250(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x60(%rsp)
leaq 0x1a0(%rsp), %rdi
leaq 0x248(%rsp), %rsi
callq 0xe3b0
movq 0x60(%rsp), %rdi
movq 0x1a0(%rsp), %rsi
callq 0x30d50
movq %rax, 0x68(%rsp)
jmp 0x2cce2
movq 0x68(%rsp), %rax
movq %rax, 0x1a8(%rsp)
movq 0x1a8(%rsp), %rax
movq %rax, 0x248(%rsp)
leaq 0x248(%rsp), %rdi
movq %rdi, 0x48(%rsp)
xorl %esi, %esi
callq 0x30dc0
movq 0x48(%rsp), %rsi
movq %rax, 0x198(%rsp)
movq 0x250(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x50(%rsp)
leaq 0x188(%rsp), %rdi
callq 0xe3b0
movq 0x50(%rsp), %rdi
movq 0x188(%rsp), %rsi
callq 0x30d50
movq %rax, 0x58(%rsp)
jmp 0x2cd57
movq 0x58(%rsp), %rax
movq %rax, 0x190(%rsp)
movq 0x190(%rsp), %rax
movq %rax, 0x248(%rsp)
leaq 0x248(%rsp), %rdi
movq %rdi, 0x30(%rsp)
xorl %esi, %esi
callq 0x30dc0
movq 0x30(%rsp), %rsi
movq %rax, 0x180(%rsp)
movq 0x250(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x38(%rsp)
leaq 0x170(%rsp), %rdi
callq 0xe3b0
movq 0x38(%rsp), %rdi
movq 0x170(%rsp), %rsi
callq 0x30d50
movq %rax, 0x40(%rsp)
jmp 0x2cdcc
movq 0x40(%rsp), %rax
movq %rax, 0x178(%rsp)
movq 0x178(%rsp), %rax
movq %rax, 0x248(%rsp)
leaq 0xe7(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x4600
movq 0x28(%rsp), %rdx
leaq 0x2475b(%rip), %rsi     # 0x51562
leaq 0xe8(%rsp), %rdi
callq 0x4f10
jmp 0x2ce16
leaq 0xc0(%rsp), %rdi
leaq 0x220(%rsp), %rsi
callq 0x4180
jmp 0x2ce2d
leaq 0x9f(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x4600
movq 0x20(%rsp), %rdx
leaq 0x259c5(%rip), %rsi     # 0x52810
leaq 0xa0(%rsp), %rdi
callq 0x4f10
jmp 0x2ce5a
leaq 0x108(%rsp), %rdi
leaq 0xe8(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
leaq 0xa0(%rsp), %rcx
callq 0xd3b0
jmp 0x2ce81
leaq 0xa0(%rsp), %rdi
callq 0x46e8
leaq 0x9f(%rsp), %rdi
callq 0x43b0
leaq 0xc0(%rsp), %rdi
callq 0x46e8
leaq 0xe8(%rsp), %rdi
callq 0x46e8
leaq 0xe7(%rsp), %rdi
callq 0x43b0
leaq 0x245f7(%rip), %rsi     # 0x514c0
leaq 0x1d0(%rsp), %rdi
callq 0xdd10
movb %al, 0x1f(%rsp)
jmp 0x2cedc
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x2cee9
jmp 0x2cfc6
leaq 0x148(%rsp), %rdi
leaq 0x2467e(%rip), %rsi     # 0x51576
callq 0x44a0
jmp 0x2ceff
jmp 0x2cfc6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
jmp 0x2cf8e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
jmp 0x2cf81
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
jmp 0x2cf67
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x46e8
leaq 0x9f(%rsp), %rdi
callq 0x43b0
leaq 0xc0(%rsp), %rdi
callq 0x46e8
leaq 0xe8(%rsp), %rdi
callq 0x46e8
leaq 0xe7(%rsp), %rdi
callq 0x43b0
jmp 0x2d06c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1f8(%rsp)
movl %eax, 0x1f4(%rsp)
leaq 0x108(%rsp), %rdi
callq 0xd490
jmp 0x2d06c
movq 0x250(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x8(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x248(%rsp), %rsi
callq 0xe3b0
movq 0x8(%rsp), %rdi
movq 0x90(%rsp), %rsi
leaq 0x108(%rsp), %rdx
callq 0x30e70
movq %rax, 0x10(%rsp)
jmp 0x2d00d
movq 0x10(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x108(%rsp), %rdi
callq 0xd490
jmp 0x2d029
movl $0x0, 0x1b4(%rsp)
leaq 0x1d0(%rsp), %rdi
callq 0x46e8
leaq 0x200(%rsp), %rdi
callq 0x46e8
leaq 0x220(%rsp), %rdi
callq 0x46e8
movl 0x1b4(%rsp), %eax
testl %eax, %eax
je 0x2d06a
jmp 0x2d068
jmp 0x2d097
jmp 0x2d095
leaq 0x1d0(%rsp), %rdi
callq 0x46e8
leaq 0x200(%rsp), %rdi
callq 0x46e8
leaq 0x220(%rsp), %rdi
callq 0x46e8
jmp 0x2d0cf
jmp 0x2d097
leaq 0x248(%rsp), %rdi
xorl %esi, %esi
callq 0x30e00
movq %rax, 0x80(%rsp)
jmp 0x2c9f9
jmp 0x2d0b5
leaq 0x260(%rsp), %rdi
callq 0x30c20
jmp 0x2c9ad
addq $0x278, %rsp            # imm = 0x278
retq
movq 0x1f8(%rsp), %rdi
callq 0x45f0
nopl (%rax)