// File: /workspace/github_cpp_makefile_star2_O2/Merulo[P]CompilerJFTT/src/IRs/SecondIR.cpp
// Function: SecondIR::stripForIterator(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Block&)
void SecondIR::stripForIterator(std::string variable, Block& b)
{
    auto firstLine = b.lines.front();
    auto lineToChange = b.lines.end();
    lineToChange--;
    lineToChange--;

    if (firstLine.operation == "CONST")
    {
        auto nextLine = b.lines.begin() + 1;
        if (nextLine->operation == "COPY")
        {
            nextLine->operation = "CONST";
            nextLine->two = firstLine.two;
        }
        auto prevprev = b.lines.end() - 2;
        if (prevprev->operation == "SUB" && prevprev->two == firstLine.one)
        {
            std::string var = getVariable(firstLine.two);
            Line line = {"CONST", var, firstLine.two};
            prevprev = b.lines.insert(prevprev, line);
            prevprev++;
            prevprev->two = var;
        }
        b.lines.erase(b.lines.begin());
    }
    else
    {
        lineToChange->two = firstLine.two;
        b.lines.erase(b.lines.begin());
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x180, %rsp            # imm = 0x180
movq %rdx, %r14
movq %rdi, %r15
leaq 0x20(%rdx), %rbx
movq 0x20(%rdx), %rsi
leaq 0xb0(%rsp), %r13
movq %r13, %rdi
callq 0x8a26
movq 0x28(%r14), %r12
leaq 0xe240(%rip), %rsi      # 0x23521
movq %r13, %rdi
callq 0x8453
testb %al, %al
je 0x15464
movq (%rbx), %r12
leaq 0x68(%r12), %r13
leaq 0xddc5(%rip), %rsi      # 0x230c5
movq %r13, %rdi
callq 0x8453
testb %al, %al
je 0x15332
leaq 0xe20e(%rip), %rsi      # 0x23521
movq %r13, %rdi
callq 0x44e0
leaq 0xf0(%rsp), %rsi
addq $0xa8, %r12
movq %r12, %rdi
callq 0x4180
movq 0x28(%r14), %r12
leaq -0xd0(%r12), %r14
leaq 0xdd51(%rip), %rsi      # 0x23096
movq %r14, %rdi
callq 0x8453
testb %al, %al
je 0x15457
addq $-0x90, %r12
leaq 0xd0(%rsp), %rsi
movq %r12, %rdi
callq 0x8141
testb %al, %al
je 0x15457
leaq 0xf0(%rsp), %r12
leaq 0x90(%rsp), %rdi
movq %r12, %rsi
callq 0x4390
leaq 0x10(%rsp), %rdi
leaq 0x90(%rsp), %rdx
movq %r15, %rsi
callq 0x1af90
leaq 0x90(%rsp), %rdi
callq 0x4548
leaq 0xe16c(%rip), %rsi      # 0x23521
leaq 0x70(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x4a54
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x4390
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x4390
leaq 0x118(%rsp), %rdi
leaq 0x70(%rsp), %rsi
leaq 0x50(%rsp), %rdx
leaq 0x30(%rsp), %rcx
callq 0x816a
leaq 0x30(%rsp), %rdi
callq 0x4548
leaq 0x50(%rsp), %rdi
callq 0x4548
leaq 0x70(%rsp), %rdi
callq 0x4548
leaq 0x118(%rsp), %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x166aa
addq $0xa8, %rax
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x4180
leaq 0x118(%rsp), %rdi
callq 0x81fe
leaq 0x10(%rsp), %rdi
callq 0x4548
movq (%rbx), %rsi
movq %rbx, %rdi
callq 0x166a4
jmp 0x15486
leaq 0xf0(%rsp), %rsi
addq $-0x90, %r12
movq %r12, %rdi
callq 0x4180
movq (%rbx), %rsi
movq %rbx, %rdi
callq 0x166a4
leaq 0xb0(%rsp), %rdi
callq 0x81fe
addq $0x180, %rsp            # imm = 0x180
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
jmp 0x154a6
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
callq 0x81fe
jmp 0x154e8
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x4548
jmp 0x154ca
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x4548
jmp 0x154d9
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x4548
jmp 0x154e8
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x4548
jmp 0x1550c
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
jmp 0x154ed
jmp 0x15509
jmp 0x15509
jmp 0x15509
jmp 0x15509
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x81fe
movq %rbx, %rdi
callq 0x4490
nop