// File: /workspace/github_cpp_makefile_star2_O2/Merulo[P]CompilerJFTT/src/IRs/FirstIR.cpp
// Function: FirstIR::createBeforeForBlock(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Data, Data, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
Block FirstIR::createBeforeForBlock(std::string iterator, Data from, Data to, bool isForTo, std::string name)
{
    Block b = generateBlock();
    b.blockName = name + "_initialForControl";
    Line iteratorInit = getLine(from);
    iteratorInit.one = iterator;

    Line counterInit = getLine(to);
    counterInit.one = iterator + forControlName;

    Line counterFinal = getLine(from);
    counterFinal.operation = "SUB";
    counterFinal.one = counterInit.one;
    counterFinal.two = iterator;

    Line inclusiveFor;
    inclusiveFor.operation = "INC";
    inclusiveFor.one = counterInit.one;

    Line l;
    if (!isForTo)
    {
        std::swap(counterInit.two, counterFinal.two);
        if (counterInit.operation == "CONST")
        {
            counterInit.operation = "COPY";
            
            std::string var = getVariable(counterFinal.two);
            l.operation = "CONST";
            l.one = var;
            l.two = counterFinal.two;
            counterFinal.two = var;
        }
    }

    b.lines.push_back(iteratorInit);
    b.lines.push_back(counterInit);
    b.lines.push_back(inclusiveFor);

    if (!isForTo && !l.operation.empty())
    {
        b.lines.push_back(l);
    }
    
    b.lines.push_back(counterFinal);
    
    Line jump;
    jump.operation = "JZERO";
    jump.one = counterInit.one;
    b.lines.push_back(jump);
    return b;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x318, %rsp            # imm = 0x318
movl %r9d, 0x4(%rsp)
movq %r8, %r14
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbp
movq 0x350(%rsp), %rbx
callq 0x1af06
leaq 0x102c3(%rip), %rdx     # 0x234b4
leaq 0x2b0(%rsp), %rdi
movq %rbx, %rsi
movq %rbp, 0x8(%rsp)
callq 0x13a99
leaq 0x2b0(%rsp), %rbx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x4340
movq %rbx, %rdi
callq 0x4548
leaq 0xe8(%rsp), %rdi
movq %r13, %rsi
callq 0x13c0e
leaq 0x2b0(%rsp), %rdi
leaq 0xe8(%rsp), %rdx
callq 0x1397c
leaq 0xf0(%rsp), %rdi
callq 0x4548
leaq 0x2d0(%rsp), %rdi
movq %r12, %rsi
callq 0x4180
leaq 0xc0(%rsp), %rdi
movq %r14, %rsi
callq 0x13c0e
leaq 0x248(%rsp), %rdi
leaq 0xc0(%rsp), %rdx
callq 0x1397c
leaq 0xc8(%rsp), %rdi
callq 0x4548
leaq 0x78(%r15), %rdx
leaq 0x178(%rsp), %rdi
movq %r12, %rsi
callq 0x10ba6
leaq 0x268(%rsp), %r14
leaq 0x178(%rsp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4340
movq %rbx, %rdi
callq 0x4548
leaq 0x98(%rsp), %rdi
movq %r13, %rsi
callq 0x13c0e
leaq 0x178(%rsp), %rdi
leaq 0x98(%rsp), %rdx
callq 0x1397c
leaq 0xa0(%rsp), %rdi
callq 0x4548
leaq 0xfd91(%rip), %rsi      # 0x23096
leaq 0x178(%rsp), %rdi
callq 0x44e0
leaq 0x198(%rsp), %rdi
movq %r14, %rsi
callq 0x4180
leaq 0x1b8(%rsp), %r13
movq %r13, %rdi
movq %r12, %rsi
callq 0x4180
leaq 0x1f0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x210(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x230(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0xfd27(%rip), %rsi      # 0x2309e
leaq 0x1e0(%rsp), %rdi
callq 0x44e0
leaq 0x200(%rsp), %rdi
movq %r14, %rsi
callq 0x4180
leaq 0x120(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x140(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x160(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
movl 0x4(%rsp), %ebp
testb %bpl, %bpl
movq 0x8(%rsp), %rbx
jne 0x13497
leaq 0x288(%rsp), %rdi
movq %r13, %rsi
callq 0x41f0
leaq 0x10129(%rip), %rsi     # 0x23521
leaq 0x248(%rsp), %rdi
callq 0x8453
testb %al, %al
je 0x13497
leaq 0xfcb1(%rip), %rsi      # 0x230c5
leaq 0x248(%rsp), %rdi
callq 0x44e0
leaq 0x78(%rsp), %rdi
movq %r13, %rsi
callq 0x4390
leaq 0x10(%rsp), %rdi
leaq 0x78(%rsp), %rdx
movq %r15, %rsi
callq 0x1af90
leaq 0x78(%rsp), %rdi
callq 0x4548
leaq 0x100d0(%rip), %rsi     # 0x23521
leaq 0x110(%rsp), %rdi
callq 0x44e0
leaq 0x130(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x4180
leaq 0x150(%rsp), %rdi
movq %r13, %rsi
callq 0x4180
leaq 0x10(%rsp), %rsi
movq %r13, %rdi
callq 0x4180
leaq 0x10(%rsp), %rdi
callq 0x4548
leaq 0x20(%rbx), %r15
leaq 0x2b0(%rsp), %rsi
movq %r15, %rdi
callq 0x13a3e
leaq 0x248(%rsp), %rsi
movq %r15, %rdi
callq 0x13a3e
leaq 0x1e0(%rsp), %rsi
movq %r15, %rdi
callq 0x13a3e
testb %bpl, %bpl
jne 0x134eb
cmpq $0x0, 0x118(%rsp)
je 0x134eb
leaq 0x110(%rsp), %rsi
movq %r15, %rdi
callq 0x13a3e
leaq 0x178(%rsp), %rsi
movq %r15, %rdi
callq 0x13a3e
leaq 0x20(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq 0x40(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0x60(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0xfc48(%rip), %rsi      # 0x2317c
leaq 0x10(%rsp), %rdi
callq 0x44e0
leaq 0x30(%rsp), %rdi
movq %r14, %rsi
callq 0x4180
leaq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x13a3e
leaq 0x10(%rsp), %rdi
callq 0x81fe
leaq 0x110(%rsp), %rdi
callq 0x81fe
leaq 0x1e0(%rsp), %rdi
callq 0x81fe
leaq 0x178(%rsp), %rdi
callq 0x81fe
leaq 0x248(%rsp), %rdi
callq 0x81fe
leaq 0x2b0(%rsp), %rdi
callq 0x81fe
movq %rbx, %rax
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
leaq 0x78(%rsp), %rdi
jmp 0x135cc
jmp 0x13637
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x4548
jmp 0x1363a
movq %rax, %r14
leaq 0xa0(%rsp), %rdi
callq 0x4548
jmp 0x13661
jmp 0x135e7
movq %rax, %r14
jmp 0x13661
movq %rax, %r14
leaq 0xc8(%rsp), %rdi
callq 0x4548
jmp 0x1366e
jmp 0x13600
movq %rax, %r14
jmp 0x1366e
movq %rax, %r14
leaq 0xf0(%rsp), %rdi
callq 0x4548
jmp 0x1367b
jmp 0x13619
movq %rax, %r14
jmp 0x1367b
movq %rax, %r14
jmp 0x13647
movq %rax, %r14
leaq 0x10(%rsp), %rdi
callq 0x81fe
jmp 0x1363a
movq %rax, %r14
jmp 0x13654
movq %rax, %r14
leaq 0x110(%rsp), %rdi
callq 0x81fe
leaq 0x1e0(%rsp), %rdi
callq 0x81fe
leaq 0x178(%rsp), %rdi
callq 0x81fe
leaq 0x248(%rsp), %rdi
callq 0x81fe
leaq 0x2b0(%rsp), %rdi
callq 0x81fe
movq 0x8(%rsp), %rdi
callq 0x13ad2
movq %r14, %rdi
callq 0x4490
nop