// File: /workspace/github_cpp_makefile_star2_O2/Merulo[P]CompilerJFTT/src/IRs/FourthIR.cpp
// Function: FourthIR::handleDiv(RegisterBlock&, Block&, Line&)
void FourthIR::handleDiv(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;

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

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

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

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

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

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

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

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

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2e8, %rsp            # imm = 0x2E8
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbp
movq %rcx, 0x28(%rsp)
leaq 0x20(%rcx), %r13
leaq 0x260(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4390
xorps %xmm0, %xmm0
leaq 0xc0(%rsp), %rcx
movaps %xmm0, (%rcx)
andq $0x0, 0x10(%rcx)
pushq $0x1
popq %r8
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
movl %r8d, %r9d
callq 0x5ec6
movq %rax, %r14
leaq 0xc0(%rsp), %rdi
callq 0x9106
leaq 0x260(%rsp), %rdi
callq 0x4548
leaq 0x240(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4390
movq %rbp, 0x20(%rsp)
movq %rbp, %rdi
movq %r14, %rcx
movq %rbx, %r8
callq 0x192a6
leaq 0x240(%rsp), %rdi
callq 0x4548
leaq 0x30(%r14), %rdi
movq %rdi, 0x58(%rsp)
movq %r13, %rsi
callq 0x4180
movb $0x1, 0x50(%r14)
movq 0x28(%rsp), %rax
leaq 0x40(%rax), %rbx
leaq 0x200(%rsp), %rdi
movq %rbx, %rsi
callq 0x4390
leaq 0x30(%rsp), %rsi
movq %r14, (%rsi)
leaq 0xa8(%rsp), %rdi
pushq $0x1
popq %rdx
leaq 0x16(%rsp), %rcx
callq 0x8492
movq %r13, 0x18(%rsp)
leaq 0x200(%rsp), %rsi
leaq 0xa8(%rsp), %rcx
pushq $0x1
popq %r9
movq %r15, %rdi
movq %r12, %rdx
xorl %r8d, %r8d
callq 0x5ec6
movq %rax, %rbp
leaq 0xa8(%rsp), %rdi
callq 0x9106
leaq 0x200(%rsp), %rdi
callq 0x4548
leaq 0x220(%rsp), %r13
movq %r13, %rdi
movq %rbx, %rsi
callq 0x4390
movq 0x20(%rsp), %rdi
movq %rbp, %rcx
movq %r13, %r8
callq 0x192a6
leaq 0x220(%rsp), %rdi
callq 0x4548
leaq 0x30(%rbp), %rdi
movq %rbx, %rsi
callq 0x4180
leaq 0xadc4(%rip), %rsi      # 0x23543
leaq 0x1e0(%rsp), %rdi
leaq 0x16(%rsp), %rdx
callq 0x4a54
leaq 0x30(%rsp), %rsi
movq %r14, (%rsi)
movq %rbp, 0x8(%rsi)
leaq 0x90(%rsp), %rdi
pushq $0x2
popq %rdx
leaq 0x17(%rsp), %rcx
callq 0x8492
leaq 0x1e0(%rsp), %rsi
leaq 0x90(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rdx
callq 0x5958
movq %rax, %r13
leaq 0x90(%rsp), %rdi
callq 0x9106
leaq 0x1e0(%rsp), %rdi
callq 0x4548
andl $0x0, (%r13)
leaq 0x30(%r13), %rdi
leaq 0xa8e9(%rip), %rsi      # 0x230e3
movq %rdi, 0x50(%rsp)
callq 0x44e0
leaq 0xad2c(%rip), %rsi      # 0x23537
leaq 0x1c0(%rsp), %rdi
leaq 0x16(%rsp), %rdx
callq 0x4a54
leaq 0x30(%rsp), %rsi
movq %r14, (%rsi)
movq %rbp, 0x8(%rsi)
movq %r13, 0x10(%rsi)
leaq 0x78(%rsp), %rdi
pushq $0x3
popq %rdx
leaq 0x17(%rsp), %rcx
callq 0x8492
leaq 0x1c0(%rsp), %rsi
leaq 0x78(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rdx
callq 0x5958
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x9106
leaq 0x1c0(%rsp), %rdi
callq 0x4548
andl $0x0, (%rbx)
leaq 0x30(%rbx), %rdi
leaq 0xa864(%rip), %rsi      # 0x230e3
callq 0x44e0
leaq 0xacc4(%rip), %rsi      # 0x2354f
leaq 0x1a0(%rsp), %rdi
leaq 0x16(%rsp), %rdx
callq 0x4a54
leaq 0x30(%rsp), %rsi
movq %r14, (%rsi)
movq %rbp, 0x8(%rsi)
movq %r13, 0x10(%rsi)
movq %rbx, 0x18(%rsi)
leaq 0x60(%rsp), %rdi
pushq $0x4
popq %rdx
leaq 0x17(%rsp), %rcx
callq 0x8492
leaq 0x1a0(%rsp), %rsi
leaq 0x60(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rdx
callq 0x5958
movq %rax, %r15
leaq 0x60(%rsp), %rdi
callq 0x9106
leaq 0x1a0(%rsp), %rdi
callq 0x4548
andl $0x0, (%r15)
leaq 0x30(%r15), %rdi
leaq 0xa7df(%rip), %rsi      # 0x230e3
callq 0x44e0
movq %r14, %rsi
addq $0x10, %rsi
leaq 0x180(%rsp), %rdi
callq 0x4390
addq $0x10, %rbp
leaq 0x160(%rsp), %rdi
movq %rbp, %rsi
callq 0x4390
movq %r13, %rsi
addq $0x10, %rsi
leaq 0x140(%rsp), %rdi
callq 0x4390
addq $0x10, %rbx
leaq 0x120(%rsp), %rdi
movq %rbx, %rsi
callq 0x4390
addq $0x10, %r15
leaq 0x100(%rsp), %rdi
movq %r15, %rsi
callq 0x4390
leaq 0x280(%rsp), %rbx
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
callq 0x8a26
movq %rbx, (%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x180(%rsp), %rsi
leaq 0x160(%rsp), %rdx
leaq 0x140(%rsp), %rcx
leaq 0x120(%rsp), %r8
leaq 0x100(%rsp), %r9
callq 0xab5c
leaq 0x280(%rsp), %rdi
callq 0x81fe
leaq 0x100(%rsp), %rdi
callq 0x4548
leaq 0x120(%rsp), %rdi
callq 0x4548
leaq 0x140(%rsp), %rdi
callq 0x4548
leaq 0x160(%rsp), %rdi
callq 0x4548
leaq 0x180(%rsp), %rdi
callq 0x4548
movq 0x28(%r12), %rsi
addq $0x20, %r12
movq 0x30(%rsp), %rdx
movq 0x38(%rsp), %rcx
movq %r12, %rdi
callq 0x85b6
leaq 0xe0(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x4390
movq 0x20(%rsp), %rdi
leaq 0xe0(%rsp), %r8
movq %r13, %rcx
callq 0x192a6
leaq 0xe0(%rsp), %rdi
callq 0x4548
movq 0x50(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x4180
movb $0x1, 0x50(%r13)
andl $0x0, (%r14)
leaq 0xa66f(%rip), %rsi      # 0x230e3
movq 0x58(%rsp), %rdi
callq 0x44e0
movb $0x0, 0x50(%r14)
leaq 0x30(%rsp), %rdi
callq 0x8236
addq $0x2e8, %rsp            # imm = 0x2E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xe0(%rsp), %rdi
callq 0x4548
jmp 0x18be1
jmp 0x18bde
movq %rax, %rbx
leaq 0x280(%rsp), %rdi
callq 0x81fe
jmp 0x18ace
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x4548
jmp 0x18ae0
movq %rax, %rbx
leaq 0x120(%rsp), %rdi
callq 0x4548
jmp 0x18af2
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x4548
jmp 0x18b04
movq %rax, %rbx
leaq 0x160(%rsp), %rdi
callq 0x4548
leaq 0x180(%rsp), %rdi
jmp 0x18bd7
movq %rax, %rbx
jmp 0x18b11
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x9106
jmp 0x18b35
movq %rax, %rbx
leaq 0x1a0(%rsp), %rdi
jmp 0x18bd7
jmp 0x18b81
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x9106
jmp 0x18b56
movq %rax, %rbx
leaq 0x1c0(%rsp), %rdi
jmp 0x18bd7
jmp 0x18b81
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x9106
jmp 0x18b77
movq %rax, %rbx
leaq 0x1e0(%rsp), %rdi
jmp 0x18bd7
movq %rax, %rbx
jmp 0x18beb
movq %rax, %rbx
leaq 0x220(%rsp), %rdi
jmp 0x18bd7
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x9106
jmp 0x18ba8
movq %rax, %rbx
leaq 0x200(%rsp), %rdi
jmp 0x18bd7
movq %rax, %rbx
leaq 0x240(%rsp), %rdi
jmp 0x18bd7
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x9106
leaq 0x260(%rsp), %rdi
callq 0x4548
jmp 0x18beb
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x8236
movq %rbx, %rdi
callq 0x4490
nop