// File: /workspace/github_cpp_makefile_star2_O3/taurheim[P]AgNES/irGenerator.cpp
// Function: IRGenerator::genTACExpression[abi:cxx11](ASTNode*)
std::string IRGenerator::genTACExpression(ASTNode * expr) {
    TAC code = TAC();
    if (expr->children.size() == 1) {
        ASTNode * onlyChild = expr->children[0];
        if(onlyChild->nodeType == AST_NUMBER) {
            // Case 1: cgen(k) where k is a constant
            code.op = IR_ASSIGN;
            code.first = genAddress();
            code.second = std::to_string(((NumberNode *)onlyChild)->value);
            intermediateCode.push_back(code);
        } else if (onlyChild->nodeType == AST_IDENTIFIER) {
            // Case 2: cgen(id) where id is an identifier
            code.op = IR_ASSIGN;
            code.first = genAddress();
            code.second = ((IdentifierNode *)onlyChild)->name;
            intermediateCode.push_back(code);
        }
    } else {
        ASTNode * secondChild = expr->children[1];
        //Check if binary op
        if (secondChild->nodeType == AST_OPERATOR) {
            code.second = genTACExpression(expr->children[0]);
            code.third = genTACExpression(expr->children[2]);
            OpNode * opNode = (OpNode *)expr->children[1];
            code.op = opStringToEnum[opNode->operation];
            code.first = genAddress();
            intermediateCode.push_back(code);
        }
        //Could be unary op, function, etc..
    }
    return code.first;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, %r13
movq %rsi, -0x30(%rbp)
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq -0xb8(%rbp), %r12
movaps %xmm0, -0x8(%r12)
movaps %xmm0, 0x8(%r12)
movaps %xmm0, 0x18(%r12)
movaps %xmm0, 0x28(%r12)
movaps %xmm0, 0x38(%r12)
movaps %xmm0, 0x48(%r12)
movq $0x0, 0x58(%r12)
leaq -0xa8(%rbp), %r14
movq %r14, -0x10(%r14)
xorl %eax, %eax
movb %al, (%r14)
leaq -0x98(%rbp), %rdx
leaq -0x88(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movb %al, (%rcx)
leaq -0x68(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movb %al, (%rcx)
movq 0x8(%r13), %rax
movq 0x10(%r13), %rcx
subq %rax, %rcx
cmpq $0x8, %rcx
jne 0xcaa8
movq (%rax), %r15
movl (%r15), %eax
cmpl $0x4, %eax
je 0xcb7e
cmpl $0x5, %eax
jne 0xcc6f
movl $0x2, -0xc0(%rbp)
leaq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xe080
leaq -0x50(%rbp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x3300
movq (%r13), %rdi
leaq -0x40(%rbp), %r14
cmpq %r14, %rdi
je 0xca3a
callq 0x3250
movl 0x20(%r15), %r12d
movl %r12d, %r13d
negl %r13d
cmovsl %r12d, %r13d
movl $0x1, %r15d
cmpl $0xa, %r13d
jb 0xcbf0
movl $0x4, %r15d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %r13d, %ecx
cmpl $0x63, %ecx
jbe 0xcbe7
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0xcbed
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0xcbf0
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r15d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0xca66
addl $-0x3, %r15d
jmp 0xcbf0
movq 0x8(%rax), %rcx
cmpl $0xd, (%rcx)
jne 0xcc6f
movq %rdx, %r15
movq (%rax), %rdx
leaq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xc952
leaq -0x50(%rbp), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x3300
movq (%r14), %rdi
leaq -0x40(%rbp), %r15
cmpq %r15, %rdi
je 0xcae8
callq 0x3250
movq 0x8(%r13), %rax
movq 0x10(%rax), %rdx
leaq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xc952
leaq -0x78(%rbp), %rdi
movq %r14, %rsi
callq 0x3300
movq (%r14), %rdi
cmpq %r15, %rdi
je 0xcb16
callq 0x3250
movq 0x8(%r13), %rax
movq 0x8(%rax), %rsi
addq $0x20, %rsi
leaq 0xb9ff(%rip), %rdi      # 0x18528
callq 0xe216
movl (%rax), %eax
movl %eax, -0xc0(%rbp)
leaq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xe080
movq %r12, %rdi
movq %r14, %rsi
callq 0x3300
movq (%r14), %rdi
cmpq %r15, %rdi
je 0xcb5b
callq 0x3250
movq -0x30(%rbp), %rax
leaq 0x10(%rax), %r15
leaq -0xc0(%rbp), %rsi
movq %r15, %rdi
callq 0x6f72
leaq -0xa8(%rbp), %r14
jmp 0xcc5c
movq %rdx, %r13
movl $0x2, -0xc0(%rbp)
leaq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xe080
leaq -0x50(%rbp), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x3300
movq (%r14), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0xcbb8
callq 0x3250
addq $0x20, %r15
movq %r13, %rdi
movq %r15, %rsi
callq 0x3180
leaq -0xa8(%rbp), %r14
movq -0x30(%rbp), %rax
leaq 0x10(%rax), %r15
leaq -0xc0(%rbp), %rsi
movq %r15, %rdi
callq 0x6f72
jmp 0xcc5c
addl $-0x2, %r15d
jmp 0xcbf0
decl %r15d
shrl $0x1f, %r12d
leal (%r15,%r12), %esi
leaq -0x50(%rbp), %rdi
movq %r14, (%rdi)
movl $0x2d, %edx
callq 0x32e0
leaq -0x50(%rbp), %r14
addq (%r14), %r12
movq %r12, %rdi
movl %r15d, %esi
movl %r13d, %edx
callq 0xa88a
leaq -0x98(%rbp), %rdi
movq %r14, %rsi
callq 0x3300
movq (%r14), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0xcc3e
callq 0x3250
movq -0x30(%rbp), %rax
leaq 0x10(%rax), %r15
leaq -0xc0(%rbp), %rsi
movq %r15, %rdi
callq 0x6f72
leaq -0xa8(%rbp), %r14
movq %rax, %rdi
movq %r15, %rsi
callq 0x3070
movq -0x30(%rbp), %rax
incq 0x20(%rax)
leaq 0x10(%rbx), %rax
movq %rax, (%rbx)
movq -0xb8(%rbp), %rsi
movq -0xb0(%rbp), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x6906
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0xcca1
callq 0x3250
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0xccb9
callq 0x3250
movq -0xb8(%rbp), %rdi
cmpq %r14, %rdi
je 0xccca
callq 0x3250
movq %rbx, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xccef
jmp 0xccef
jmp 0xccef
jmp 0xccef
jmp 0xccef
jmp 0xccef
jmp 0xccef
jmp 0xccef
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0xe1ce
movq %rbx, %rdi
callq 0x3420