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

    if (_symbolTable->isConst(l.two) && _symbolTable->getConstValue(l.two) == "2")
    {
        auto lines = MathOperations::generateModuloTwo(registerB.name, l);
        b.insert(lines);
        return;
    }

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

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

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

    auto lines = MathOperations::generateModulo(
        registerB.name, registerC.name, 
        registerE.name, registerF.name, l);

    b.lines.insert(b.lines.end(), lines.begin(), lines.end());
}

// Assembly:
subq $0x578, %rsp            # imm = 0x578
movq %rdi, 0x570(%rsp)
movq %rsi, 0x568(%rsp)
movq %rdx, 0x560(%rsp)
movq %rcx, 0x558(%rsp)
movq 0x570(%rsp), %rax
movq %rax, 0x118(%rsp)
movq 0x568(%rsp), %rax
movq %rax, 0x120(%rsp)
movq 0x558(%rsp), %rsi
addq $0x20, %rsi
leaq 0x530(%rsp), %rdi
movq %rdi, 0x128(%rsp)
callq 0x4180
movq 0x560(%rsp), %rax
movq %rax, 0x130(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x510(%rsp)
movq $0x0, 0x520(%rsp)
leaq 0x510(%rsp), %rdi
movq %rdi, 0x138(%rsp)
callq 0x391c0
movq 0x120(%rsp), %rdi
movq 0x128(%rsp), %rsi
movq 0x130(%rsp), %rdx
movq 0x138(%rsp), %rcx
movl $0x1, %r9d
movl %r9d, %r8d
callq 0x7ac0
movq %rax, 0x140(%rsp)
jmp 0x369ec
leaq 0x510(%rsp), %rdi
callq 0xd9c0
leaq 0x530(%rsp), %rdi
callq 0x46e8
movq 0x140(%rsp), %rax
movq %rax, 0x550(%rsp)
movq 0x560(%rsp), %rax
movq %rax, 0xf8(%rsp)
movq 0x568(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x550(%rsp), %rax
movq %rax, 0x108(%rsp)
movq 0x558(%rsp), %rsi
addq $0x20, %rsi
leaq 0x4e0(%rsp), %rdi
movq %rdi, 0x110(%rsp)
callq 0x4180
movq 0x118(%rsp), %rdi
movq 0xf8(%rsp), %rsi
movq 0x100(%rsp), %rdx
movq 0x108(%rsp), %rcx
movq 0x110(%rsp), %r8
callq 0x37870
jmp 0x36a96
leaq 0x4e0(%rsp), %rdi
callq 0x46e8
movq 0x558(%rsp), %rsi
addq $0x20, %rsi
movq 0x550(%rsp), %rdi
addq $0x30, %rdi
callq 0x4050
movq 0x118(%rsp), %rdi
movq 0x550(%rsp), %rax
movb $0x1, 0x50(%rax)
callq 0xdde0
movq %rax, 0xe0(%rsp)
movq 0x558(%rsp), %rsi
addq $0x40, %rsi
leaq 0x4c0(%rsp), %rdi
movq %rdi, 0xe8(%rsp)
callq 0x4180
movq 0xe0(%rsp), %rdi
movq 0xe8(%rsp), %rsi
movb $0x0, 0x47f(%rsp)
movb $0x0, 0x47e(%rsp)
callq 0x20600
movb %al, 0xf7(%rsp)
jmp 0x36b30
movb 0xf7(%rsp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0xdf(%rsp)
jne 0x36b4a
jmp 0x36bd6
movq 0x118(%rsp), %rdi
callq 0xdde0
movq %rax, 0xd0(%rsp)
movq 0x558(%rsp), %rsi
addq $0x40, %rsi
leaq 0x480(%rsp), %rdi
callq 0x4180
jmp 0x36b7a
movq 0xd0(%rsp), %rsi
movb $0x1, 0x47f(%rsp)
leaq 0x4a0(%rsp), %rdi
leaq 0x480(%rsp), %rdx
callq 0x21240
jmp 0x36ba1
movb $0x1, 0x47e(%rsp)
leaq 0x1bca3(%rip), %rsi     # 0x52853
leaq 0x4a0(%rsp), %rdi
callq 0xdd10
movb %al, 0xcf(%rsp)
jmp 0x36bc6
movb 0xcf(%rsp), %al
movb %al, 0xdf(%rsp)
jmp 0x36bd6
movb 0xdf(%rsp), %al
movb %al, 0xce(%rsp)
testb $0x1, 0x47e(%rsp)
jne 0x36bf0
jmp 0x36bfd
leaq 0x4a0(%rsp), %rdi
callq 0x46e8
testb $0x1, 0x47f(%rsp)
jne 0x36c09
jmp 0x36c16
leaq 0x480(%rsp), %rdi
callq 0x46e8
leaq 0x4c0(%rsp), %rdi
callq 0x46e8
movb 0xce(%rsp), %al
testb $0x1, %al
jne 0x36c33
jmp 0x36e15
movq 0x550(%rsp), %rsi
addq $0x10, %rsi
leaq 0x440(%rsp), %rdi
callq 0x4180
movq 0x558(%rsp), %rsi
leaq 0x3d8(%rsp), %rdi
callq 0xfb20
jmp 0x36c63
leaq 0x460(%rsp), %rdi
leaq 0x440(%rsp), %rsi
leaq 0x3d8(%rsp), %rdx
callq 0x1cba0
jmp 0x36c82
leaq 0x3d8(%rsp), %rdi
callq 0xd490
leaq 0x440(%rsp), %rdi
callq 0x46e8
movq 0x560(%rsp), %rdi
leaq 0x460(%rsp), %rsi
callq 0xd4d0
jmp 0x36cb3
leaq 0x460(%rsp), %rdi
callq 0xd550
jmp 0x37430
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
leaq 0x510(%rsp), %rdi
callq 0xd9c0
leaq 0x530(%rsp), %rdi
callq 0x46e8
jmp 0x37679
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
leaq 0x4e0(%rsp), %rdi
callq 0x46e8
jmp 0x37679
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
jmp 0x36d94
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
jmp 0x36d79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
testb $0x1, 0x47e(%rsp)
jne 0x36d6a
jmp 0x36d77
leaq 0x4a0(%rsp), %rdi
callq 0x46e8
jmp 0x36d79
testb $0x1, 0x47f(%rsp)
jne 0x36d85
jmp 0x36d92
leaq 0x480(%rsp), %rdi
callq 0x46e8
jmp 0x36d94
leaq 0x4c0(%rsp), %rdi
callq 0x46e8
jmp 0x37679
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
jmp 0x36ddd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
leaq 0x3d8(%rsp), %rdi
callq 0xd490
leaq 0x440(%rsp), %rdi
callq 0x46e8
jmp 0x37679
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
leaq 0x460(%rsp), %rdi
callq 0xd550
jmp 0x37679
movq 0x568(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq 0x558(%rsp), %rsi
addq $0x40, %rsi
leaq 0x3b0(%rsp), %rdi
callq 0x4180
movq 0x560(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0x550(%rsp), %rsi
leaq 0x380(%rsp), %rdi
movq %rdi, 0xb8(%rsp)
callq 0xddf0
movq 0xb8(%rsp), %rax
movq %rax, 0x388(%rsp)
movq $0x1, 0x390(%rsp)
leaq 0x37f(%rsp), %rdi
movq %rdi, 0xc0(%rsp)
callq 0xde20
movq 0xc0(%rsp), %rcx
movq 0x388(%rsp), %rsi
movq 0x390(%rsp), %rdx
leaq 0x398(%rsp), %rdi
callq 0xde30
jmp 0x36ec3
movq 0xb0(%rsp), %rdx
movq 0xa8(%rsp), %rdi
leaq 0x3b0(%rsp), %rsi
leaq 0x398(%rsp), %rcx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x7ac0
movq %rax, 0xa0(%rsp)
jmp 0x36efb
leaq 0x398(%rsp), %rdi
callq 0xd9c0
leaq 0x37f(%rsp), %rdi
callq 0xdec0
leaq 0x3b0(%rsp), %rdi
callq 0x46e8
movq 0xa0(%rsp), %rax
movq %rax, 0x3d0(%rsp)
movq 0x560(%rsp), %rax
movq %rax, 0x80(%rsp)
movq 0x568(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0x3d0(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x558(%rsp), %rsi
addq $0x40, %rsi
leaq 0x358(%rsp), %rdi
movq %rdi, 0x98(%rsp)
callq 0x4180
movq 0x118(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
movq 0x90(%rsp), %rcx
movq 0x98(%rsp), %r8
callq 0x37870
jmp 0x36fb2
leaq 0x358(%rsp), %rdi
callq 0x46e8
movq 0x558(%rsp), %rsi
addq $0x40, %rsi
movq 0x3d0(%rsp), %rdi
addq $0x30, %rdi
callq 0x4050
movq 0x568(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x32f(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x4600
movq 0x78(%rsp), %rdx
leaq 0x1a571(%rip), %rsi     # 0x51578
leaq 0x330(%rsp), %rdi
callq 0x4f10
jmp 0x37016
movq 0x560(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x550(%rsp), %rsi
leaq 0x2f0(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0xddf0
leaq 0x2f8(%rsp), %rdi
movq 0x3d0(%rsp), %rsi
callq 0xddf0
movq 0x60(%rsp), %rax
movq %rax, 0x300(%rsp)
movq $0x2, 0x308(%rsp)
leaq 0x2ef(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0xde20
movq 0x68(%rsp), %rcx
movq 0x300(%rsp), %rsi
movq 0x308(%rsp), %rdx
leaq 0x310(%rsp), %rdi
callq 0xde30
jmp 0x370a1
movq 0x58(%rsp), %rdx
movq 0x70(%rsp), %rdi
leaq 0x330(%rsp), %rsi
leaq 0x310(%rsp), %rcx
callq 0x73c0
movq %rax, 0x50(%rsp)
jmp 0x370c7
leaq 0x310(%rsp), %rdi
callq 0xd9c0
leaq 0x2ef(%rsp), %rdi
callq 0xdec0
leaq 0x330(%rsp), %rdi
callq 0x46e8
leaq 0x32f(%rsp), %rdi
callq 0x43b0
movq 0x50(%rsp), %rax
movq %rax, 0x350(%rsp)
movq 0x350(%rsp), %rax
movl $0x0, (%rax)
movq 0x350(%rsp), %rdi
addq $0x30, %rdi
leaq 0x19ff2(%rip), %rsi     # 0x5111b
callq 0x44a0
movq 0x568(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x2bf(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x4600
movq 0x48(%rsp), %rdx
leaq 0x1a437(%rip), %rsi     # 0x51590
leaq 0x2c0(%rsp), %rdi
callq 0x4f10
jmp 0x37168
movq 0x560(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x550(%rsp), %rsi
leaq 0x278(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0xddf0
leaq 0x280(%rsp), %rdi
movq 0x3d0(%rsp), %rsi
callq 0xddf0
leaq 0x288(%rsp), %rdi
movq 0x350(%rsp), %rsi
callq 0xddf0
movq 0x30(%rsp), %rax
movq %rax, 0x290(%rsp)
movq $0x3, 0x298(%rsp)
leaq 0x277(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0xde20
movq 0x38(%rsp), %rcx
movq 0x290(%rsp), %rsi
movq 0x298(%rsp), %rdx
leaq 0x2a0(%rsp), %rdi
callq 0xde30
jmp 0x37208
movq 0x28(%rsp), %rdx
movq 0x40(%rsp), %rdi
leaq 0x2c0(%rsp), %rsi
leaq 0x2a0(%rsp), %rcx
callq 0x73c0
movq %rax, 0x20(%rsp)
jmp 0x3722e
leaq 0x2a0(%rsp), %rdi
callq 0xd9c0
leaq 0x277(%rsp), %rdi
callq 0xdec0
leaq 0x2c0(%rsp), %rdi
callq 0x46e8
leaq 0x2bf(%rsp), %rdi
callq 0x43b0
movq 0x20(%rsp), %rax
movq %rax, 0x2e0(%rsp)
movq 0x2e0(%rsp), %rax
movl $0x0, (%rax)
movq 0x2e0(%rsp), %rdi
addq $0x30, %rdi
leaq 0x19e8b(%rip), %rsi     # 0x5111b
callq 0x44a0
movq 0x550(%rsp), %rsi
addq $0x10, %rsi
leaq 0x238(%rsp), %rdi
callq 0x4180
movq 0x3d0(%rsp), %rsi
addq $0x10, %rsi
leaq 0x218(%rsp), %rdi
callq 0x4180
jmp 0x372c9
movq 0x350(%rsp), %rsi
addq $0x10, %rsi
leaq 0x1f8(%rsp), %rdi
callq 0x4180
jmp 0x372e4
movq 0x2e0(%rsp), %rsi
addq $0x10, %rsi
leaq 0x1d8(%rsp), %rdi
callq 0x4180
jmp 0x372ff
movq 0x558(%rsp), %rsi
leaq 0x170(%rsp), %rdi
callq 0xfb20
jmp 0x37316
leaq 0x258(%rsp), %rdi
leaq 0x238(%rsp), %rsi
leaq 0x218(%rsp), %rdx
leaq 0x1f8(%rsp), %rcx
leaq 0x1d8(%rsp), %r8
leaq 0x170(%rsp), %r9
callq 0x19610
jmp 0x3734d
leaq 0x170(%rsp), %rdi
callq 0xd490
leaq 0x1d8(%rsp), %rdi
callq 0x46e8
leaq 0x1f8(%rsp), %rdi
callq 0x46e8
leaq 0x218(%rsp), %rdi
callq 0x46e8
leaq 0x238(%rsp), %rdi
callq 0x46e8
movq 0x560(%rsp), %rdi
addq $0x20, %rdi
movq %rdi, 0x10(%rsp)
callq 0xe380
movq %rax, 0x160(%rsp)
leaq 0x168(%rsp), %rdi
leaq 0x160(%rsp), %rsi
callq 0xe3b0
leaq 0x258(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0xe3f0
movq 0x8(%rsp), %rdi
movq %rax, 0x158(%rsp)
callq 0xe380
movq 0x10(%rsp), %rdi
movq %rax, 0x150(%rsp)
movq 0x168(%rsp), %rsi
movq 0x158(%rsp), %rdx
movq 0x150(%rsp), %rcx
callq 0xe2c0
movq %rax, 0x18(%rsp)
jmp 0x37416
movq 0x18(%rsp), %rax
movq %rax, 0x148(%rsp)
leaq 0x258(%rsp), %rdi
callq 0xd550
addq $0x578, %rsp            # imm = 0x578
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
jmp 0x3746f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
leaq 0x398(%rsp), %rdi
callq 0xd9c0
leaq 0x37f(%rsp), %rdi
callq 0xdec0
leaq 0x3b0(%rsp), %rdi
callq 0x46e8
jmp 0x37679
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
leaq 0x358(%rsp), %rdi
callq 0x46e8
jmp 0x37679
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
jmp 0x3751b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
jmp 0x37501
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
leaq 0x310(%rsp), %rdi
callq 0xd9c0
leaq 0x2ef(%rsp), %rdi
callq 0xdec0
leaq 0x330(%rsp), %rdi
callq 0x46e8
leaq 0x32f(%rsp), %rdi
callq 0x43b0
jmp 0x37679
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
jmp 0x37594
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
jmp 0x3757a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
leaq 0x2a0(%rsp), %rdi
callq 0xd9c0
leaq 0x277(%rsp), %rdi
callq 0xdec0
leaq 0x2c0(%rsp), %rdi
callq 0x46e8
leaq 0x2bf(%rsp), %rdi
callq 0x43b0
jmp 0x37679
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
jmp 0x37649
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
jmp 0x3763c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
jmp 0x3762f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
jmp 0x37622
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
leaq 0x170(%rsp), %rdi
callq 0xd490
leaq 0x1d8(%rsp), %rdi
callq 0x46e8
leaq 0x1f8(%rsp), %rdi
callq 0x46e8
leaq 0x218(%rsp), %rdi
callq 0x46e8
leaq 0x238(%rsp), %rdi
callq 0x46e8
jmp 0x37679
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x508(%rsp)
movl %eax, 0x504(%rsp)
leaq 0x258(%rsp), %rdi
callq 0xd550
movq 0x508(%rsp), %rdi
callq 0x45f0
nopw %cs:(%rax,%rax)