// File: Merulo[P]CompilerJFTT/src/IRs/FourthIR.cpp
// Function: FourthIR::parse(std::vector<Block, std::allocator<Block>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool)
void FourthIR::parse(std::vector<Block> bs, std::string fileName, bool useEmulator)
{
    for(auto& b : bs)
    {
        Pair p;
        p.block = b;
        _notYetConvertedBlocks.push_back(p);
    }

    if (isDeterministic() && useEmulator)
    {
        _blocks = bs;
        std::string tmpFile = "tmp.ir";
        print(tmpFile);
        EmulatorRunner er;
        bool value = er.emulate(tmpFile, fileName);
        _blocks = {};
        if (value)
        {
            exit(0);
        }
    }

    _symbolTable->assignMemory();
    convertToAssembler();

}

// Assembly:
subq $0x2b8, %rsp            # imm = 0x2B8
movq %rdx, 0x20(%rsp)
movq %rsi, 0x28(%rsp)
movb %cl, %al
movq %rdi, 0x2b0(%rsp)
movq %rsi, 0x2a8(%rsp)
movq %rdx, 0x2a0(%rsp)
andb $0x1, %al
movb %al, 0x29f(%rsp)
movq 0x2b0(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %rsi, 0x290(%rsp)
movq 0x290(%rsp), %rdi
callq 0x29fd0
movq %rax, 0x288(%rsp)
movq 0x290(%rsp), %rdi
callq 0x2a870
movq %rax, 0x280(%rsp)
leaq 0x288(%rsp), %rdi
leaq 0x280(%rsp), %rsi
callq 0x30be0
testb $0x1, %al
jne 0x321b1
jmp 0x3224c
leaq 0x288(%rsp), %rdi
callq 0x2bda0
movq %rax, 0x278(%rsp)
leaq 0xc0(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x38a30
movq 0x18(%rsp), %rdi
movq 0x278(%rsp), %rsi
callq 0x38ad0
jmp 0x321ec
movq 0x30(%rsp), %rdi
addq $0xb8, %rdi
leaq 0xc0(%rsp), %rsi
callq 0x38b70
jmp 0x32207
leaq 0xc0(%rsp), %rdi
callq 0x38bf0
leaq 0x288(%rsp), %rdi
callq 0x30c20
jmp 0x32193
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x38bf0
jmp 0x32428
movq 0x30(%rsp), %rdi
callq 0x32440
testb $0x1, %al
jne 0x3225f
jmp 0x32404
testb $0x1, 0x29f(%rsp)
je 0x32404
movq 0x28(%rsp), %rsi
movq 0x30(%rsp), %rdi
addq $0x10, %rdi
callq 0x38c30
leaq 0x8f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x4600
movq 0x10(%rsp), %rdx
leaq 0x1f2ae(%rip), %rsi     # 0x5154c
leaq 0x90(%rsp), %rdi
callq 0x4f10
jmp 0x322ad
leaq 0x8f(%rsp), %rdi
callq 0x43b0
movq 0x30(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x3d870
jmp 0x322ce
leaq 0x68(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x4180
jmp 0x322e2
movq 0x20(%rsp), %rsi
leaq 0x48(%rsp), %rdi
callq 0x4180
jmp 0x322f3
leaq 0x8e(%rsp), %rdi
leaq 0x68(%rsp), %rsi
leaq 0x48(%rsp), %rdx
callq 0x4c00
movb %al, 0xf(%rsp)
jmp 0x32310
leaq 0x48(%rsp), %rdi
callq 0x46e8
leaq 0x68(%rsp), %rdi
callq 0x46e8
movb 0xf(%rsp), %al
andb $0x1, %al
movb %al, 0x8d(%rsp)
leaq 0x38(%rsp), %rdi
callq 0x38f00
movq 0x30(%rsp), %rdi
addq $0x10, %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
callq 0x38f20
jmp 0x32355
testb $0x1, 0x8d(%rsp)
je 0x323e6
xorl %edi, %edi
callq 0x4420
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
leaq 0x8f(%rsp), %rdi
callq 0x43b0
jmp 0x32428
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
jmp 0x323f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
jmp 0x323da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb8(%rsp)
movl %eax, 0xb4(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x46e8
leaq 0x68(%rsp), %rdi
callq 0x46e8
jmp 0x323f5
leaq 0x90(%rsp), %rdi
callq 0x46e8
jmp 0x32404
leaq 0x90(%rsp), %rdi
callq 0x46e8
jmp 0x32428
movq 0x30(%rsp), %rdi
callq 0xdde0
movq %rax, %rdi
callq 0x20390
movq 0x30(%rsp), %rdi
callq 0x32540
addq $0x2b8, %rsp            # imm = 0x2B8
retq
movq 0xb8(%rsp), %rdi
callq 0x45f0
nopw %cs:(%rax,%rax)