// File: /workspace/github_cpp_makefile_star2_O2/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 $0x218, %rsp            # imm = 0x218
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
movq 0x10(%rdi), %rdi
movq 0x18(%r14), %rsi
movq %rbx, %rdx
callq 0x1aaba
cmpq 0x18(%r14), %rax
jne 0x1703b
leaq 0x128(%rbx), %rdi
movq %r15, %rsi
callq 0x19daa
movb $0x1, 0x1b0(%rbx)
leaq 0x78(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
andq $0x0, 0x20(%rax)
leaq 0xb0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0xd0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq 0xf0(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
movb %cl, 0x10(%rax)
leaq 0x68(%rsp), %rdi
movq %rbx, %rsi
callq 0x4180
leaq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rbx), %rbp
movq %rbx, 0x18(%rsp)
movq 0x28(%rbx), %rax
movq %rax, 0x20(%rsp)
leaq 0xc3bc(%rip), %r12      # 0x230e3
cmpq 0x20(%rsp), %rbp
je 0x16fde
movq %rbp, %rdi
leaq 0xc7e5(%rip), %rsi      # 0x23521
callq 0x8453
testb %al, %al
je 0x16d58
movq %r14, %rdi
movq %r15, %rsi
leaq 0x68(%rsp), %rdx
movq %rbp, %rcx
callq 0x170ba
movq %rbp, %rdi
leaq 0xc76e(%rip), %rsi      # 0x234d0
callq 0x8453
testb %al, %al
je 0x16d7e
movq %r14, %rdi
movq %r15, %rsi
leaq 0x68(%rsp), %rdx
movq %rbp, %rcx
callq 0x1738e
movq %rbp, %rdi
leaq 0xc77e(%rip), %rsi      # 0x23506
callq 0x8453
testb %al, %al
je 0x16da4
movq %r14, %rdi
movq %r15, %rsi
leaq 0x68(%rsp), %rdx
movq %rbp, %rcx
callq 0x175c0
movq %rbp, %rdi
leaq 0xc317(%rip), %rsi      # 0x230c5
callq 0x8453
testb %al, %al
je 0x16dca
movq %r14, %rdi
movq %r15, %rsi
leaq 0x68(%rsp), %rdx
movq %rbp, %rcx
callq 0x17788
movq %rbp, %rdi
leaq 0xc2ce(%rip), %rsi      # 0x230a2
callq 0x8453
testb %al, %al
jne 0x16df0
movq %rbp, %rdi
leaq 0xc2af(%rip), %rsi      # 0x23096
callq 0x8453
testb %al, %al
je 0x16e03
movq %r14, %rdi
movq %r15, %rsi
leaq 0x68(%rsp), %rdx
movq %rbp, %rcx
callq 0x17aae
movq %rbp, %rdi
leaq 0xc672(%rip), %rsi      # 0x2347f
callq 0x8453
testb %al, %al
je 0x16eb3
leaq 0x48(%rsp), %rdi
leaq 0xc659(%rip), %rsi      # 0x2347f
leaq 0xf(%rsp), %rdx
callq 0x4a54
leaq 0x28(%rsp), %rdi
movq %r12, %r13
movq %r12, %rsi
leaq 0xe(%rsp), %rdx
callq 0x4a54
leaq 0x108(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
leaq 0xd(%rsp), %rdx
callq 0x4a54
leaq 0x1b0(%rsp), %r13
movq %r13, %rdi
leaq 0x48(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movq %rbx, %rcx
callq 0x816a
leaq 0x88(%rsp), %rdi
movq %r13, %rsi
callq 0x8f90
movq %r13, %rdi
callq 0x81fe
leaq 0x108(%rsp), %rdi
callq 0x4548
leaq 0x28(%rsp), %rdi
callq 0x4548
leaq 0x48(%rsp), %rdi
callq 0x4548
movq %rbp, %rdi
leaq 0xc2cf(%rip), %rsi      # 0x2318c
callq 0x8453
testb %al, %al
je 0x16ed6
leaq 0x88(%rsp), %rdi
movq %rbp, %rsi
callq 0x13a3e
movq %rbp, %rdi
leaq 0xc29c(%rip), %rsi      # 0x2317c
callq 0x8453
testb %al, %al
jne 0x16f35
movq %rbp, %rdi
leaq 0xc28f(%rip), %rsi      # 0x23182
callq 0x8453
testb %al, %al
jne 0x16f35
movq %rbp, %rdi
leaq 0xc198(%rip), %rsi      # 0x2309e
callq 0x8453
testb %al, %al
jne 0x16f35
movq %rbp, %rdi
leaq 0xc181(%rip), %rsi      # 0x2309a
callq 0x8453
testb %al, %al
jne 0x16f35
movq %rbp, %rdi
leaq 0xc25b(%rip), %rsi      # 0x23187
callq 0x8453
testb %al, %al
je 0x16f48
movq %r14, %rdi
movq %r15, %rsi
leaq 0x68(%rsp), %rdx
movq %rbp, %rcx
callq 0x17ede
movq %rbp, %rdi
leaq 0xc536(%rip), %rsi      # 0x23488
callq 0x8453
testb %al, %al
je 0x16f6e
movq %r14, %rdi
movq %r15, %rsi
leaq 0x68(%rsp), %rdx
movq %rbp, %rcx
callq 0x180c8
movq %rbp, %rdi
leaq 0xc514(%rip), %rsi      # 0x2348c
callq 0x8453
testb %al, %al
je 0x16f94
movq %r14, %rdi
movq %r15, %rsi
leaq 0x68(%rsp), %rdx
movq %rbp, %rcx
callq 0x185fe
movq %rbp, %rdi
leaq 0xc4f2(%rip), %rsi      # 0x23490
callq 0x8453
testb %al, %al
je 0x16fba
movq %r14, %rdi
movq %r15, %rsi
leaq 0x68(%rsp), %rdx
movq %rbp, %rcx
callq 0x18bf4
movq %rbp, %rdi
leaq 0xc54e(%rip), %rsi      # 0x23512
callq 0x8453
testb %al, %al
je 0x16fd5
movb $0x0, 0xd0(%r14)
addq $0x68, %rbp
jmp 0x16d27
movq 0x18(%rsp), %rbx
leaq 0xa0(%rbx), %rdi
movq %r15, %rsi
callq 0x19daa
leaq 0x68(%rsp), %rsi
movq 0x10(%rsp), %rdi
callq 0x13a6a
leaq 0x128(%rsp), %rdi
movq %r15, %rsi
callq 0x4c30
leaq 0x128(%rsp), %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x191c2
leaq 0x128(%rsp), %rdi
callq 0x19d86
leaq 0x68(%rsp), %rdi
callq 0x13ad2
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x19d86
jmp 0x170a8
jmp 0x170a5
jmp 0x170a5
movq %rax, %rbx
jmp 0x1708f
movq %rax, %rbx
leaq 0x1b0(%rsp), %rdi
callq 0x81fe
jmp 0x17082
movq %rax, %rbx
jmp 0x17099
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x4548
leaq 0x28(%rsp), %rdi
callq 0x4548
leaq 0x48(%rsp), %rdi
callq 0x4548
jmp 0x170a8
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x13ad2
movq %rbx, %rdi
callq 0x4490