// File: /workspace/github_cpp_makefile_star2_O1/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 0x2b0d2
cmpq 0x18(%r15), %rax
jne 0x2508a
movq (%r12), %rax
movq %rax, 0x128(%r14)
leaq 0x130(%r14), %rdi
leaq 0x8(%r12), %rsi
movq %rsi, 0x88(%rsp)
callq 0xc33e
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 0x2a520
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 0x24ec8
leaq 0x48(%rsp), %rbp
leaq 0x28(%rsp), %rbx
leaq 0x138(%rsp), %r12
movq %r13, %rdi
leaq 0x139ce(%rip), %rsi     # 0x38521
callq 0x40d0
testl %eax, %eax
jne 0x24b73
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x25140
movq %r13, %rdi
leaq 0x13953(%rip), %rsi     # 0x384d0
callq 0x40d0
testl %eax, %eax
jne 0x24b9d
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x25620
movq %r13, %rdi
leaq 0x1395f(%rip), %rsi     # 0x38506
callq 0x40d0
testl %eax, %eax
jne 0x24bc7
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x25a0a
movq %r13, %rdi
leaq 0x134f4(%rip), %rsi     # 0x380c5
callq 0x40d0
testl %eax, %eax
jne 0x24bf1
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x25d28
movq %r13, %rdi
leaq 0x134a7(%rip), %rsi     # 0x380a2
callq 0x40d0
testl %eax, %eax
je 0x24c17
movq %r13, %rdi
leaq 0x13488(%rip), %rsi     # 0x38096
callq 0x40d0
testl %eax, %eax
jne 0x24c2e
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x2629c
movq %r13, %rdi
leaq 0x13847(%rip), %rsi     # 0x3847f
callq 0x40d0
testl %eax, %eax
jne 0x24d84
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x8(%rsp), %rdi
leaq 0x13824(%rip), %rsi     # 0x3847f
leaq 0x13821(%rip), %rdx     # 0x38483
callq 0x54fc
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movq %rbp, %rdi
leaq 0x13468(%rip), %r14     # 0x380e3
movq %r14, %rsi
movq %r14, %rdx
callq 0x54fc
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movq %r14, %rdx
callq 0x54fc
movq %r12, %rdi
leaq 0x8(%rsp), %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0xbe58
leaq 0xb8(%rsp), %rdi
movq %r12, %rsi
callq 0xcf0e
movq 0x178(%rsp), %rdi
leaq 0x188(%rsp), %rax
cmpq %rax, %rdi
je 0x24ce6
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x158(%rsp), %rdi
leaq 0x168(%rsp), %rax
cmpq %rax, %rdi
je 0x24d0b
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x138(%rsp), %rdi
leaq 0x148(%rsp), %rax
cmpq %rax, %rdi
je 0x24d30
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x24d4c
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x24d68
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x24d84
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42a0
movq %r13, %rdi
leaq 0x133fe(%rip), %rsi     # 0x3818c
callq 0x40d0
testl %eax, %eax
jne 0x24da7
leaq 0xb8(%rsp), %rdi
movq %r13, %rsi
callq 0x1f9be
movq %r13, %rdi
leaq 0x133cb(%rip), %rsi     # 0x3817c
callq 0x40d0
testl %eax, %eax
je 0x24e06
movq %r13, %rdi
leaq 0x133be(%rip), %rsi     # 0x38182
callq 0x40d0
testl %eax, %eax
je 0x24e06
movq %r13, %rdi
leaq 0x132c7(%rip), %rsi     # 0x3809e
callq 0x40d0
testl %eax, %eax
je 0x24e06
movq %r13, %rdi
leaq 0x132b0(%rip), %rsi     # 0x3809a
callq 0x40d0
testl %eax, %eax
je 0x24e06
movq %r13, %rdi
leaq 0x1338a(%rip), %rsi     # 0x38187
callq 0x40d0
testl %eax, %eax
jne 0x24e1d
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x26a10
movq %r13, %rdi
leaq 0x13661(%rip), %rsi     # 0x38488
callq 0x40d0
testl %eax, %eax
jne 0x24e47
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x26d60
movq %r13, %rdi
leaq 0x1363b(%rip), %rsi     # 0x3848c
callq 0x40d0
testl %eax, %eax
jne 0x24e71
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x27768
movq %r13, %rdi
leaq 0x13615(%rip), %rsi     # 0x38490
callq 0x40d0
testl %eax, %eax
jne 0x24e9b
movq %r15, %rdi
movq (%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rcx
callq 0x28244
movq %r13, %rdi
leaq 0x1366d(%rip), %rsi     # 0x38512
callq 0x40d0
testl %eax, %eax
jne 0x24eb6
movb $0x0, 0xd0(%r15)
addq $0x68, %r13
cmpq 0x90(%rsp), %r13
jne 0x24b49
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 0xc33e
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 0x2a520
leaq 0x10(%r15), %rdi
movl 0x80(%r12), %eax
movl %eax, 0x120(%r14)
leaq 0x98(%rsp), %rsi
callq 0x1f9e8
leaq 0x1a0(%rsp), %rdi
movq %r12, %rsi
callq 0x5614
leaq 0x1a0(%rsp), %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0x28d88
leaq 0x208(%rsp), %rbx
movq %rbx, %rdi
callq 0xbe28
movq -0x28(%rbx), %rdi
leaq 0x1f0(%rsp), %rax
cmpq %rax, %rdi
je 0x24fb6
movq 0x1f0(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x1d0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x24fd7
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x1a8(%rsp), %rdi
testq %rdi, %rdi
je 0x24fe9
callq 0xc384
movq 0x110(%rsp), %rdi
leaq 0x120(%rsp), %rax
cmpq %rax, %rdi
je 0x2500e
movq 0x120(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0xf0(%rsp), %rdi
leaq 0x100(%rsp), %rax
cmpq %rax, %rdi
je 0x25033
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0x25058
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0xb8(%rsp), %rdi
callq 0xbf5e
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x2508a
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 0x2a05c
jmp 0x2512a
jmp 0x25127
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
callq 0xbf10
jmp 0x250c7
jmp 0x25127
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x250e8
movq 0x38(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x250e8
movq %rax, %rbx
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x25109
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x25109
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2512a
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x2512a
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x1fa18
movq %rbx, %rdi
callq 0x44c0
nop