// File: /workspace/github_cpp_makefile_star2_O3/Davidc2525[P]Leaf/compiler/backend/x86_64_linux/generator.cpp
// Function: x86_64_linux_generator_visitor::visit2(LEAF::AST::Ident*)
void x86_64_linux_generator_visitor::visit2(Ident *ident)
{
    UPDATE_STATICS

    Section *st = assembly->get_program()->section(Sections::text);
    if (this->ax == Load)
    {
        if(ident->obj->type->kind == symbol_table::floatType->kind){
        
        }
        DInstruccion *i = new DInstruccion("mov");
        MemoryOperand *ops = new MemoryOperand();
        ops->add_operand(new RegisterOperand("rbp"));
        ops->add_operand(load_mod::sub, new InmediateIntOperand(ident->obj->adr));
        RegisterOperand *opd = new RegisterOperand(this->reg->getName());
        i->add_operand(opd);
        i->add_operand(ops);
        st->add(i);
    }

    if (this->ax == op_types::Plus)
    {
        DInstruccion *i = new DInstruccion("add");
        MemoryOperand *ops = new MemoryOperand();
        ops->add_operand(new RegisterOperand("rbp"));
        ops->add_operand(load_mod::sub, new InmediateIntOperand(ident->obj->adr));
        RegisterOperand *opd = new RegisterOperand(this->reg->getName());
        i->add_operand(opd);
        i->add_operand(ops);
        st->add(i);
    }

    if (this->ax == op_types::Store)
    {
        DInstruccion *i = new DInstruccion("mov");
        if (ident->obj->type->kind == Struct::Float)
        {
            i->set_instruccion("movss");
        }
        MemoryOperand *ops = new MemoryOperand();
        ops->add_operand(new RegisterOperand("rbp"));
        ops->add_operand(load_mod::sub, new InmediateIntOperand(ident->obj->adr));
        RegisterOperand *opd = new RegisterOperand(this->reg->getName());
        i->add_operand(ops);
        i->add_operand(opd);
        st->add(i);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %r14
incl 0x8(%rdi)
movq %rsi, %r15
movq 0x10(%rdi), %rax
movq (%rax), %rdi
movl $0x2, %esi
callq 0x10346
movq %rax, %rbx
movl 0x38(%r14), %eax
cmpl $0x1, %eax
jne 0x166e3
movl $0x28, %edi
callq 0x5290
movq %rax, %r12
leaq 0x4dbb(%rip), %rsi      # 0x1b3e4
movq %rax, %rdi
callq 0xfc44
movl $0x20, %edi
callq 0x5290
movq %rax, %r13
movq %rax, %rdi
callq 0xff08
movl $0x10, %edi
callq 0x5290
movq %rax, %rbp
leaq 0x4920(%rip), %rsi      # 0x1af7a
movq %rax, %rdi
callq 0xfe82
movq %r13, %rdi
movq %rbp, %rsi
callq 0xff60
movl $0x10, %edi
callq 0x5290
movq %rax, %rbp
movq 0x8(%r15), %rax
movl 0x30(%rax), %esi
movq %rbp, %rdi
callq 0xfe48
movq %r13, %rdi
movl $0x1, %esi
movq %rbp, %rdx
callq 0xff22
movl $0x10, %edi
callq 0x5290
movq %rax, %rbp
movq 0x20(%r14), %rdi
callq 0x118ec
movq %rbp, %rdi
movq %rax, %rsi
callq 0xfe82
movq (%r12), %rax
movq %r12, %rdi
movq %rbp, %rsi
callq *0x20(%rax)
movq (%r12), %rax
movq %r12, %rdi
movq %r13, %rsi
callq *0x20(%rax)
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf294
movl 0x38(%r14), %eax
cmpl $0x2, %eax
jne 0x167ba
movl $0x28, %edi
callq 0x5290
movq %rax, %r12
leaq 0x4cdb(%rip), %rsi      # 0x1b3db
movq %rax, %rdi
callq 0xfc44
movl $0x20, %edi
callq 0x5290
movq %rax, %r13
movq %rax, %rdi
callq 0xff08
movl $0x10, %edi
callq 0x5290
movq %rax, %rbp
leaq 0x4849(%rip), %rsi      # 0x1af7a
movq %rax, %rdi
callq 0xfe82
movq %r13, %rdi
movq %rbp, %rsi
callq 0xff60
movl $0x10, %edi
callq 0x5290
movq %rax, %rbp
movq 0x8(%r15), %rax
movl 0x30(%rax), %esi
movq %rbp, %rdi
callq 0xfe48
movq %r13, %rdi
movl $0x1, %esi
movq %rbp, %rdx
callq 0xff22
movl $0x10, %edi
callq 0x5290
movq %rax, %rbp
movq 0x20(%r14), %rdi
callq 0x118ec
movq %rbp, %rdi
movq %rax, %rsi
callq 0xfe82
movq (%r12), %rax
movq %r12, %rdi
movq %rbp, %rsi
callq *0x20(%rax)
movq (%r12), %rax
movq %r12, %rdi
movq %r13, %rsi
callq *0x20(%rax)
movq %rbx, %rdi
movq %r12, %rsi
callq 0xf294
movl 0x38(%r14), %eax
testl %eax, %eax
je 0x167cd
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x28, %edi
callq 0x5290
movq %rax, %r12
leaq 0x4c03(%rip), %rsi      # 0x1b3e4
movq %rax, %rdi
callq 0xfc44
movq 0x8(%r15), %rax
movq 0x18(%rax), %rax
cmpl $0x2, 0x10(%rax)
jne 0x16808
movq (%r12), %rax
leaq 0x4bf2(%rip), %rsi      # 0x1b3f4
movq %r12, %rdi
callq *0x10(%rax)
movl $0x20, %edi
callq 0x5290
movq %rax, %r13
movq %rax, %rdi
callq 0xff08
movl $0x10, %edi
callq 0x5290
movq %rax, %rbp
leaq 0x4749(%rip), %rsi      # 0x1af7a
movq %rax, %rdi
callq 0xfe82
movq %r13, %rdi
movq %rbp, %rsi
callq 0xff60
movl $0x10, %edi
callq 0x5290
movq %rax, %rbp
movq 0x8(%r15), %rax
movl 0x30(%rax), %esi
movq %rbp, %rdi
callq 0xfe48
movq %r13, %rdi
movl $0x1, %esi
movq %rbp, %rdx
callq 0xff22
movl $0x10, %edi
callq 0x5290
movq %rax, %r15
movq 0x20(%r14), %rdi
callq 0x118ec
movq %r15, %rdi
movq %rax, %rsi
callq 0xfe82
movq (%r12), %rax
movq %r12, %rdi
movq %r13, %rsi
callq *0x20(%rax)
movq (%r12), %rax
movq %r12, %rdi
movq %r15, %rsi
callq *0x20(%rax)
movq %rbx, %rdi
movq %r12, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xf294
jmp 0x16901
jmp 0x16901
jmp 0x168d8
jmp 0x168e5
jmp 0x16901
jmp 0x16901
jmp 0x168d8
jmp 0x168e5
jmp 0x16901
jmp 0x16901
movq %rax, %rbx
movl $0x20, %esi
movq %r13, %rdi
jmp 0x1690c
movq %rax, %rbx
movl $0x28, %esi
movq %r12, %rdi
jmp 0x1690c
movq %rax, %rbx
movl $0x10, %esi
movq %r15, %rdi
jmp 0x1690c
jmp 0x16901
movq %rax, %rbx
movl $0x10, %esi
movq %rbp, %rdi
callq 0x52a0
movq %rbx, %rdi
callq 0x5470
nop