// File: kelwinfc[P]ci4721-Fernandez-Gyomrey/src/AST/to_tac.cpp
// Function: AST_struct_access::gen_tac_lval(Tac*, int*)
opd *AST_struct_access::gen_tac_lval(Tac* t, int *sta_base){
    opd *din_base = value->gen_tac_lval(t, sta_base);
    if (union_access) {
        union_type *ud = (union_type*)types.types[ sym->getType() ];
        din_base = gen_tac_lval_disp(t, din_base, sta_base);
        opd *t1 = new opd(), *t2 = new opd((int)sym->index);
        t->append_quad(inst::CP, t1, din_base, new opd(ud->width - 4), "cargando identificador de tipo usado en el union");
        // TODO esto apunta a una instrucción que no existe.
        // se asume que justo después de calcular la posición del campo del struct está la siguiente instrucción que se debe ejecutar.
        t->append_quad(inst::IFEQ, new opd(0), t2, new opd(t->next_instruction() + 7, O_LABEL),
            "permitir la asignación por primera vez a una unión");
        t->append_quad(inst::IFEQ, t1, t2, new opd(t->next_instruction() + 7, O_LABEL),
            "validar que en caso estar actualizado el tipo usado, se mantiene");
        t->append_quad(inst::WRITE, new opd(0), 0, 0, "dirección relativa del string en la tabla \"Se trató de utilizar una propiedad no activa de la unión en (\"");
        t->append_quad(inst::WRITE, new opd(value->line), 0, 0, "número de línea del error");
        t->append_quad(inst::WRITE, new opd(62), 0, 0, "dirección relativa del string en la tabla \", \"");
        t->append_quad(inst::WRITE, new opd(value->column), 0, 0, "número de columna del error");
        t->append_quad(inst::WRITE, new opd(65), 0, 0, "dirección relativa del string en la tabla \")\"");
        t->append_quad(inst::CP, t2, din_base, new opd(ud->width - 4),
            "guardando nuevo identificador de tipo usado en el union");
    }
    *sta_base += sym->offset;
    return din_base;
}

