// File: /workspace/github_cpp_makefile_star2_O3/zgimbutas[P]mwrap/src/mwrap-typecheck.cc
// Function: assign_tinfo(Var*, int)
int assign_tinfo(Var* v, int line)
{
    if (is_scalar_type(v->basetype)) {

        return assign_scalar_tinfo(v, line, VT_scalar, VT_p_scalar, 
                                   VT_r_scalar, VT_array, VT_rarray);

    } else if (is_cscalar_type(v->basetype)) {

        return assign_scalar_tinfo(v, line, VT_cscalar, VT_p_cscalar, 
                                   VT_r_cscalar, VT_carray, VT_unk);

    } else if (is_zscalar_type(v->basetype)) {

        return assign_scalar_tinfo(v, line, VT_zscalar, VT_p_zscalar, 
                                   VT_r_zscalar, VT_zarray, VT_unk);

    } else if (strcmp(v->basetype, "const") == 0) {

        if (v->qual) {
            fprintf(stderr, "Error (%d): ", line);
            fprintf(stderr, "Constant %s cannot have modifiers\n", v->name);
            return 1;
        }
        v->tinfo = VT_const;
        if (v->name[0] == '\'') {
            char* p_out = v->name;
            char* p_in  = v->name;
            for (; *p_in; ++p_in) {
                if (*p_in != '\'')
                    *p_out++ = *p_in;
            }
            *p_out++ = 0;
        }

    } else if (strcmp(v->basetype, "cstring") == 0) {

        // String type
        if (v->qual && v->qual->qual != 'a') {
            fprintf(stderr, "Error (%d): ", line);
            fprintf(stderr, "String type %s cannot have modifiers\n",
                    v->name);
            return 1;
        }
        if (v->qual && v->qual->args && v->qual->args->next) {
            fprintf(stderr, "Error (%d): ", line);
            fprintf(stderr, "Strings are one dimensional\n");
            return 1;
        }
        v->tinfo = VT_string;

    } else if (strcmp(v->basetype, "mxArray") == 0) {

        // MATLAB intrinsic type
        if (v->qual) {
            fprintf(stderr, "Error (%d): ", line);
            fprintf(stderr, "mxArray %s cannot have modifiers\n",
                    v->name);
            return 1;
        }
        v->tinfo = VT_mx;

    } else {

        // Object type
        if (!v->qual)
            v->tinfo = VT_obj;
        else if (v->qual->qual == '*')
            v->tinfo = VT_p_obj;
        else if (v->qual->qual == '&')
            v->tinfo = VT_r_obj;
        else if (v->qual->qual == 'a' || v->qual->qual == 'r') {
            fprintf(stderr, "Error (%d): ", line);
            fprintf(stderr, "%s cannot be an array of object %s\n",
                    v->name, v->basetype);
            return 1;
        } else
            assert(0);

    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movl %esi, %r14d
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
callq 0x5df2
testb %al, %al
je 0x7580
movl $0x5, (%rsp)
movq %rbx, %rdi
movl %r14d, %esi
movl $0x6, %edx
movl $0xc, %ecx
movl $0x10, %r8d
movl $0x2, %r9d
jmp 0x75e4
leaq 0x10(%rbx), %r15
movq (%r15), %rdi
callq 0x5e71
testb %al, %al
je 0x75b5
movl $0x0, (%rsp)
movq %rbx, %rdi
movl %r14d, %esi
movl $0x7, %edx
movl $0xd, %ecx
movl $0x11, %r8d
movl $0x3, %r9d
jmp 0x75e4
movq (%r15), %rdi
callq 0x5ef0
testb %al, %al
je 0x75f6
movl $0x0, (%rsp)
movq %rbx, %rdi
movl %r14d, %esi
movl $0x8, %edx
movl $0xe, %ecx
movl $0x12, %r8d
movl $0x4, %r9d
callq 0x7468
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq (%r15), %r12
leaq 0xd211(%rip), %rsi      # 0x14811
movq %r12, %rdi
callq 0x3260
testl %eax, %eax
je 0x7668
leaq 0x66e8(%rip), %rsi      # 0xdcfb
movq %r12, %rdi
callq 0x3260
testl %eax, %eax
je 0x76ac
leaq 0x5e15(%rip), %rsi      # 0xd43f
movq %r12, %rdi
callq 0x3260
movq 0x18(%rbx), %rcx
testl %eax, %eax
je 0x76db
testq %rcx, %rcx
je 0x76e9
movzbl (%rcx), %eax
cmpl $0x29, %eax
jle 0x76f2
cmpl $0x2a, %eax
jne 0x7712
movl $0xb, 0x20(%rbx)
jmp 0x76fe
cmpq $0x0, 0x18(%rbx)
jne 0x7705
movl $0x13, 0x20(%rbx)
movq 0x28(%rbx), %rcx
xorl %eax, %eax
cmpb $0x27, (%rcx)
jne 0x75e9
leaq 0x1(%rcx), %rdx
movb $0x27, %sil
cmpb $0x27, %sil
je 0x76a4
movzbl %sil, %edi
testl %edi, %edi
je 0x76d3
movb %sil, (%rcx)
incq %rcx
movb (%rdx), %sil
incq %rdx
jmp 0x7690
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x76ca
cmpb $0x61, (%rax)
jne 0x772c
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x76ca
cmpq $0x0, 0x10(%rax)
jne 0x7746
movl $0x9, 0x20(%rbx)
jmp 0x76fe
movb $0x0, (%rcx)
jmp 0x75e9
testq %rcx, %rcx
jne 0x7739
movl $0xa, 0x20(%rbx)
jmp 0x76fe
movl $0x1, 0x20(%rbx)
jmp 0x76fe
cmpl $0x26, %eax
jne 0x7758
movl $0xf, 0x20(%rbx)
xorl %eax, %eax
jmp 0x75e9
movl %r14d, %edi
movq %rbx, %rsi
callq 0x3773
jmp 0x774e
cmpl $0x61, %eax
je 0x771c
cmpl $0x72, %eax
jne 0x7758
movl %r14d, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x3672
jmp 0x774e
movl %r14d, %edi
movq %rbx, %rsi
callq 0x36fb
jmp 0x774e
movl %r14d, %edi
movq %rbx, %rsi
callq 0x36be
jmp 0x774e
movl %r14d, %edi
callq 0x3738
movl $0x1, %eax
jmp 0x75e9
leaq 0x67d7(%rip), %rdi      # 0xdf36
leaq 0x6522(%rip), %rsi      # 0xdc88
leaq 0x661f(%rip), %rcx      # 0xdd8c
movl $0x107, %edx            # imm = 0x107
callq 0x3100