// File: sighingnow[P]compile-pascal/pl0_tac_gen.cpp
// Function: pl0_tac_expr[abi:cxx11](pl0_ast_expression const*)
pair<Value *, string> pl0_tac_expr(pl0_ast_expression const *expr) {
    cout << __func__;
    bool needtmp = true;
    std::string t = "";
    pair<Value *, string> head = pl0_tac_term(expr->terms[0].second);
    Value *ans = head.first, *prev = head.first;
    if (expr->terms[0].first->op == '-') {
        ans = new Value(irb.maketmp(), head.second);
        irb.emit("-", ans, new Value(0, head.second), prev);
        needtmp = false; // no more temporary variable.
    }
    if (expr->terms.size() > 1) {
        head.second = "integer"; // type casting.
        for (size_t i = 1; i < expr->terms.size(); ++i) {
            if (needtmp) { ans = new Value(irb.maketmp(), head.second); }
            auto element = pl0_tac_term(expr->terms[i].second);
            // if (element.second != head.second) {
            //     pl0_ast_error(expr->terms[i].second->loc, "do +/- operation on two terms with different types.");
            // }
            irb.emit(string(1, expr->terms[i].first->op), ans, needtmp ? prev : ans, element.first);
            needtmp = false; // no more temporary variable.
        }
    }
    ans->dt = head.second;
    return make_pair(ans, head.second);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movq %rdi, -0x1e0(%rbp)
movq %rdi, %rax
movq %rax, -0x1d8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq 0xa49ad(%rip), %rdi     # 0x15efd8
leaq 0x375fd(%rip), %rsi     # 0xf1c2f
movq %rsi, -0x1d0(%rbp)
callq 0x5330
movb $0x1, -0x11(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x55d0
movq -0x1d0(%rbp), %rsi
movq -0x1c8(%rbp), %rdx
leaq -0x38(%rbp), %rdi
callq 0x19840
jmp 0xba66b
leaq -0x39(%rbp), %rdi
callq 0x53c0
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xc0360
movq 0x8(%rax), %rsi
leaq -0x78(%rbp), %rdi
callq 0xbac60
jmp 0xba694
movq -0x78(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xc0360
movq (%rax), %rax
movsbl 0xc(%rax), %eax
cmpl $0x2d, %eax
jne 0xba944
movl $0x48, %edi
callq 0x5340
movq %rax, -0x1e8(%rbp)
jmp 0xba6db
movb $0x1, -0xc9(%rbp)
leaq 0xa5fe7(%rip), %rsi     # 0x1606d0
leaq -0xa8(%rbp), %rdi
callq 0xa0200
jmp 0xba6f7
leaq -0x70(%rbp), %rsi
leaq -0xc8(%rbp), %rdi
callq 0x5150
jmp 0xba709
movq -0x1e8(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
leaq -0xc8(%rbp), %rdx
callq 0xbeae0
jmp 0xba725
movq -0x1e8(%rbp), %rax
movb $0x0, -0xc9(%rbp)
movq %rax, -0x80(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x5200
leaq -0xa8(%rbp), %rdi
callq 0x5200
leaq -0xf1(%rbp), %rdi
movq %rdi, -0x1f0(%rbp)
callq 0x55d0
movq -0x1f0(%rbp), %rdx
leaq 0x37057(%rip), %rsi     # 0xf17c7
leaq -0xf0(%rbp), %rdi
callq 0x19840
jmp 0xba77e
movq -0x80(%rbp), %rax
movq %rax, -0x200(%rbp)
movl $0x48, %edi
callq 0x5340
movq %rax, -0x1f8(%rbp)
jmp 0xba79c
movb $0x1, -0x119(%rbp)
leaq -0x70(%rbp), %rsi
leaq -0x118(%rbp), %rdi
callq 0x5150
jmp 0xba7b5
movq -0x1f8(%rbp), %rdi
xorl %esi, %esi
leaq -0x118(%rbp), %rdx
callq 0xbdfe0
jmp 0xba7cc
movq -0x1f8(%rbp), %rcx
movq -0x200(%rbp), %rdx
movb $0x0, -0x119(%rbp)
movq -0x88(%rbp), %r8
leaq 0xa5ee1(%rip), %rdi     # 0x1606d0
leaq -0xf0(%rbp), %rsi
callq 0xbdf00
jmp 0xba7fd
leaq -0x118(%rbp), %rdi
callq 0x5200
leaq -0xf0(%rbp), %rdi
callq 0x5200
leaq -0xf1(%rbp), %rdi
callq 0x53c0
movb $0x0, -0x11(%rbp)
jmp 0xba944
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x53c0
jmp 0xbac48
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xbac3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xbac36
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xba8a6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xba89a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x5200
leaq -0xa8(%rbp), %rdi
callq 0x5200
testb $0x1, -0xc9(%rbp)
jne 0xba8b1
jmp 0xba8c2
movq -0x1e8(%rbp), %rdi
movl $0x48, %esi
callq 0x5350
jmp 0xbac36
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xba933
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xba927
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xba909
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x5200
testb $0x1, -0x119(%rbp)
jne 0xba914
jmp 0xba925
movq -0x1f8(%rbp), %rdi
movl $0x48, %esi
callq 0x5350
jmp 0xba927
leaq -0xf0(%rbp), %rdi
callq 0x5200
leaq -0xf1(%rbp), %rdi
callq 0x53c0
jmp 0xbac36
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
callq 0x43720
cmpq $0x1, %rax
jbe 0xbabeb
leaq -0x70(%rbp), %rdi
leaq 0x348e1(%rip), %rsi     # 0xef247
callq 0x5480
jmp 0xba96d
movq $0x1, -0x128(%rbp)
movq -0x128(%rbp), %rax
movq %rax, -0x208(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
callq 0x43720
movq %rax, %rcx
movq -0x208(%rbp), %rax
cmpq %rcx, %rax
jae 0xbabe9
testb $0x1, -0x11(%rbp)
je 0xbaa9a
movl $0x48, %edi
callq 0x5340
movq %rax, -0x210(%rbp)
jmp 0xba9c3
movb $0x1, -0x169(%rbp)
leaq 0xa5cff(%rip), %rsi     # 0x1606d0
leaq -0x148(%rbp), %rdi
callq 0xa0200
jmp 0xba9df
leaq -0x70(%rbp), %rsi
leaq -0x168(%rbp), %rdi
callq 0x5150
jmp 0xba9f1
movq -0x210(%rbp), %rdi
leaq -0x148(%rbp), %rsi
leaq -0x168(%rbp), %rdx
callq 0xbeae0
jmp 0xbaa0d
movq -0x210(%rbp), %rax
movb $0x0, -0x169(%rbp)
movq %rax, -0x80(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x5200
leaq -0x148(%rbp), %rdi
callq 0x5200
jmp 0xbaa9a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xbaa79
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xbaa6d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x5200
leaq -0x148(%rbp), %rdi
callq 0x5200
testb $0x1, -0x169(%rbp)
jne 0xbaa84
jmp 0xbaa95
movq -0x210(%rbp), %rdi
movl $0x48, %esi
callq 0x5350
jmp 0xbac36
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movq -0x128(%rbp), %rsi
callq 0xc0360
movq 0x8(%rax), %rsi
leaq -0x198(%rbp), %rdi
callq 0xbac60
jmp 0xbaac0
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movq -0x128(%rbp), %rsi
callq 0xc0360
movq (%rax), %rax
movsbl 0xc(%rax), %eax
movl %eax, -0x21c(%rbp)
leaq -0x1b9(%rbp), %rdi
movq %rdi, -0x218(%rbp)
callq 0x55d0
movl -0x21c(%rbp), %edx
movq -0x218(%rbp), %rcx
leaq -0x1b8(%rbp), %rdi
movl $0x1, %esi
callq 0x19b20
jmp 0xbab14
movq -0x80(%rbp), %rax
movq %rax, -0x228(%rbp)
testb $0x1, -0x11(%rbp)
je 0xbab35
movq -0x88(%rbp), %rax
movq %rax, -0x230(%rbp)
jmp 0xbab40
movq -0x80(%rbp), %rax
movq %rax, -0x230(%rbp)
movq -0x228(%rbp), %rdx
movq -0x230(%rbp), %rcx
movq -0x198(%rbp), %r8
leaq 0xa5b74(%rip), %rdi     # 0x1606d0
leaq -0x1b8(%rbp), %rsi
callq 0xbdf00
jmp 0xbab6a
leaq -0x1b8(%rbp), %rdi
callq 0x5200
leaq -0x1b9(%rbp), %rdi
callq 0x53c0
movb $0x0, -0x11(%rbp)
leaq -0x198(%rbp), %rdi
callq 0xbf290
movq -0x128(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x128(%rbp)
jmp 0xba978
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0xbabcf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x1b8(%rbp), %rdi
callq 0x5200
leaq -0x1b9(%rbp), %rdi
callq 0x53c0
leaq -0x198(%rbp), %rdi
callq 0xbf290
jmp 0xbac36
jmp 0xbabeb
leaq -0x70(%rbp), %rsi
movq -0x80(%rbp), %rdi
addq $0x28, %rdi
callq 0x5050
jmp 0xbabfe
movq -0x1e0(%rbp), %rdi
leaq -0x70(%rbp), %rdx
leaq -0x80(%rbp), %rsi
callq 0xc0380
jmp 0xbac14
leaq -0x78(%rbp), %rdi
callq 0xbf290
leaq -0x38(%rbp), %rdi
callq 0x5200
movq -0x1d8(%rbp), %rax
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
leaq -0x78(%rbp), %rdi
callq 0xbf290
leaq -0x38(%rbp), %rdi
callq 0x5200
movq -0x48(%rbp), %rdi
callq 0x55b0
nopw %cs:(%rax,%rax)