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

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

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

    b.lines.push_back({"COPY", regOne.name, regTwo.name});  

    regOne.constValue = regTwo.constValue;
}

// Assembly:
subq $0x2d8, %rsp            # imm = 0x2D8
movq %rdi, 0x2d0(%rsp)
movq %rsi, 0x2c8(%rsp)
movq %rdx, 0x2c0(%rsp)
movq %rcx, 0x2b8(%rsp)
movq 0x2d0(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0x2c8(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq 0x2b8(%rsp), %rsi
addq $0x40, %rsi
leaq 0x290(%rsp), %rdi
movq %rdi, 0xb0(%rsp)
callq 0x4180
movq 0x2c0(%rsp), %rax
movq %rax, 0xb8(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x270(%rsp)
movq $0x0, 0x280(%rsp)
leaq 0x270(%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 0x33e8c
leaq 0x270(%rsp), %rdi
callq 0xd9c0
leaq 0x290(%rsp), %rdi
callq 0x46e8
movq 0xc8(%rsp), %rax
movq %rax, 0x2b0(%rsp)
movq 0x2c0(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x2c8(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x2b0(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x2b8(%rsp), %rsi
addq $0x40, %rsi
leaq 0x240(%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 0x33f36
leaq 0x240(%rsp), %rdi
callq 0x46e8
movq 0x2b8(%rsp), %rsi
addq $0x40, %rsi
movq 0x2b0(%rsp), %rdi
addq $0x30, %rdi
callq 0x4050
movq 0x2c8(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x2b8(%rsp), %rsi
addq $0x20, %rsi
leaq 0x218(%rsp), %rdi
callq 0x4180
movq 0x2c0(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x2b0(%rsp), %rsi
leaq 0x1e8(%rsp), %rdi
movq %rdi, 0x70(%rsp)
callq 0xddf0
movq 0x70(%rsp), %rax
movq %rax, 0x1f0(%rsp)
movq $0x1, 0x1f8(%rsp)
leaq 0x1e7(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0xde20
movq 0x78(%rsp), %rcx
movq 0x1f0(%rsp), %rsi
movq 0x1f8(%rsp), %rdx
leaq 0x200(%rsp), %rdi
callq 0xde30
jmp 0x33ffc
movq 0x68(%rsp), %rdx
movq 0x60(%rsp), %rdi
leaq 0x218(%rsp), %rsi
leaq 0x200(%rsp), %rcx
movl $0x1, %r8d
xorl %r9d, %r9d
callq 0x7ac0
movq %rax, 0x58(%rsp)
jmp 0x3402b
leaq 0x200(%rsp), %rdi
callq 0xd9c0
leaq 0x1e7(%rsp), %rdi
callq 0xdec0
leaq 0x218(%rsp), %rdi
callq 0x46e8
movq 0x58(%rsp), %rax
movq %rax, 0x238(%rsp)
movq 0x2c0(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x2c8(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x238(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x2b8(%rsp), %rsi
addq $0x20, %rsi
leaq 0x1c0(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x4180
movq 0xa0(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %r8
callq 0x37870
jmp 0x340c7
leaq 0x1c0(%rsp), %rdi
callq 0x46e8
movq 0x2b8(%rsp), %rsi
addq $0x20, %rsi
movq 0x238(%rsp), %rdi
addq $0x30, %rdi
callq 0x4050
movq 0xa0(%rsp), %rdi
movq 0x238(%rsp), %rax
movb $0x1, 0x50(%rax)
callq 0xdde0
movq %rax, 0x20(%rsp)
movq 0x2b8(%rsp), %rsi
addq $0x40, %rsi
leaq 0x1a0(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x4180
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rsi
callq 0x20600
movb %al, 0x37(%rsp)
jmp 0x34142
movb 0x37(%rsp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0x1f(%rsp)
jne 0x34153
jmp 0x34165
movq 0xa0(%rsp), %rax
movb 0xd0(%rax), %al
movb %al, 0x1f(%rsp)
movb 0x1f(%rsp), %al
movb %al, 0x1e(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0x46e8
movb 0x1e(%rsp), %al
testb $0x1, %al
jne 0x34187
jmp 0x342ad
movq 0x2b0(%rsp), %rdi
addq $0x30, %rdi
leaq 0x1cf81(%rip), %rsi     # 0x5111b
callq 0x44a0
movq 0x2b0(%rsp), %rax
movl $0x0, (%rax)
jmp 0x342ad
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0x270(%rsp), %rdi
callq 0xd9c0
leaq 0x290(%rsp), %rdi
callq 0x46e8
jmp 0x3446d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0x240(%rsp), %rdi
callq 0x46e8
jmp 0x3446d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0x34242
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0x200(%rsp), %rdi
callq 0xd9c0
leaq 0x1e7(%rsp), %rdi
callq 0xdec0
leaq 0x218(%rsp), %rdi
callq 0x46e8
jmp 0x3446d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x46e8
jmp 0x3446d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0x46e8
jmp 0x3446d
movq 0x2c0(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x8(%rsp)
leaq 0x117(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x4600
movq 0x10(%rsp), %rdx
leaq 0x1ce21(%rip), %rsi     # 0x510fd
leaq 0x118(%rsp), %rdi
callq 0x4f10
jmp 0x342eb
movq 0x238(%rsp), %rsi
addq $0x10, %rsi
leaq 0xf0(%rsp), %rdi
callq 0x4180
jmp 0x34306
movq 0x2b0(%rsp), %rsi
addq $0x10, %rsi
leaq 0xd0(%rsp), %rdi
callq 0x4180
jmp 0x34321
leaq 0x138(%rsp), %rdi
leaq 0x118(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
leaq 0xd0(%rsp), %rcx
callq 0xd3b0
jmp 0x34348
movq 0x8(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0xd380
jmp 0x3435c
leaq 0x138(%rsp), %rdi
callq 0xd490
leaq 0xd0(%rsp), %rdi
callq 0x46e8
leaq 0xf0(%rsp), %rdi
callq 0x46e8
leaq 0x118(%rsp), %rdi
callq 0x46e8
leaq 0x117(%rsp), %rdi
callq 0x43b0
movq 0x2b0(%rsp), %rax
movq 0x8(%rax), %rcx
movq 0x238(%rsp), %rax
movq %rcx, 0x8(%rax)
addq $0x2d8, %rsp            # imm = 0x2D8
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0x34460
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0x34453
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0x34446
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
jmp 0x34439
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x268(%rsp)
movl %eax, 0x264(%rsp)
leaq 0x138(%rsp), %rdi
callq 0xd490
leaq 0xd0(%rsp), %rdi
callq 0x46e8
leaq 0xf0(%rsp), %rdi
callq 0x46e8
leaq 0x118(%rsp), %rdi
callq 0x46e8
leaq 0x117(%rsp), %rdi
callq 0x43b0
movq 0x268(%rsp), %rdi
callq 0x45f0
nopw (%rax,%rax)