// File: /workspace/github_cpp_makefile_star2_O2/Merulo[P]CompilerJFTT/src/IRs/FirstIR.cpp
// Function: FirstIR::insertFor(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Data, Data, bool)
void FirstIR::insertFor(std::string iterator, Data from, Data to, bool isForTo)
{
    closeForBlock();
    Block b1 = _forBlocks.top();
    _forBlocks.pop();
    Block b2 = _forBlocks.top();
    _forBlocks.pop();

    std::string name = generateForName();
    Block firstControlBlock = createBeforeForBlock(iterator, from, to, isForTo, name);
    firstControlBlock.blockIfFalse = b2.blockName;
    firstControlBlock.blockIfTrue = b1.blockName;

    Block secondControlBlock = createSecondControlBlock(iterator, isForTo, name);
    secondControlBlock.blockIfFalse = b2.blockName;
    secondControlBlock.blockIfTrue = b1.blockName;        
    
    for(size_t i = 0; i < _blocks.size(); i++)
    {
        if (_blocks[i] == b2)
        {
            _blocks.insert(_blocks.begin() + i, firstControlBlock);
            break;
        }
    }

    _blocks.push_back(_currentBlock.top());
    _currentBlock.pop();
    Block testing = generateBlock();
    _currentBlock.push(testing);

    for(size_t i = 0; i < _blocks.size(); i++)
    {
        if (_blocks[i] == b1)
        {
            _blocks.insert(_blocks.begin() + i, secondControlBlock);
            return;
        }
    }        

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movl %r8d, %ebp
movq %rcx, %r15
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
callq 0x12c18
leaq 0x168(%rbx), %r13
movq 0x198(%rbx), %rsi
cmpq 0x1a0(%rbx), %rsi
jne 0x12dce
movq 0x1b0(%rbx), %rax
movl $0x1e0, %esi            # imm = 0x1E0
addq -0x8(%rax), %rsi
addq $-0xa0, %rsi
leaq 0x2d8(%rsp), %rdi
callq 0x13b04
movq %r13, %rdi
callq 0x14360
movq 0x198(%rbx), %rsi
cmpq 0x1a0(%rbx), %rsi
jne 0x12e0a
movq 0x1b0(%rbx), %rax
movl $0x1e0, %esi            # imm = 0x1E0
addq -0x8(%rax), %rsi
addq $-0xa0, %rsi
leaq 0x238(%rsp), %rdi
callq 0x13b04
movq %r13, %rdi
callq 0x14360
leaq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x1b0a0
leaq 0x68(%rsp), %rdi
movq %r14, %rsi
callq 0x4390
leaq 0xb0(%rsp), %rdi
movq %r12, %rsi
callq 0x13c0e
leaq 0x88(%rsp), %rdi
movq %r15, %rsi
callq 0x13c0e
leaq 0xd8(%rsp), %r15
leaq 0x8(%rsp), %rsi
movq %r15, %rdi
callq 0x4390
movq %r15, (%rsp)
movzbl %bpl, %ebp
leaq 0x198(%rsp), %rdi
leaq 0x68(%rsp), %rdx
leaq 0xb0(%rsp), %rcx
leaq 0x88(%rsp), %r8
movq %rbx, %rsi
movl %ebp, %r9d
callq 0x131b8
leaq 0xd8(%rsp), %rdi
callq 0x4548
leaq 0x90(%rsp), %rdi
callq 0x4548
leaq 0xb8(%rsp), %rdi
callq 0x4548
leaq 0x68(%rsp), %rdi
callq 0x4548
leaq 0x1f0(%rsp), %rdi
leaq 0x238(%rsp), %rsi
callq 0x4180
leaq 0x1d0(%rsp), %rdi
leaq 0x2d8(%rsp), %rsi
callq 0x4180
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x4390
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x4390
leaq 0xf8(%rsp), %rdi
leaq 0x48(%rsp), %rdx
leaq 0x28(%rsp), %r8
movq %rbx, %rsi
movl %ebp, %ecx
callq 0x1368e
leaq 0x28(%rsp), %rdi
callq 0x4548
leaq 0x48(%rsp), %rdi
callq 0x4548
leaq 0x150(%rsp), %rdi
leaq 0x238(%rsp), %rsi
callq 0x4180
leaq 0x130(%rsp), %rdi
leaq 0x2d8(%rsp), %rsi
callq 0x4180
leaq 0x10(%rbx), %r14
xorl %r15d, %r15d
movl $0xa0, %r13d
leaq 0x238(%rsp), %r12
xorl %ebp, %ebp
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rax
subq %rdi, %rax
cqto
idivq %r13
cmpq %rax, %rbp
jae 0x12fd3
addq %r15, %rdi
movq %r12, %rsi
callq 0x8141
testb %al, %al
jne 0x12fbd
incq %rbp
addq $0xa0, %r15
jmp 0x12f8d
addq (%r14), %r15
leaq 0x198(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x13c22
movq 0x58(%rbx), %rsi
cmpq 0x60(%rbx), %rsi
jne 0x12fea
movq 0x70(%rbx), %rax
movl $0x1e0, %esi            # imm = 0x1E0
addq -0x8(%rax), %rsi
addq $-0xa0, %rsi
movq %r14, %rdi
callq 0x13a6a
leaq 0x28(%rbx), %r15
movq %r15, %rdi
callq 0x14360
leaq 0x378(%rsp), %rdi
movq %rbx, %rsi
callq 0x1af06
leaq 0x378(%rsp), %rsi
movq %r15, %rdi
callq 0x14092
xorl %r15d, %r15d
movl $0xa0, %r13d
leaq 0x2d8(%rsp), %r12
xorl %ebp, %ebp
movq 0x10(%rbx), %rdi
movq 0x18(%rbx), %rax
subq %rdi, %rax
cqto
idivq %r13
cmpq %rax, %rbp
jae 0x1307e
addq %r15, %rdi
movq %r12, %rsi
callq 0x8141
testb %al, %al
jne 0x13068
incq %rbp
addq $0xa0, %r15
jmp 0x13038
addq (%r14), %r15
leaq 0xf8(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0x13c22
leaq 0x378(%rsp), %rdi
callq 0x13ad2
leaq 0xf8(%rsp), %rdi
callq 0x13ad2
leaq 0x198(%rsp), %rdi
callq 0x13ad2
leaq 0x8(%rsp), %rdi
callq 0x4548
leaq 0x238(%rsp), %rdi
callq 0x13ad2
leaq 0x2d8(%rsp), %rdi
callq 0x13ad2
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x130e2
jmp 0x1316f
movq %rax, %rbx
leaq 0x378(%rsp), %rdi
callq 0x13ad2
jmp 0x13172
jmp 0x1316f
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x4548
jmp 0x13108
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x4548
jmp 0x1317f
jmp 0x1316a
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x4548
jmp 0x1312b
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x4548
jmp 0x1313d
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x4548
jmp 0x1314f
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x4548
jmp 0x1318c
movq %rax, %rbx
jmp 0x1318c
movq %rax, %rbx
jmp 0x13196
movq %rax, %rbx
jmp 0x131a3
movq %rax, %rbx
jmp 0x1317f
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x13ad2
leaq 0x198(%rsp), %rdi
callq 0x13ad2
leaq 0x8(%rsp), %rdi
callq 0x4548
leaq 0x238(%rsp), %rdi
callq 0x13ad2
leaq 0x2d8(%rsp), %rdi
callq 0x13ad2
movq %rbx, %rdi
callq 0x4490