// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x308, %rsp            # imm = 0x308
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r13
movq %rcx, 0x8(%rsp)
leaq 0x20(%rcx), %r14
leaq 0x218(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x4390
xorps %xmm0, %xmm0
leaq 0x80(%rsp), %rcx
movaps %xmm0, (%rcx)
andq $0x0, 0x10(%rcx)
pushq $0x1
popq %r8
movq %r12, 0x10(%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %rbx, %rdx
movl %r8d, %r9d
callq 0x5ec6
movq %rax, %r15
leaq 0x80(%rsp), %rdi
callq 0x9106
leaq 0x218(%rsp), %rdi
callq 0x4548
leaq 0x1f8(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0x4390
movq %r13, %rdi
movq %r15, %rcx
movq %rbp, %r8
callq 0x192a6
leaq 0x1f8(%rsp), %rdi
callq 0x4548
leaq 0x30(%r15), %rdi
movq %r14, %rsi
callq 0x4180
movb $0x1, 0x50(%r15)
movq (%r13), %rbp
movq 0x8(%rsp), %rax
leaq 0x40(%rax), %r14
leaq 0x1b8(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x4390
movq %rbp, %rdi
movq %r12, %rsi
callq 0x10282
testb %al, %al
je 0x18db8
movq (%r13), %rbp
leaq 0x198(%rsp), %rdi
movq %r14, %rsi
callq 0x4390
leaq 0x18(%rsp), %rdi
leaq 0x198(%rsp), %rdx
movq %rbp, %rsi
callq 0x107fa
leaq 0xba2b(%rip), %rsi      # 0x24741
leaq 0x18(%rsp), %r12
movq %r12, %rdi
callq 0x8453
movl %eax, %ebp
movq %r12, %rdi
callq 0x4548
leaq 0x198(%rsp), %rdi
callq 0x4548
leaq 0x1b8(%rsp), %rdi
callq 0x4548
testb %bpl, %bpl
je 0x18dc5
addq $0x10, %r15
leaq 0x178(%rsp), %rdi
movq %r15, %rsi
callq 0x4390
leaq 0x2a0(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x8a26
leaq 0x18(%rsp), %rdi
leaq 0x178(%rsp), %rsi
leaq 0x2a0(%rsp), %rdx
callq 0xe966
leaq 0x2a0(%rsp), %rdi
callq 0x81fe
leaq 0x178(%rsp), %rdi
callq 0x4548
leaq 0x18(%rsp), %rsi
movq %rbx, %rdi
callq 0x821e
jmp 0x19057
leaq 0x1b8(%rsp), %rdi
callq 0x4548
leaq 0x158(%rsp), %rdi
movq %r14, %rsi
callq 0x4390
leaq 0x18(%rsp), %rsi
movq %r15, (%rsi)
leaq 0x68(%rsp), %rdi
pushq $0x1
popq %rdx
leaq 0x6(%rsp), %rcx
callq 0x8492
leaq 0x158(%rsp), %rsi
leaq 0x68(%rsp), %rcx
pushq $0x1
popq %r9
movq 0x10(%rsp), %rdi
movq %rbx, %rdx
xorl %r8d, %r8d
callq 0x5ec6
movq %rax, %rbp
leaq 0x68(%rsp), %rdi
callq 0x9106
leaq 0x158(%rsp), %rdi
callq 0x4548
leaq 0x1d8(%rsp), %r12
movq %r12, %rdi
movq %r14, %rsi
callq 0x4390
movq %r13, %rdi
movq %rbp, %rcx
movq %r12, %r8
callq 0x192a6
leaq 0x1d8(%rsp), %rdi
callq 0x4548
leaq 0x30(%rbp), %rdi
movq %r14, %rsi
callq 0x4180
leaq 0xa6cc(%rip), %rsi      # 0x23537
leaq 0x138(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0x4a54
leaq 0x18(%rsp), %rsi
movq %r15, (%rsi)
movq %rbp, 0x8(%rsi)
leaq 0x50(%rsp), %rdi
pushq $0x2
popq %rdx
leaq 0x7(%rsp), %rcx
callq 0x8492
leaq 0x138(%rsp), %rsi
leaq 0x50(%rsp), %rcx
movq 0x10(%rsp), %rdi
movq %rbx, %rdx
callq 0x5958
movq %rax, %r14
leaq 0x50(%rsp), %rdi
callq 0x9106
leaq 0x138(%rsp), %rdi
callq 0x4548
andl $0x0, (%r14)
leaq 0x30(%r14), %rdi
leaq 0xa205(%rip), %rsi      # 0x230e3
callq 0x44e0
leaq 0xa665(%rip), %rsi      # 0x2354f
leaq 0x118(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0x4a54
leaq 0x18(%rsp), %rsi
movq %r15, (%rsi)
movq %rbp, 0x8(%rsi)
movq %r14, 0x10(%rsi)
leaq 0x38(%rsp), %rdi
pushq $0x3
popq %rdx
leaq 0x7(%rsp), %rcx
callq 0x8492
leaq 0x118(%rsp), %rsi
leaq 0x38(%rsp), %rcx
movq 0x10(%rsp), %rdi
movq %rbx, %rdx
callq 0x5958
movq %rax, %r12
leaq 0x38(%rsp), %rdi
callq 0x9106
leaq 0x118(%rsp), %rdi
callq 0x4548
andl $0x0, (%r12)
leaq 0x30(%r12), %rdi
leaq 0xa180(%rip), %rsi      # 0x230e3
callq 0x44e0
addq $0x10, %r15
leaq 0xf8(%rsp), %rdi
movq %r15, %rsi
callq 0x4390
addq $0x10, %rbp
leaq 0xd8(%rsp), %rdi
movq %rbp, %rsi
callq 0x4390
addq $0x10, %r14
leaq 0xb8(%rsp), %rdi
movq %r14, %rsi
callq 0x4390
addq $0x10, %r12
leaq 0x98(%rsp), %rdi
movq %r12, %rsi
callq 0x4390
leaq 0x238(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x8a26
leaq 0x18(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
leaq 0xb8(%rsp), %rcx
leaq 0x98(%rsp), %r8
leaq 0x238(%rsp), %r9
callq 0xcc30
leaq 0x238(%rsp), %rdi
callq 0x81fe
leaq 0x98(%rsp), %rdi
callq 0x4548
leaq 0xb8(%rsp), %rdi
callq 0x4548
leaq 0xd8(%rsp), %rdi
callq 0x4548
leaq 0xf8(%rsp), %rdi
callq 0x4548
movq 0x28(%rbx), %rsi
addq $0x20, %rbx
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %rcx
movq %rbx, %rdi
callq 0x85b6
leaq 0x18(%rsp), %rdi
callq 0x8236
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x190b1
movq %rax, %rbx
leaq 0x2a0(%rsp), %rdi
callq 0x81fe
jmp 0x1908a
movq %rax, %rbx
leaq 0x178(%rsp), %rdi
jmp 0x191b5
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
callq 0x4548
jmp 0x19186
jmp 0x19183
movq %rax, %rbx
leaq 0x18(%rsp), %rdi
callq 0x8236
jmp 0x191ba
movq %rax, %rbx
leaq 0x238(%rsp), %rdi
callq 0x81fe
jmp 0x190d8
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x4548
jmp 0x190ea
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x4548
jmp 0x190fc
movq %rax, %rbx
leaq 0xd8(%rsp), %rdi
callq 0x4548
jmp 0x1910e
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
jmp 0x191b5
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x9106
jmp 0x1912d
movq %rax, %rbx
leaq 0x118(%rsp), %rdi
jmp 0x191b5
jmp 0x19155
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x9106
jmp 0x1914b
movq %rax, %rbx
leaq 0x138(%rsp), %rdi
jmp 0x191b5
movq %rax, %rbx
jmp 0x191ba
movq %rax, %rbx
leaq 0x1d8(%rsp), %rdi
jmp 0x191b5
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x9106
jmp 0x19179
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
jmp 0x191b5
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
jmp 0x191b5
movq %rax, %rbx
leaq 0x1f8(%rsp), %rdi
jmp 0x191b5
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x9106
leaq 0x218(%rsp), %rdi
callq 0x4548
movq %rbx, %rdi
callq 0x4490