// File: /workspace/github_cpp_makefile_star2_O1/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 0x285e(%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 0x25a4(%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 0x2584(%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 0x6992
movq %rbx, %rdi
movq %r15, %rsi
callq 0x10bda
movq %rax, -0x30(%rbp)
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
je 0x10259
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 0x6992
movq %rbx, %rdi
movq %r15, %rsi
callq 0x10bda
movq %rax, %r13
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x1029a
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 0x6992
movq %rbx, %rdi
movq %r15, %rsi
callq 0x10bda
movq %rax, %r12
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x102db
callq 0x3250
shrq $0x20, %r12
movq -0x30(%rbp), %r15
shrq $0x20, %r15
shrq $0x20, %r13
movq %rbx, %rdi
xorl %esi, %esi
callq 0x10ee0
leaq 0x26e5(%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 0x26be(%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 0x269c(%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 0x2666(%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
movq %r13, %rsi
callq 0x32d0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x32d0
leaq 0x263f(%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 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 0x1040e
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x10418
callq 0x3250
movq %rbx, %rdi
callq 0x3420
movq %rax, %rbx
movq -0x90(%rbp), %rdi
cmpq %r13, %rdi
jne 0x10413
jmp 0x10418
nop