// File: Merulo[P]CompilerJFTT/src/IRs/FirstIR.cpp
// Function: FirstIR::createSecondControlBlock(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
Block FirstIR::createSecondControlBlock(std::string iterator, bool isForTo, std::string name)
{
    Block b = generateBlock();
    b.blockName = name + "_exitFor";    
    Line incLine;
    incLine.operation = "INC";
    incLine.one = iterator;

    Line decLine;
    decLine.operation = "DEC";
    decLine.one = iterator + forControlName;

    Line writeLine;
    writeLine.operation = "WRITE";
    writeLine.one = iterator + forControlName;    

    Line line;
    line.operation = "JZERO";
    line.one = iterator + forControlName;

    if (!isForTo)
    {
        incLine.operation = "DEC";
    }

    b.lines.push_back(incLine);
    b.lines.push_back(decLine);
    b.lines.push_back(line);    

    return b;
}

// Assembly:
subq $0x2a8, %rsp            # imm = 0x2A8
movq %r8, 0x40(%rsp)
movq %rdx, 0x20(%rsp)
movq %rdi, 0x28(%rsp)
movb %cl, %al
movq %rdi, %rcx
movq %rcx, 0x30(%rsp)
movq %rdi, 0x2a0(%rsp)
movq %rsi, 0x298(%rsp)
movq %rdx, 0x290(%rsp)
andb $0x1, %al
movb %al, 0x28f(%rsp)
movq %r8, 0x280(%rsp)
movq 0x298(%rsp), %rsi
movq %rsi, 0x38(%rsp)
movb $0x0, 0x27f(%rsp)
callq 0x3d200
movq 0x40(%rsp), %rsi
leaq 0x28138(%rip), %rdx     # 0x514f7
leaq 0x258(%rsp), %rdi
callq 0x299c0
jmp 0x293ce
movq 0x28(%rsp), %rdi
leaq 0x258(%rsp), %rsi
movq %rsi, 0x18(%rsp)
callq 0x4440
movq 0x18(%rsp), %rdi
callq 0x46e8
leaq 0x1e0(%rsp), %rdi
callq 0xda30
jmp 0x293fe
leaq 0x27cd1(%rip), %rsi     # 0x510d6
leaq 0x1e0(%rsp), %rdi
callq 0x44a0
jmp 0x29414
movq 0x20(%rsp), %rsi
leaq 0x200(%rsp), %rdi
callq 0x4050
jmp 0x29428
leaq 0x178(%rsp), %rdi
callq 0xda30
jmp 0x29437
leaq 0x27c94(%rip), %rsi     # 0x510d2
leaq 0x178(%rsp), %rdi
callq 0x44a0
jmp 0x2944d
movq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq $0x78, %rdx
leaq 0x158(%rsp), %rdi
callq 0x21f70
jmp 0x2946a
leaq 0x198(%rsp), %rdi
leaq 0x158(%rsp), %rsi
movq %rsi, 0x10(%rsp)
callq 0x4440
movq 0x10(%rsp), %rdi
callq 0x46e8
leaq 0xf0(%rsp), %rdi
callq 0xda30
jmp 0x2949d
leaq 0x2805c(%rip), %rsi     # 0x51500
leaq 0xf0(%rsp), %rdi
callq 0x44a0
jmp 0x294b3
movq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq $0x78, %rdx
leaq 0xd0(%rsp), %rdi
callq 0x21f70
jmp 0x294d0
leaq 0x110(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
movq %rsi, 0x8(%rsp)
callq 0x4440
movq 0x8(%rsp), %rdi
callq 0x46e8
leaq 0x68(%rsp), %rdi
callq 0xda30
jmp 0x29500
leaq 0x27cad(%rip), %rsi     # 0x511b4
leaq 0x68(%rsp), %rdi
callq 0x44a0
jmp 0x29513
movq 0x20(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq $0x78, %rdx
leaq 0x48(%rsp), %rdi
callq 0x21f70
jmp 0x2952d
leaq 0x68(%rsp), %rdi
addq $0x20, %rdi
leaq 0x48(%rsp), %rsi
callq 0x4440
leaq 0x48(%rsp), %rdi
callq 0x46e8
testb $0x1, 0x28f(%rsp)
jne 0x295fa
leaq 0x27b73(%rip), %rsi     # 0x510d2
leaq 0x1e0(%rsp), %rdi
callq 0x44a0
jmp 0x2956e
jmp 0x295fa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x296c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x2969e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x29691
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
jmp 0x29684
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x250(%rsp)
movl %eax, 0x24c(%rsp)
leaq 0x68(%rsp), %rdi
callq 0xd490
jmp 0x29684
movq 0x28(%rsp), %rdi
addq $0x20, %rdi
leaq 0x1e0(%rsp), %rsi
callq 0x297e0
jmp 0x29612
movq 0x28(%rsp), %rdi
addq $0x20, %rdi
leaq 0x178(%rsp), %rsi
callq 0x297e0
jmp 0x2962a
movq 0x28(%rsp), %rdi
addq $0x20, %rdi
leaq 0x68(%rsp), %rsi
callq 0x297e0
jmp 0x2963f
movb $0x1, 0x27f(%rsp)
leaq 0x68(%rsp), %rdi
callq 0xd490
leaq 0xf0(%rsp), %rdi
callq 0xd490
leaq 0x178(%rsp), %rdi
callq 0xd490
leaq 0x1e0(%rsp), %rdi
callq 0xd490
testb $0x1, 0x27f(%rsp)
jne 0x296b7
jmp 0x296ad
leaq 0xf0(%rsp), %rdi
callq 0xd490
leaq 0x178(%rsp), %rdi
callq 0xd490
leaq 0x1e0(%rsp), %rdi
callq 0xd490
jmp 0x296c4
movq 0x28(%rsp), %rdi
callq 0x29a50
movq 0x30(%rsp), %rax
addq $0x2a8, %rsp            # imm = 0x2A8
retq
movq 0x28(%rsp), %rdi
callq 0x29a50
movq 0x250(%rsp), %rdi
callq 0x45f0
nopl (%rax,%rax)