// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rsi, %rbx
movq %rdi, %r12
leaq 0x18(%rdi), %r15
movq %r15, %rdi
callq 0x124ce
movq 0xa8(%r12), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
callq *0x18(%rax)
movq %rax, 0x18(%rsp)
movq 0xb0(%r12), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
callq *0x18(%rax)
movq %rax, 0x10(%rsp)
pushq $0x18
popq %rdi
callq 0x62d0
movq %rax, %r14
movq %rax, %rdi
callq 0x18148
pushq $0x18
popq %rdi
callq 0x62d0
movq 0x98(%r12), %rsi
movq %rax, 0x20(%rsp)
movq %rax, %rdi
callq 0x18140
pushq $0x18
popq %rdi
callq 0x62d0
movq %rax, %r13
pushq $-0x1
popq %rsi
pushq $0x2
popq %rdx
movq %rax, %rdi
callq 0x1815e
leaq 0x14cea(%rip), %rsi     # 0x24dcf
leaq 0x148(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x6d6c
leaq 0x148(%rsp), %r9
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0x212de
leaq 0x148(%rsp), %rdi
callq 0x65c8
pushq $0x18
popq %rdi
callq 0x62d0
movq %rax, %r13
movq %rbx, %rdi
callq 0x2138a
addl $0x2, %eax
pushq $0x6
popq %rdx
movq %r13, %rdi
movl %eax, %esi
callq 0x1815e
leaq 0x14cb0(%rip), %rsi     # 0x24df9
leaq 0x128(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x6d6c
pushq $0x1d
popq %rsi
leaq 0x128(%rsp), %r9
movq %rbx, %rdi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %r13, %r8
callq 0x212de
leaq 0x128(%rsp), %rdi
callq 0x65c8
pushq $0x18
popq %rdi
callq 0x62d0
movq %rax, %r13
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
movq %rax, %rdi
callq 0x1815e
leaq 0x14c85(%rip), %rsi     # 0x24e2d
leaq 0x108(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x6d6c
leaq 0x108(%rsp), %r9
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0x212de
leaq 0x108(%rsp), %rdi
callq 0x65c8
movq %rbx, %rdi
callq 0x2138a
movl %eax, 0xc(%rsp)
pushq $0x18
popq %rdi
callq 0x62d0
movq %rax, %r13
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
movq %rax, %rdi
callq 0x1815e
pushq $0x18
popq %rdi
callq 0x62d0
movq %rax, %rbp
movq %rbx, %rdi
callq 0x2138a
addl $0x3, %eax
pushq $0x6
popq %rdx
movq %rbp, %rdi
movl %eax, %esi
callq 0x1815e
leaq 0x14c3a(%rip), %rsi     # 0x24e6b
leaq 0xe8(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x6d6c
pushq $0x18
popq %rsi
leaq 0xe8(%rsp), %r9
movq %rbx, %rdi
movq %r14, %rdx
movq %r13, %rcx
movq %rbp, %r8
callq 0x212de
leaq 0xe8(%rsp), %rdi
callq 0x65c8
pushq $0x18
popq %rdi
callq 0x62d0
movq %rax, %r13
movq %rbx, %rdi
callq 0x2138a
addl $0x4, %eax
pushq $0x6
popq %rdx
movq %r13, %rdi
movl %eax, %esi
callq 0x1815e
leaq 0x14bf5(%rip), %rsi     # 0x24e8b
leaq 0xc8(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x6d6c
pushq $0x1d
popq %rsi
leaq 0xc8(%rsp), %r9
movq %rbx, %rdi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %r13, %r8
callq 0x212de
leaq 0xc8(%rsp), %rdi
callq 0x65c8
movq %rbx, %rdi
callq 0x2138a
leaq 0x8(%rsp), %rsi
movl %eax, (%rsi)
movq %r15, %rdi
callq 0x1243c
leaq 0x14be5(%rip), %rsi     # 0x24ed8
leaq 0xa8(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x6d6c
pushq $0x16
popq %rsi
leaq 0xa8(%rsp), %r9
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x212de
leaq 0xa8(%rsp), %rdi
callq 0x65c8
pushq $0x18
popq %rdi
callq 0x62d0
movq %rax, %r13
movq %rbx, %rdi
callq 0x2138a
addl $0x2, %eax
pushq $0x6
popq %rdx
movq %r13, %rdi
movl %eax, %esi
callq 0x1815e
leaq 0x14bc6(%rip), %rsi     # 0x24f1c
leaq 0x88(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x6d6c
pushq $0x1b
popq %rsi
leaq 0x88(%rsp), %r9
movq %rbx, %rdi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %r13, %r8
callq 0x212de
leaq 0x88(%rsp), %rdi
callq 0x65c8
movq %rbx, %rdi
callq 0x2138a
leaq 0x8(%rsp), %rsi
movl %eax, (%rsi)
movq %r15, %rdi
callq 0x1243c
leaq 0x14b25(%rip), %rsi     # 0x24ed8
leaq 0x68(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x6d6c
pushq $0x16
popq %rsi
leaq 0x68(%rsp), %r9
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x212de
leaq 0x68(%rsp), %rdi
callq 0x65c8
movq 0xb8(%r12), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
callq *0x10(%rax)
movq 0xb8(%r12), %rsi
addq $0x30, %rsi
movq %rbx, %rdi
movl 0xc(%rsp), %ebp
movl %ebp, %edx
callq 0x21394
movq 0xb8(%r12), %rsi
addq $0x18, %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x21394
movq 0xb8(%r12), %rdx
addq $0x48, %rdx
movq %r15, %rdi
movq %r15, %rsi
callq 0x128e0
leaq 0x14b26(%rip), %rsi     # 0x24f68
leaq 0x48(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x6d6c
pushq $0x11
popq %rsi
leaq 0x48(%rsp), %r9
movq %rbx, %rdi
movq 0x20(%rsp), %rcx
movq %rcx, %rdx
movq %r14, %r8
callq 0x212de
leaq 0x48(%rsp), %rdi
callq 0x65c8
pushq $0x18
popq %rdi
callq 0x62d0
movq %rax, %r14
pushq $0x6
popq %rdx
movq %rax, %rdi
movl 0xc(%rsp), %esi
callq 0x1815e
leaq 0x14b11(%rip), %rsi     # 0x24fa8
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x6d6c
pushq $0x16
popq %rsi
leaq 0x28(%rsp), %r9
movq %rbx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r14, %r8
callq 0x212de
leaq 0x28(%rsp), %rdi
callq 0x65c8
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x10571
jmp 0x10578
jmp 0x1058c
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x10571
jmp 0x10578
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x10571
jmp 0x10578
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x10571
jmp 0x10578
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0x10571
jmp 0x10578
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
jmp 0x10571
jmp 0x10578
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
jmp 0x10571
jmp 0x10578
jmp 0x105a6
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
jmp 0x10571
jmp 0x10578
jmp 0x105a6
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
jmp 0x10571
jmp 0x10578
movq %rax, %rbx
leaq 0x148(%rsp), %rdi
callq 0x65c8
jmp 0x105b4
movq %rax, %rbx
jmp 0x105b4
jmp 0x105a6
movq %rax, %rbx
pushq $0x18
popq %rsi
movq 0x20(%rsp), %rdi
jmp 0x105af
movq %rax, %rbx
pushq $0x18
popq %rsi
movq %r14, %rdi
jmp 0x105af
jmp 0x105a6
jmp 0x105a6
movq %rax, %rbx
pushq $0x18
popq %rsi
movq %rbp, %rdi
jmp 0x105af
movq %rax, %rbx
pushq $0x18
popq %rsi
movq %r13, %rdi
callq 0x62e0
movq %rbx, %rdi
callq 0x6530