// File: zgimbutas[P]mwrap/src/mwrap-typecheck.cc
// Function: typecheck_return(Var*, int)
int typecheck_return(Var* v, int line)
{
    if (!v)
        return 0;

    int err = assign_tinfo(v, line);
    if ((v->tinfo == VT_array ||
         v->tinfo == VT_carray ||
         v->tinfo == VT_zarray) && 
        !(v->qual && v->qual->args)) {
        fprintf(stderr, "Error (%d): ", line);
        fprintf(stderr, "Return array %s must have dims\n", v->name);
        ++err;
    } else if (v->tinfo == VT_const) {
        fprintf(stderr, "Error (%d): ", line);
        fprintf(stderr, "Cannot return constant\n");
        ++err;
    } else if (v->tinfo == VT_rarray) {
        fprintf(stderr, "Error (%d): ", line);
        fprintf(stderr, "Ref to array %s looks just like array on return\n", 
                v->name);
        ++err;
    } else if (v->tinfo == VT_string && v->qual) {
        fprintf(stderr, "Error (%d): ", line);
        fprintf(stderr, "Return string %s cannot have dims\n", v->name);
        ++err;
    }
    return err;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xc122
movl $0x0, -0x4(%rbp)
jmp 0xc2b2
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0xbcb0
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x2, 0x20(%rax)
je 0xc14f
movq -0x10(%rbp), %rax
cmpl $0x3, 0x20(%rax)
je 0xc14f
movq -0x10(%rbp), %rax
cmpl $0x4, 0x20(%rax)
jne 0xc1b2
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0xc169
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
cmpq $0x0, 0x8(%rax)
jne 0xc1b2
movq 0x18e68(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x8a46(%rip), %rsi      # 0x14bc3
movb $0x0, %al
callq 0x33a0
movq 0x18e4d(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0x8c63(%rip), %rsi      # 0x14e00
movb $0x0, %al
callq 0x33a0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xc2ac
movq -0x10(%rbp), %rax
cmpl $0x13, 0x20(%rax)
jne 0xc1fd
movq 0x18e15(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x89f3(%rip), %rsi      # 0x14bc3
movb $0x0, %al
callq 0x33a0
movq 0x18dfa(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
leaq 0x8c38(%rip), %rsi      # 0x14e20
movb $0x0, %al
callq 0x33a0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xc2aa
movq -0x10(%rbp), %rax
cmpl $0x5, 0x20(%rax)
jne 0xc24d
movq 0x18dca(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x89a8(%rip), %rsi      # 0x14bc3
movb $0x0, %al
callq 0x33a0
movq 0x18daf(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0x8bfd(%rip), %rsi      # 0x14e38
movb $0x0, %al
callq 0x33a0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xc2a8
movq -0x10(%rbp), %rax
cmpl $0x9, 0x20(%rax)
jne 0xc2a6
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0xc2a6
movq 0x18d6f(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x894d(%rip), %rsi      # 0x14bc3
movb $0x0, %al
callq 0x33a0
movq 0x18d54(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0x8bd3(%rip), %rsi      # 0x14e69
movb $0x0, %al
callq 0x33a0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xc2a8
jmp 0xc2aa
jmp 0xc2ac
movl -0x18(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)