// File: /workspace/github_cpp_makefile_star2_O3/Merulo[P]CompilerJFTT/src/IRs/FourthIR.cpp
// Function: FourthIR::convertBlockToAssembler(Pair&, RegisterBlock&)
void FourthIR::convertBlockToAssembler(Pair& pair, RegisterBlock& registerBlock)
{
    if (std::find(_blocks.begin(), _blocks.end(), pair.block) != _blocks.end())
    {
        return;
    }
    pair.startRegisterBlock = registerBlock;
    pair.registerBlockIsSet = true;

    Block resultBlock;
    resultBlock.blockName = pair.block.blockName;
    for(auto& l : pair.block.lines)
    {
        if (l.operation == "CONST")
        {
            handleConst(registerBlock, resultBlock, l);
        }
        if (l.operation == "WRITE")
        {
            handleWrite(registerBlock, resultBlock, l);
        }
        if (l.operation == "READ")
        {
            handleRead(registerBlock, resultBlock, l);
        }
        if (l.operation == "COPY")
        {
            handleCopy(registerBlock, resultBlock, l);
        }
        if (l.operation == "ADD" || l.operation == "SUB")
        {
            handleDirectTranslation(registerBlock, resultBlock, l);
        }        
        if (l.operation == "HALT")
        {
            resultBlock.lines.push_back({"HALT"});
        }
        if (l.operation == "JUMP")
        {
            resultBlock.lines.push_back(l);
        }
        if (l.operation == "JZERO" || l.operation == "JODD" || l.operation == "INC" || l.operation == "DEC" || l.operation == "HALF")
        {
            handleSimpleOperation(registerBlock, resultBlock, l);
        }
        if (l.operation == "MUL")
        {
            handleMul(registerBlock, resultBlock, l);
        }
        if (l.operation == "DIV")
        {
            handleDiv(registerBlock, resultBlock, l);
        }
        if (l.operation == "MOD")
        {
            handleMod(registerBlock, resultBlock, l);
        }        
        if (l.operation == "#DO NOT REMOVE CONST")
        {
            _removeConsts = false;
        }    
    }
    pair.endRegisterBlock = registerBlock; 
    _blocks.push_back(resultBlock);
    continueConverting(pair, registerBlock);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %r15
movq 0x10(%rdi), %rdi
movq 0x18(%r15), %rsi
movq %r14, %rdx
callq 0x2ae1c
cmpq 0x18(%r15), %rax
jne 0x24e0a
movq (%r12), %rax
movq %rax, 0x128(%r14)
leaq 0x130(%r14), %rdi
leaq 0x8(%r12), %rsi
movq %rsi, 0x88(%rsp)
callq 0xc0d2
movups 0x10(%r12), %xmm0
movups %xmm0, 0x138(%r14)
leaq 0x148(%r14), %rdi
leaq 0x20(%r12), %rsi
movq %rsi, 0x80(%rsp)
callq 0x4170
leaq 0x168(%r14), %rdi
leaq 0x40(%r12), %rbx
movq %rbx, %rsi
callq 0x4170
movb 0x60(%r12), %al
movb %al, 0x188(%r14)
leaq 0x190(%r14), %rdi
leaq 0x68(%r12), %rsi
movq %rsi, 0x68(%rsp)
callq 0x2a256
movl 0x80(%r12), %eax
movl %eax, 0x1a8(%r14)
movb $0x1, 0x1b0(%r14)
leaq 0xa8(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rcx)
movq %rax, 0x20(%rcx)
leaq 0xe0(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x100(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x120(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movb %al, 0x10(%rcx)
leaq 0x98(%rsp), %rdi
movq %r14, %rsi
callq 0x4170
movq %r12, (%rsp)
movq %rbx, 0x78(%rsp)
movq 0x20(%r14), %r13
movq %r14, 0x70(%rsp)
movq 0x28(%r14), %rax
movq %rax, 0x90(%rsp)
cmpq %rax, %r13
je 0x24c48
leaq 0x48(%rsp), %rbp
leaq 0x28(%rsp), %rbx
leaq 0x138(%rsp), %r12
movq %r13, %rdi
leaq 0x12c4e(%rip), %rsi     # 0x37521
callq 0x40d0
testl %eax, %eax
jne 0x248f3
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x24ec0
movq %r13, %rdi
leaq 0x12bd3(%rip), %rsi     # 0x374d0
callq 0x40d0
testl %eax, %eax
jne 0x2491d
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x253b2
movq %r13, %rdi
leaq 0x12bdf(%rip), %rsi     # 0x37506
callq 0x40d0
testl %eax, %eax
jne 0x24947
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x2579c
movq %r13, %rdi
leaq 0x12774(%rip), %rsi     # 0x370c5
callq 0x40d0
testl %eax, %eax
jne 0x24971
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x25aba
movq %r13, %rdi
leaq 0x12727(%rip), %rsi     # 0x370a2
callq 0x40d0
testl %eax, %eax
je 0x24997
movq %r13, %rdi
leaq 0x12708(%rip), %rsi     # 0x37096
callq 0x40d0
testl %eax, %eax
jne 0x249ae
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x2602e
movq %r13, %rdi
leaq 0x12ac7(%rip), %rsi     # 0x3747f
callq 0x40d0
testl %eax, %eax
jne 0x24b04
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
leaq 0x12aa4(%rip), %rsi     # 0x3747f
leaq 0x12aa1(%rip), %rdx     # 0x37483
callq 0x53cc
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movq %rbp, %rdi
leaq 0x126e8(%rip), %r14     # 0x370e3
movq %r14, %rsi
movq %r14, %rdx
callq 0x53cc
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movq %r14, %rdx
callq 0x53cc
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0xbbea
leaq 0xb8(%rsp), %rdi
movq %r12, %rsi
callq 0xccac
movq 0x178(%rsp), %rdi
leaq 0x188(%rsp), %rax
cmpq %rax, %rdi
je 0x24a66
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x158(%rsp), %rdi
leaq 0x168(%rsp), %rax
cmpq %rax, %rdi
je 0x24a8b
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x138(%rsp), %rdi
leaq 0x148(%rsp), %rax
cmpq %rax, %rdi
je 0x24ab0
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x24acc
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x24ae8
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x24b04
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42a0
movq %r13, %rdi
leaq 0x1267e(%rip), %rsi     # 0x3718c
callq 0x40d0
testl %eax, %eax
jne 0x24b27
leaq 0xb8(%rsp), %rdi
movq %r13, %rsi
callq 0x1f6f6
movq %r13, %rdi
leaq 0x1264b(%rip), %rsi     # 0x3717c
callq 0x40d0
testl %eax, %eax
je 0x24b86
movq %r13, %rdi
leaq 0x1263e(%rip), %rsi     # 0x37182
callq 0x40d0
testl %eax, %eax
je 0x24b86
movq %r13, %rdi
leaq 0x12547(%rip), %rsi     # 0x3709e
callq 0x40d0
testl %eax, %eax
je 0x24b86
movq %r13, %rdi
leaq 0x12530(%rip), %rsi     # 0x3709a
callq 0x40d0
testl %eax, %eax
je 0x24b86
movq %r13, %rdi
leaq 0x1260a(%rip), %rsi     # 0x37187
callq 0x40d0
testl %eax, %eax
jne 0x24b9d
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x267aa
movq %r13, %rdi
leaq 0x128e1(%rip), %rsi     # 0x37488
callq 0x40d0
testl %eax, %eax
jne 0x24bc7
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x26afa
movq %r13, %rdi
leaq 0x128bb(%rip), %rsi     # 0x3748c
callq 0x40d0
testl %eax, %eax
jne 0x24bf1
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x27502
movq %r13, %rdi
leaq 0x12895(%rip), %rsi     # 0x37490
callq 0x40d0
testl %eax, %eax
jne 0x24c1b
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x27fde
movq %r13, %rdi
leaq 0x128ed(%rip), %rsi     # 0x37512
callq 0x40d0
testl %eax, %eax
jne 0x24c36
movb $0x0, 0xd0(%r15)
addq $0x68, %r13
cmpq 0x90(%rsp), %r13
jne 0x248c9
movq (%rsp), %r12
leaq 0x10(%r12), %rbx
movq (%r12), %rax
movq 0x70(%rsp), %r14
movq %rax, 0xa0(%r14)
leaq 0xa8(%r14), %rdi
movq 0x88(%rsp), %rsi
callq 0xc0d2
movups (%rbx), %xmm0
movups %xmm0, 0xb0(%r14)
leaq 0xc0(%r14), %rdi
movq 0x80(%rsp), %rsi
callq 0x4170
movq 0x78(%rsp), %rsi
leaq 0xe0(%r14), %rdi
callq 0x4170
movb 0x60(%r12), %al
movb %al, 0x100(%r14)
leaq 0x108(%r14), %rdi
movq 0x68(%rsp), %rsi
callq 0x2a256
leaq 0x10(%r15), %rdi
movl 0x80(%r12), %eax
movl %eax, 0x120(%r14)
leaq 0x98(%rsp), %rsi
callq 0x1f720
leaq 0x1a0(%rsp), %rdi
movq %r12, %rsi
callq 0x54ec
leaq 0x1a0(%rsp), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x28b1a
leaq 0x208(%rsp), %rbx
movq %rbx, %rdi
callq 0xbbba
movq -0x28(%rbx), %rdi
leaq 0x1f0(%rsp), %rax
cmpq %rax, %rdi
je 0x24d36
movq 0x1f0(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x1d0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x24d57
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x1a8(%rsp), %rdi
testq %rdi, %rdi
je 0x24d69
callq 0xc11c
movq 0x110(%rsp), %rdi
leaq 0x120(%rsp), %rax
cmpq %rax, %rdi
je 0x24d8e
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0xf0(%rsp), %rdi
leaq 0x100(%rsp), %rax
cmpq %rax, %rdi
je 0x24db3
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x24dd8
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0xb8(%rsp), %rdi
callq 0xbcf0
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x24e0a
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x42a0
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x1a0(%rsp), %rdi
callq 0x29daa
jmp 0x24eaa
jmp 0x24ea7
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0xbca2
jmp 0x24e47
jmp 0x24ea7
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x24e68
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x24e68
movq %rax, %rbx
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x24e89
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x24e89
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x24eaa
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x24eaa
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x1f750
movq %rbx, %rdi
callq 0x44c0
nop