// File: /workspace/github_cpp_makefile_star2_O1/taurheim[P]AgNES/codeGenerator.cpp
// Function: CodeGenerator::generateAddition(TAC)
void CodeGenerator::generateAddition(TAC tac) {
    code << "; add " << tac.first << " := " << tac.second << " + " << tac.third << nl;
    CodeVar assignTo = lookup(tac.first);
    CodeVar arg1 = lookup(tac.second);
    CodeVar arg2 = lookup(tac.third);

    // For now, use $0 as our adder
    // This is bad and should not be done this way
    // Reset A to 0
    loadConstIntoA(0);
    code << "STA $0" << nl;

    // Add arg1
    loadLocalIntoA(arg1.value);
    code << "CLC" << nl;
    code << "ADC $0" << nl;
    code << "STA $0" << nl;

    // Add arg2
    loadLocalIntoA(arg2.value);
    code << "CLC" << nl;
    code << "ADC $0" << nl;

    // Store the output
    storeAIntoLocal(assignTo.value);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r12
movq %rdi, %rbx
leaq 0x80(%rdi), %r14
leaq 0x2b07(%rip), %rsi      # 0x129da
movl $0x6, %edx
movq %r14, %rdi
callq 0x32d0
movq 0x8(%r12), %rsi
movq 0x10(%r12), %rdx
movq %r14, %rdi
callq 0x32d0
movq %rax, %r15
leaq 0x2866(%rip), %rsi      # 0x12762
movl $0x4, %edx
movq %rax, %rdi
callq 0x32d0
movq 0x28(%r12), %rsi
movq 0x30(%r12), %rdx
movq %r15, %rdi
callq 0x32d0
movq %rax, %r15
leaq 0x2842(%rip), %rsi      # 0x12767
movl $0x3, %edx
movq %rax, %rdi
callq 0x32d0
movq 0x48(%r12), %rsi
movq 0x50(%r12), %rdx
movq %r15, %rdi
callq 0x32d0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %rax, %rdi
callq 0x32d0
leaq -0x80(%rbp), %r13
movq %r13, -0x10(%r13)
movq 0x8(%r12), %rsi
movq 0x10(%r12), %rdx
addq %rsi, %rdx
leaq -0x90(%rbp), %r15
movq %r15, %rdi
callq 0x6992
movq %rbx, %rdi
movq %r15, %rsi
callq 0x10bda
movq %rax, -0x30(%rbp)
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
je 0xff97
callq 0x3250
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x28(%r12), %rsi
movq 0x30(%r12), %rdx
addq %rsi, %rdx
leaq -0x70(%rbp), %r15
movq %r15, %rdi
callq 0x6992
movq %rbx, %rdi
movq %r15, %rsi
callq 0x10bda
movq %rax, %r13
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xffd8
callq 0x3250
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x48(%r12), %rsi
movq 0x50(%r12), %rdx
addq %rsi, %rdx
leaq -0x50(%rbp), %r15
movq %r15, %rdi
callq 0x6992
movq %rbx, %rdi
movq %r15, %rsi
callq 0x10bda
movq %rax, %r12
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x10019
callq 0x3250
shrq $0x20, %r12
movq -0x30(%rbp), %r15
shrq $0x20, %r15
shrq $0x20, %r13
movq %rbx, %rdi
xorl %esi, %esi
callq 0x10ee0
leaq 0x29a7(%rip), %rsi      # 0x129e1
movl $0x6, %edx
movq %r14, %rdi
callq 0x32d0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x32d0
movq %rbx, %rdi
movl %r13d, %esi
callq 0x10da2
leaq 0x2980(%rip), %rsi      # 0x129e8
movl $0x3, %edx
movq %r14, %rdi
callq 0x32d0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x32d0
leaq 0x2961(%rip), %r13      # 0x129ec
movl $0x6, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x32d0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x32d0
movl $0x6, %edx
movq %r14, %rdi
leaq 0x2928(%rip), %rsi      # 0x129e1
callq 0x32d0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x32d0
movq %rbx, %rdi
movl %r12d, %esi
callq 0x10da2
movl $0x3, %edx
movq %r14, %rdi
leaq 0x2901(%rip), %rsi      # 0x129e8
callq 0x32d0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x32d0
movl $0x6, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x32d0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x32d0
movq %rbx, %rdi
movl %r15d, %esi
callq 0x10f2e
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
jmp 0x1014c
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x10156
callq 0x3250
movq %rbx, %rdi
callq 0x3420
movq %rax, %rbx
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
jne 0x10151
jmp 0x10156
nop