// File: /workspace/github_cpp_makefile_star2_O3/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 0x2c6b(%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 0x29ca(%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 0x29a6(%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 0x6906
movq %rbx, %rdi
movq %r15, %rsi
callq 0x10a76
movq %rax, -0x30(%rbp)
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
je 0xfe33
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 0x6906
movq %rbx, %rdi
movq %r15, %rsi
callq 0x10a76
movq %rax, %r13
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xfe74
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 0x6906
movq %rbx, %rdi
movq %r15, %rsi
callq 0x10a76
movq %rax, %r12
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0xfeb5
callq 0x3250
shrq $0x20, %r12
movq -0x30(%rbp), %r15
shrq $0x20, %r15
shrq $0x20, %r13
movq %rbx, %rdi
xorl %esi, %esi
callq 0x10d7c
leaq 0x2b0b(%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 0x10c3e
leaq 0x2ae4(%rip), %rsi      # 0x129e8
movl $0x3, %edx
movq %r14, %rdi
callq 0x32d0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x32d0
leaq 0x2ac5(%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 0x2a8c(%rip), %rsi      # 0x129e1
callq 0x32d0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x32d0
movq %rbx, %rdi
movl %r12d, %esi
callq 0x10c3e
movl $0x3, %edx
movq %r14, %rdi
leaq 0x2a65(%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 0x10dca
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 0xffe8
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0xfff2
callq 0x3250
movq %rbx, %rdi
callq 0x3420
movq %rax, %rbx
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
jne 0xffed
jmp 0xfff2
nop