// File: /workspace/github_cpp_makefile_star2_O1/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 0x5f11
testb %al, %al
je 0x7654
movl $0x5, (%rsp)
movq %rbx, %rdi
movl %r14d, %esi
movl $0x6, %edx
movl $0xc, %ecx
movl $0x10, %r8d
movl $0x2, %r9d
jmp 0x76b8
leaq 0x10(%rbx), %r15
movq (%r15), %rdi
callq 0x5f90
testb %al, %al
je 0x7689
movl $0x0, (%rsp)
movq %rbx, %rdi
movl %r14d, %esi
movl $0x7, %edx
movl $0xd, %ecx
movl $0x11, %r8d
movl $0x3, %r9d
jmp 0x76b8
movq (%r15), %rdi
callq 0x600f
testb %al, %al
je 0x76ca
movl $0x0, (%rsp)
movq %rbx, %rdi
movl %r14d, %esi
movl $0x8, %edx
movl $0xe, %ecx
movl $0x12, %r8d
movl $0x4, %r9d
callq 0x753c
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq (%r15), %r12
leaq 0xd15d(%rip), %rsi      # 0x14831
movq %r12, %rdi
callq 0x3260
testl %eax, %eax
je 0x773c
leaq 0x6634(%rip), %rsi      # 0xdd1b
movq %r12, %rdi
callq 0x3260
testl %eax, %eax
je 0x7777
leaq 0x5d41(%rip), %rsi      # 0xd43f
movq %r12, %rdi
callq 0x3260
movq 0x18(%rbx), %rcx
testl %eax, %eax
je 0x77ab
testq %rcx, %rcx
je 0x77b9
movzbl (%rcx), %eax
cmpl $0x29, %eax
jle 0x77c2
cmpl $0x2a, %eax
jne 0x77e2
movl $0xb, 0x20(%rbx)
jmp 0x77ce
cmpq $0x0, 0x18(%rbx)
jne 0x77d5
movl $0x13, 0x20(%rbx)
movq 0x28(%rbx), %rcx
xorl %eax, %eax
cmpb $0x27, (%rcx)
jne 0x76bd
movq %rcx, %rdx
movzbl (%rdx), %esi
cmpl $0x27, %esi
je 0x7772
testl %esi, %esi
je 0x77a3
movb %sil, (%rcx)
incq %rcx
incq %rdx
jmp 0x7760
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x779a
cmpb $0x61, (%rax)
jne 0x77fc
testq %rax, %rax
je 0x779a
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x779a
cmpq $0x0, 0x10(%rax)
jne 0x7816
movl $0x9, 0x20(%rbx)
jmp 0x77ce
movb $0x0, (%rcx)
jmp 0x76bd
testq %rcx, %rcx
jne 0x7809
movl $0xa, 0x20(%rbx)
jmp 0x77ce
movl $0x1, 0x20(%rbx)
jmp 0x77ce
cmpl $0x26, %eax
jne 0x7828
movl $0xf, 0x20(%rbx)
xorl %eax, %eax
jmp 0x76bd
movl %r14d, %edi
movq %rbx, %rsi
callq 0x3773
jmp 0x781e
cmpl $0x61, %eax
je 0x77ec
cmpl $0x72, %eax
jne 0x7828
movl %r14d, %edi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x3672
jmp 0x781e
movl %r14d, %edi
movq %rbx, %rsi
callq 0x36fb
jmp 0x781e
movl %r14d, %edi
movq %rbx, %rsi
callq 0x36be
jmp 0x781e
movl %r14d, %edi
callq 0x3738
movl $0x1, %eax
jmp 0x76bd
leaq 0x6727(%rip), %rdi      # 0xdf56
leaq 0x6472(%rip), %rsi      # 0xdca8
leaq 0x656f(%rip), %rcx      # 0xddac
movl $0x107, %edx            # imm = 0x107
callq 0x3100