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

    int err = assign_tinfo(v, line);
    if (v->iospec == 'i')
        return err + typecheck_args(v->next, line);

    if (isdigit(v->name[0])) {
        fprintf(stderr, "Error (%d): ", line);
        fprintf(stderr, "Number %s cannot be output\n", v->name);
        ++err;
    }

    if ((v->tinfo == VT_obj || v->tinfo == VT_p_obj || v->tinfo == VT_r_obj) &&
        !is_mxarray_type(v->basetype)) {
        fprintf(stderr, "Error (%d): ", line);
        fprintf(stderr, "Object %s cannot be output\n", v->name);
        ++err;
    } else if ((v->tinfo == VT_array || 
                v->tinfo == VT_carray ||
                v->tinfo == VT_zarray ||
                v->tinfo == VT_rarray) && 
               v->iospec == 'o' && 
               !(v->qual && v->qual->args)) {
        fprintf(stderr, "Error (%d): ", line);
        fprintf(stderr, "Output array %s must have dims\n", v->name);
        ++err;
    } else if (v->tinfo == VT_rarray && v->iospec != 'o') {
        fprintf(stderr, "Error (%d): ", line);
        fprintf(stderr, "Array ref %s *must* be output\n", v->name);
        ++err;
    } else if (v->tinfo == VT_scalar) {
        fprintf(stderr, "Error (%d): ", line);
        fprintf(stderr, "Scalar %s cannot be output\n", v->name);
        ++err;
    } else if (v->tinfo == VT_const) {
        fprintf(stderr, "Error (%d): ", line);
        fprintf(stderr, "Constant %s cannot be output\n", v->name);
        ++err;
    } else if (v->tinfo == VT_string && 
               !(v->qual && v->qual->args)) {
        fprintf(stderr, "Error (%d): ", line);
        fprintf(stderr, "String %s cannot be output without size\n", v->name);
        ++err;
    } else if (v->tinfo == VT_mx && v->iospec == 'b') {
        fprintf(stderr, "Error (%d): ", line);
        fprintf(stderr, "mxArray %s cannot be used for inout\n", v->name);
        ++err;
    }
    return err + typecheck_args(v->next, line);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
cmpq $0x0, -0x10(%rbp)
jne 0xc2e2
movl $0x0, -0x4(%rbp)
jmp 0xc683
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0xbcb0
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x8(%rax), %eax
cmpl $0x69, %eax
jne 0xc323
movl -0x18(%rbp), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movl -0x14(%rbp), %esi
callq 0xc2c0
movl %eax, %ecx
movl -0x1c(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x4(%rbp)
jmp 0xc683
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movsbl (%rax), %edi
callq 0x31f0
cmpl $0x0, %eax
je 0xc37c
movq 0x18c99(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x8877(%rip), %rsi      # 0x14bc3
movb $0x0, %al
callq 0x33a0
movq 0x18c7e(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0x8b20(%rip), %rsi      # 0x14e8c
movb $0x0, %al
callq 0x33a0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x1, 0x20(%rax)
je 0xc39a
movq -0x10(%rbp), %rax
cmpl $0xb, 0x20(%rax)
je 0xc39a
movq -0x10(%rbp), %rax
cmpl $0xf, 0x20(%rax)
jne 0xc3f4
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x8290
testb $0x1, %al
jne 0xc3f4
movq 0x18c26(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x8804(%rip), %rsi      # 0x14bc3
movb $0x0, %al
callq 0x33a0
movq 0x18c0b(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0x8ac9(%rip), %rsi      # 0x14ea8
movb $0x0, %al
callq 0x33a0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xc663
movq -0x10(%rbp), %rax
cmpl $0x2, 0x20(%rax)
je 0xc41c
movq -0x10(%rbp), %rax
cmpl $0x3, 0x20(%rax)
je 0xc41c
movq -0x10(%rbp), %rax
cmpl $0x4, 0x20(%rax)
je 0xc41c
movq -0x10(%rbp), %rax
cmpl $0x5, 0x20(%rax)
jne 0xc48c
movq -0x10(%rbp), %rax
movsbl 0x8(%rax), %eax
cmpl $0x6f, %eax
jne 0xc48c
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0xc443
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
cmpq $0x0, 0x8(%rax)
jne 0xc48c
movq 0x18b8e(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x876c(%rip), %rsi      # 0x14bc3
movb $0x0, %al
callq 0x33a0
movq 0x18b73(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0x8a4d(%rip), %rsi      # 0x14ec4
movb $0x0, %al
callq 0x33a0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xc661
movq -0x10(%rbp), %rax
cmpl $0x5, 0x20(%rax)
jne 0xc4ec
movq -0x10(%rbp), %rax
movsbl 0x8(%rax), %eax
cmpl $0x6f, %eax
je 0xc4ec
movq 0x18b2e(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x870c(%rip), %rsi      # 0x14bc3
movb $0x0, %al
callq 0x33a0
movq 0x18b13(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0x8a0d(%rip), %rsi      # 0x14ee4
movb $0x0, %al
callq 0x33a0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xc65f
movq -0x10(%rbp), %rax
cmpl $0x6, 0x20(%rax)
jne 0xc53f
movq 0x18adb(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x86b9(%rip), %rsi      # 0x14bc3
movb $0x0, %al
callq 0x33a0
movq 0x18ac0(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0x89d9(%rip), %rsi      # 0x14f03
movb $0x0, %al
callq 0x33a0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xc65d
movq -0x10(%rbp), %rax
cmpl $0x13, 0x20(%rax)
jne 0xc592
movq 0x18a88(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x8666(%rip), %rsi      # 0x14bc3
movb $0x0, %al
callq 0x33a0
movq 0x18a6d(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0x89a2(%rip), %rsi      # 0x14f1f
movb $0x0, %al
callq 0x33a0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xc65b
movq -0x10(%rbp), %rax
cmpl $0x9, 0x20(%rax)
jne 0xc5fc
movq -0x10(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0xc5b6
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
cmpq $0x0, 0x8(%rax)
jne 0xc5fc
movq 0x18a1b(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x85f9(%rip), %rsi      # 0x14bc3
movb $0x0, %al
callq 0x33a0
movq 0x18a00(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0x8953(%rip), %rsi      # 0x14f3d
movb $0x0, %al
callq 0x33a0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xc659
movq -0x10(%rbp), %rax
cmpl $0xa, 0x20(%rax)
jne 0xc657
movq -0x10(%rbp), %rax
movsbl 0x8(%rax), %eax
cmpl $0x62, %eax
jne 0xc657
movq 0x189be(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movl -0x14(%rbp), %edx
leaq 0x859c(%rip), %rsi      # 0x14bc3
movb $0x0, %al
callq 0x33a0
movq 0x189a3(%rip), %rax     # 0x24fd8
movq (%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdx
leaq 0x891f(%rip), %rsi      # 0x14f66
movb $0x0, %al
callq 0x33a0
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0xc659
jmp 0xc65b
jmp 0xc65d
jmp 0xc65f
jmp 0xc661
jmp 0xc663
movl -0x18(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
movl -0x14(%rbp), %esi
callq 0xc2c0
movl %eax, %ecx
movl -0x20(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)