// File: /workspace/github_cpp_makefile_star2_O1/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 0x102f0
movq %rax, %rbx
cmpl $0x1, 0x38(%r14)
jne 0x168f5
movl $0x28, %edi
callq 0x5290
movq %rax, %r12
leaq 0x4b45(%rip), %rsi      # 0x1b384
movq %rax, %rdi
callq 0xfc18
movl $0x20, %edi
callq 0x5290
movq %rax, %r13
movq %rax, %rdi
callq 0xfed4
movl $0x10, %edi
callq 0x5290
movq %rax, %rbp
leaq 0x46aa(%rip), %rsi      # 0x1af1a
movq %rax, %rdi
callq 0xfe4e
movq %r13, %rdi
movq %rbp, %rsi
callq 0xff2c
movl $0x10, %edi
callq 0x5290
movq %rax, %rbp
movq 0x8(%r15), %rax
movl 0x30(%rax), %esi
movq %rbp, %rdi
callq 0xfe14
movq %r13, %rdi
movl $0x1, %esi
movq %rbp, %rdx
callq 0xfeee
movl $0x10, %edi
callq 0x5290
movq %rax, %rbp
movq 0x20(%r14), %rdi
callq 0x1196c
movq %rbp, %rdi
movq %rax, %rsi
callq 0xfe4e
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 0xf258
cmpl $0x2, 0x38(%r14)
jne 0x169ca
movl $0x28, %edi
callq 0x5290
movq %rax, %r12
leaq 0x4a67(%rip), %rsi      # 0x1b37b
movq %rax, %rdi
callq 0xfc18
movl $0x20, %edi
callq 0x5290
movq %rax, %r13
movq %rax, %rdi
callq 0xfed4
movl $0x10, %edi
callq 0x5290
movq %rax, %rbp
leaq 0x45d5(%rip), %rsi      # 0x1af1a
movq %rax, %rdi
callq 0xfe4e
movq %r13, %rdi
movq %rbp, %rsi
callq 0xff2c
movl $0x10, %edi
callq 0x5290
movq %rax, %rbp
movq 0x8(%r15), %rax
movl 0x30(%rax), %esi
movq %rbp, %rdi
callq 0xfe14
movq %r13, %rdi
movl $0x1, %esi
movq %rbp, %rdx
callq 0xfeee
movl $0x10, %edi
callq 0x5290
movq %rax, %rbp
movq 0x20(%r14), %rdi
callq 0x1196c
movq %rbp, %rdi
movq %rax, %rsi
callq 0xfe4e
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 0xf258
cmpl $0x0, 0x38(%r14)
je 0x169e0
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 0x4990(%rip), %rsi      # 0x1b384
movq %rax, %rdi
callq 0xfc18
movq 0x8(%r15), %rax
movq 0x18(%rax), %rax
cmpl $0x2, 0x10(%rax)
jne 0x16a1b
movq (%r12), %rax
leaq 0x497f(%rip), %rsi      # 0x1b394
movq %r12, %rdi
callq *0x10(%rax)
movl $0x20, %edi
callq 0x5290
movq %rax, %r13
movq %rax, %rdi
callq 0xfed4
movl $0x10, %edi
callq 0x5290
movq %rax, %rbp
leaq 0x44d6(%rip), %rsi      # 0x1af1a
movq %rax, %rdi
callq 0xfe4e
movq %r13, %rdi
movq %rbp, %rsi
callq 0xff2c
movl $0x10, %edi
callq 0x5290
movq %rax, %rbp
movq 0x8(%r15), %rax
movl 0x30(%rax), %esi
movq %rbp, %rdi
callq 0xfe14
movq %r13, %rdi
movl $0x1, %esi
movq %rbp, %rdx
callq 0xfeee
movl $0x10, %edi
callq 0x5290
movq %rax, %r15
movq 0x20(%r14), %rdi
callq 0x1196c
movq %r15, %rdi
movq %rax, %rsi
callq 0xfe4e
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 0xf258
jmp 0x16b14
jmp 0x16b14
jmp 0x16aeb
jmp 0x16af8
jmp 0x16b14
jmp 0x16b14
jmp 0x16aeb
jmp 0x16af8
jmp 0x16b14
jmp 0x16b14
movq %rax, %rbx
movl $0x20, %esi
movq %r13, %rdi
jmp 0x16b1f
movq %rax, %rbx
movl $0x28, %esi
movq %r12, %rdi
jmp 0x16b1f
movq %rax, %rbx
movl $0x10, %esi
movq %r15, %rdi
jmp 0x16b1f
jmp 0x16b14
movq %rax, %rbx
movl $0x10, %esi
movq %rbp, %rdi
callq 0x52a0
movq %rbx, %rdi
callq 0x5470