// File: fondoger[P]C0-Compiler/src/grammar.cpp
// Function: pNonVoidFunctionCall(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, DataType&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, _TabEntry const&)
static void pNonVoidFunctionCall(std::string &res, DataType &res_dtype, 
        const std::string &id, const TabEntry &entry)
{
    assert(entry.itype == IT_FUNCTION);
    if (entry.dtype == DT_VOID) {
        error(ERR_EXPECT_NON_VOID_FUNCTION);
        return;
    }
    const std::vector<DataType> &params = tabGetParams(id);

    if (g_sym == LPARENT) {
        pArgumentsList(params);
    } else if (params.size() != 0) {
        error(ERR_EXPECT_ARGUMENTS);
        return;
    }
    genMidCode(CALL, id, std::to_string(params.size()), NONE);
    // create a temp variable for holding return value
    res = genTempVar(); 
    res_dtype = entry.dtype;
    genMidCode(TEMP, (res_dtype == DT_INT ? "int": "char"), res, NONE);
    // return statement in non-void functions will always
    // write return value to a fixed register $v0
    // get return value from $t0 and save it to a temp variable
    genMidCode(GETRET, NONE, NONE, res);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpl $0x2, 0x4(%rax)
jne 0x205f7
jmp 0x20616
leaq 0x15031(%rip), %rdi     # 0x3562f
leaq 0x14e23(%rip), %rsi     # 0x35428
movl $0x259, %edx            # imm = 0x259
leaq 0x15039(%rip), %rcx     # 0x3564a
callq 0x3230
movq -0x20(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x2069c
leaq -0x41(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x3570
movq -0x100(%rbp), %rdx
leaq 0x15068(%rip), %rsi     # 0x356a6
leaq -0x40(%rbp), %rdi
callq 0x3440
jmp 0x20649
leaq -0x40(%rbp), %rdi
callq 0x18620
jmp 0x20654
leaq -0x40(%rbp), %rdi
callq 0x35e8
leaq -0x41(%rbp), %rdi
callq 0x3370
jmp 0x208b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x2068e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x35e8
leaq -0x41(%rbp), %rdi
callq 0x3370
jmp 0x20908
movq -0x18(%rbp), %rdi
callq 0x2f030
movq %rax, -0x60(%rbp)
leaq 0x2b000(%rip), %rax     # 0x4b6b0
cmpl $0x1d, (%rax)
jne 0x206c3
movq -0x60(%rbp), %rdi
callq 0x20ff0
jmp 0x2075d
movq -0x60(%rbp), %rdi
callq 0x22bf0
cmpq $0x0, %rax
je 0x2075b
leaq -0x81(%rbp), %rdi
movq %rdi, -0x108(%rbp)
callq 0x3570
movq -0x108(%rbp), %rdx
leaq 0x14fd6(%rip), %rsi     # 0x356cd
leaq -0x80(%rbp), %rdi
callq 0x3440
jmp 0x20702
leaq -0x80(%rbp), %rdi
callq 0x18620
jmp 0x2070d
leaq -0x80(%rbp), %rdi
callq 0x35e8
leaq -0x81(%rbp), %rdi
callq 0x3370
jmp 0x208b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x2074a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x35e8
leaq -0x81(%rbp), %rdi
callq 0x3370
jmp 0x20908
jmp 0x2075d
movl $0xa, -0x88(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x60(%rbp), %rdi
callq 0x22bf0
movq %rax, %rsi
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x110(%rbp)
callq 0x22c10
movq -0x118(%rbp), %rsi
movq -0x110(%rbp), %rdx
leaq 0x2685a(%rip), %rcx     # 0x47000
leaq -0x88(%rbp), %rdi
callq 0x26340
jmp 0x207b4
leaq -0xa8(%rbp), %rdi
callq 0x35e8
leaq -0xc8(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x271d0
movq -0x130(%rbp), %rsi
movq -0x8(%rbp), %rdi
callq 0x33d0
movq -0x130(%rbp), %rdi
callq 0x35e8
movq -0x20(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movl $0x17, -0xcc(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
subl $0x1, %eax
leaq 0x14f93(%rip), %rcx     # 0x357a9
leaq 0x14896(%rip), %rax     # 0x350b3
cmoveq %rcx, %rax
movq %rax, -0x128(%rbp)
leaq -0xf1(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x3570
movq -0x128(%rbp), %rsi
movq -0x120(%rbp), %rdx
leaq -0xf0(%rbp), %rdi
callq 0x3440
jmp 0x20857
movq -0x8(%rbp), %rdx
leaq 0x2679e(%rip), %rcx     # 0x47000
leaq -0xcc(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x26340
jmp 0x20877
leaq -0xf0(%rbp), %rdi
callq 0x35e8
leaq -0xf1(%rbp), %rdi
callq 0x3370
movl $0xc, -0xf8(%rbp)
movq -0x8(%rbp), %rcx
leaq -0xf8(%rbp), %rdi
leaq 0x26755(%rip), %rdx     # 0x47000
movq %rdx, %rsi
callq 0x26340
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x35e8
jmp 0x20908
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x208fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x35e8
leaq -0xf1(%rbp), %rdi
callq 0x3370
movq -0x50(%rbp), %rdi
callq 0x3560
nopw %cs:(%rax,%rax)