// File: /workspace/github_cpp_makefile_star2_O1/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)
xorl %eax, %eax
movq %rax, 0x58(%r12)
leaq -0xa8(%rbp), %r14
movq %r14, -0x10(%r14)
movq %rax, -0x8(%r14)
movb %al, (%r14)
leaq -0x98(%rbp), %rdx
leaq -0x88(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq -0x68(%rbp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movq 0x8(%r13), %rax
movq 0x10(%r13), %rcx
subq %rax, %rcx
cmpq $0x8, %rcx
jne 0xcc38
movq (%rax), %r15
movl (%r15), %eax
cmpl $0x4, %eax
je 0xcd0e
cmpl $0x5, %eax
jne 0xcdff
movl $0x2, -0xc0(%rbp)
leaq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xe20e
leaq -0x50(%rbp), %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x3300
movq (%r13), %rdi
leaq -0x40(%rbp), %r14
cmpq %r14, %rdi
je 0xcbca
callq 0x3250
movl 0x20(%r15), %r12d
movl %r12d, %r13d
negl %r13d
cmovsl %r12d, %r13d
movl $0x1, %r15d
cmpl $0xa, %r13d
jb 0xcd80
movl $0x4, %r15d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %r13d, %ecx
cmpl $0x63, %ecx
jbe 0xcd77
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0xcd7d
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0xcd80
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r15d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0xcbf6
addl $-0x3, %r15d
jmp 0xcd80
movq 0x8(%rax), %rcx
cmpl $0xd, (%rcx)
jne 0xcdff
movq %rdx, %r15
movq (%rax), %rdx
leaq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xcada
leaq -0x50(%rbp), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x3300
movq (%r14), %rdi
leaq -0x40(%rbp), %r15
cmpq %r15, %rdi
je 0xcc78
callq 0x3250
movq 0x8(%r13), %rax
movq 0x10(%rax), %rdx
leaq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xcada
leaq -0x78(%rbp), %rdi
movq %r14, %rsi
callq 0x3300
movq (%r14), %rdi
cmpq %r15, %rdi
je 0xcca6
callq 0x3250
movq 0x8(%r13), %rax
movq 0x8(%rax), %rsi
addq $0x20, %rsi
leaq 0xb86f(%rip), %rdi      # 0x18528
callq 0xe3a4
movl (%rax), %eax
movl %eax, -0xc0(%rbp)
leaq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xe20e
movq %r12, %rdi
movq %r14, %rsi
callq 0x3300
movq (%r14), %rdi
cmpq %r15, %rdi
je 0xcceb
callq 0x3250
movq -0x30(%rbp), %rax
leaq 0x10(%rax), %r15
leaq -0xc0(%rbp), %rsi
movq %r15, %rdi
callq 0x7014
leaq -0xa8(%rbp), %r14
jmp 0xcdec
movq %rdx, %r13
movl $0x2, -0xc0(%rbp)
leaq -0x50(%rbp), %rdi
movq -0x30(%rbp), %rsi
callq 0xe20e
leaq -0x50(%rbp), %r14
movq %r12, %rdi
movq %r14, %rsi
callq 0x3300
movq (%r14), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0xcd48
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 0x7014
jmp 0xcdec
addl $-0x2, %r15d
jmp 0xcd80
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 0xa9d4
leaq -0x98(%rbp), %rdi
movq %r14, %rsi
callq 0x3300
movq (%r14), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0xcdce
callq 0x3250
movq -0x30(%rbp), %rax
leaq 0x10(%rax), %r15
leaq -0xc0(%rbp), %rsi
movq %r15, %rdi
callq 0x7014
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 0x6992
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0xce31
callq 0x3250
movq -0x98(%rbp), %rdi
leaq -0x88(%rbp), %rax
cmpq %rax, %rdi
je 0xce49
callq 0x3250
movq -0xb8(%rbp), %rdi
cmpq %r14, %rdi
je 0xce5a
callq 0x3250
movq %rbx, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xce7f
jmp 0xce7f
jmp 0xce7f
jmp 0xce7f
jmp 0xce7f
jmp 0xce7f
jmp 0xce7f
jmp 0xce7f
movq %rax, %rbx
leaq -0xc0(%rbp), %rdi
callq 0xe35c
movq %rbx, %rdi
callq 0x3420