// File: sighingnow[P]compile-pascal/pl0_tac_gen.cpp
// Function: pl0_tac_term[abi:cxx11](pl0_ast_term const*)
pair<Value *, string> pl0_tac_term(pl0_ast_term const *term) {
    cout << __func__;
    bool needtmp = true;
    pair<Value *, string> head = pl0_tac_factor(term->factors[0].second);
    Value *ans = head.first, *prev = head.first;
    if (term->factors.size() > 1) {
        head.second = "integer"; // type casting.
        for (size_t i = 1; i < term->factors.size(); ++i) {
            if (needtmp) { ans = new Value(irb.maketmp(), head.second); }
            auto element = pl0_tac_factor(term->factors[i].second);
            // if (element.second != head.second) {
            //     pl0_ast_error(term->factors[i].second->loc, "do *// operation on two factors with different types.");
            // }
            irb.emit(string(1, term->factors[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 $0x140, %rsp            # imm = 0x140
movq %rdi, -0x110(%rbp)
movq %rdi, %rax
movq %rax, -0x108(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq 0xa434d(%rip), %rdi     # 0x15efd8
leaq 0x36f9d(%rip), %rsi     # 0xf1c2f
callq 0x5330
movb $0x1, -0x11(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0xc03c0
movq 0x8(%rax), %rsi
leaq -0x40(%rbp), %rdi
callq 0xbafc0
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
callq 0x3b220
cmpq $0x1, %rax
jbe 0xbaf6c
leaq -0x38(%rbp), %rdi
leaq 0x3455c(%rip), %rsi     # 0xef247
callq 0x5480
jmp 0xbacf2
movq $0x1, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
callq 0x3b220
movq %rax, %rcx
movq -0x118(%rbp), %rax
cmpq %rcx, %rax
jae 0xbaf6a
testb $0x1, -0x11(%rbp)
je 0xbae2a
movl $0x48, %edi
callq 0x5340
movq %rax, -0x120(%rbp)
jmp 0xbad42
movb $0x1, -0xa9(%rbp)
leaq 0xa5980(%rip), %rsi     # 0x1606d0
leaq -0x88(%rbp), %rdi
callq 0xa0200
jmp 0xbad5e
leaq -0x38(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
callq 0x5150
jmp 0xbad70
movq -0x120(%rbp), %rdi
leaq -0x88(%rbp), %rsi
leaq -0xa8(%rbp), %rdx
callq 0xbeae0
jmp 0xbad8c
movq -0x120(%rbp), %rax
movb $0x0, -0xa9(%rbp)
movq %rax, -0x48(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x5200
leaq -0x88(%rbp), %rdi
callq 0x5200
jmp 0xbae2a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0xbafae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0xbae09
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0xbadfd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x5200
leaq -0x88(%rbp), %rdi
callq 0x5200
testb $0x1, -0xa9(%rbp)
jne 0xbae14
jmp 0xbae25
movq -0x120(%rbp), %rdi
movl $0x48, %esi
callq 0x5350
jmp 0xbafae
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movq -0x68(%rbp), %rsi
callq 0xc03c0
movq 0x8(%rax), %rsi
leaq -0xd8(%rbp), %rdi
callq 0xbafc0
jmp 0xbae4d
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movq -0x68(%rbp), %rsi
callq 0xc03c0
movq (%rax), %rax
movsbl 0xc(%rax), %eax
movl %eax, -0x12c(%rbp)
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x55d0
movl -0x12c(%rbp), %edx
movq -0x128(%rbp), %rcx
leaq -0xf8(%rbp), %rdi
movl $0x1, %esi
callq 0x19b20
jmp 0xbae9e
movq -0x48(%rbp), %rax
movq %rax, -0x138(%rbp)
testb $0x1, -0x11(%rbp)
je 0xbaebc
movq -0x50(%rbp), %rax
movq %rax, -0x140(%rbp)
jmp 0xbaec7
movq -0x48(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x138(%rbp), %rdx
movq -0x140(%rbp), %rcx
movq -0xd8(%rbp), %r8
leaq 0xa57ed(%rip), %rdi     # 0x1606d0
leaq -0xf8(%rbp), %rsi
callq 0xbdf00
jmp 0xbaef1
leaq -0xf8(%rbp), %rdi
callq 0x5200
leaq -0xf9(%rbp), %rdi
callq 0x53c0
movb $0x0, -0x11(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0xbf290
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x68(%rbp)
jmp 0xbacfa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0xbaf50
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x5200
leaq -0xf9(%rbp), %rdi
callq 0x53c0
leaq -0xd8(%rbp), %rdi
callq 0xbf290
jmp 0xbafae
jmp 0xbaf6c
leaq -0x38(%rbp), %rsi
movq -0x48(%rbp), %rdi
addq $0x28, %rdi
callq 0x5050
jmp 0xbaf7f
movq -0x110(%rbp), %rdi
leaq -0x38(%rbp), %rdx
leaq -0x48(%rbp), %rsi
callq 0xc0380
jmp 0xbaf95
leaq -0x40(%rbp), %rdi
callq 0xbf290
movq -0x108(%rbp), %rax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0xbf290
movq -0x58(%rbp), %rdi
callq 0x55b0