// File: kelwinfc[P]ci4721-Fernandez-Gyomrey/src/AST/to_tac.cpp
// Function: AST_bounded_loop::to_tac(Tac*)
void AST_bounded_loop::to_tac(Tac* t){
    next_list.clear();

    opd* l = left_bound->to_tac(t);
    opd* r = right_bound->to_tac(t);
    opd* i = new opd(), *os = new opd(sym);
    // prólogo
    t->append_quad(inst::CP, i, new opd(-1), 0, "se asume que se va a restar en cada ciclo");
    t->append_quad(inst::IFGEQ, l, r, new opd(t->next_instruction() + 2, O_LABEL), "en este caso, efectivamente, se resta en cada ciclo");
    t->append_quad(inst::CP, i, new opd(1), 0, "si se alcanzó esta instrucción, se va a sumar en cada ciclo");
    int start_instr = t->next_instruction();
    // comienzo del ciclo
    t->append_quad(inst::IFEQ, i, new opd(1), new opd(t->next_instruction() + 3, O_LABEL), "verificar que se suma por ciclo");
    t->append_quad(inst::IFGEQ, l, r, new opd(t->next_instruction() + 4, O_LABEL),
        "dado que se resta por ciclo, verificar que no se alcanzó el mínimo derecho");
    next_list.push_back( t->next_instruction() );
    t->append_quad(inst::GOTO, 0, 0, 0, "si se llegó hasta aquí, es porque el ciclo finalizó naturalmente");
    t->append_quad(inst::IFLEQ, l, r, new opd(t->next_instruction() + 2, O_LABEL),
        "dado que se suma por ciclo, verificar que no se alcanzó el máximo derecho");
    next_list.push_back( t->next_instruction() );
    t->append_quad(inst::GOTO, 0, 0, 0, "si se llegó hasta aquí, es porque el ciclo finalizó naturalmente");
    // ciclo
    blck->to_tac(t);
    // si ocurre un continue en el ciclo
    t->backpatch(blck->continue_list, start_instr);
    t->backpatch(blck->next_list, start_instr);
    // si ocurre un break en el ciclo
    next_list.splice(next_list.end(), blck->break_list);

    t->append_quad(inst::ADD, os, os, i, "tanto para enteros como para caracteres sumar uno hasta llegars");
    // comenzar de nuevo
    t->append_quad(inst::GOTO, 0, 0, new opd(start_instr, O_LABEL), "volver a comenzar el for acotado");
}