// Assembly:
subq $0x2f8, %rsp            # imm = 0x2F8
movq %rdi, 0x2f0(%rsp)
movq %rsi, 0x2e8(%rsp)
movq %rdx, 0x2e0(%rsp)
movq 0x2f0(%rsp), %rax
movq %rax, 0x140(%rsp)
movq 0x48(%rax), %rdi
movq 0x2e8(%rsp), %rsi
movq 0x2e0(%rsp), %rdx
movq (%rdi), %rax
callq *0x38(%rax)
movq %rax, %rcx
movq 0x140(%rsp), %rax
movq %rcx, 0x2d8(%rsp)
testb $0x1, 0x78(%rax)
je 0x17e75
movq 0x140(%rsp), %rax
movq 0x70(%rax), %rdi
callq 0x295f0
movslq %eax, %rsi
leaq 0x5728f(%rip), %rdi     # 0x6e4e0
callq 0x1fc90
movq (%rax), %rax
movq %rax, 0x2d0(%rsp)
movq 0x2e8(%rsp), %rdi
movq 0x2d8(%rsp), %rsi
movq 0x2e0(%rsp), %rdx
callq 0x16440
movq %rax, 0x2d8(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x138(%rsp)
callq 0x37ff0
jmp 0x172a5
movq 0x138(%rsp), %rax
movq %rax, 0x2c8(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, %rdi
movq 0x140(%rsp), %rax
movq %rdi, %rcx
movq %rcx, 0x130(%rsp)
movq 0x70(%rax), %rax
movl 0x40(%rax), %esi
movl $0x2, %edx
callq 0x38010
jmp 0x172e8
movq 0x130(%rsp), %rax
movq %rax, 0x2b0(%rsp)
movq 0x2e8(%rsp), %rax
movq %rax, 0x110(%rsp)
movq 0x2c8(%rsp), %rax
movq %rax, 0x118(%rsp)
movq 0x2d8(%rsp), %rax
movq %rax, 0x120(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x128(%rsp)
movq 0x2d0(%rsp), %rax
movl 0x28(%rax), %esi
addl $-0x4, %esi
movl $0x2, %edx
callq 0x38010
jmp 0x1735a
leaq 0x28f(%rsp), %rdi
movq %rdi, 0x108(%rsp)
callq 0x66c0
movq 0x108(%rsp), %rdx
leaq 0x3c3bd(%rip), %rsi     # 0x5373b
leaq 0x290(%rsp), %rdi
callq 0x7500
jmp 0x1738d
movq 0x128(%rsp), %r8
movq 0x120(%rsp), %rcx
movq 0x118(%rsp), %rdx
movq 0x110(%rsp), %rdi
xorl %esi, %esi
leaq 0x290(%rsp), %r9
callq 0x4de80
jmp 0x173be
leaq 0x290(%rsp), %rdi
callq 0x6778
leaq 0x28f(%rsp), %rdi
callq 0x6400
movq 0x2e8(%rsp), %rax
movq %rax, 0xf8(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x100(%rsp)
xorl %esi, %esi
movl $0x2, %edx
callq 0x38010
jmp 0x1740e
movq 0x2b0(%rsp), %rax
movq %rax, 0xe0(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, 0xe8(%rsp)
movq 0x2e8(%rsp), %rdi
callq 0x4dfb0
movl %eax, 0xf4(%rsp)
jmp 0x17446
movq 0xe8(%rsp), %rdi
movl 0xf4(%rsp), %esi
addl $0x7, %esi
movl $0x6, %edx
callq 0x38010
jmp 0x17464
leaq 0x267(%rsp), %rdi
movq %rdi, 0xd8(%rsp)
callq 0x66c0
movq 0xd8(%rsp), %rdx
leaq 0x3c2e4(%rip), %rsi     # 0x5376c
leaq 0x268(%rsp), %rdi
callq 0x7500
jmp 0x17497
movq 0xe8(%rsp), %r8
movq 0xe0(%rsp), %rcx
movq 0x100(%rsp), %rdx
movq 0xf8(%rsp), %rdi
movl $0x18, %esi
leaq 0x268(%rsp), %r9
callq 0x4de80
jmp 0x174cb
leaq 0x268(%rsp), %rdi
callq 0x6778
leaq 0x267(%rsp), %rdi
callq 0x6400
movq 0x2e8(%rsp), %rax
movq %rax, 0xb0(%rsp)
movq 0x2c8(%rsp), %rax
movq %rax, 0xb8(%rsp)
movq 0x2b0(%rsp), %rax
movq %rax, 0xc0(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, 0xc8(%rsp)
movq 0x2e8(%rsp), %rdi
callq 0x4dfb0
movl %eax, 0xd4(%rsp)
jmp 0x1753d
movq 0xc8(%rsp), %rdi
movl 0xd4(%rsp), %esi
addl $0x7, %esi
movl $0x6, %edx
callq 0x38010
jmp 0x1755b
leaq 0x23f(%rsp), %rdi
movq %rdi, 0xa8(%rsp)
callq 0x66c0
movq 0xa8(%rsp), %rdx
leaq 0x3c222(%rip), %rsi     # 0x537a1
leaq 0x240(%rsp), %rdi
callq 0x7500
jmp 0x1758e
movq 0xc8(%rsp), %r8
movq 0xc0(%rsp), %rcx
movq 0xb8(%rsp), %rdx
movq 0xb0(%rsp), %rdi
movl $0x18, %esi
leaq 0x240(%rsp), %r9
callq 0x4de80
jmp 0x175c2
leaq 0x240(%rsp), %rdi
callq 0x6778
leaq 0x23f(%rsp), %rdi
callq 0x6400
movq 0x2e8(%rsp), %rax
movq %rax, 0x98(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0xa0(%rsp)
xorl %esi, %esi
movl $0x2, %edx
callq 0x38010
jmp 0x17612
leaq 0x217(%rsp), %rdi
movq %rdi, 0x90(%rsp)
callq 0x66c0
movq 0x90(%rsp), %rdx
leaq 0x3c1ac(%rip), %rsi     # 0x537e2
leaq 0x218(%rsp), %rdi
callq 0x7500
jmp 0x17645
movq 0xa0(%rsp), %rdx
movq 0x98(%rsp), %rdi
xorl %eax, %eax
movl %eax, %r8d
movl $0xa, %esi
leaq 0x218(%rsp), %r9
movq %r8, %rcx
callq 0x4de80
jmp 0x17671
leaq 0x218(%rsp), %rdi
callq 0x6778
leaq 0x217(%rsp), %rdi
callq 0x6400
movq 0x2e8(%rsp), %rax
movq %rax, 0x80(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, %rdi
movq 0x140(%rsp), %rax
movq %rdi, %rcx
movq %rcx, 0x88(%rsp)
movq 0x48(%rax), %rax
movl 0x8(%rax), %esi
movl $0x2, %edx
callq 0x38010
jmp 0x176ce
leaq 0x1ef(%rsp), %rdi
movq %rdi, 0x78(%rsp)
callq 0x66c0
movq 0x78(%rsp), %rdx
leaq 0x3c163(%rip), %rsi     # 0x5384f
leaq 0x1f0(%rsp), %rdi
callq 0x7500
jmp 0x176fb
movq 0x88(%rsp), %rdx
movq 0x80(%rsp), %rdi
xorl %eax, %eax
movl %eax, %r8d
movl $0xa, %esi
leaq 0x1f0(%rsp), %r9
movq %r8, %rcx
callq 0x4de80
jmp 0x17727
leaq 0x1f0(%rsp), %rdi
callq 0x6778
leaq 0x1ef(%rsp), %rdi
callq 0x6400
movq 0x2e8(%rsp), %rax
movq %rax, 0x68(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x70(%rsp)
movl $0x3e, %esi
movl $0x2, %edx
callq 0x38010
jmp 0x17774
leaq 0x1c7(%rsp), %rdi
movq %rdi, 0x60(%rsp)
callq 0x66c0
movq 0x60(%rsp), %rdx
leaq 0x3c0d9(%rip), %rsi     # 0x5386b
leaq 0x1c8(%rsp), %rdi
callq 0x7500
jmp 0x177a1
movq 0x70(%rsp), %rdx
movq 0x68(%rsp), %rdi
xorl %eax, %eax
movl %eax, %r8d
movl $0xa, %esi
leaq 0x1c8(%rsp), %r9
movq %r8, %rcx
callq 0x4de80
jmp 0x177c7
leaq 0x1c8(%rsp), %rdi
callq 0x6778
leaq 0x1c7(%rsp), %rdi
callq 0x6400
movq 0x2e8(%rsp), %rax
movq %rax, 0x50(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, %rdi
movq 0x140(%rsp), %rax
movq %rdi, %rcx
movq %rcx, 0x58(%rsp)
movq 0x48(%rax), %rax
movl 0xc(%rax), %esi
movl $0x2, %edx
callq 0x38010
jmp 0x1781e
leaq 0x19f(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x66c0
movq 0x48(%rsp), %rdx
leaq 0x3c05f(%rip), %rsi     # 0x5389b
leaq 0x1a0(%rsp), %rdi
callq 0x7500
jmp 0x1784b
movq 0x58(%rsp), %rdx
movq 0x50(%rsp), %rdi
xorl %eax, %eax
movl %eax, %r8d
movl $0xa, %esi
leaq 0x1a0(%rsp), %r9
movq %r8, %rcx
callq 0x4de80
jmp 0x17871
leaq 0x1a0(%rsp), %rdi
callq 0x6778
leaq 0x19f(%rsp), %rdi
callq 0x6400
movq 0x2e8(%rsp), %rax
movq %rax, 0x38(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x40(%rsp)
movl $0x41, %esi
movl $0x2, %edx
callq 0x38010
jmp 0x178be
leaq 0x177(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x66c0
movq 0x30(%rsp), %rdx
leaq 0x3bfdc(%rip), %rsi     # 0x538b8
leaq 0x178(%rsp), %rdi
callq 0x7500
jmp 0x178eb
movq 0x40(%rsp), %rdx
movq 0x38(%rsp), %rdi
xorl %eax, %eax
movl %eax, %r8d
movl $0xa, %esi
leaq 0x178(%rsp), %r9
movq %r8, %rcx
callq 0x4de80
jmp 0x17911
leaq 0x178(%rsp), %rdi
callq 0x6778
leaq 0x177(%rsp), %rdi
callq 0x6400
movq 0x2e8(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x2b0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x2d8(%rsp), %rax
movq %rax, 0x20(%rsp)
movl $0x18, %edi
callq 0x6390
movq %rax, %rdi
movq %rdi, %rax
movq %rax, 0x28(%rsp)
movq 0x2d0(%rsp), %rax
movl 0x28(%rax), %esi
addl $-0x4, %esi
movl $0x2, %edx
callq 0x38010
jmp 0x17981
leaq 0x14f(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x66c0
movq 0x8(%rsp), %rdx
leaq 0x3bf48(%rip), %rsi     # 0x538e7
leaq 0x150(%rsp), %rdi
callq 0x7500
jmp 0x179ae
movq 0x28(%rsp), %r8
movq 0x20(%rsp), %rcx
movq 0x18(%rsp), %rdx
movq 0x10(%rsp), %rdi
xorl %esi, %esi
leaq 0x150(%rsp), %r9
callq 0x4de80
jmp 0x179d3
leaq 0x150(%rsp), %rdi
callq 0x6778
leaq 0x14f(%rsp), %rdi
callq 0x6400
jmp 0x17e75
movq 0x138(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x17ea0
movq 0x130(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x17ea0
movq 0x128(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x17ea0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
jmp 0x17aaa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
leaq 0x290(%rsp), %rdi
callq 0x6778
leaq 0x28f(%rsp), %rdi
callq 0x6400
jmp 0x17ea0
movq 0x100(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x17ea0
movq 0xe8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x17ea0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
jmp 0x17b49
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
leaq 0x268(%rsp), %rdi
callq 0x6778
leaq 0x267(%rsp), %rdi
callq 0x6400
jmp 0x17ea0
movq 0xc8(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x17ea0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
jmp 0x17bbd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
leaq 0x240(%rsp), %rdi
callq 0x6778
leaq 0x23f(%rsp), %rdi
callq 0x6400
jmp 0x17ea0
movq 0xa0(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x17ea0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
jmp 0x17c31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
leaq 0x218(%rsp), %rdi
callq 0x6778
leaq 0x217(%rsp), %rdi
callq 0x6400
jmp 0x17ea0
movq 0x88(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x17ea0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
jmp 0x17ca5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
leaq 0x1f0(%rsp), %rdi
callq 0x6778
leaq 0x1ef(%rsp), %rdi
callq 0x6400
jmp 0x17ea0
movq 0x70(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x17ea0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
jmp 0x17d16
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
leaq 0x1c8(%rsp), %rdi
callq 0x6778
leaq 0x1c7(%rsp), %rdi
callq 0x6400
jmp 0x17ea0
movq 0x58(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x17ea0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
jmp 0x17d87
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
leaq 0x1a0(%rsp), %rdi
callq 0x6778
leaq 0x19f(%rsp), %rdi
callq 0x6400
jmp 0x17ea0
movq 0x40(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x17ea0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
jmp 0x17df8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x6778
leaq 0x177(%rsp), %rdi
callq 0x6400
jmp 0x17ea0
movq 0x28(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
movl $0x18, %esi
callq 0x63a0
jmp 0x17ea0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
jmp 0x17e66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2c0(%rsp)
movl %eax, 0x2bc(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x6778
leaq 0x14f(%rsp), %rdi
callq 0x6400
jmp 0x17ea0
movq 0x140(%rsp), %rax
movq 0x70(%rax), %rax
movl 0x34(%rax), %ecx
movq 0x2e0(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movq 0x2d8(%rsp), %rax
addq $0x2f8, %rsp            # imm = 0x2F8
retq
movq 0x2c0(%rsp), %rdi
callq 0x66b0
nopl (%rax)