// File: Davidc2525[P]Leaf/tree.cpp
// Function: EffectiveAddr::toString()
char *EffectiveAddr::toString()
{
    RegisterProvider *rp = RegisterManager::getInstance()->getProviderBy(64);
    string *addr = new string();

    /**
     * TODO: delete
     * TODO: colocar el registro dependiendo de la arquitectura
    */
    if (withBp)
    {
        //  RegisterProvider *rp = RegisterManager::getInstance()->getProviderBy(64);

        addr->append(rp->get_by_name("rbp")->getName());
        addr->append("+");
    }

    if (!this->parts.empty())
    {
        //std::sort(regis.begin(), regis.end(), compareEfectivePart);

        for (int i = 0; i < parts.size(); i++)
        {

            if (i != 0)
                addr->append(modoToString(parts[i]->mode));
            if (parts[i]->type == Reg)
            {

                addr->append(rp->get(parts[i]->load)->getName());
            }
            else if (parts[i]->type == Num)
            {
                addr->append(to_string(parts[i]->load));
            }
        }
    }

    return (char *)addr->c_str();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x58(%rbp)
callq 0x21500
movq %rax, %rdi
movl $0x40, %esi
callq 0x21620
movq %rax, -0x10(%rbp)
movl $0x20, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, -0x60(%rbp)
callq 0x6430
movq -0x60(%rbp), %rcx
movq -0x58(%rbp), %rax
movq %rcx, -0x18(%rbp)
testb $0x1, (%rax)
je 0x1e351
movq -0x18(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
movq (%rdi), %rax
leaq 0x17a10(%rip), %rsi     # 0x35d3a
callq *0x10(%rax)
movq %rax, %rdi
callq 0x21350
movq -0x68(%rbp), %rdi
movq %rax, %rsi
callq 0x6540
movq -0x18(%rbp), %rdi
leaq 0x17914(%rip), %rsi     # 0x35c60
callq 0x6540
movq -0x58(%rbp), %rdi
addq $0x8, %rdi
callq 0x1e4f0
testb $0x1, %al
jne 0x1e4c7
movl $0x0, -0x1c(%rbp)
movq -0x58(%rbp), %rdi
movslq -0x1c(%rbp), %rax
movq %rax, -0x70(%rbp)
addq $0x8, %rdi
callq 0x1e530
movq %rax, %rcx
movq -0x70(%rbp), %rax
cmpq %rcx, %rax
jae 0x1e4c5
cmpl $0x0, -0x1c(%rbp)
je 0x1e3c8
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rax
movq %rax, -0x78(%rbp)
addq $0x8, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x1e550
movq (%rax), %rax
movl 0x4(%rax), %edi
callq 0x1e220
movq -0x78(%rbp), %rdi
movq %rax, %rsi
callq 0x6540
movq -0x58(%rbp), %rdi
addq $0x8, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x1e550
movq (%rax), %rax
cmpl $0x0, 0x8(%rax)
jne 0x1e431
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x88(%rbp)
addq $0x8, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x1e550
movq -0x88(%rbp), %rdi
movq (%rax), %rax
movl (%rax), %esi
movq (%rdi), %rax
callq *0x8(%rax)
movq %rax, %rdi
callq 0x21350
movq -0x80(%rbp), %rdi
movq %rax, %rsi
callq 0x6540
jmp 0x1e4b5
movq -0x58(%rbp), %rdi
addq $0x8, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x1e550
movq (%rax), %rax
cmpl $0x1, 0x8(%rax)
jne 0x1e4b3
movq -0x58(%rbp), %rdi
movq -0x18(%rbp), %rax
movq %rax, -0x98(%rbp)
addq $0x8, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x1e550
movq (%rax), %rax
movl (%rax), %esi
leaq -0x40(%rbp), %rdi
movq %rdi, -0x90(%rbp)
callq 0xae50
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0x6550
jmp 0x1e491
leaq -0x40(%rbp), %rdi
callq 0x6588
jmp 0x1e4b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x6588
jmp 0x1e4d9
jmp 0x1e4b5
jmp 0x1e4b7
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x1e36d
jmp 0x1e4c7
movq -0x18(%rbp), %rdi
callq 0x6120
addq $0xa0, %rsp
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x64f0
nopw %cs:(%rax,%rax)
nopl (%rax)