// File: /workspace/github_cpp_makefile_star2_O1/Merulo[P]CompilerJFTT/src/Register/RegisterBlock.cpp
// Function: RegisterBlock::saveVariableToMemory(Block&, Register&, Register&)
void RegisterBlock::saveVariableToMemory(Block& b, Register& r, Register& freeRegister)
 {
    unsigned long long memoryCell = _symbolTable->getMemoryCell(r.variableName);
    
    if (_addressRegister.state == RegisterState::UNKNOWN)
    {
        b.lines.push_back({"SUB", "A", "A"});
        _addressRegister.state = RegisterState::CONST;
        _addressRegister.constValue = 0;
    }
    auto lines = generateNumberFrom(_addressRegister.constValue, memoryCell, freeRegister);

    lines.push_back({"STORE", r.name});
    b.insert(lines);
 }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
movq (%rdi), %r12
leaq 0xf0(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq 0x30(%rdx), %rsi
movq 0x38(%rdx), %rdx
addq %rsi, %rdx
leaq 0xe0(%rsp), %r13
movq %r13, %rdi
callq 0xca12
movq %r12, %rdi
movq %r13, %rsi
callq 0x1a7e6
movq %rax, %r12
movq 0xe0(%rsp), %rdi
cmpq %rbp, %rdi
je 0x9b41
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x42a0
cmpl $0x0, 0x10(%r15)
jne 0x9cb7
leaq 0x18(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x2e53a(%rip), %rsi     # 0x38096
leaq 0x2e536(%rip), %rdx     # 0x38099
leaq 0x8(%rsp), %rdi
callq 0x54fc
leaq 0xd0(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x2e514(%rip), %rsi     # 0x38094
leaq 0x2e50e(%rip), %rdx     # 0x38095
leaq 0xc0(%rsp), %rdi
callq 0x54fc
leaq 0xb0(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x2e4ed(%rip), %rsi     # 0x38094
leaq 0x2e4e7(%rip), %rdx     # 0x38095
leaq 0xa0(%rsp), %rdi
callq 0x54fc
leaq 0x100(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0xc0(%rsp), %rdx
leaq 0xa0(%rsp), %rcx
callq 0xbe58
leaq 0x20(%rbx), %rdi
leaq 0x100(%rsp), %rsi
callq 0xcf0e
leaq 0x150(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9c0f
movq 0x150(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x130(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9c30
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x110(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9c51
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0xa0(%rsp), %rdi
cmpq %r13, %rdi
je 0x9c6e
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0xc0(%rsp), %rdi
cmpq %rbp, %rdi
leaq 0x18(%rsp), %r13
je 0x9c90
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x8(%rsp), %rdi
cmpq %r13, %rdi
je 0x9ca7
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x42a0
movl $0x2, 0x10(%r15)
movq $0x0, 0x18(%r15)
addq $0x18, %r15
leaq 0x28(%rsp), %rdi
movq %r15, %rdx
movq %r12, %rcx
callq 0x65be
leaq 0x90(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x2e3dc(%rip), %rsi     # 0x380ba
leaq 0x2e3da(%rip), %rdx     # 0x380bf
leaq 0x80(%rsp), %rdi
callq 0x54fc
leaq 0x70(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x10(%r14), %rsi
movq 0x18(%r14), %rdx
addq %rsi, %rdx
leaq 0x60(%rsp), %rdi
callq 0xca12
leaq 0x50(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x2e3c2(%rip), %rdx     # 0x380e3
leaq 0x40(%rsp), %rdi
movq %rdx, %rsi
callq 0x54fc
leaq 0x100(%rsp), %rdi
leaq 0x80(%rsp), %rsi
leaq 0x60(%rsp), %rdx
leaq 0x40(%rsp), %rcx
callq 0xbe58
leaq 0x28(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0xcf0e
leaq 0x150(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9d80
movq 0x150(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x130(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9da1
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x42a0
leaq 0x110(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x9dc2
movq 0x110(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0x9dd9
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x60(%rsp), %rdi
cmpq %r12, %rdi
je 0x9df0
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x80(%rsp), %rdi
cmpq %r15, %rdi
je 0x9e0d
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x42a0
movq 0x28(%rbx), %rsi
addq $0x20, %rbx
movq 0x28(%rsp), %rdx
movq 0x30(%rsp), %rcx
movq %rbx, %rdi
callq 0xc3f4
leaq 0x28(%rsp), %rdi
callq 0xbf5e
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0xbf10
jmp 0x9e58
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
cmpq %r13, %rdi
je 0x9e7a
movq 0xb0(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x9e7a
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
cmpq %rbp, %rdi
je 0x9e9c
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x9e9c
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x9f39
movq 0x18(%rsp), %rsi
jmp 0x9f59
movq %rax, %rbx
jmp 0x9f39
jmp 0x9f2c
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0xbf10
jmp 0x9ed5
movq %rax, %rbx
movq 0x40(%rsp), %rdi
cmpq %r14, %rdi
je 0x9ef1
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x9ef1
movq %rax, %rbx
movq 0x60(%rsp), %rdi
cmpq %r12, %rdi
je 0x9f0d
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x9f0d
movq %rax, %rbx
movq 0x80(%rsp), %rdi
cmpq %r15, %rdi
je 0x9f2f
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x9f2f
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0xbf5e
movq %rbx, %rdi
callq 0x44c0
movq %rax, %rbx
movq 0xe0(%rsp), %rdi
cmpq %rbp, %rdi
je 0x9f39
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0x42a0
jmp 0x9f39
nop