// File: Merulo[P]CompilerJFTT/src/IRs/SecondIR.cpp
// Function: SecondIR::removeUnusedIterators()
void SecondIR::removeUnusedIterators()
{
    for(auto& b : _blocks)
    {
        if (b.blockName.find("_initialForControl") != std::string::npos)
        {
            auto lastLine = b.lines.back();
            std::string iteratorName = lastLine.one;
            iteratorName = iteratorName.substr(0, iteratorName.find(_symbolTable->getForControl()));

            Block& nextBlock = getBlockByName(b.blockIfFalse, _blocks);
            std::string name = b.blockName;
            name = name.substr(0, name.find_last_of("_"));
            name = name + "_exitFor";
            Block& endingBlock = getBlockByName(name, _blocks);
            resetBlocks();
            bool result = isUsedInEndingBlock(iteratorName, nextBlock, endingBlock);
            
            if (!result)
            {
                continue;
            }
            stripVariable(iteratorName, endingBlock);
            stripForIterator(iteratorName, b);
        }
    }
}

// Assembly:
subq $0x288, %rsp            # imm = 0x288
movq %rdi, 0x280(%rsp)
movq 0x280(%rsp), %rax
movq %rax, 0x60(%rsp)
addq $0x10, %rax
movq %rax, 0x278(%rsp)
movq 0x278(%rsp), %rdi
callq 0x29fd0
movq %rax, 0x270(%rsp)
movq 0x278(%rsp), %rdi
callq 0x2a870
movq %rax, 0x268(%rsp)
leaq 0x270(%rsp), %rdi
leaq 0x268(%rsp), %rsi
callq 0x30be0
testb $0x1, %al
jne 0x2d150
jmp 0x2d64b
leaq 0x270(%rsp), %rdi
callq 0x2bda0
movq %rax, 0x260(%rsp)
movq 0x260(%rsp), %rdi
leaq 0x24370(%rip), %rsi     # 0x514e4
xorl %eax, %eax
movl %eax, %edx
callq 0x46b0
cmpq $-0x1, %rax
je 0x2d637
movq 0x260(%rsp), %rdi
addq $0x20, %rdi
callq 0x11660
movq %rax, %rsi
leaq 0x1f8(%rsp), %rdi
callq 0xfb20
leaq 0x218(%rsp), %rsi
leaq 0x1d8(%rsp), %rdi
callq 0x4180
jmp 0x2d1bf
movq 0x60(%rsp), %rdi
callq 0xdde0
movq %rax, %rsi
leaq 0x188(%rsp), %rdi
callq 0x21380
jmp 0x2d1db
xorl %eax, %eax
movl %eax, %edx
movq %rdx, 0x58(%rsp)
leaq 0x1d8(%rsp), %rdi
movq %rdi, 0x50(%rsp)
leaq 0x188(%rsp), %rsi
callq 0x46d0
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq %rax, %rcx
leaq 0x1a8(%rsp), %rdi
callq 0x4350
jmp 0x2d21a
leaq 0x1d8(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
movq %rsi, 0x48(%rsp)
callq 0x4440
movq 0x48(%rsp), %rdi
callq 0x46e8
leaq 0x188(%rsp), %rdi
callq 0x46e8
movq 0x260(%rsp), %rsi
addq $0x58, %rsi
leaq 0x160(%rsp), %rdi
callq 0x4180
jmp 0x2d266
movq 0x60(%rsp), %rdi
movq %rdi, %rdx
addq $0x10, %rdx
leaq 0x160(%rsp), %rsi
callq 0x3d720
movq %rax, 0x40(%rsp)
jmp 0x2d286
leaq 0x160(%rsp), %rdi
callq 0x46e8
movq 0x40(%rsp), %rax
movq %rax, 0x180(%rsp)
movq 0x260(%rsp), %rsi
leaq 0x140(%rsp), %rdi
callq 0x4180
jmp 0x2d2b7
leaq 0x23ef4(%rip), %rsi     # 0x511b2
leaq 0x140(%rsp), %rdi
movq %rdi, 0x38(%rsp)
movq $-0x1, %rdx
callq 0x42f0
movq 0x38(%rsp), %rsi
movq %rax, %rcx
xorl %eax, %eax
movl %eax, %edx
leaq 0x120(%rsp), %rdi
callq 0x4350
jmp 0x2d2f2
leaq 0x140(%rsp), %rdi
movq %rdi, 0x30(%rsp)
leaq 0x120(%rsp), %rsi
movq %rsi, 0x28(%rsp)
callq 0x4440
movq 0x28(%rsp), %rdi
callq 0x46e8
movq 0x30(%rsp), %rsi
leaq 0x241d0(%rip), %rdx     # 0x514f7
leaq 0x100(%rsp), %rdi
callq 0x299c0
jmp 0x2d336
leaq 0x140(%rsp), %rdi
movq %rdi, 0x20(%rsp)
leaq 0x100(%rsp), %rsi
movq %rsi, 0x18(%rsp)
callq 0x4440
movq 0x18(%rsp), %rdi
callq 0x46e8
movq 0x20(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x4180
jmp 0x2d373
movq 0x60(%rsp), %rdi
movq %rdi, %rdx
addq $0x10, %rdx
leaq 0xd8(%rsp), %rsi
callq 0x3d720
movq %rax, 0x10(%rsp)
jmp 0x2d393
leaq 0xd8(%rsp), %rdi
callq 0x46e8
movq 0x10(%rsp), %rax
movq 0x60(%rsp), %rdi
movq %rax, 0xf8(%rsp)
callq 0x3d6a0
jmp 0x2d3b9
leaq 0xb0(%rsp), %rdi
leaq 0x1d8(%rsp), %rsi
callq 0x4180
jmp 0x2d3d0
movq 0x60(%rsp), %rdi
movq 0x180(%rsp), %rdx
movq 0xf8(%rsp), %rcx
leaq 0xb0(%rsp), %rsi
callq 0x2da80
movb %al, 0xf(%rsp)
jmp 0x2d3f8
leaq 0xb0(%rsp), %rdi
callq 0x46e8
movb 0xf(%rsp), %al
andb $0x1, %al
movb %al, 0xd7(%rsp)
testb $0x1, 0xd7(%rsp)
jne 0x2d513
movl $0x3, 0xac(%rsp)
jmp 0x2d595
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
jmp 0x2d628
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
jmp 0x2d61b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
leaq 0x188(%rsp), %rdi
callq 0x46e8
jmp 0x2d61b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
leaq 0x160(%rsp), %rdi
callq 0x46e8
jmp 0x2d61b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
jmp 0x2d60e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x46e8
jmp 0x2d60e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x46e8
jmp 0x2d60e
leaq 0x88(%rsp), %rdi
leaq 0x1d8(%rsp), %rsi
callq 0x4180
jmp 0x2d52a
movq 0x60(%rsp), %rdi
movq 0xf8(%rsp), %rdx
leaq 0x88(%rsp), %rsi
callq 0x2e010
jmp 0x2d546
leaq 0x88(%rsp), %rdi
callq 0x46e8
leaq 0x68(%rsp), %rdi
leaq 0x1d8(%rsp), %rsi
callq 0x4180
jmp 0x2d567
movq 0x60(%rsp), %rdi
movq 0x260(%rsp), %rdx
leaq 0x68(%rsp), %rsi
callq 0x2e110
jmp 0x2d580
leaq 0x68(%rsp), %rdi
callq 0x46e8
movl $0x0, 0xac(%rsp)
leaq 0x140(%rsp), %rdi
callq 0x46e8
leaq 0x1d8(%rsp), %rdi
callq 0x46e8
leaq 0x1f8(%rsp), %rdi
callq 0xd490
movl 0xac(%rsp), %eax
testl %eax, %eax
je 0x2d5cb
jmp 0x2d5c9
jmp 0x2d639
jmp 0x2d637
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
leaq 0x88(%rsp), %rdi
callq 0x46e8
jmp 0x2d60e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1d0(%rsp)
movl %eax, 0x1cc(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x46e8
leaq 0x140(%rsp), %rdi
callq 0x46e8
leaq 0x1d8(%rsp), %rdi
callq 0x46e8
leaq 0x1f8(%rsp), %rdi
callq 0xd490
jmp 0x2d653
jmp 0x2d639
leaq 0x270(%rsp), %rdi
callq 0x30c20
jmp 0x2d132
addq $0x288, %rsp            # imm = 0x288
retq
movq 0x1d0(%rsp), %rdi
callq 0x45f0