// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
pushq %rax
movl %esi, %r14d
movq %rdi, %rbx
movq 0x10(%rdi), %rdi
callq 0x5667
testb %al, %al
je 0x6ca5
movl $0x5, (%rsp)
pushq $0x6
popq %rdx
pushq $0xc
popq %rcx
pushq $0x10
popq %r8
pushq $0x2
jmp 0x6ce1
movq 0x10(%rbx), %rdi
callq 0x56c5
testb %al, %al
je 0x6cc4
andl $0x0, (%rsp)
pushq $0x7
popq %rdx
pushq $0xd
popq %rcx
pushq $0x11
popq %r8
pushq $0x3
jmp 0x6ce1
movq 0x10(%rbx), %rdi
callq 0x5723
testb %al, %al
je 0x6cf9
andl $0x0, (%rsp)
pushq $0x8
popq %rdx
pushq $0xe
popq %rcx
pushq $0x12
popq %r8
pushq $0x4
popq %r9
movq %rbx, %rdi
movl %r14d, %esi
callq 0x6b80
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rbx), %r15
leaq 0xcb0d(%rip), %rsi      # 0x13811
movq %r15, %rdi
callq 0x32a0
testl %eax, %eax
je 0x6d6c
leaq 0x5fe4(%rip), %rsi      # 0xccfb
movq %r15, %rdi
callq 0x32a0
testl %eax, %eax
je 0x6db0
leaq 0x5711(%rip), %rsi      # 0xc43f
movq %r15, %rdi
callq 0x32a0
movq 0x18(%rbx), %rcx
testl %eax, %eax
je 0x6de7
testq %rcx, %rcx
je 0x6df9
movzbl (%rcx), %eax
cmpl $0x26, %eax
je 0x6e02
cmpl $0x2a, %eax
jne 0x6e3e
movl $0xb, 0x20(%rbx)
jmp 0x6e09
cmpq $0x0, 0x18(%rbx)
jne 0x6e10
movl $0x13, 0x20(%rbx)
movq 0x28(%rbx), %rcx
xorl %eax, %eax
cmpb $0x27, (%rcx)
jne 0x6cee
leaq 0x1(%rcx), %rdx
movb $0x27, %sil
cmpb $0x27, %sil
je 0x6da8
movzbl %sil, %edi
testl %edi, %edi
je 0x6ddf
movb %sil, (%rcx)
incq %rcx
movb (%rdx), %sil
incq %rdx
jmp 0x6d94
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x6dd6
cmpb $0x61, (%rax)
jne 0x6e82
movq 0x8(%rax), %rax
testq %rax, %rax
je 0x6dd6
cmpq $0x0, 0x10(%rax)
jne 0x6ee5
movl $0x9, 0x20(%rbx)
jmp 0x6e09
movb $0x0, (%rcx)
jmp 0x6cee
testq %rcx, %rcx
jne 0x6ead
movl $0xa, 0x20(%rbx)
jmp 0x6e09
movl $0x1, 0x20(%rbx)
jmp 0x6e09
movl $0xf, 0x20(%rbx)
xorl %eax, %eax
jmp 0x6cee
movq 0x141c1(%rip), %r15     # 0x1afd8
movq (%r15), %rdi
leaq 0x5d4b(%rip), %rsi      # 0xcb6c
movl %r14d, %edx
xorl %eax, %eax
callq 0x32b0
movq (%r15), %rdi
movq 0x28(%rbx), %rdx
leaq 0x5e9f(%rip), %rsi      # 0xccd8
jmp 0x6ed6
cmpl $0x61, %eax
je 0x6e4c
cmpl $0x72, %eax
jne 0x6f17
movq 0x14185(%rip), %r15     # 0x1afd8
movq (%r15), %rdi
leaq 0x5d0f(%rip), %rsi      # 0xcb6c
movl %r14d, %edx
xorl %eax, %eax
callq 0x32b0
movq (%r15), %rdi
movq 0x10(%rbx), %rcx
movq 0x28(%rbx), %rdx
leaq 0x5eef(%rip), %rsi      # 0xcd68
xorl %eax, %eax
callq 0x32b0
jmp 0x6edd
movq 0x1414f(%rip), %r15     # 0x1afd8
movq (%r15), %rdi
leaq 0x5cd9(%rip), %rsi      # 0xcb6c
movl %r14d, %edx
xorl %eax, %eax
callq 0x32b0
movq (%r15), %rdi
movq 0x28(%rbx), %rdx
leaq 0x5e58(%rip), %rsi      # 0xcd03
jmp 0x6ed6
movq 0x14124(%rip), %r15     # 0x1afd8
movq (%r15), %rdi
leaq 0x5cae(%rip), %rsi      # 0xcb6c
movl %r14d, %edx
xorl %eax, %eax
callq 0x32b0
movq (%r15), %rdi
movq 0x28(%rbx), %rdx
leaq 0x5e70(%rip), %rsi      # 0xcd46
xorl %eax, %eax
callq 0x32b0
pushq $0x1
popq %rax
jmp 0x6cee
movq 0x140ec(%rip), %rbx     # 0x1afd8
movq (%rbx), %rdi
leaq 0x5c76(%rip), %rsi      # 0xcb6c
movl %r14d, %edx
xorl %eax, %eax
callq 0x32b0
movq (%rbx), %rcx
leaq 0x5e1f(%rip), %rdi      # 0xcd29
pushq $0x1c
popq %rsi
pushq $0x1
popq %rdx
callq 0x33a0
jmp 0x6edd
leaq 0x6018(%rip), %rdi      # 0xcf36
leaq 0x5d63(%rip), %rsi      # 0xcc88
leaq 0x5e60(%rip), %rcx      # 0xcd8c
movl $0x107, %edx            # imm = 0x107
callq 0x3110