// File: taurheim[P]AgNES/codeGenerator.cpp
// Function: CodeGenerator::generateAssign(TAC)
void CodeGenerator::generateAssign(TAC tac) {
    code << "; assign " << tac.first <<" := " << tac.second << nl;
    CodeVar left = lookup(tac.first);
    CodeVar right = lookup(tac.second);
    if (left.type == CVT_GLOBAL) {
        if (right.type == CVT_LOCAL) {
            // GLOBAL = LOCAL
            code << "; global = local" << nl;
            loadLocalIntoA(right.value);
            storeAIntoGlobal(left.value);
        }
        else {
            // GLOBAL = CONST
            code << "; global = const" << nl;
            loadConstIntoA(right.value);
            storeAIntoGlobal(left.value);
        }
    }
    else if (left.type == CVT_LOCAL) {
        if (right.type == CVT_GLOBAL) {
            // LOCAL = GLOBAL
            code << "; local := global" << nl;
            loadGlobalIntoA(right.value);
            storeAIntoLocal(left.value);
        }
        else if (right.type == CVT_LOCAL) {
            // LOCAL = LOCAL
            code << "; local := local" << nl;
            loadLocalIntoA(right.value);
            storeAIntoLocal(left.value);
        }
        else if (right.type == CVT_PARAM) {
            code << "; local := param" << nl;
            loadParamIntoA(right.value);
            storeAIntoLocal(left.value);
        }
        else {
            // LOCAL = CONST
            code << "; local := const" << nl;
            loadConstIntoA(right.value);
            storeAIntoLocal(left.value);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rsi, -0x98(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x88(%rbp)
subq $-0x80, %rdi
leaq 0x480d(%rip), %rsi      # 0x24a3d
callq 0x32e0
movq -0x98(%rbp), %rsi
movq %rax, %rdi
addq $0x8, %rsi
movq %rsi, -0x90(%rbp)
callq 0x32a0
movq %rax, %rdi
leaq 0x45dd(%rip), %rsi      # 0x24836
callq 0x32e0
movq -0x98(%rbp), %rsi
movq %rax, %rdi
addq $0x28, %rsi
callq 0x32a0
movq -0x88(%rbp), %rsi
movq %rax, %rdi
callq 0x32a0
movq -0x90(%rbp), %rsi
leaq -0x38(%rbp), %rdi
movq %rdi, -0x80(%rbp)
callq 0x3140
movq -0x88(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x21250
movq %rax, -0x78(%rbp)
jmp 0x202aa
movq -0x78(%rbp), %rax
movq %rax, -0x18(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x31d0
movq -0x98(%rbp), %rsi
addq $0x28, %rsi
leaq -0x70(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x3140
movq -0x88(%rbp), %rdi
movq -0xa8(%rbp), %rsi
callq 0x21250
movq %rax, -0xa0(%rbp)
jmp 0x202f2
movq -0xa0(%rbp), %rax
movq %rax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x31d0
cmpl $0x1, -0x18(%rbp)
jne 0x203df
cmpl $0x0, -0x4c(%rbp)
jne 0x20393
movq -0x88(%rbp), %rdi
addq $0x80, %rdi
leaq 0x471c(%rip), %rsi      # 0x24a47
callq 0x32e0
movq -0x88(%rbp), %rsi
movq %rax, %rdi
callq 0x32a0
movq -0x88(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x214d0
movq -0x88(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x21570
jmp 0x203da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x31d0
jmp 0x20534
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x31d0
jmp 0x20534
movq -0x88(%rbp), %rdi
addq $0x80, %rdi
leaq 0x46b0(%rip), %rsi      # 0x24a58
callq 0x32e0
movq -0x88(%rbp), %rsi
movq %rax, %rdi
callq 0x32a0
movq -0x88(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x21600
movq -0x88(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x21570
jmp 0x2052b
cmpl $0x0, -0x18(%rbp)
jne 0x20529
cmpl $0x1, -0x4c(%rbp)
jne 0x2043b
movq -0x88(%rbp), %rdi
addq $0x80, %rdi
leaq 0x4665(%rip), %rsi      # 0x24a69
callq 0x32e0
movq -0x88(%rbp), %rsi
movq %rax, %rdi
callq 0x32a0
movq -0x88(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x21080
movq -0x88(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x21650
jmp 0x20527
cmpl $0x0, -0x4c(%rbp)
jne 0x2048d
movq -0x88(%rbp), %rdi
addq $0x80, %rdi
leaq 0x4625(%rip), %rsi      # 0x24a7b
callq 0x32e0
movq -0x88(%rbp), %rsi
movq %rax, %rdi
callq 0x32a0
movq -0x88(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x214d0
movq -0x88(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x21650
jmp 0x20525
cmpl $0x3, -0x4c(%rbp)
jne 0x204dc
movq -0x88(%rbp), %rdi
addq $0x80, %rdi
leaq 0x45e4(%rip), %rsi      # 0x24a8c
callq 0x32e0
movq -0x88(%rbp), %rsi
movq %rax, %rdi
callq 0x32a0
movq -0x88(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x216f0
movq -0x88(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x21650
jmp 0x20523
movq -0x88(%rbp), %rdi
addq $0x80, %rdi
leaq 0x45ac(%rip), %rsi      # 0x24a9d
callq 0x32e0
movq -0x88(%rbp), %rsi
movq %rax, %rdi
callq 0x32a0
movq -0x88(%rbp), %rdi
movl -0x48(%rbp), %esi
callq 0x21600
movq -0x88(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x21650
jmp 0x20525
jmp 0x20527
jmp 0x20529
jmp 0x2052b
addq $0xb0, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rdi
callq 0x3520
nopl (%rax)