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

    std::string argument = l.two;
    if (l.one == l.two)
    {
        argument = "";
    }

    Register& registerC = rb.getRegistersForOperation(argument, b, {registerB});
    registerC.state = RegisterState::UNKNOWN;
    registerC.variableName = "";

    if (l.one == l.two)
    {
        b.lines.push_back({"COPY", registerC.name, registerB.name});
    }

    Register& registerD = rb.getRegistersForOperation("TEMPORARY_2", b, {registerB, registerC});
    registerD.state = RegisterState::UNKNOWN;
    registerD.variableName = "";

    auto lines = MathOperations::generateMultiplication(registerB.name, registerC.name, registerD.name, l);
    b.lines.insert(b.lines.end(), lines.begin(), lines.end());

    registerD.variableName = l.one;
    updateRegisterState(b, rb, registerD, l.one);
    registerD.needToSafe = true;

    registerB.state = RegisterState::UNKNOWN;
    registerB.variableName = "";
    registerB.needToSafe = false;
}

// Assembly:
subq $0x468, %rsp            # imm = 0x468
movq %rdi, 0x460(%rsp)
movq %rsi, 0x458(%rsp)
movq %rdx, 0x450(%rsp)
movq %rcx, 0x448(%rsp)
movq 0x460(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0x458(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0x448(%rsp), %rsi
addq $0x20, %rsi
leaq 0x420(%rsp), %rdi
movq %rdi, 0xc8(%rsp)
callq 0x4180
movq 0x450(%rsp), %rax
movq %rax, 0xd0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x400(%rsp)
movq $0x0, 0x410(%rsp)
leaq 0x400(%rsp), %rdi
movq %rdi, 0xd8(%rsp)
callq 0x391c0
movq 0xc0(%rsp), %rdi
movq 0xc8(%rsp), %rsi
movq 0xd0(%rsp), %rdx
movq 0xd8(%rsp), %rcx
movl $0x1, %r9d
movl %r9d, %r8d
callq 0x7ac0
movq %rax, 0xe0(%rsp)
jmp 0x350ec
leaq 0x400(%rsp), %rdi
callq 0xd9c0
leaq 0x420(%rsp), %rdi
callq 0x46e8
movq 0xe0(%rsp), %rax
movq %rax, 0x440(%rsp)
movq 0x448(%rsp), %rsi
addq $0x20, %rsi
movq 0x440(%rsp), %rdi
addq $0x30, %rdi
callq 0x4050
movq 0x450(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x458(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0x440(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq 0x448(%rsp), %rsi
addq $0x20, %rsi
leaq 0x3d0(%rsp), %rdi
movq %rdi, 0xb0(%rsp)
callq 0x4180
movq 0xb8(%rsp), %rdi
movq 0x98(%rsp), %rsi
movq 0xa0(%rsp), %rdx
movq 0xa8(%rsp), %rcx
movq 0xb0(%rsp), %r8
callq 0x37870
jmp 0x351b3
leaq 0x3d0(%rsp), %rdi
callq 0x46e8
movq 0x440(%rsp), %rax
movb $0x1, 0x50(%rax)
movq 0x448(%rsp), %rsi
addq $0x40, %rsi
leaq 0x3b0(%rsp), %rdi
callq 0x4180
movq 0x448(%rsp), %rdi
addq $0x20, %rdi
movq 0x448(%rsp), %rsi
addq $0x40, %rsi
callq 0xd2c0
testb $0x1, %al
jne 0x3520b
jmp 0x35295
leaq 0x1bf09(%rip), %rsi     # 0x5111b
leaq 0x3b0(%rsp), %rdi
callq 0x44a0
jmp 0x35221
jmp 0x35295
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
leaq 0x400(%rsp), %rdi
callq 0xd9c0
leaq 0x420(%rsp), %rdi
callq 0x46e8
jmp 0x35ae7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
leaq 0x3d0(%rsp), %rdi
callq 0x46e8
jmp 0x35ae7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
jmp 0x35ada
movq 0x458(%rsp), %rax
movq %rax, 0x90(%rsp)
leaq 0x388(%rsp), %rdi
leaq 0x3b0(%rsp), %rsi
callq 0x4180
jmp 0x352bc
movq 0x450(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x440(%rsp), %rsi
leaq 0x358(%rsp), %rdi
movq %rdi, 0x80(%rsp)
callq 0xddf0
movq 0x80(%rsp), %rax
movq %rax, 0x360(%rsp)
movq $0x1, 0x368(%rsp)
leaq 0x357(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0xde20
movq 0x88(%rsp), %rcx
movq 0x360(%rsp), %rsi
movq 0x368(%rsp), %rdx
leaq 0x370(%rsp), %rdi
callq 0xde30
jmp 0x3533e
movq 0x78(%rsp), %rdx
movq 0x90(%rsp), %rdi
leaq 0x388(%rsp), %rsi
leaq 0x370(%rsp), %rcx
callq 0x73c0
movq %rax, 0x70(%rsp)
jmp 0x35367
leaq 0x370(%rsp), %rdi
callq 0xd9c0
leaq 0x357(%rsp), %rdi
callq 0xdec0
leaq 0x388(%rsp), %rdi
callq 0x46e8
movq 0x70(%rsp), %rax
movq %rax, 0x3a8(%rsp)
movq 0x3a8(%rsp), %rax
movl $0x0, (%rax)
movq 0x3a8(%rsp), %rdi
addq $0x30, %rdi
leaq 0x1bd5f(%rip), %rsi     # 0x5111b
callq 0x44a0
jmp 0x353c3
movq 0x448(%rsp), %rdi
addq $0x20, %rdi
movq 0x448(%rsp), %rsi
addq $0x40, %rsi
callq 0xd2c0
testb $0x1, %al
jne 0x353e9
jmp 0x355e9
movq 0x450(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x60(%rsp)
leaq 0x2c7(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x4600
movq 0x68(%rsp), %rdx
leaq 0x1bce5(%rip), %rsi     # 0x510fd
leaq 0x2c8(%rsp), %rdi
callq 0x4f10
jmp 0x35427
movq 0x3a8(%rsp), %rsi
addq $0x10, %rsi
leaq 0x2a0(%rsp), %rdi
callq 0x4180
jmp 0x35442
movq 0x440(%rsp), %rsi
addq $0x10, %rsi
leaq 0x280(%rsp), %rdi
callq 0x4180
jmp 0x3545d
leaq 0x2e8(%rsp), %rdi
leaq 0x2c8(%rsp), %rsi
leaq 0x2a0(%rsp), %rdx
leaq 0x280(%rsp), %rcx
callq 0xd3b0
jmp 0x35484
movq 0x60(%rsp), %rdi
leaq 0x2e8(%rsp), %rsi
callq 0xd380
jmp 0x35498
leaq 0x2e8(%rsp), %rdi
callq 0xd490
leaq 0x280(%rsp), %rdi
callq 0x46e8
leaq 0x2a0(%rsp), %rdi
callq 0x46e8
leaq 0x2c8(%rsp), %rdi
callq 0x46e8
leaq 0x2c7(%rsp), %rdi
callq 0x43b0
jmp 0x355e9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
jmp 0x35515
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
leaq 0x370(%rsp), %rdi
callq 0xd9c0
leaq 0x357(%rsp), %rdi
callq 0xdec0
leaq 0x388(%rsp), %rdi
callq 0x46e8
jmp 0x35ada
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
jmp 0x355d7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
jmp 0x355ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
jmp 0x355bd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
jmp 0x355b0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
leaq 0x2e8(%rsp), %rdi
callq 0xd490
leaq 0x280(%rsp), %rdi
callq 0x46e8
leaq 0x2a0(%rsp), %rdi
callq 0x46e8
leaq 0x2c8(%rsp), %rdi
callq 0x46e8
leaq 0x2c7(%rsp), %rdi
callq 0x43b0
jmp 0x35ada
movq 0x458(%rsp), %rax
movq %rax, 0x50(%rsp)
leaq 0x257(%rsp), %rdi
movq %rdi, 0x58(%rsp)
callq 0x4600
movq 0x58(%rsp), %rdx
leaq 0x1bf64(%rip), %rsi     # 0x51578
leaq 0x258(%rsp), %rdi
callq 0x4f10
jmp 0x35623
movq 0x450(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x440(%rsp), %rsi
leaq 0x218(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0xddf0
leaq 0x220(%rsp), %rdi
movq 0x3a8(%rsp), %rsi
callq 0xddf0
movq 0x40(%rsp), %rax
movq %rax, 0x228(%rsp)
movq $0x2, 0x230(%rsp)
leaq 0x217(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0xde20
movq 0x48(%rsp), %rcx
movq 0x228(%rsp), %rsi
movq 0x230(%rsp), %rdx
leaq 0x238(%rsp), %rdi
callq 0xde30
jmp 0x356ae
movq 0x38(%rsp), %rdx
movq 0x50(%rsp), %rdi
leaq 0x258(%rsp), %rsi
leaq 0x238(%rsp), %rcx
callq 0x73c0
movq %rax, 0x30(%rsp)
jmp 0x356d4
leaq 0x238(%rsp), %rdi
callq 0xd9c0
leaq 0x217(%rsp), %rdi
callq 0xdec0
leaq 0x258(%rsp), %rdi
callq 0x46e8
leaq 0x257(%rsp), %rdi
callq 0x43b0
movq 0x30(%rsp), %rax
movq %rax, 0x278(%rsp)
movq 0x278(%rsp), %rax
movl $0x0, (%rax)
movq 0x278(%rsp), %rdi
addq $0x30, %rdi
leaq 0x1b9e5(%rip), %rsi     # 0x5111b
callq 0x44a0
jmp 0x3573d
movq 0x440(%rsp), %rsi
addq $0x10, %rsi
leaq 0x1d8(%rsp), %rdi
callq 0x4180
jmp 0x35758
movq 0x3a8(%rsp), %rsi
addq $0x10, %rsi
leaq 0x1b8(%rsp), %rdi
callq 0x4180
jmp 0x35773
movq 0x278(%rsp), %rsi
addq $0x10, %rsi
leaq 0x198(%rsp), %rdi
callq 0x4180
jmp 0x3578e
movq 0x448(%rsp), %rsi
leaq 0x130(%rsp), %rdi
callq 0xfb20
jmp 0x357a5
leaq 0x1f8(%rsp), %rdi
leaq 0x1d8(%rsp), %rsi
leaq 0x1b8(%rsp), %rdx
leaq 0x198(%rsp), %rcx
leaq 0x130(%rsp), %r8
callq 0x13150
jmp 0x357d4
leaq 0x130(%rsp), %rdi
callq 0xd490
leaq 0x198(%rsp), %rdi
callq 0x46e8
leaq 0x1b8(%rsp), %rdi
callq 0x46e8
leaq 0x1d8(%rsp), %rdi
callq 0x46e8
movq 0x450(%rsp), %rdi
addq $0x20, %rdi
movq %rdi, 0x20(%rsp)
callq 0xe380
movq %rax, 0x120(%rsp)
leaq 0x128(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0xe3b0
leaq 0x1f8(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0xe3f0
movq 0x18(%rsp), %rdi
movq %rax, 0x118(%rsp)
callq 0xe380
movq 0x20(%rsp), %rdi
movq %rax, 0x110(%rsp)
movq 0x128(%rsp), %rsi
movq 0x118(%rsp), %rdx
movq 0x110(%rsp), %rcx
callq 0xe2c0
movq %rax, 0x28(%rsp)
jmp 0x35890
movq 0x28(%rsp), %rax
movq %rax, 0x108(%rsp)
movq 0x448(%rsp), %rsi
addq $0x20, %rsi
movq 0x278(%rsp), %rdi
addq $0x30, %rdi
callq 0x4050
jmp 0x358bc
movq 0x450(%rsp), %rax
movq %rax, (%rsp)
movq 0x458(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x278(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x448(%rsp), %rsi
addq $0x20, %rsi
leaq 0xe8(%rsp), %rdi
callq 0x4180
jmp 0x358fd
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rdx
movq (%rsp), %rsi
movq 0xb8(%rsp), %rdi
leaq 0xe8(%rsp), %r8
callq 0x37870
jmp 0x35922
leaq 0xe8(%rsp), %rdi
callq 0x46e8
movq 0x278(%rsp), %rax
movb $0x1, 0x50(%rax)
movq 0x440(%rsp), %rax
movl $0x0, (%rax)
movq 0x440(%rsp), %rdi
addq $0x30, %rdi
leaq 0x1b7bf(%rip), %rsi     # 0x5111b
callq 0x44a0
jmp 0x35963
movq 0x440(%rsp), %rax
movb $0x0, 0x50(%rax)
leaq 0x1f8(%rsp), %rdi
callq 0xd550
leaq 0x3b0(%rsp), %rdi
callq 0x46e8
addq $0x468, %rsp            # imm = 0x468
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
jmp 0x359f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
jmp 0x359de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
leaq 0x238(%rsp), %rdi
callq 0xd9c0
leaq 0x217(%rsp), %rdi
callq 0xdec0
leaq 0x258(%rsp), %rdi
callq 0x46e8
leaq 0x257(%rsp), %rdi
callq 0x43b0
jmp 0x35ada
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
jmp 0x35a87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
jmp 0x35a7a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
jmp 0x35a6d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
leaq 0x130(%rsp), %rdi
callq 0xd490
leaq 0x198(%rsp), %rdi
callq 0x46e8
leaq 0x1b8(%rsp), %rdi
callq 0x46e8
leaq 0x1d8(%rsp), %rdi
callq 0x46e8
jmp 0x35ada
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
jmp 0x35acd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x3f8(%rsp)
movl %eax, 0x3f4(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0x46e8
leaq 0x1f8(%rsp), %rdi
callq 0xd550
leaq 0x3b0(%rsp), %rdi
callq 0x46e8
movq 0x3f8(%rsp), %rdi
callq 0x45f0
nopw %cs:(%rax,%rax)