// File: Merulo[P]CompilerJFTT/src/IRs/FourthIR.cpp
// Function: FourthIR::handleDirectTranslation(RegisterBlock&, Block&, Line&)
void FourthIR::handleDirectTranslation(RegisterBlock& rb, Block& b, Line& l)
{   
    Register& regOne = rb.getRegister(l.one, b, {}, true, true);
    updateRegisterState(b, rb, regOne, l.one);
    regOne.variableName = l.one;
    regOne.needToSafe = true;

    if (l.one == l.two && l.operation == "ADD")
    {
        b.lines.push_back({l.operation, regOne.name, regOne.name});
        return;
    }

    Register& regTwo = rb.getRegister(l.two, b, {regOne}, false, true);
    updateRegisterState(b, rb, regTwo, l.two);
    regTwo.variableName = l.two;

    b.lines.push_back({l.operation, regOne.name, regTwo.name});  

    if (_symbolTable->isConst(l.two) && _removeConsts)
    {
        regTwo.variableName = "";
        regTwo.state = RegisterState::UNKNOWN;
    }
}

// Assembly:
subq $0x398, %rsp            # imm = 0x398
movq %rdi, 0x390(%rsp)
movq %rsi, 0x388(%rsp)
movq %rdx, 0x380(%rsp)
movq %rcx, 0x378(%rsp)
movq 0x390(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0x388(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq 0x378(%rsp), %rsi
addq $0x20, %rsi
leaq 0x350(%rsp), %rdi
movq %rdi, 0xb0(%rsp)
callq 0x4180
movq 0x380(%rsp), %rax
movq %rax, 0xb8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x330(%rsp)
movq $0x0, 0x340(%rsp)
leaq 0x330(%rsp), %rdi
movq %rdi, 0xc0(%rsp)
callq 0x391c0
movq 0xa8(%rsp), %rdi
movq 0xb0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
movq 0xc0(%rsp), %rcx
movl $0x1, %r9d
movl %r9d, %r8d
callq 0x7ac0
movq %rax, 0xc8(%rsp)
jmp 0x3455c
leaq 0x330(%rsp), %rdi
callq 0xd9c0
leaq 0x350(%rsp), %rdi
callq 0x46e8
movq 0xc8(%rsp), %rax
movq %rax, 0x370(%rsp)
movq 0x380(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x388(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x370(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x378(%rsp), %rsi
addq $0x20, %rsi
leaq 0x300(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x4180
movq 0xa0(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq 0x90(%rsp), %rcx
movq 0x98(%rsp), %r8
callq 0x37870
jmp 0x34606
leaq 0x300(%rsp), %rdi
callq 0x46e8
movq 0x378(%rsp), %rsi
addq $0x20, %rsi
movq 0x370(%rsp), %rdi
addq $0x30, %rdi
callq 0x4050
movq 0x370(%rsp), %rax
movb $0x1, 0x50(%rax)
movq 0x378(%rsp), %rdi
addq $0x20, %rdi
movq 0x378(%rsp), %rsi
addq $0x40, %rsi
callq 0xd2c0
testb $0x1, %al
jne 0x34662
jmp 0x34837
movq 0x378(%rsp), %rdi
leaq 0x1ca69(%rip), %rsi     # 0x510da
callq 0xdd10
testb $0x1, %al
jne 0x3467f
jmp 0x34837
movq 0x380(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x78(%rsp)
movq 0x378(%rsp), %rsi
leaq 0x278(%rsp), %rdi
callq 0x4180
movq 0x370(%rsp), %rsi
addq $0x10, %rsi
leaq 0x258(%rsp), %rdi
callq 0x4180
jmp 0x346c0
movq 0x370(%rsp), %rsi
addq $0x10, %rsi
leaq 0x238(%rsp), %rdi
callq 0x4180
jmp 0x346db
leaq 0x298(%rsp), %rdi
leaq 0x278(%rsp), %rsi
leaq 0x258(%rsp), %rdx
leaq 0x238(%rsp), %rcx
callq 0xd3b0
jmp 0x34702
movq 0x78(%rsp), %rdi
leaq 0x298(%rsp), %rsi
callq 0xd380
jmp 0x34716
leaq 0x298(%rsp), %rdi
callq 0xd490
leaq 0x238(%rsp), %rdi
callq 0x46e8
leaq 0x258(%rsp), %rdi
callq 0x46e8
leaq 0x278(%rsp), %rdi
callq 0x46e8
jmp 0x34c73
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x328(%rsp)
movl %eax, 0x324(%rsp)
leaq 0x330(%rsp), %rdi
callq 0xd9c0
leaq 0x350(%rsp), %rdi
callq 0x46e8
jmp 0x34c7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x328(%rsp)
movl %eax, 0x324(%rsp)
leaq 0x300(%rsp), %rdi
callq 0x46e8
jmp 0x34c7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x328(%rsp)
movl %eax, 0x324(%rsp)
jmp 0x34825
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x328(%rsp)
movl %eax, 0x324(%rsp)
jmp 0x34818
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x328(%rsp)
movl %eax, 0x324(%rsp)
jmp 0x3480b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x328(%rsp)
movl %eax, 0x324(%rsp)
leaq 0x298(%rsp), %rdi
callq 0xd490
leaq 0x238(%rsp), %rdi
callq 0x46e8
leaq 0x258(%rsp), %rdi
callq 0x46e8
leaq 0x278(%rsp), %rdi
callq 0x46e8
jmp 0x34c7b
movq 0x388(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x378(%rsp), %rsi
addq $0x40, %rsi
leaq 0x210(%rsp), %rdi
callq 0x4180
movq 0x380(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x370(%rsp), %rsi
leaq 0x1e0(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0xddf0
movq 0x68(%rsp), %rax
movq %rax, 0x1e8(%rsp)
movq $0x1, 0x1f0(%rsp)
leaq 0x1df(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0xde20
movq 0x70(%rsp), %rcx
movq 0x1e8(%rsp), %rsi
movq 0x1f0(%rsp), %rdx
leaq 0x1f8(%rsp), %rdi
callq 0xde30
jmp 0x348d3
movq 0x60(%rsp), %rdx
movq 0x58(%rsp), %rdi
leaq 0x210(%rsp), %rsi
leaq 0x1f8(%rsp), %rcx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x7ac0
movq %rax, 0x50(%rsp)
jmp 0x34902
leaq 0x1f8(%rsp), %rdi
callq 0xd9c0
leaq 0x1df(%rsp), %rdi
callq 0xdec0
leaq 0x210(%rsp), %rdi
callq 0x46e8
movq 0x50(%rsp), %rax
movq %rax, 0x230(%rsp)
movq 0x380(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x388(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x230(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x378(%rsp), %rsi
addq $0x40, %rsi
leaq 0x1b8(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x4180
movq 0xa0(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq 0x40(%rsp), %rcx
movq 0x48(%rsp), %r8
callq 0x37870
jmp 0x3499e
leaq 0x1b8(%rsp), %rdi
callq 0x46e8
movq 0x378(%rsp), %rsi
addq $0x40, %rsi
movq 0x230(%rsp), %rdi
addq $0x30, %rdi
callq 0x4050
movq 0x380(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x28(%rsp)
movq 0x378(%rsp), %rsi
leaq 0x130(%rsp), %rdi
callq 0x4180
movq 0x370(%rsp), %rsi
addq $0x10, %rsi
leaq 0x110(%rsp), %rdi
callq 0x4180
jmp 0x34a09
movq 0x230(%rsp), %rsi
addq $0x10, %rsi
leaq 0xf0(%rsp), %rdi
callq 0x4180
jmp 0x34a24
leaq 0x150(%rsp), %rdi
leaq 0x130(%rsp), %rsi
leaq 0x110(%rsp), %rdx
leaq 0xf0(%rsp), %rcx
callq 0xd3b0
jmp 0x34a4b
movq 0x28(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0xd380
jmp 0x34a5f
leaq 0x150(%rsp), %rdi
callq 0xd490
leaq 0xf0(%rsp), %rdi
callq 0x46e8
leaq 0x110(%rsp), %rdi
callq 0x46e8
leaq 0x130(%rsp), %rdi
callq 0x46e8
movq 0xa0(%rsp), %rdi
callq 0xdde0
movq %rax, 0x10(%rsp)
movq 0x378(%rsp), %rsi
addq $0x40, %rsi
leaq 0xd0(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x4180
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x20600
movb %al, 0x27(%rsp)
jmp 0x34ad8
movb 0x27(%rsp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0xf(%rsp)
jne 0x34ae9
jmp 0x34afb
movq 0xa0(%rsp), %rax
movb 0xd0(%rax), %al
movb %al, 0xf(%rsp)
movb 0xf(%rsp), %al
movb %al, 0xe(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x46e8
movb 0xe(%rsp), %al
testb $0x1, %al
jne 0x34b1d
jmp 0x34c73
movq 0x230(%rsp), %rdi
addq $0x30, %rdi
leaq 0x1c5eb(%rip), %rsi     # 0x5111b
callq 0x44a0
movq 0x230(%rsp), %rax
movl $0x0, (%rax)
jmp 0x34c73
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x328(%rsp)
movl %eax, 0x324(%rsp)
jmp 0x34b7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x328(%rsp)
movl %eax, 0x324(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0xd9c0
leaq 0x1df(%rsp), %rdi
callq 0xdec0
leaq 0x210(%rsp), %rdi
callq 0x46e8
jmp 0x34c7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x328(%rsp)
movl %eax, 0x324(%rsp)
leaq 0x1b8(%rsp), %rdi
callq 0x46e8
jmp 0x34c7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x328(%rsp)
movl %eax, 0x324(%rsp)
jmp 0x34c41
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x328(%rsp)
movl %eax, 0x324(%rsp)
jmp 0x34c34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x328(%rsp)
movl %eax, 0x324(%rsp)
jmp 0x34c27
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x328(%rsp)
movl %eax, 0x324(%rsp)
leaq 0x150(%rsp), %rdi
callq 0xd490
leaq 0xf0(%rsp), %rdi
callq 0x46e8
leaq 0x110(%rsp), %rdi
callq 0x46e8
leaq 0x130(%rsp), %rdi
callq 0x46e8
jmp 0x34c7b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x328(%rsp)
movl %eax, 0x324(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0x46e8
jmp 0x34c7b
addq $0x398, %rsp            # imm = 0x398
retq
movq 0x328(%rsp), %rdi
callq 0x45f0
nopl (%rax,%rax)