// File: /workspace/github_cpp_makefile_star2_O3/taurheim[P]AgNES/codeGenerator.cpp
// Function: CodeGenerator::generateSubtraction(TAC)
void CodeGenerator::generateSubtraction(TAC tac) {
    code << "; subtract " << tac.first << " := " << tac.second << " - " << tac.third << nl;
    CodeVar assignTo = lookup(tac.first);
    // TODO why are these flipped?
    CodeVar arg1 = lookup(tac.third);
    CodeVar arg2 = lookup(tac.second);

    // 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;

    // Subtract arg2
    loadLocalIntoA(arg2.value);
    code << "CLC" << nl;
    code << "SBC $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 0x29c2(%rip), %rsi      # 0x129f3
movl $0xb, %edx
movq %r14, %rdi
callq 0x32d0
movq 0x8(%r12), %rsi
movq 0x10(%r12), %rdx
movq %r14, %rdi
callq 0x32d0
movq %rax, %r15
leaq 0x2708(%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 0x26e8(%rip), %rsi      # 0x1276b
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 0x100f5
callq 0x3250
leaq -0x60(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x48(%r12), %rsi
movq 0x50(%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 0x10136
callq 0x3250
leaq -0x40(%rbp), %rax
movq %rax, -0x10(%rax)
movq 0x28(%r12), %rsi
movq 0x30(%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 0x10177
callq 0x3250
shrq $0x20, %r12
movq -0x30(%rbp), %r15
shrq $0x20, %r15
shrq $0x20, %r13
movq %rbx, %rdi
xorl %esi, %esi
callq 0x10d7c
leaq 0x2849(%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 0x2822(%rip), %r13      # 0x129e8
movl $0x3, %edx
movq %r14, %rdi
movq %r13, %rsi
callq 0x32d0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x32d0
leaq 0x2800(%rip), %rsi      # 0x129ec
movl $0x6, %edx
movq %r14, %rdi
callq 0x32d0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x32d0
movl $0x6, %edx
movq %r14, %rdi
leaq 0x27ca(%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
movq %r13, %rsi
callq 0x32d0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x32d0
leaq 0x27a3(%rip), %rsi      # 0x129ff
movl $0x6, %edx
movq %r14, %rdi
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 0x102aa
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x102b4
callq 0x3250
movq %rbx, %rdi
callq 0x3420
movq %rax, %rbx
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
jne 0x102af
jmp 0x102b4
nop