// File: /workspace/github_cpp_makefile_star2_O3/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 0x16888
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 0x62f0
movq %rax, %r14
movq %rax, %rdi
callq 0x1d014
movl $0x18, %edi
callq 0x62f0
movq %rax, %r12
movq 0x98(%r15), %rsi
movq %rax, %rdi
callq 0x1d00c
movq %r12, 0x30(%rsp)
movl $0x18, %edi
callq 0x62f0
movq %rax, %r12
movq %rax, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x2, %edx
callq 0x1d02a
leaq 0x168(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x1b62c(%rip), %rsi     # 0x2edcf
leaq 0x1b64e(%rip), %rdx     # 0x2edf8
leaq 0x158(%rsp), %r13
movq %r13, %rdi
callq 0x7008
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %r12, %rcx
xorl %r8d, %r8d
movq %r13, %r9
callq 0x2b238
movq 0x158(%rsp), %rdi
cmpq %rbp, %rdi
je 0x137ed
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x6300
movl $0x18, %edi
callq 0x62f0
movq %rax, %r12
movq %rbx, %rdi
callq 0x2b316
addl $0x2, %eax
movq %r12, %rdi
movl %eax, %esi
movl $0x6, %edx
callq 0x1d02a
leaq 0x148(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x1b5d2(%rip), %rsi     # 0x2edf9
leaq 0x1b5fe(%rip), %rdx     # 0x2ee2c
leaq 0x138(%rsp), %r13
movq %r13, %rdi
callq 0x7008
movq %rbx, %rdi
movl $0x1d, %esi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %r12, %r8
movq %r13, %r9
callq 0x2b238
movq 0x138(%rsp), %rdi
cmpq %rbp, %rdi
je 0x13878
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x6300
movl $0x18, %edi
callq 0x62f0
movq %rax, %r12
movq %rax, %rdi
movl $0x1, %esi
movl $0x2, %edx
callq 0x1d02a
leaq 0x128(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x1b583(%rip), %rsi     # 0x2ee2d
leaq 0x1b5b9(%rip), %rdx     # 0x2ee6a
leaq 0x118(%rsp), %r13
movq %r13, %rdi
callq 0x7008
movq %rbx, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq %r12, %rcx
xorl %r8d, %r8d
movq %r13, %r9
callq 0x2b238
movq 0x118(%rsp), %rdi
cmpq %rbp, %rdi
je 0x138f4
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x6300
movq %rbx, %rdi
callq 0x2b316
movl %eax, 0x24(%rsp)
movl $0x18, %edi
callq 0x62f0
movq %rax, %rbp
movq %rax, %rdi
movl $0x1, %esi
movl $0x2, %edx
callq 0x1d02a
movq %r14, 0x28(%rsp)
movl $0x18, %edi
callq 0x62f0
movq %rax, %r13
movq %rbx, %rdi
callq 0x2b316
addl $0x3, %eax
movq %r13, %rdi
movl %eax, %esi
movl $0x6, %edx
callq 0x1d02a
leaq 0x108(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1b50d(%rip), %rsi     # 0x2ee6b
leaq 0x1b525(%rip), %rdx     # 0x2ee8a
leaq 0xf8(%rsp), %r12
movq %r12, %rdi
callq 0x7008
movq %rbx, %rdi
movl $0x18, %esi
movq 0x28(%rsp), %rdx
movq %rbp, %rcx
movq %r13, %r8
movq %r12, %r9
callq 0x2b238
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0x139ad
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x6300
movl $0x18, %edi
callq 0x62f0
movq %rax, %r13
movq %rbx, %rdi
callq 0x2b316
addl $0x4, %eax
movq %r13, %rdi
movl %eax, %esi
movl $0x6, %edx
callq 0x1d02a
leaq 0xe8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1b4a4(%rip), %rsi     # 0x2ee8b
leaq 0x1b4e9(%rip), %rdx     # 0x2eed7
leaq 0xd8(%rsp), %r12
movq %r12, %rdi
callq 0x7008
movq %rbx, %rdi
movl $0x1d, %esi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %r13, %r8
movq %r12, %r9
callq 0x2b238
movq 0xd8(%rsp), %rdi
cmpq %r14, %rdi
je 0x13a38
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x6300
movq %rbx, %rdi
callq 0x2b316
movl %eax, %ebp
movl $0x18, %edi
callq 0x62f0
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 0x1b465(%rip), %rsi     # 0x2eed8
leaq 0x1b4a1(%rip), %rdx     # 0x2ef1b
leaq 0xb8(%rsp), %r12
movq %r12, %rdi
callq 0x7008
movq %rbx, %rdi
movl $0x16, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r12, %r9
callq 0x2b238
movq 0xb8(%rsp), %rdi
cmpq %r13, %rdi
je 0x13abe
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x6300
movl $0x18, %edi
callq 0x62f0
movq %rax, %r13
movq %rbx, %rdi
callq 0x2b316
addl $0x2, %eax
movq %r13, %rdi
movl %eax, %esi
movl $0x6, %edx
callq 0x1d02a
leaq 0xa8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1b424(%rip), %rsi     # 0x2ef1c
leaq 0x1b468(%rip), %rdx     # 0x2ef67
leaq 0x98(%rsp), %r12
movq %r12, %rdi
callq 0x7008
movq %rbx, %rdi
movl $0x1b, %esi
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %r13, %r8
movq %r12, %r9
callq 0x2b238
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0x13b49
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x6300
movq %rbx, %rdi
callq 0x2b316
movl %eax, %ebp
movl $0x18, %edi
callq 0x62f0
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 0x1b354(%rip), %rsi     # 0x2eed8
leaq 0x1b390(%rip), %rdx     # 0x2ef1b
leaq 0x78(%rsp), %r12
movq %r12, %rdi
callq 0x7008
movq %rbx, %rdi
movl $0x16, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r12, %r9
callq 0x2b238
movq 0x78(%rsp), %rdi
cmpq %r13, %rdi
movl 0x24(%rsp), %ebp
je 0x13bcd
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x6300
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 0x2b320
movq 0xb8(%r15), %rsi
addq $0x18, %rsi
movq %rbx, %rdi
movl %ebp, %edx
callq 0x2b320
movq 0xb8(%r15), %r14
leaq 0x48(%r14), %rdx
movq 0x48(%r14), %rsi
cmpq %rdx, %rsi
movq 0x30(%rsp), %r12
je 0x13c3a
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 0x1b31e(%rip), %rsi     # 0x2ef68
leaq 0x1b356(%rip), %rdx     # 0x2efa7
leaq 0x58(%rsp), %r15
movq %r15, %rdi
callq 0x7008
movq %rbx, %rdi
movl $0x11, %esi
movq %r12, %rdx
movq %r12, %rcx
movq 0x28(%rsp), %r8
movq %r15, %r9
callq 0x2b238
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x13c90
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x6300
movl $0x18, %edi
callq 0x62f0
movq %rax, %r14
movq %rax, %rdi
movl %ebp, %esi
movl $0x6, %edx
callq 0x1d02a
leaq 0x48(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x1b2eb(%rip), %rsi     # 0x2efa8
leaq 0x1b304(%rip), %rdx     # 0x2efc8
leaq 0x38(%rsp), %r15
movq %r15, %rdi
callq 0x7008
movq %rbx, %rdi
movl $0x16, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r14, %r8
movq %r15, %r9
callq 0x2b238
movq 0x38(%rsp), %rdi
cmpq %r12, %rdi
je 0x13cff
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x6300
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 0x13e7d
movq 0x48(%rsp), %rsi
jmp 0x13e46
jmp 0x13e4f
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0x13e7d
movq 0x68(%rsp), %rsi
jmp 0x13e46
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r13, %rdi
je 0x13e7d
movq 0x88(%rsp), %rsi
jmp 0x13e46
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0x13e7d
movq 0xa8(%rsp), %rsi
jmp 0x13e46
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r13, %rdi
je 0x13e7d
movq 0xc8(%rsp), %rsi
jmp 0x13e46
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %r14, %rdi
je 0x13e7d
movq 0xe8(%rsp), %rsi
jmp 0x13e46
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0x13e7d
movq 0x108(%rsp), %rsi
jmp 0x13e46
movq %rax, %rbx
movl $0x18, %esi
movq %rbp, %rdi
jmp 0x13e78
movq %rax, %rbx
movq 0x118(%rsp), %rdi
cmpq %rbp, %rdi
je 0x13e7d
movq 0x128(%rsp), %rsi
jmp 0x13e46
jmp 0x13e6d
movq %rax, %rbx
movq 0x138(%rsp), %rdi
cmpq %rbp, %rdi
je 0x13e7d
movq 0x148(%rsp), %rsi
jmp 0x13e46
movq %rax, %rbx
movq 0x158(%rsp), %rdi
cmpq %rbp, %rdi
je 0x13e7d
movq 0x168(%rsp), %rsi
incq %rsi
jmp 0x13e78
jmp 0x13e6d
jmp 0x13e6d
movq %rax, %rbx
movl $0x18, %esi
movq %r14, %rdi
jmp 0x13e78
jmp 0x13e60
jmp 0x13e60
movq %rax, %rbx
movl $0x18, %esi
movq %r13, %rdi
jmp 0x13e78
movq %rax, %rbx
movl $0x18, %esi
movq %r12, %rdi
callq 0x6300
movq %rbx, %rdi
callq 0x6560
nop