// Assembly:
subq $0x378, %rsp            # imm = 0x378
movq %rdi, 0x370(%rsp)
movq %rsi, 0x368(%rsp)
movq 0x370(%rsp), %rdi
movq %rdi, 0x188(%rsp)
addq $0x18, %rdi
callq 0x20ad0
movq 0x188(%rsp), %rax
movq 0xa8(%rax), %rdi
movq 0x368(%rsp), %rsi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
movq %rax, %rcx
movq 0x188(%rsp), %rax
movq %rcx, 0x360(%rsp)
movq 0xb0(%rax), %rdi
movq 0x368(%rsp), %rsi
movq (%rdi), %rax
movq 0x18(%rax), %rax
callq *%rax
movq %rax, 0x358(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x190(%rsp)
callq 0x37ff0
jmp 0x1bc02
movq 0x190(%rsp), %rax
movq %rax, 0x350(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, %rdi
movq 0x188(%rsp), %rax
movq %rdi, %rcx
movq %rcx, 0x180(%rsp)
movq 0x98(%rax), %rsi
callq 0x37fd0
jmp 0x1bc40
movq 0x180(%rsp), %rax
movq %rax, 0x338(%rsp)
movq 0x368(%rsp), %rax
movq %rax, 0x168(%rsp)
movq 0x350(%rsp), %rax
movq %rax, 0x170(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x178(%rsp)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x2, %edx
callq 0x38010
jmp 0x1bc99
leaq 0x317(%rsp), %rdi
movq %rdi, 0x160(%rsp)
callq 0x66c0
movq 0x160(%rsp), %rdx
leaq 0x380fe(%rip), %rsi     # 0x53dbb
leaq 0x318(%rsp), %rdi
callq 0x7500
jmp 0x1bccc
movq 0x178(%rsp), %rcx
movq 0x170(%rsp), %rdx
movq 0x168(%rsp), %rdi
xorl %esi, %esi
movl %esi, %r8d
leaq 0x318(%rsp), %r9
callq 0x4de80
jmp 0x1bcf8
leaq 0x318(%rsp), %rdi
callq 0x6778
leaq 0x317(%rsp), %rdi
callq 0x6400
movq 0x368(%rsp), %rax
movq %rax, 0x138(%rsp)
movq 0x360(%rsp), %rax
movq %rax, 0x140(%rsp)
movq 0x358(%rsp), %rax
movq %rax, 0x148(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, 0x150(%rsp)
movq 0x368(%rsp), %rdi
callq 0x4dfb0
movl %eax, 0x15c(%rsp)
jmp 0x1bd6a
movq 0x150(%rsp), %rdi
movl 0x15c(%rsp), %esi
addl $0x2, %esi
movl $0x6, %edx
callq 0x38010
jmp 0x1bd88
leaq 0x2ef(%rsp), %rdi
movq %rdi, 0x130(%rsp)
callq 0x66c0
movq 0x130(%rsp), %rdx
leaq 0x38039(%rip), %rsi     # 0x53de5
leaq 0x2f0(%rsp), %rdi
callq 0x7500
jmp 0x1bdbb
movq 0x150(%rsp), %r8
movq 0x148(%rsp), %rcx
movq 0x140(%rsp), %rdx
movq 0x138(%rsp), %rdi
movl $0x1d, %esi
leaq 0x2f0(%rsp), %r9
callq 0x4de80
jmp 0x1bdef
leaq 0x2f0(%rsp), %rdi
callq 0x6778
leaq 0x2ef(%rsp), %rdi
callq 0x6400
movq 0x368(%rsp), %rax
movq %rax, 0x118(%rsp)
movq 0x350(%rsp), %rax
movq %rax, 0x120(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x128(%rsp)
movl $0x1, %esi
movl $0x2, %edx
callq 0x38010
jmp 0x1be52
leaq 0x2c7(%rsp), %rdi
movq %rdi, 0x110(%rsp)
callq 0x66c0
movq 0x110(%rsp), %rdx
leaq 0x37fa3(%rip), %rsi     # 0x53e19
leaq 0x2c8(%rsp), %rdi
callq 0x7500
jmp 0x1be85
movq 0x128(%rsp), %rcx
movq 0x120(%rsp), %rdx
movq 0x118(%rsp), %rdi
xorl %esi, %esi
movl %esi, %r8d
leaq 0x2c8(%rsp), %r9
callq 0x4de80
jmp 0x1beb1
leaq 0x2c8(%rsp), %rdi
callq 0x6778
leaq 0x2c7(%rsp), %rdi
callq 0x6400
movq 0x368(%rsp), %rdi
callq 0x4dfb0
movl %eax, 0x2c0(%rsp)
movq 0x368(%rsp), %rax
movq %rax, 0xf8(%rsp)
movq 0x350(%rsp), %rax
movq %rax, 0x100(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x108(%rsp)
movl $0x1, %esi
movl $0x2, %edx
callq 0x38010
jmp 0x1bf28
movl $0x18, %edi
callq 0x6390
movq %rax, 0xe8(%rsp)
movq 0x368(%rsp), %rdi
callq 0x4dfb0
movl %eax, 0xf4(%rsp)
jmp 0x1bf50
movq 0xe8(%rsp), %rdi
movl 0xf4(%rsp), %esi
addl $0x3, %esi
movl $0x6, %edx
callq 0x38010
jmp 0x1bf6e
leaq 0x29f(%rsp), %rdi
movq %rdi, 0xe0(%rsp)
callq 0x66c0
movq 0xe0(%rsp), %rdx
leaq 0x37ec5(%rip), %rsi     # 0x53e57
leaq 0x2a0(%rsp), %rdi
callq 0x7500
jmp 0x1bfa1
movq 0xe8(%rsp), %r8
movq 0x108(%rsp), %rcx
movq 0x100(%rsp), %rdx
movq 0xf8(%rsp), %rdi
movl $0x18, %esi
leaq 0x2a0(%rsp), %r9
callq 0x4de80
jmp 0x1bfd5
leaq 0x2a0(%rsp), %rdi
callq 0x6778
leaq 0x29f(%rsp), %rdi
callq 0x6400
movq 0x368(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0x360(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0x358(%rsp), %rax
movq %rax, 0xc8(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, 0xd0(%rsp)
movq 0x368(%rsp), %rdi
callq 0x4dfb0
movl %eax, 0xdc(%rsp)
jmp 0x1c047
movq 0xd0(%rsp), %rdi
movl 0xdc(%rsp), %esi
addl $0x4, %esi
movl $0x6, %edx
callq 0x38010
jmp 0x1c065
leaq 0x277(%rsp), %rdi
movq %rdi, 0xb0(%rsp)
callq 0x66c0
movq 0xb0(%rsp), %rdx
leaq 0x37dee(%rip), %rsi     # 0x53e77
leaq 0x278(%rsp), %rdi
callq 0x7500
jmp 0x1c098
movq 0xd0(%rsp), %r8
movq 0xc8(%rsp), %rcx
movq 0xc0(%rsp), %rdx
movq 0xb8(%rsp), %rdi
movl $0x1d, %esi
leaq 0x278(%rsp), %r9
callq 0x4de80
jmp 0x1c0cc
leaq 0x278(%rsp), %rdi
callq 0x6778
leaq 0x277(%rsp), %rdi
callq 0x6400
movq 0x188(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x98(%rsp)
movq 0x368(%rsp), %rdi
callq 0x4dfb0
movq 0x98(%rsp), %rdi
movl %eax, 0x270(%rsp)
leaq 0x270(%rsp), %rsi
callq 0x20950
movq 0x368(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0x24f(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0x66c0
movq 0xa8(%rsp), %rdx
leaq 0x37d6d(%rip), %rsi     # 0x53ec4
leaq 0x250(%rsp), %rdi
callq 0x7500
jmp 0x1c166
movq 0xa0(%rsp), %rdi
xorl %eax, %eax
movl %eax, %r8d
movl $0x16, %esi
leaq 0x250(%rsp), %r9
movq %r8, %rdx
movq %r8, %rcx
callq 0x4de80
jmp 0x1c18d
leaq 0x250(%rsp), %rdi
callq 0x6778
leaq 0x24f(%rsp), %rdi
callq 0x6400
movq 0x368(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x360(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x358(%rsp), %rax
movq %rax, 0x80(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, 0x88(%rsp)
movq 0x368(%rsp), %rdi
callq 0x4dfb0
movl %eax, 0x94(%rsp)
jmp 0x1c1f9
movq 0x88(%rsp), %rdi
movl 0x94(%rsp), %esi
addl $0x2, %esi
movl $0x6, %edx
callq 0x38010
jmp 0x1c217
leaq 0x227(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x66c0
movq 0x68(%rsp), %rdx
leaq 0x37cd3(%rip), %rsi     # 0x53f08
leaq 0x228(%rsp), %rdi
callq 0x7500
jmp 0x1c244
movq 0x88(%rsp), %r8
movq 0x80(%rsp), %rcx
movq 0x78(%rsp), %rdx
movq 0x70(%rsp), %rdi
movl $0x1b, %esi
leaq 0x228(%rsp), %r9
callq 0x4de80
jmp 0x1c272
leaq 0x228(%rsp), %rdi
callq 0x6778
leaq 0x227(%rsp), %rdi
callq 0x6400
movq 0x188(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x50(%rsp)
movq 0x368(%rsp), %rdi
callq 0x4dfb0
movq 0x50(%rsp), %rdi
movl %eax, 0x220(%rsp)
leaq 0x220(%rsp), %rsi
callq 0x20950
movq 0x368(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x1ff(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x66c0
movq 0x60(%rsp), %rdx
leaq 0x37bd6(%rip), %rsi     # 0x53ec4
leaq 0x200(%rsp), %rdi
callq 0x7500
jmp 0x1c2fd
movq 0x58(%rsp), %rdi
xorl %eax, %eax
movl %eax, %r8d
movl $0x16, %esi
leaq 0x200(%rsp), %r9
movq %r8, %rdx
movq %r8, %rcx
callq 0x4de80
jmp 0x1c321
leaq 0x200(%rsp), %rdi
callq 0x6778
leaq 0x1ff(%rsp), %rdi
callq 0x6400
movq 0x188(%rsp), %rax
movq 0xb8(%rax), %rdi
movq 0x368(%rsp), %rsi
movq (%rdi), %rax
movq 0x10(%rax), %rax
callq *%rax
movq 0x188(%rsp), %rax
movq 0x368(%rsp), %rdi
movq 0xb8(%rax), %rsi
addq $0x30, %rsi
movl 0x2c0(%rsp), %edx
callq 0x4dfc0
movq 0x188(%rsp), %rax
movq 0x368(%rsp), %rdi
movq 0xb8(%rax), %rsi
addq $0x18, %rsi
movl 0x2c0(%rsp), %edx
callq 0x4dfc0
movq 0x188(%rsp), %rdi
addq $0x18, %rdi
movq %rdi, 0x20(%rsp)
callq 0x208a0
movq %rax, 0x1e8(%rsp)
leaq 0x1f0(%rsp), %rdi
leaq 0x1e8(%rsp), %rsi
callq 0x208d0
movq 0x188(%rsp), %rax
movq 0x20(%rsp), %rdi
movq 0xb8(%rax), %rdx
addq $0x48, %rdx
movq 0x1f0(%rsp), %rsi
callq 0x20860
movq 0x368(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0x338(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %rax, 0x38(%rsp)
movq 0x350(%rsp), %rax
movq %rax, 0x40(%rsp)
leaq 0x1c7(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x66c0
movq 0x48(%rsp), %rdx
leaq 0x37b09(%rip), %rsi     # 0x53f54
leaq 0x1c8(%rsp), %rdi
callq 0x7500
jmp 0x1c45a
movq 0x40(%rsp), %r8
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rdx
movq 0x28(%rsp), %rdi
movl $0x11, %esi
leaq 0x1c8(%rsp), %r9
callq 0x4de80
jmp 0x1c482
leaq 0x1c8(%rsp), %rdi
callq 0x6778
leaq 0x1c7(%rsp), %rdi
callq 0x6400
movq 0x368(%rsp), %rax
movq %rax, 0x10(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x18(%rsp)
movl 0x2c0(%rsp), %esi
movl $0x6, %edx
callq 0x38010
jmp 0x1c4d1
leaq 0x19f(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x66c0
movq 0x8(%rsp), %rdx
leaq 0x37aa5(%rip), %rsi     # 0x53f94
leaq 0x1a0(%rsp), %rdi
callq 0x7500
jmp 0x1c4fe
movq 0x18(%rsp), %r8
movq 0x10(%rsp), %rdi
xorl %eax, %eax
movl %eax, %ecx
movl $0x16, %esi
leaq 0x1a0(%rsp), %r9
movq %rcx, %rdx
callq 0x4de80
jmp 0x1c523
leaq 0x1a0(%rsp), %rdi
callq 0x6778
leaq 0x19f(%rsp), %rdi
callq 0x6400
addq $0x378, %rsp            # imm = 0x378
retq
movq 0x190(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x1c9bf
movq 0x180(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x1c9bf
movq 0x178(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x1c9bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x1c5fd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x318(%rsp), %rdi
callq 0x6778
leaq 0x317(%rsp), %rdi
callq 0x6400
jmp 0x1c9bf
movq 0x150(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x1c9bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x1c671
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x2f0(%rsp), %rdi
callq 0x6778
leaq 0x2ef(%rsp), %rdi
callq 0x6400
jmp 0x1c9bf
movq 0x128(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x1c9bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x1c6e5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x2c8(%rsp), %rdi
callq 0x6778
leaq 0x2c7(%rsp), %rdi
callq 0x6400
jmp 0x1c9bf
movq 0x108(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x1c9bf
movq 0xe8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x1c9bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x1c784
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x2a0(%rsp), %rdi
callq 0x6778
leaq 0x29f(%rsp), %rdi
callq 0x6400
jmp 0x1c9bf
movq 0xd0(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x1c9bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x1c7f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x278(%rsp), %rdi
callq 0x6778
leaq 0x277(%rsp), %rdi
callq 0x6400
jmp 0x1c9bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x1c841
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x250(%rsp), %rdi
callq 0x6778
leaq 0x24f(%rsp), %rdi
callq 0x6400
jmp 0x1c9bf
movq 0x88(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x1c9bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x1c8b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x228(%rsp), %rdi
callq 0x6778
leaq 0x227(%rsp), %rdi
callq 0x6400
jmp 0x1c9bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x1c8fe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x200(%rsp), %rdi
callq 0x6778
leaq 0x1ff(%rsp), %rdi
callq 0x6400
jmp 0x1c9bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x1c947
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x1c8(%rsp), %rdi
callq 0x6778
leaq 0x1c7(%rsp), %rdi
callq 0x6400
jmp 0x1c9bf
movq 0x18(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x1c9bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
jmp 0x1c9b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x348(%rsp)
movl %eax, 0x344(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0x6778
leaq 0x19f(%rsp), %rdi
callq 0x6400
movq 0x348(%rsp), %rdi
callq 0x66b0
nopl (%rax)