// File: /workspace/github_cpp_makefile_star2_O1/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 $0x1f8, %rsp            # imm = 0x1F8
movq %rdi, %rbx
movq 0x4c79c(%rip), %rdi     # 0xbffd8
leaq 0x25ccc(%rip), %rsi     # 0x9950f
xorl %edx, %edx
callq 0x52e0
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
movq %rbx, 0x28(%rsp)
movq 0x20(%rbx), %rax
testq %rax, %rax
je 0x738d3
movq 0x8(%rax), %rbx
movq 0x10(%rax), %rbp
cmpq %rbp, %rbx
je 0x738d3
leaq 0x98(%rsp), %r13
leaq 0x80(%rsp), %r14
leaq 0x40(%rsp), %r15
movq (%rbx), %rax
movq 0x40(%rsp), %r12
movq 0x8(%rax), %rsi
movq %r14, %rdi
callq 0x77914
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x7ec6c
movq 0x88(%rsp), %rdi
cmpq %r13, %rdi
je 0x738ca
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x5260
addq $0x8, %rbx
cmpq %rbp, %rbx
jne 0x7388b
leaq 0x90(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb $0x0, (%rcx)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rcx)
movq %rax, 0x20(%rcx)
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rsi
addq $0x8, %rsi
leaq 0x4dd49(%rip), %rdi     # 0xc1650
leaq 0x80(%rsp), %rcx
movl $0x1, %edx
callq 0x7c954
cmpq $0x0, 0x88(%rsp)
jne 0x739ef
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rdx
movq (%rdx), %r14
addq $0x8, %rdx
leaq 0x25183(%rip), %rsi     # 0x98ac2
leaq 0x60(%rsp), %rdi
callq 0x1621e
leaq 0x2518f(%rip), %rsi     # 0x98adf
leaq 0x60(%rsp), %rdi
callq 0x5420
leaq 0x108(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x7398a
movq %rdx, 0xf8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x108(%rsp)
jmp 0x73990
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
leaq 0xf8(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r14, %rdi
callq 0x6be78
movq 0xf8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x739d4
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x5260
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x739ef
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x5260
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
movabsq $-0x3333333333333333, %r13 # imm = 0xCCCCCCCCCCCCCCCD
imulq %rdx, %r13
movq 0xa8(%rsp), %rdx
subq 0xa0(%rsp), %rdx
sarq $0x5, %rdx
cmpq %rdx, %r13
jne 0x73bf7
cmpq %rax, %rcx
je 0x73c57
cmpq $0x1, %r13
movq %r13, %rax
adcq $0x0, %rax
movq %rax, 0x8(%rsp)
shlq $0x5, %r13
addq $-0x20, %r13
xorl %ebp, %ebp
leaq 0x60(%rsp), %r14
leaq 0xd8(%rsp), %r15
xorl %ebx, %ebx
movq 0xa0(%rsp), %rsi
movq 0x8(%rsi,%r13), %r12
cmpq $0x5, %r12
jb 0x73aad
addq %r13, %rsi
movl $0x4, %ecx
movq %r14, %rdi
xorl %edx, %edx
callq 0x52a0
movq %r14, %rdi
leaq 0x24f2d(%rip), %rsi     # 0x989cd
callq 0x50c0
testl %eax, %eax
sete %r14b
jmp 0x73ab0
xorl %r14d, %r14d
cmpq $0x5, %r12
jb 0x73ad2
movq 0x60(%rsp), %rdi
leaq 0x70(%rsp), %rax
cmpq %rax, %rdi
je 0x73ad2
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x5260
testb %r14b, %r14b
je 0x73b9c
movq 0x40(%rsp), %rax
movq (%rax,%rbp), %rax
cmpl $0x0, (%rax)
leaq 0x60(%rsp), %r14
je 0x73b02
movq 0x8(%rax), %rcx
movq 0x10(%rax), %rax
cmpb $0x23, -0x1(%rcx,%rax)
je 0x73b6c
cmpb $0x7e, (%rcx)
jne 0x73b6c
movq 0x28(%rsp), %rax
movq 0x20(%rax), %rax
movq 0x8(%rax), %rax
movq (%rax,%rbx,8), %rax
movq (%rax), %r12
leaq 0xe8(%rsp), %rax
movq %rax, 0xd8(%rsp)
movq %r15, %rdi
leaq 0x24fdf(%rip), %rsi     # 0x98b0f
leaq 0x25006(%rip), %rdx     # 0x98b3d
callq 0x2670a
movq %r12, %rdi
movq %r15, %rsi
callq 0x6be78
movq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0x73b6c
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x40(%rsp), %rax
movq (%rax,%rbp), %rax
movq %rax, 0x30(%rsp)
movb $0x1, 0x38(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
jne 0x73bc0
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x7f038
jmp 0x73bdf
movq 0x40(%rsp), %rax
movq (%rax,%rbp), %rax
movq %rax, 0x30(%rsp)
movb $0x0, 0x38(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
leaq 0x60(%rsp), %r14
je 0x73bd0
movups 0x30(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x18(%rsp)
jmp 0x73bdf
leaq 0x10(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x7f038
incq %rbx
addq $-0x20, %r13
addq $0x28, %rbp
cmpq %rbx, 0x8(%rsp)
jne 0x73a71
jmp 0x73c57
movq 0x28(%rsp), %rax
movq 0x20(%rax), %rax
movq (%rax), %rbx
leaq 0x1e8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x24ecb(%rip), %rsi     # 0x98ae1
leaq 0x24ef1(%rip), %rdx     # 0x98b0e
leaq 0x1d8(%rsp), %rdi
callq 0x2670a
leaq 0x1d8(%rsp), %rsi
movq %rbx, %rdi
callq 0x6be78
movq 0x1d8(%rsp), %rdi
cmpq %r14, %rdi
je 0x73c57
movq 0x1e8(%rsp), %rsi
incq %rsi
callq 0x5260
leaq 0x1c8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x23dfc(%rip), %rsi     # 0x97a66
leaq 0x23df9(%rip), %rdx     # 0x97a6a
leaq 0x1b8(%rsp), %rdi
callq 0x2670a
movl $0x48, %edi
callq 0x5250
movq %rax, %r14
leaq 0x1a8(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x80(%rsp), %rsi
movq 0x88(%rsp), %rdx
addq %rsi, %rdx
leaq 0x198(%rsp), %rdi
callq 0x36590
leaq 0x188(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x255ad(%rip), %rsi     # 0x99278
leaq 0x255ac(%rip), %rdx     # 0x9927e
leaq 0x178(%rsp), %rdi
callq 0x2670a
movb $0x1, %r13b
leaq 0x198(%rsp), %rsi
leaq 0x178(%rsp), %rdx
movq %r14, %rdi
callq 0x7be1c
xorl %r13d, %r13d
leaq 0x4d8a4(%rip), %rdi     # 0xc15a8
leaq 0x1b8(%rsp), %rsi
leaq 0x10(%rsp), %rcx
movq %r14, %rdx
xorl %r8d, %r8d
callq 0x7cad6
movq 0x178(%rsp), %rdi
cmpq %rbx, %rdi
je 0x73d39
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x198(%rsp), %rdi
cmpq %r12, %rdi
je 0x73d56
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x1b8(%rsp), %rdi
cmpq %r15, %rdi
je 0x73d73
movq 0x1c8(%rsp), %rsi
incq %rsi
callq 0x5260
leaq 0x168(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x24db8(%rip), %rsi     # 0x98b3e
leaq 0x24db6(%rip), %rdx     # 0x98b43
leaq 0x158(%rsp), %rdi
callq 0x2670a
movl $0x48, %edi
callq 0x5250
movq %rax, %r14
leaq 0x4d7fa(%rip), %rdi     # 0xc15a8
callq 0x69188
movl %eax, %ebx
leaq 0xc8(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x23347(%rip), %rsi     # 0x9710f
leaq 0x23347(%rip), %rdx     # 0x97116
leaq 0xb8(%rsp), %rdi
callq 0x2670a
movb $0x1, %bpl
leaq 0xb8(%rsp), %rdx
movq %r14, %rdi
movl %ebx, %esi
callq 0x7b654
xorl %ebp, %ebp
movl $0x48, %edi
callq 0x5250
movq %rax, %r15
leaq 0x148(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x24d31(%rip), %rsi     # 0x98b44
leaq 0x24d33(%rip), %rdx     # 0x98b4d
leaq 0x138(%rsp), %rdi
callq 0x2670a
leaq 0x128(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x2543d(%rip), %rsi     # 0x99278
leaq 0x2543c(%rip), %rdx     # 0x9927e
leaq 0x118(%rsp), %rdi
callq 0x2670a
movb $0x1, %bl
leaq 0x138(%rsp), %rsi
leaq 0x118(%rsp), %rdx
movq %r15, %rdi
callq 0x7be1c
xorl %ebx, %ebx
leaq 0x4d736(%rip), %rdi     # 0xc15a8
leaq 0x158(%rsp), %rsi
movq %r14, %rdx
movq %r15, %rcx
xorl %r8d, %r8d
callq 0x7b53e
movq 0x118(%rsp), %rdi
cmpq %r12, %rdi
je 0x73ea5
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x138(%rsp), %rdi
cmpq %rbp, %rdi
leaq 0x90(%rsp), %r14
leaq 0xc8(%rsp), %rbx
je 0x73ed2
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0xb8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x73eef
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x158(%rsp), %rdi
cmpq %r13, %rdi
je 0x73f0c
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x5260
leaq 0xa0(%rsp), %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x73f2b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x5260
movq %rbx, %rdi
callq 0x7b062
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
je 0x73f50
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x5260
leaq 0x40(%rsp), %rdi
callq 0x7cbc4
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, 0x8(%rsp)
movq 0xf8(%rsp), %rdi
cmpq %rbx, %rdi
je 0x73f95
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x5260
jmp 0x73f95
movq %rax, 0x8(%rsp)
leaq 0x70(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x741b4
movq 0x70(%rsp), %rsi
incq %rsi
jmp 0x741af
jmp 0x74040
movq %rax, 0x8(%rsp)
movq 0x1d8(%rsp), %rdi
cmpq %r14, %rdi
je 0x7419d
movq 0x1e8(%rsp), %rsi
jmp 0x7418c
jmp 0x74198
movq %rax, 0x8(%rsp)
movb $0x1, %bl
jmp 0x74076
movq %rax, 0x8(%rsp)
movb $0x1, %bl
jmp 0x74093
jmp 0x73ffb
movq %rax, 0x8(%rsp)
movb $0x1, %bpl
jmp 0x740d2
movq %rax, 0x8(%rsp)
jmp 0x740e4
jmp 0x74198
movq %rax, 0x8(%rsp)
movb $0x1, %r13b
jmp 0x74124
movq %rax, 0x8(%rsp)
movb $0x1, %r13b
jmp 0x74141
movq %rax, 0x8(%rsp)
jmp 0x74153
jmp 0x74198
movq %rax, 0x8(%rsp)
jmp 0x741b4
jmp 0x74198
jmp 0x74198
movq %rax, 0x8(%rsp)
movq 0x118(%rsp), %rdi
cmpq %r12, %rdi
je 0x74076
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x138(%rsp), %rdi
cmpq %rbp, %rdi
je 0x74093
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x5260
testb %bl, %bl
je 0x740a4
movl $0x48, %esi
movq %r15, %rdi
callq 0x5260
xorl %ebp, %ebp
jmp 0x740ad
movq %rax, 0x8(%rsp)
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0x740d2
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x5260
testb %bpl, %bpl
je 0x740e4
movl $0x48, %esi
movq %r14, %rdi
callq 0x5260
movq 0x158(%rsp), %rdi
cmpq %r13, %rdi
je 0x7419d
movq 0x168(%rsp), %rsi
jmp 0x7418c
movq %rax, 0x8(%rsp)
movq 0x178(%rsp), %rdi
cmpq %rbx, %rdi
je 0x74124
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x5260
movq 0x198(%rsp), %rdi
cmpq %r12, %rdi
je 0x74141
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x5260
testb %r13b, %r13b
je 0x74153
movl $0x48, %esi
movq %r14, %rdi
callq 0x5260
movq 0x1b8(%rsp), %rdi
cmpq %r15, %rdi
je 0x7419d
movq 0x1c8(%rsp), %rsi
jmp 0x7418c
movq %rax, 0x8(%rsp)
movq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0x7419d
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x5260
jmp 0x7419d
jmp 0x74198
movq %rax, 0x8(%rsp)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x741b4
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x5260
leaq 0x80(%rsp), %rdi
callq 0x7c17e
jmp 0x741ec
movq %rax, 0x8(%rsp)
jmp 0x741ec
movq %rax, 0x8(%rsp)
movq 0x88(%rsp), %rdi
cmpq %r13, %rdi
je 0x741ec
movq 0x98(%rsp), %rsi
incq %rsi
callq 0x5260
leaq 0x40(%rsp), %rdi
callq 0x7cbc4
movq 0x8(%rsp), %rdi
callq 0x53d0