// File: Davidc2525[P]Leaf/compiler/backend/x86_64_linux/generator.cpp
// Function: x86_64_linux_generator_visitor::visit(LEAF::AST::CatchStatementNode*)
void x86_64_linux_generator_visitor::visit(CatchStatementNode *_catch_)
{

    UPDATE_STATICS
    Section *st = assembly->get_program()->section(Sections::text);
    DInstruccion *i = new DInstruccion(";start catch");
    st->add(i);

    Label *try_label = new Label((char *)_catch_->start_label->c_str());
    st->add(try_label);

    i = new DInstruccion("mov");
    MemoryOperand *var_ex = new MemoryOperand();
    var_ex->add_operand(new RegisterOperand("rbp"));
    var_ex->add_operand(load_mod::sub, new InmediateIntOperand(_catch_->ex_var->obj->adr));
    i->add_operand(var_ex);
    i->add_operand(new RegisterOperand("rax"));
    st->add(i);

    vector<ASTU>::iterator x = _catch_->nodos.begin();
    for (; x != _catch_->nodos.end(); x++)
    {
        (*x)->accept(this);
    }

    i = new DInstruccion(";end catch");
    st->add(i);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movl 0x8(%rax), %ecx
incl %ecx
movl %ecx, 0x8(%rax)
movq 0x10(%rax), %rdi
callq 0xb010
movq %rax, %rdi
movl $0x2, %esi
callq 0x1c3c0
movq %rax, -0x18(%rbp)
movl $0x28, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x60(%rbp)
leaq 0x534b(%rip), %rsi      # 0x36223
callq 0x1a4e0
jmp 0x30edf
movq -0x60(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x18670
movl $0x10, %edi
callq 0x62e0
movq %rax, -0x70(%rbp)
movq %rax, -0x78(%rbp)
movq -0x10(%rbp), %rax
movq 0x40(%rax), %rdi
callq 0x6120
movq -0x70(%rbp), %rdi
movq %rax, %rsi
callq 0x19b10
jmp 0x30f21
movq -0x78(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x18670
movl $0x28, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x80(%rbp)
leaq 0x5238(%rip), %rsi      # 0x36189
callq 0x1a4e0
jmp 0x30f58
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 0x30f7e
movq -0x88(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x98(%rbp)
movl $0x10, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x90(%rbp)
leaq 0x4d88(%rip), %rsi      # 0x35d3a
callq 0x1b1e0
jmp 0x30fb9
movq -0x90(%rbp), %rsi
movq -0x98(%rbp), %rdi
callq 0x1b420
movq -0x40(%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 0x58(%rax), %rax
movq 0x8(%rax), %rax
movl 0x30(%rax), %esi
callq 0x1b0f0
jmp 0x31004
movq -0xa0(%rbp), %rdx
movq -0xa8(%rbp), %rdi
movl $0x1, %esi
callq 0x1b3a0
movq -0x20(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq (%rdi), %rax
movq 0x20(%rax), %rax
callq *%rax
movq -0x20(%rbp), %rax
movq %rax, -0xb8(%rbp)
movl $0x10, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xb0(%rbp)
leaq 0x4cae(%rip), %rsi      # 0x35d04
callq 0x1b1e0
jmp 0x3105d
movq -0xb0(%rbp), %rsi
movq -0xb8(%rbp), %rdi
movq (%rdi), %rax
callq *0x20(%rax)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x18670
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
callq 0xdd70
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
addq $0x28, %rdi
callq 0xdc00
movq %rax, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x31da0
testb $0x1, %al
jne 0x310b6
jmp 0x311be
leaq -0x48(%rbp), %rdi
callq 0x31de0
movq -0x68(%rbp), %rsi
movq (%rax), %rdi
movq (%rdi), %rax
callq *(%rax)
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
callq 0x31e00
movq %rax, -0x58(%rbp)
jmp 0x3108f
movq -0x60(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x28, %esi
callq 0x62f0
jmp 0x31221
movq -0x78(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x10, %esi
callq 0x62f0
jmp 0x31221
movq -0x80(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x28, %esi
callq 0x62f0
jmp 0x31221
movq -0x88(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x20, %esi
callq 0x62f0
jmp 0x31221
movq -0x90(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x10, %esi
callq 0x62f0
jmp 0x31221
movq -0xa0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x10, %esi
callq 0x62f0
jmp 0x31221
movq -0xb0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x10, %esi
callq 0x62f0
jmp 0x31221
movl $0x28, %edi
callq 0x62e0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0xc0(%rbp)
leaq 0x5054(%rip), %rsi      # 0x36230
callq 0x1a4e0
jmp 0x311e3
movq -0xc0(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x18670
addq $0xc0, %rsp
popq %rbp
retq
movq -0xc0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
movl $0x28, %esi
callq 0x62f0
movq -0x28(%rbp), %rdi
callq 0x64f0
nopw (%rax,%rax)