// File: 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
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq 0x10(%rax), %rdi
callq 0xb010
movq %rax, %rdi
movl $0x2, %esi
callq 0x1c3c0
movq %rax, %rcx
movq -0x78(%rbp), %rax
movq %rcx, -0x18(%rbp)
cmpl $0x1, 0x38(%rax)
jne 0x2f020
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
movl 0x10(%rax), %eax
leaq 0x1c24b(%rip), %rcx     # 0x4b060
movq (%rcx), %rcx
cmpl 0x10(%rcx), %eax
jne 0x2ee1f
jmp 0x2ee1f
movl $0x28, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x80(%rbp)
leaq 0x734f(%rip), %rsi      # 0x36189
callq 0x1a4e0
jmp 0x2ee41
movq -0x80(%rbp), %rax
movq %rax, -0x20(%rbp)
movl $0x20, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x88(%rbp)
callq 0x1b360
jmp 0x2ee67
movq -0x88(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x98(%rbp)
movl $0x10, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x90(%rbp)
leaq 0x6e9f(%rip), %rsi      # 0x35d3a
callq 0x1b1e0
jmp 0x2eea2
movq -0x90(%rbp), %rsi
movq -0x98(%rbp), %rdi
callq 0x1b420
movq -0x38(%rbp), %rax
movq %rax, -0xa8(%rbp)
movl $0x10, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x30(%rax), %esi
callq 0x1b0f0
jmp 0x2eee9
movq -0xa0(%rbp), %rdx
movq -0xa8(%rbp), %rdi
movl $0x1, %esi
callq 0x1b3a0
movl $0x10, %edi
callq 0x62e0
movq %rax, %rcx
movq -0x78(%rbp), %rax
movq %rcx, -0xb8(%rbp)
movq 0x20(%rax), %rdi
callq 0x21350
movq %rax, -0xb0(%rbp)
jmp 0x2ef2b
movq -0xb0(%rbp), %rsi
movq -0xb8(%rbp), %rdi
callq 0x1b1e0
jmp 0x2ef40
movq -0xb8(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq (%rdi), %rax
callq *0x20(%rax)
movq -0x20(%rbp), %rdi
movq -0x38(%rbp), %rsi
movq (%rdi), %rax
callq *0x20(%rax)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x18670
jmp 0x2f020
movq -0x80(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x28, %esi
callq 0x62f0
jmp 0x2f46f
movq -0x88(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x20, %esi
callq 0x62f0
jmp 0x2f46f
movq -0x90(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x10, %esi
callq 0x62f0
jmp 0x2f46f
movq -0xa0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x10, %esi
callq 0x62f0
jmp 0x2f46f
movq -0xb8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x10, %esi
callq 0x62f0
jmp 0x2f46f
movq -0x78(%rbp), %rax
cmpl $0x2, 0x38(%rax)
jne 0x2f238
movl $0x28, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xc0(%rbp)
leaq 0x7134(%rip), %rsi      # 0x36180
callq 0x1a4e0
jmp 0x2f053
movq -0xc0(%rbp), %rax
movq %rax, -0x48(%rbp)
movl $0x20, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xc8(%rbp)
callq 0x1b360
jmp 0x2f07c
movq -0xc8(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0xd8(%rbp)
movl $0x10, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xd0(%rbp)
leaq 0x6c8a(%rip), %rsi      # 0x35d3a
callq 0x1b1e0
jmp 0x2f0b7
movq -0xd0(%rbp), %rsi
movq -0xd8(%rbp), %rdi
callq 0x1b420
movq -0x50(%rbp), %rax
movq %rax, -0xe8(%rbp)
movl $0x10, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xe0(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x30(%rax), %esi
callq 0x1b0f0
jmp 0x2f0fe
movq -0xe0(%rbp), %rdx
movq -0xe8(%rbp), %rdi
movl $0x1, %esi
callq 0x1b3a0
movl $0x10, %edi
callq 0x62e0
movq %rax, %rcx
movq -0x78(%rbp), %rax
movq %rcx, -0xf8(%rbp)
movq 0x20(%rax), %rdi
callq 0x21350
movq %rax, -0xf0(%rbp)
jmp 0x2f140
movq -0xf0(%rbp), %rsi
movq -0xf8(%rbp), %rdi
callq 0x1b1e0
jmp 0x2f155
movq -0xf8(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq (%rdi), %rax
callq *0x20(%rax)
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
movq (%rdi), %rax
callq *0x20(%rax)
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x18670
jmp 0x2f238
movq -0xc0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x28, %esi
callq 0x62f0
jmp 0x2f46f
movq -0xc8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x20, %esi
callq 0x62f0
jmp 0x2f46f
movq -0xd0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x10, %esi
callq 0x62f0
jmp 0x2f46f
movq -0xe0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x10, %esi
callq 0x62f0
jmp 0x2f46f
movq -0xf8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x10, %esi
callq 0x62f0
jmp 0x2f46f
movq -0x78(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0x2f466
movl $0x28, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x100(%rbp)
leaq 0x6f25(%rip), %rsi      # 0x36189
callq 0x1a4e0
jmp 0x2f26b
movq -0x100(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rax), %rax
cmpl $0x2, 0x10(%rax)
jne 0x2f2bd
movq -0x60(%rbp), %rdi
movq (%rdi), %rax
leaq 0x6f03(%rip), %rsi      # 0x36199
callq *0x10(%rax)
jmp 0x2f2bd
movq -0x100(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x28, %esi
callq 0x62f0
jmp 0x2f46f
movl $0x20, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x108(%rbp)
callq 0x1b360
jmp 0x2f2db
movq -0x108(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x118(%rbp)
movl $0x10, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x110(%rbp)
leaq 0x6a2b(%rip), %rsi      # 0x35d3a
callq 0x1b1e0
jmp 0x2f316
movq -0x110(%rbp), %rsi
movq -0x118(%rbp), %rdi
callq 0x1b420
movq -0x68(%rbp), %rax
movq %rax, -0x128(%rbp)
movl $0x10, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x120(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movl 0x30(%rax), %esi
callq 0x1b0f0
jmp 0x2f35d
movq -0x120(%rbp), %rdx
movq -0x128(%rbp), %rdi
movl $0x1, %esi
callq 0x1b3a0
movl $0x10, %edi
callq 0x62e0
movq %rax, %rcx
movq -0x78(%rbp), %rax
movq %rcx, -0x138(%rbp)
movq 0x20(%rax), %rdi
callq 0x21350
movq %rax, -0x130(%rbp)
jmp 0x2f39f
movq -0x130(%rbp), %rsi
movq -0x138(%rbp), %rdi
callq 0x1b1e0
jmp 0x2f3b4
movq -0x138(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq (%rdi), %rax
callq *0x20(%rax)
movq -0x60(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq (%rdi), %rax
callq *0x20(%rax)
movq -0x18(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x18670
jmp 0x2f466
movq -0x108(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x20, %esi
callq 0x62f0
jmp 0x2f46f
movq -0x110(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x10, %esi
callq 0x62f0
jmp 0x2f46f
movq -0x120(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x10, %esi
callq 0x62f0
jmp 0x2f46f
movq -0x138(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x10, %esi
callq 0x62f0
jmp 0x2f46f
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
movq -0x28(%rbp), %rdi
callq 0x64f0
nopl (%rax,%rax)