// File: /workspace/github_cpp_makefile_star2_O2/Merulo[P]CompilerJFTT/src/Register/RegisterBlock.cpp
// Function: RegisterBlock::getRegister(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, Block&, std::vector<std::reference_wrapper<Register>, std::allocator<std::reference_wrapper<Register>>>, bool, bool)
Register& RegisterBlock::getRegister(std::string name, 
    Block& b, std::vector<std::reference_wrapper<Register>> usedRegisters, 
    bool changeValue, bool load)
{
    if (changeValue)
    {
        storeSameTable(name , b);
    }
    for(auto& reg : _registers)
    {
        if (std::find_if(usedRegisters.begin(), usedRegisters.end(), [reg](auto i)
                {
                    return i.get() == reg;
                }) != usedRegisters.end())
        {      
            continue;
        }         
        if (reg.variableName == name)
        {
            return reg;
        }
    }
    for(auto& reg : _registers)
    {
        if (reg.state == RegisterState::UNKNOWN)
        {
            if (load)
            {
                loadFromMemory(b, name, reg, _addressRegister);
            }
            return reg;
        }
    }

    auto & reg = _registers[_currentRegister];
    _currentRegister++;
    if (_currentRegister == _registers.size())
    {
        _currentRegister = 0;
    }

    if (reg.state == RegisterState::CONST)
    {
        return getRegister(name, b, usedRegisters, changeValue, load);
    }

    if (std::find_if(usedRegisters.begin(), usedRegisters.end(), [reg](auto i)
            {
                return i.get() == reg;
            }) == usedRegisters.end())
    {
        saveToMemory(b, reg, _addressRegister);
        if (load)
        {
            loadFromMemory(b, name, reg, _addressRegister);
        }        
        return reg;
    }    

    return getRegister(name, b, usedRegisters, changeValue, load); 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2c8, %rsp            # imm = 0x2C8
movl %r9d, 0xc(%rsp)
movq %rcx, %r12
movq %rdx, %r14
movq %rsi, 0x10(%rsp)
movq %rdi, %r15
movl %r8d, 0x2c(%rsp)
testl %r8d, %r8d
movq %rdi, 0x20(%rsp)
je 0x5f28
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
callq 0x4390
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x6546
leaq 0x40(%rsp), %rdi
callq 0x4548
movq 0x20(%rsp), %r15
movq %r14, 0x30(%rsp)
movq 0x68(%r15), %rax
movq 0x70(%r15), %rcx
movq %rcx, 0x38(%rsp)
movq %rax, %r15
leaq 0xe8(%rsp), %rbp
leaq 0x60(%rsp), %r14
movq %r12, (%rsp)
cmpq 0x38(%rsp), %r15
je 0x611a
movq %rbp, %r13
movq (%r12), %rbp
movq 0x8(%r12), %rax
movq %rax, 0x18(%rsp)
leaq 0x270(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x8050
movq %r13, %rdi
movq %rbx, %rsi
callq 0x8050
movq %r15, %rbx
movq %r14, %rdi
movq %r13, %rsi
callq 0x8f56
leaq 0x140(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x8f56
movq %r14, %rdi
callq 0x80ca
movq %r14, %rdi
movq %r15, %rsi
callq 0x8050
movq 0x18(%rsp), %r12
subq %rbp, %r12
movq %r12, %r15
sarq $0x5, %r15
testq %r15, %r15
jle 0x6029
movq %r14, %rdi
movq %rbp, %rsi
callq 0x7f94
testb %al, %al
jne 0x6067
leaq 0x8(%rbp), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x7f94
testb %al, %al
jne 0x606a
leaq 0x10(%rbp), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x7f94
testb %al, %al
jne 0x606a
leaq 0x18(%rbp), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x7f94
testb %al, %al
jne 0x606a
addq $0x20, %rbp
decq %r15
addq $-0x20, %r12
jmp 0x5fcb
sarq $0x3, %r12
cmpq $0x1, %r12
je 0x60e4
cmpq $0x2, %r12
movq %rbx, %r15
je 0x60cc
cmpq $0x3, %r12
jne 0x60ed
movq %r14, %rdi
movq %rbp, %rsi
callq 0x7f94
testb %al, %al
movq (%rsp), %r12
jne 0x60df
addq $0x8, %rbp
jmp 0x60d0
movq %rbp, %r13
movq (%rsp), %r12
movq %rbx, %r15
movq %r14, %rdi
callq 0x80ca
leaq 0x140(%rsp), %rdi
callq 0x80ca
leaq 0xe8(%rsp), %rbp
movq %rbp, %rdi
callq 0x80ca
movq 0x8(%r12), %rbx
leaq 0x270(%rsp), %rdi
callq 0x80ca
cmpq %rbx, %r13
jne 0x60c3
leaq 0x30(%r15), %rdi
movq 0x10(%rsp), %rsi
callq 0x8141
testb %al, %al
jne 0x63c9
addq $0x58, %r15
jmp 0x5f4e
movq (%rsp), %r12
movq %r14, %rdi
movq %rbp, %rsi
callq 0x7f94
testb %al, %al
je 0x60fb
movq %rbp, %r13
jmp 0x6071
movq (%rsp), %r12
movq %rbx, %r15
jmp 0x60ff
movq 0x18(%rsp), %r13
movq (%rsp), %r12
jmp 0x6071
addq $0x8, %rbp
movq %r14, %rdi
movq %rbp, %rsi
callq 0x7f94
testb %al, %al
movq 0x18(%rsp), %r13
cmovneq %rbp, %r13
jmp 0x6071
movq 0x20(%rsp), %rbx
movq 0x68(%rbx), %rbp
movq 0x70(%rbx), %rax
movl 0xc(%rsp), %ecx
xorb $0x1, %cl
movq %rbp, %r15
cmpq %rax, %r15
je 0x6156
movl (%r15), %edx
testl %edx, %edx
setne %sil
orb %cl, %sil
je 0x61d1
testl %edx, %edx
je 0x63c9
addq $0x58, %r15
jmp 0x6131
movl 0x80(%rbx), %edx
imulq $0x58, %rdx, %rcx
leal 0x1(%rdx), %esi
subq %rbp, %rax
pushq $0x58
popq %rdi
cqto
idivq %rdi
xorl %edx, %edx
cmpq %rsi, %rax
cmovnel %esi, %edx
movl %edx, 0x80(%rbx)
cmpl $0x2, (%rbp,%rcx)
jne 0x6202
leaq 0x1d8(%rsp), %r14
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x4390
leaq 0xd0(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x834a
movzbl 0x2c(%rsp), %r8d
movzbl 0xc(%rsp), %r9d
movq 0x20(%rsp), %rdi
movq %r14, %rsi
movq 0x30(%rsp), %rdx
movq %r15, %rcx
callq 0x5ec6
jmp 0x63b3
leaq 0x1f8(%rsp), %r14
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x4390
leaq 0x10(%rbx), %r8
movq %rbx, %rdi
movq 0x30(%rsp), %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x5316
jmp 0x63c1
addq %rcx, %rbp
movq (%r12), %rbx
movq 0x8(%r12), %r13
leaq 0x218(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x8050
leaq 0xe8(%rsp), %rdi
movq %r14, %rsi
callq 0x8050
leaq 0x60(%rsp), %r14
leaq 0xe8(%rsp), %rsi
movq %r14, %rdi
callq 0x8f56
leaq 0x140(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x8f56
movq %r14, %rdi
callq 0x80ca
leaq 0x60(%rsp), %rdi
movq %r15, %rsi
callq 0x8050
movq %r13, 0x18(%rsp)
movq %r13, %r12
subq %rbx, %r12
movq %r12, %r13
sarq $0x5, %r13
leaq 0x60(%rsp), %r15
testq %r13, %r13
jle 0x62e3
movq %r15, %rdi
movq %rbx, %rsi
callq 0x7fa8
testb %al, %al
jne 0x6328
leaq 0x8(%rbx), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x7fa8
testb %al, %al
jne 0x632b
leaq 0x10(%rbx), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x7fa8
testb %al, %al
jne 0x632b
leaq 0x18(%rbx), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x7fa8
testb %al, %al
jne 0x632b
addq $0x20, %rbx
decq %r13
addq $-0x20, %r12
jmp 0x6285
sarq $0x3, %r12
cmpq $0x1, %r12
je 0x6455
cmpq $0x2, %r12
movq 0x18(%rsp), %r14
je 0x6438
cmpq $0x3, %r12
jne 0x632b
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x7fa8
testb %al, %al
movq (%rsp), %r12
jne 0x644d
addq $0x8, %rbx
jmp 0x643c
movq %rbx, %r14
movq (%rsp), %r12
leaq 0x60(%rsp), %rdi
callq 0x80ca
leaq 0x140(%rsp), %rdi
callq 0x80ca
leaq 0xe8(%rsp), %rdi
callq 0x80ca
movq 0x8(%r12), %rbx
leaq 0x218(%rsp), %rdi
callq 0x80ca
cmpq %rbx, %r14
je 0x63de
leaq 0x198(%rsp), %r14
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x4390
leaq 0xb8(%rsp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x834a
movzbl 0x2c(%rsp), %r8d
movzbl 0xc(%rsp), %r9d
movq 0x20(%rsp), %rdi
movq %r14, %rsi
movq 0x30(%rsp), %rdx
movq %r15, %rcx
callq 0x5ec6
movq %rax, %rbx
movq %r15, %rdi
callq 0x9106
movq %rbx, %r15
movq %r14, %rdi
callq 0x4548
movq %r15, %rax
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x20(%rsp), %r12
leaq 0x10(%r12), %rbx
movq %r12, %rdi
movq 0x30(%rsp), %r15
movq %r15, %rsi
movq %rbp, %rdx
movq %rbx, %rcx
callq 0x51c8
cmpb $0x0, 0xc(%rsp)
je 0x6433
leaq 0x1b8(%rsp), %r14
movq %r14, %rdi
movq 0x10(%rsp), %rsi
callq 0x4390
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbp, %rcx
movq %rbx, %r8
callq 0x5316
movq %rbp, %r15
jmp 0x63c1
movq %rbp, %r15
jmp 0x63c9
movq (%rsp), %r12
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x7fa8
testb %al, %al
je 0x6460
movq %rbx, %r14
jmp 0x632f
movq (%rsp), %r12
movq 0x18(%rsp), %r14
jmp 0x6464
addq $0x8, %rbx
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq 0x7fa8
testb %al, %al
cmovneq %rbx, %r14
jmp 0x632f
movq %rax, %rbx
leaq 0x1b8(%rsp), %rdi
jmp 0x6508
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x9106
jmp 0x649e
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
jmp 0x6508
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x80ca
leaq 0xe8(%rsp), %rdi
callq 0x80ca
jmp 0x64dc
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x9106
jmp 0x64e9
movq %rax, %rbx
leaq 0x218(%rsp), %rdi
jmp 0x6539
movq %rax, %rbx
leaq 0x1d8(%rsp), %rdi
jmp 0x6508
movq %rax, %rbx
leaq 0x1f8(%rsp), %rdi
jmp 0x6508
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x4548
jmp 0x653e
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0x80ca
leaq 0xe8(%rsp), %rdi
callq 0x80ca
jmp 0x6531
movq %rax, %rbx
leaq 0x270(%rsp), %rdi
callq 0x80ca
movq %rbx, %rdi
callq 0x4490