// File: /workspace/github_cpp_makefile_star2_O2/sighingnow[P]compile-pascal/pl0_tac_gen.cpp
// Function: pl0_tac_call_proc(pl0_ast_call_proc const*)
void pl0_tac_call_proc(pl0_ast_call_proc const *stmt) {
    cout << __func__;
    std::vector<std::pair<Value *, std::string>> args;
    if (stmt->args) {
        for (auto argexpr: stmt->args->args) {
            args.emplace(args.begin(), pl0_tac_expr(argexpr->arg));
        }
    }
    proc p;
    proctb.find(stmt->id->id, true, p);
    if (p.name.length() == 0) {
        pl0_ast_error(stmt->id->loc, "use of undeclared identifier '" + stmt->id->id + "'");
    }
    std::vector<std::pair<Value *, bool>> pushes; // <Value * val, bool is_ref>
    if (args.size() != p.param_t.size()) {
        pl0_ast_error(stmt->args->loc, string("unmatched number of parameters and arguments."));
    }
    else {
        size_t len = args.size();
        for (size_t i = 0; i < len; ++i) {
            bool is_ref = p.param_t[len-1-i].length() > 4 && p.param_t[len-1-i].substr(0, 4) == "ref_";
            // if (args[i].second != (is_ref ? p.param_t[len-1-i].substr(4): p.param_t[len-1-i])) {
            //     pl0_ast_error(stmt->args->args[i]->loc, string("unmatched type of parameter and argument."));
            // }
            if (is_ref) {
                if (args[i].first->t == Value::TYPE::IMM || (args[i].first->sv.back() != '#' && args[i].first->sv.front() == '~')) {
                    pl0_ast_error(stmt->args->args[i]->loc, string("use constant or expression as reference value."));
                }
                pushes.emplace_back(make_pair(args[i].first, true));
            }
            else {
                pushes.emplace_back(make_pair(args[i].first, false));
            }
        }
    }
    irb.emit("call", new Value(p.name, "string"), pushes);
    irb.emit("label", new Value(irb.makelabel(), "integer"), new Value("allsuffix", "string"));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rdi, %rbx
movq 0x48ed9(%rip), %rdi     # 0x8afd8
leaq 0x19439(%rip), %rsi     # 0x5b53f
callq 0x5250
andq $0x0, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq %rbx, 0x8(%rsp)
movq 0x20(%rbx), %rax
testq %rax, %rax
je 0x42174
movq 0x8(%rax), %r13
movq 0x10(%rax), %rbp
leaq 0x78(%rsp), %r14
leaq 0x70(%rsp), %rbx
leaq 0x10(%rsp), %r15
cmpq %rbp, %r13
je 0x42174
movq (%r13), %rax
movq 0x10(%rsp), %r12
movq 0x8(%rax), %rsi
movq %rbx, %rdi
callq 0x44859
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x495aa
movq %r14, %rdi
callq 0x5120
addq $0x8, %r13
jmp 0x4213e
leaq 0x70(%rsp), %rdi
callq 0x477f8
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rsi
addq $0x8, %rsi
leaq 0x4a4e6(%rip), %rdi     # 0x8c678
pushq $0x1
popq %rdx
leaq 0x70(%rsp), %rcx
callq 0x47824
cmpq $0x0, 0x78(%rsp)
jne 0x42208
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rdx
movq (%rdx), %rbx
addq $0x8, %rdx
leaq 0x18924(%rip), %rsi     # 0x5aae2
leaq 0x30(%rsp), %rdi
callq 0xfbb3
leaq 0x18930(%rip), %rdx     # 0x5aaff
leaq 0x1a8(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xfd14
leaq 0x1a8(%rsp), %rsi
movq %rbx, %rdi
callq 0x3da88
leaq 0x1a8(%rsp), %rdi
callq 0x5120
leaq 0x30(%rsp), %rdi
callq 0x5120
andq $0x0, 0x60(%rsp)
xorps %xmm0, %xmm0
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
movaps %xmm0, 0x50(%rsp)
pushq $0x28
popq %rcx
cqto
idivq %rcx
movq 0x98(%rsp), %rcx
subq 0x90(%rsp), %rcx
sarq $0x5, %rcx
cmpq %rcx, %rax
jne 0x42373
movq %rax, %r14
shlq $0x5, %r14
addq $-0x20, %r14
xorl %r13d, %r13d
leaq 0x30(%rsp), %r15
leaq 0x1c8(%rsp), %rbp
xorl %ebx, %ebx
movq %rax, 0x28(%rsp)
cmpq %rbx, %rax
je 0x423b5
movq 0x90(%rsp), %rsi
cmpq $0x4, 0x8(%rsi,%r14)
jbe 0x42339
movq %rbp, %r12
addq %r14, %rsi
movq %r15, %rdi
xorl %edx, %edx
pushq $0x4
popq %rcx
callq 0x52a0
movq %r15, %rdi
leaq 0x1874c(%rip), %rsi     # 0x5a9ed
callq 0x15c52
movl %eax, %ebp
movq %r15, %rdi
callq 0x5120
movq 0x10(%rsp), %rax
testb %bpl, %bpl
je 0x42340
movq (%rax,%r13), %rax
cmpl $0x0, (%rax)
movq %r12, %rbp
je 0x422de
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rdx
cmpb $0x23, -0x1(%rcx,%rdx)
je 0x42320
cmpb $0x7e, (%rcx)
jne 0x42320
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax,%rbx,8), %rax
movq (%rax), %r12
movq %rbp, %rdi
leaq 0x18833(%rip), %rsi     # 0x5ab2f
movq %r15, %rdx
callq 0xfa26
movq %r12, %rdi
movq %rbp, %rsi
callq 0x3da88
movq %rbp, %rdi
callq 0x5120
movq 0x10(%rsp), %rax
movq (%rax,%r13), %rax
movq %rax, 0x30(%rsp)
movb $0x1, 0x38(%rsp)
leaq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0x47932
jmp 0x4235e
movq 0x10(%rsp), %rax
jmp 0x42343
movq %r12, %rbp
movq (%rax,%r13), %rax
movq %rax, 0x30(%rsp)
movb $0x0, 0x38(%rsp)
leaq 0x50(%rsp), %rdi
movq %r15, %rsi
callq 0x47932
movq 0x28(%rsp), %rax
incq %rbx
addq $0x28, %r13
addq $-0x20, %r14
jmp 0x42267
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rbx
leaq 0x1877b(%rip), %rsi     # 0x5ab01
leaq 0x188(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0xfa26
leaq 0x188(%rsp), %rsi
movq %rbx, %rdi
callq 0x3da88
leaq 0x188(%rsp), %rdi
callq 0x5120
leaq 0x176d7(%rip), %rsi     # 0x59a93
leaq 0x168(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0xfa26
pushq $0x48
popq %rdi
callq 0x5260
movq %rax, %r14
leaq 0x148(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x5340
leaq 0x18eb6(%rip), %rsi     # 0x5b2a8
leaq 0x128(%rsp), %rdi
leaq 0x5(%rsp), %rdx
callq 0xfa26
movb $0x1, %r15b
leaq 0x148(%rsp), %rsi
leaq 0x128(%rsp), %rdx
movq %r14, %rdi
callq 0x46fc0
xorl %r15d, %r15d
leaq 0x4a1a7(%rip), %rdi     # 0x8c5d0
leaq 0x168(%rsp), %rsi
leaq 0x50(%rsp), %rcx
movq %r14, %rdx
xorl %r8d, %r8d
callq 0x4796a
leaq 0x128(%rsp), %rdi
callq 0x5120
leaq 0x148(%rsp), %rdi
callq 0x5120
leaq 0x168(%rsp), %rdi
callq 0x5120
leaq 0x186ef(%rip), %rsi     # 0x5ab5e
leaq 0x108(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0xfa26
pushq $0x48
popq %rdi
callq 0x5260
movq %rax, %r14
leaq 0x4a13d(%rip), %rdi     # 0x8c5d0
callq 0x3bb88
movl %eax, %ebx
leaq 0x16c6e(%rip), %rsi     # 0x5910f
leaq 0xe8(%rsp), %rdi
leaq 0x5(%rsp), %rdx
callq 0xfa26
movb $0x1, %bpl
leaq 0xe8(%rsp), %rdx
movq %r14, %rdi
movl %ebx, %esi
callq 0x46ac6
xorl %ebp, %ebp
pushq $0x48
popq %rdi
callq 0x5260
movq %rax, %r15
leaq 0x18688(%rip), %rsi     # 0x5ab64
leaq 0xc8(%rsp), %rdi
leaq 0x7(%rsp), %rdx
callq 0xfa26
leaq 0x18db3(%rip), %rsi     # 0x5b2a8
leaq 0xa8(%rsp), %rdi
leaq 0x6(%rsp), %rdx
callq 0xfa26
movb $0x1, %r12b
leaq 0xc8(%rsp), %rsi
leaq 0xa8(%rsp), %rdx
movq %r15, %rdi
callq 0x46fc0
xorl %r12d, %r12d
leaq 0x4a0a4(%rip), %rdi     # 0x8c5d0
leaq 0x108(%rsp), %rsi
movq %r14, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x46a38
leaq 0xa8(%rsp), %rdi
callq 0x5120
leaq 0xc8(%rsp), %rdi
callq 0x5120
leaq 0xe8(%rsp), %rdi
callq 0x5120
leaq 0x108(%rsp), %rdi
callq 0x5120
leaq 0x50(%rsp), %rdi
callq 0x3ce3a
leaq 0x70(%rsp), %rdi
callq 0x47242
leaq 0x10(%rsp), %rdi
callq 0x479f8
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x1a8(%rsp), %rdi
callq 0x5120
jmp 0x425bb
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x5120
jmp 0x426e9
jmp 0x42625
movq %rax, %rbx
leaq 0x188(%rsp), %rdi
jmp 0x426cf
jmp 0x426dc
movq %rax, %rbx
movb $0x1, %r12b
jmp 0x42642
movq %rax, %rbx
jmp 0x42654
jmp 0x425f0
movq %rax, %rbx
jmp 0x42678
movq %rax, %rbx
jmp 0x42683
jmp 0x426dc
movq %rax, %rbx
movb $0x1, %r15b
jmp 0x4269d
movq %rax, %rbx
jmp 0x426af
movq %rax, %rbx
jmp 0x426ba
jmp 0x426dc
movq %rax, %rbx
jmp 0x426e9
jmp 0x426f5
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x5120
leaq 0xc8(%rsp), %rdi
callq 0x5120
testb %r12b, %r12b
je 0x4265f
pushq $0x48
popq %rsi
movq %r15, %rdi
callq 0x5270
xorl %ebp, %ebp
jmp 0x42666
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x5120
testb %bpl, %bpl
je 0x42683
pushq $0x48
popq %rsi
movq %r14, %rdi
callq 0x5270
leaq 0x108(%rsp), %rdi
jmp 0x426cf
movq %rax, %rbx
leaq 0x128(%rsp), %rdi
callq 0x5120
leaq 0x148(%rsp), %rdi
callq 0x5120
testb %r15b, %r15b
je 0x426ba
pushq $0x48
popq %rsi
movq %r14, %rdi
callq 0x5270
leaq 0x168(%rsp), %rdi
jmp 0x426cf
movq %rax, %rbx
leaq 0x1c8(%rsp), %rdi
callq 0x5120
jmp 0x426df
jmp 0x426dc
jmp 0x426dc
jmp 0x426dc
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x3ce3a
leaq 0x70(%rsp), %rdi
callq 0x47242
jmp 0x42705
movq %rax, %rbx
jmp 0x42705
movq %rax, %rbx
movq %r14, %rdi
callq 0x5120
leaq 0x10(%rsp), %rdi
callq 0x479f8
movq %rbx, %rdi
callq 0x53f0