// File: /workspace/github_cpp_makefile_star2_O1/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 $0x178, %rsp            # imm = 0x178
movq %rsi, %rbx
movq %rdi, %r15
addq $0x18, %rdi
movq %rdi, 0x8(%rsp)
callq 0x1686a
movq 0xa8(%r15), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
callq *0x18(%rax)
movq %rax, 0x18(%rsp)
movq 0xb0(%r15), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
callq *0x18(%rax)
movq %rax, 0x10(%rsp)
movl $0x18, %edi
callq 0x62e0
movq %rax, %r14
movq %rax, %rdi
callq 0x1cfb4
movl $0x18, %edi
callq 0x62e0
movq %rax, %r12
movq 0x98(%r15), %rsi
movq %rax, %rdi
callq 0x1cfac
movq %r12, 0x30(%rsp)
movl $0x18, %edi
callq 0x62e0
movq %rax, %r12
movq %rax, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x2, %edx
callq 0x1cfca
leaq 0x168(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x1a67c(%rip), %rsi     # 0x2ddcf
leaq 0x1a69e(%rip), %rdx     # 0x2ddf8
leaq 0x158(%rsp), %r13
movq %r13, %rdi
callq 0x6fec
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %r12, %rcx
xorl %r8d, %r8d
movq %r13, %r9
callq 0x2ae24
movq 0x158(%rsp), %rdi
cmpq %rbp, %rdi
je 0x1379d
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x62f0
movl $0x18, %edi
callq 0x62e0
movq %rax, %r12
movq %rbx, %rdi
callq 0x2af04
addl $0x2, %eax
movq %r12, %rdi
movl %eax, %esi
movl $0x6, %edx
callq 0x1cfca
leaq 0x148(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x1a622(%rip), %rsi     # 0x2ddf9
leaq 0x1a64e(%rip), %rdx     # 0x2de2c
leaq 0x138(%rsp), %r13
movq %r13, %rdi
callq 0x6fec
movq %rbx, %rdi
movl $0x1d, %esi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %r12, %r8
movq %r13, %r9
callq 0x2ae24
movq 0x138(%rsp), %rdi
cmpq %rbp, %rdi
je 0x13828
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x62f0
movl $0x18, %edi
callq 0x62e0
movq %rax, %r12
movq %rax, %rdi
movl $0x1, %esi
movl $0x2, %edx
callq 0x1cfca
leaq 0x128(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x1a5d3(%rip), %rsi     # 0x2de2d
leaq 0x1a609(%rip), %rdx     # 0x2de6a
leaq 0x118(%rsp), %r13
movq %r13, %rdi
callq 0x6fec
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %r12, %rcx
xorl %r8d, %r8d
movq %r13, %r9
callq 0x2ae24
movq 0x118(%rsp), %rdi
cmpq %rbp, %rdi
je 0x138a4
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x62f0
movq %rbx, %rdi
callq 0x2af04
movl %eax, 0x24(%rsp)
movl $0x18, %edi
callq 0x62e0
movq %rax, %rbp
movq %rax, %rdi
movl $0x1, %esi
movl $0x2, %edx
callq 0x1cfca
movq %r14, 0x28(%rsp)
movl $0x18, %edi
callq 0x62e0
movq %rax, %r13
movq %rbx, %rdi
callq 0x2af04
addl $0x3, %eax
movq %r13, %rdi
movl %eax, %esi
movl $0x6, %edx
callq 0x1cfca
leaq 0x108(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1a55d(%rip), %rsi     # 0x2de6b
leaq 0x1a575(%rip), %rdx     # 0x2de8a
leaq 0xf8(%rsp), %r12
movq %r12, %rdi
callq 0x6fec
movq %rbx, %rdi
movl $0x18, %esi
movq 0x28(%rsp), %rdx
movq %rbp, %rcx
movq %r13, %r8
movq %r12, %r9
callq 0x2ae24
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0x1395d
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x62f0
movl $0x18, %edi
callq 0x62e0
movq %rax, %r13
movq %rbx, %rdi
callq 0x2af04
addl $0x4, %eax
movq %r13, %rdi
movl %eax, %esi
movl $0x6, %edx
callq 0x1cfca
leaq 0xe8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1a4f4(%rip), %rsi     # 0x2de8b
leaq 0x1a539(%rip), %rdx     # 0x2ded7
leaq 0xd8(%rsp), %r12
movq %r12, %rdi
callq 0x6fec
movq %rbx, %rdi
movl $0x1d, %esi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %r13, %r8
movq %r12, %r9
callq 0x2ae24
movq 0xd8(%rsp), %rdi
cmpq %r14, %rdi
je 0x139e8
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x62f0
movq %rbx, %rdi
callq 0x2af04
movl %eax, %ebp
movl $0x18, %edi
callq 0x62e0
movl %ebp, 0x10(%rax)
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x6080
incq 0x28(%r15)
leaq 0xc8(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x1a4b5(%rip), %rsi     # 0x2ded8
leaq 0x1a4f1(%rip), %rdx     # 0x2df1b
leaq 0xb8(%rsp), %r12
movq %r12, %rdi
callq 0x6fec
movq %rbx, %rdi
movl $0x16, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r12, %r9
callq 0x2ae24
movq 0xb8(%rsp), %rdi
cmpq %r13, %rdi
je 0x13a6e
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x62f0
movl $0x18, %edi
callq 0x62e0
movq %rax, %r13
movq %rbx, %rdi
callq 0x2af04
addl $0x2, %eax
movq %r13, %rdi
movl %eax, %esi
movl $0x6, %edx
callq 0x1cfca
leaq 0xa8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1a474(%rip), %rsi     # 0x2df1c
leaq 0x1a4b8(%rip), %rdx     # 0x2df67
leaq 0x98(%rsp), %r12
movq %r12, %rdi
callq 0x6fec
movq %rbx, %rdi
movl $0x1b, %esi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %r13, %r8
movq %r12, %r9
callq 0x2ae24
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0x13af9
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x62f0
movq %rbx, %rdi
callq 0x2af04
movl %eax, %ebp
movl $0x18, %edi
callq 0x62e0
movl %ebp, 0x10(%rax)
movq %rax, %rdi
movq 0x8(%rsp), %rsi
callq 0x6080
incq 0x28(%r15)
leaq 0x88(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x1a3a4(%rip), %rsi     # 0x2ded8
leaq 0x1a3e0(%rip), %rdx     # 0x2df1b
leaq 0x78(%rsp), %r12
movq %r12, %rdi
callq 0x6fec
movq %rbx, %rdi
movl $0x16, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r12, %r9
callq 0x2ae24
movq 0x78(%rsp), %rdi
cmpq %r13, %rdi
movl 0x24(%rsp), %ebp
je 0x13b7d
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x62f0
movq 0xb8(%r15), %rdi
movq (%rdi), %rax
movq %rbx, %rsi
callq *0x10(%rax)
movq 0xb8(%r15), %rsi
addq $0x30, %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x2af0e
movq 0xb8(%r15), %rsi
addq $0x18, %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x2af0e
movq 0xb8(%r15), %r14
leaq 0x48(%r14), %rdx
movq 0x48(%r14), %rsi
cmpq %rdx, %rsi
movq 0x30(%rsp), %r12
je 0x13bea
movq 0x8(%rsp), %rdi
callq 0x6160
movq 0x58(%r14), %rax
addq %rax, 0x28(%r15)
movq $0x0, 0x58(%r14)
leaq 0x68(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1a36e(%rip), %rsi     # 0x2df68
leaq 0x1a3a6(%rip), %rdx     # 0x2dfa7
leaq 0x58(%rsp), %r15
movq %r15, %rdi
callq 0x6fec
movq %rbx, %rdi
movl $0x11, %esi
movq %r12, %rdx
movq %r12, %rcx
movq 0x28(%rsp), %r8
movq %r15, %r9
callq 0x2ae24
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x13c40
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x62f0
movl $0x18, %edi
callq 0x62e0
movq %rax, %r14
movq %rax, %rdi
movl %ebp, %esi
movl $0x6, %edx
callq 0x1cfca
leaq 0x48(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x1a33b(%rip), %rsi     # 0x2dfa8
leaq 0x1a354(%rip), %rdx     # 0x2dfc8
leaq 0x38(%rsp), %r15
movq %r15, %rdi
callq 0x6fec
movq %rbx, %rdi
movl $0x16, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r14, %r8
movq %r15, %r9
callq 0x2ae24
movq 0x38(%rsp), %rdi
cmpq %r12, %rdi
je 0x13caf
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x62f0
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r12, %rdi
je 0x13e2d
movq 0x48(%rsp), %rsi
jmp 0x13df6
jmp 0x13dff
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x13e2d
movq 0x68(%rsp), %rsi
jmp 0x13df6
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r13, %rdi
je 0x13e2d
movq 0x88(%rsp), %rsi
jmp 0x13df6
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0x13e2d
movq 0xa8(%rsp), %rsi
jmp 0x13df6
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r13, %rdi
je 0x13e2d
movq 0xc8(%rsp), %rsi
jmp 0x13df6
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %r14, %rdi
je 0x13e2d
movq 0xe8(%rsp), %rsi
jmp 0x13df6
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0x13e2d
movq 0x108(%rsp), %rsi
jmp 0x13df6
movq %rax, %rbx
movl $0x18, %esi
movq %rbp, %rdi
jmp 0x13e28
movq %rax, %rbx
movq 0x118(%rsp), %rdi
cmpq %rbp, %rdi
je 0x13e2d
movq 0x128(%rsp), %rsi
jmp 0x13df6
jmp 0x13e1d
movq %rax, %rbx
movq 0x138(%rsp), %rdi
cmpq %rbp, %rdi
je 0x13e2d
movq 0x148(%rsp), %rsi
jmp 0x13df6
movq %rax, %rbx
movq 0x158(%rsp), %rdi
cmpq %rbp, %rdi
je 0x13e2d
movq 0x168(%rsp), %rsi
incq %rsi
jmp 0x13e28
jmp 0x13e1d
jmp 0x13e1d
movq %rax, %rbx
movl $0x18, %esi
movq %r14, %rdi
jmp 0x13e28
jmp 0x13e10
jmp 0x13e10
movq %rax, %rbx
movl $0x18, %esi
movq %r13, %rdi
jmp 0x13e28
movq %rax, %rbx
movl $0x18, %esi
movq %r12, %rdi
callq 0x62f0
movq %rbx, %rdi
callq 0x6550
nop