// File: /workspace/github_cpp_makefile_star2_O2/zgimbutas[P]mwrap/src/mwrap-cgen.cc
// Function: mex_marshal_array(_IO_FILE*, Var*)
void mex_marshal_array(FILE* fp, Var* v)
{
    if (v->devicespec != 'g'){
    Expr* e = v->qual->args;
    char namebuf[128];
    const char* mtype = complex_tinfo(v) ? "mxCOMPLEX" : "mxREAL";
    const char* ws = "    ";

    if (v->tinfo == VT_rarray) {
        ws = "        ";
        fprintf(fp, "    if (out%d_ == NULL) {\n", v->output_label);
        fprintf(fp, "        plhs[%d] = mxCreateDoubleMatrix(0,0, mxREAL);\n",
                v->output_label);
        fprintf(fp, "    } else {\n");
    }

    if (!e) {

        // No dimension info -- must be an inout array
        if (strcmp(v->basetype, "float") == 0 || strcmp(v->basetype, "fcomplex") == 0)
	  {
        fprintf(fp, "%splhs[%d] = mxCreateNumericMatrix("
                "mxGetM(prhs[%d]), mxGetN(prhs[%d]), mxSINGLE_CLASS, %s);\n", ws,
                v->output_label, v->input_label, v->input_label, mtype);
        fprintf(fp, "%smxWrapCopy_single_%s(plhs[%d], in%d_, ", ws,
                v->basetype, v->output_label, v->input_label);
	  }
	else
	  {
        fprintf(fp, "%splhs[%d] = mxCreateDoubleMatrix("
                "mxGetM(prhs[%d]), mxGetN(prhs[%d]), %s);\n", ws,
                v->output_label, v->input_label, v->input_label, mtype);
        fprintf(fp, "%smxWrapCopy_%s(plhs[%d], in%d_, ", ws,
                v->basetype, v->output_label, v->input_label);
	  }
        fprintf(fp, "mxGetM(prhs[%d])*mxGetN(prhs[%d])",
                v->input_label, v->input_label);
        fprintf(fp, ");\n");

    } else if (!(e->next)) {

        // Only size given
        if (strcmp(v->basetype, "float") == 0 || strcmp(v->basetype, "fcomplex") == 0)
	  {
        fprintf(fp, "%splhs[%d] = mxCreateNumericMatrix(dim%d_, 1, mxSINGLE_CLASS, %s);\n", ws,
                v->output_label, e->input_label, mtype);
        fprintf(fp, "%smxWrapCopy_single_%s(plhs[%d], %s, ", ws,
                v->basetype, v->output_label, vname(v, namebuf));
	  }
	else
	  {
        fprintf(fp, "%splhs[%d] = mxCreateDoubleMatrix(dim%d_, 1, %s);\n", ws,
                v->output_label, e->input_label, mtype);
        fprintf(fp, "%smxWrapCopy_%s(plhs[%d], %s, ", ws,
                v->basetype, v->output_label, vname(v, namebuf));
	  }
        fprintf(fp, "dim%d_",
                e->input_label);
        fprintf(fp, ");\n");

    } else if (!(e->next->next)) {

        // Two dimensions given
        if (strcmp(v->basetype, "float") == 0 || strcmp(v->basetype, "fcomplex") == 0)
	  {
        fprintf(fp, "%splhs[%d] = mxCreateNumericMatrix("
                "dim%d_, dim%d_, mxSINGLE_CLASS, %s);\n", ws,
                v->output_label, e->input_label, e->next->input_label, mtype);
        fprintf(fp, "%smxWrapCopy_single_%s(plhs[%d], %s, ", ws,
                v->basetype, v->output_label, vname(v, namebuf));
	  }
	else
	  {
        fprintf(fp, "%splhs[%d] = mxCreateDoubleMatrix("
                "dim%d_, dim%d_, %s);\n", ws,
                v->output_label, e->input_label, e->next->input_label, mtype);
        fprintf(fp, "%smxWrapCopy_%s(plhs[%d], %s, ", ws,
                v->basetype, v->output_label, vname(v, namebuf));
	  }
        fprintf(fp, "dim%d_*dim%d_",
                e->input_label, e->next->input_label);
        fprintf(fp, ");\n");

    } else {

        // Three or more dimensions given -- punt and make it 1D
        if (strcmp(v->basetype, "float") == 0 || strcmp(v->basetype, "fcomplex") == 0)
	  {
        fprintf(fp, "%splhs[%d] = mxCreateNumericMatrix(", ws,
                v->output_label);
        mex_alloc_size(fp, e);
        fprintf(fp, ", 1, mxSINGLE_CLASS, %s);\n", mtype);
        fprintf(fp, "%smxWrapCopy_single_%s(plhs[%d], %s, ", ws,
                v->basetype, v->output_label, vname(v, namebuf));
	  }
	else
	  {
        fprintf(fp, "%splhs[%d] = mxCreateDoubleMatrix(", ws,
                v->output_label);
        mex_alloc_size(fp, e);
        fprintf(fp, ", 1, %s);\n", mtype);
        fprintf(fp, "%smxWrapCopy_%s(plhs[%d], %s, ", ws,
                v->basetype, v->output_label, vname(v, namebuf));
	  }
        mex_alloc_size(fp, e);
        fprintf(fp, ");\n");

    }

    if (v->tinfo == VT_rarray) {
        fprintf(fp, "    }\n");
    }
    }

    if (v->devicespec == 'g'){
        if (v->iospec == 'b') {
            fprintf(fp, "    plhs[%d] = prhs[%d];\n", v->output_label, v->input_label);
        }
        if (v->iospec == 'o') {
            fprintf(fp, "    plhs[%d] = mxGPUCreateMxArrayOnGPU(mxGPUArray_out%d_);\n", v->output_label, v->output_label);
        }
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %r14
movq %rdi, %rbx
cmpb $0x67, 0x9(%rsi)
je 0x9a7d
movq 0x18(%r14), %rax
movl 0x20(%r14), %ecx
leal -0x3(%rcx), %edx
cmpl $0xf, %edx
ja 0x9665
movl %edx, %edx
leaq 0x116c1(%rip), %rsi     # 0x1ad20
movq (%rsi,%rdx,8), %r13
jmp 0x966c
leaq 0xb143(%rip), %r13      # 0x147af
movq 0x8(%rax), %r15
cmpl $0x5, %ecx
jne 0x96bd
movl 0x4(%r14), %edx
leaq 0xb451(%rip), %rsi      # 0x14ad1
movq %rbx, %rdi
xorl %eax, %eax
callq 0x32b0
movl 0x4(%r14), %edx
leaq 0xb457(%rip), %rsi      # 0x14aec
movq %rbx, %rdi
xorl %eax, %eax
callq 0x32b0
leaq 0xb47d(%rip), %rdi      # 0x14b23
pushq $0xd
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x33a0
leaq 0xb40d(%rip), %r12      # 0x14ac8
jmp 0x96c4
leaq 0xb2ad(%rip), %r12      # 0x14971
testq %r15, %r15
je 0x976b
movq %r13, -0x30(%rbp)
movq %r15, -0x38(%rbp)
movq 0x10(%r15), %r15
testq %r15, %r15
je 0x97c3
movq %r12, -0x48(%rbp)
movq 0x10(%r15), %r12
movq 0x10(%r14), %r13
leaq 0x3392(%rip), %rsi      # 0xca87
movq %r13, %rdi
callq 0x32a0
testq %r12, %r12
je 0x981c
leaq 0xb57e(%rip), %r12      # 0x14c8b
leaq 0xb55c(%rip), %rcx      # 0x14c70
movq %rcx, -0x40(%rbp)
leaq 0xb673(%rip), %rsi      # 0x14d92
testl %eax, %eax
movq -0x48(%rbp), %r15
je 0x98ba
leaq 0x2d04(%rip), %rsi      # 0xc436
movq %r13, %rdi
callq 0x32a0
leaq 0xb651(%rip), %rsi      # 0x14d92
testl %eax, %eax
movq -0x38(%rbp), %r13
je 0x98be
leaq 0xb590(%rip), %r12      # 0x14ce4
leaq 0xb57e(%rip), %rax      # 0x14cd9
movq %rax, -0x40(%rbp)
leaq 0xb650(%rip), %rsi      # 0x14db6
jmp 0x98be
movq %r12, %r15
movq 0x10(%r14), %r12
leaq 0x330e(%rip), %rsi      # 0xca87
movq %r12, %rdi
callq 0x32a0
testl %eax, %eax
je 0x9862
leaq 0x2ca6(%rip), %rsi      # 0xc436
movq %r12, %rdi
callq 0x32a0
testl %eax, %eax
leaq 0xb390(%rip), %rax      # 0x14b31
leaq 0xb40f(%rip), %rsi      # 0x14bb7
cmoveq %rax, %rsi
leaq 0xb3db(%rip), %rax      # 0x14b8e
leaq 0xb449(%rip), %r12      # 0x14c03
cmoveq %rax, %r12
jmp 0x9870
movq 0x10(%r14), %r13
leaq 0x32b9(%rip), %rsi      # 0xca87
movq %r13, %rdi
callq 0x32a0
testl %eax, %eax
je 0x9936
leaq 0x2c51(%rip), %rsi      # 0xc436
movq %r13, %rdi
callq 0x32a0
testl %eax, %eax
leaq 0xb451(%rip), %rax      # 0x14c47
leaq 0xb4b4(%rip), %rsi      # 0x14cb1
cmoveq %rax, %rsi
leaq 0xb483(%rip), %rax      # 0x14c8b
leaq 0xb4d5(%rip), %rcx      # 0x14ce4
cmoveq %rax, %rcx
movq %rcx, -0x48(%rbp)
jmp 0x9948
testl %eax, %eax
je 0x99b5
leaq 0x2c0b(%rip), %rsi      # 0xc436
movq %r13, %rdi
callq 0x32a0
testl %eax, %eax
leaq 0xb4c7(%rip), %rax      # 0x14d03
leaq 0xb509(%rip), %rsi      # 0x14d4c
cmoveq %rax, %rsi
leaq 0xb43d(%rip), %rax      # 0x14c8b
leaq 0xb48f(%rip), %rcx      # 0x14ce4
cmoveq %rax, %rcx
movq %rcx, -0x40(%rbp)
jmp 0x99c7
leaq 0xb325(%rip), %r12      # 0x14b8e
leaq 0xb2c1(%rip), %rsi      # 0x14b31
movl (%r14), %r8d
movl 0x4(%r14), %ecx
movq %r13, (%rsp)
movq %rbx, %rdi
movq %r15, %rdx
movl %r8d, %r9d
xorl %eax, %eax
callq 0x32b0
movq 0x10(%r14), %rcx
movl (%r14), %r9d
movl 0x4(%r14), %r8d
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x32b0
movl (%r14), %ecx
leaq 0xb375(%rip), %rsi      # 0x14c25
movq %rbx, %rdi
movl %ecx, %edx
jmp 0x9a3e
movq -0x38(%rbp), %r13
movl 0x4(%r14), %ecx
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x32b0
movq %rbx, %rdi
movq %r13, %rsi
callq 0x8aa8
movq %rbx, %rdi
movq -0x40(%rbp), %rsi
movq -0x30(%rbp), %rdx
xorl %eax, %eax
callq 0x32b0
movq 0x10(%r14), %rax
movq %rax, -0x30(%rbp)
movl 0x4(%r14), %r13d
leaq -0xd0(%rbp), %rsi
movq %r14, %rdi
callq 0x769c
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq -0x30(%rbp), %rcx
movl %r13d, %r8d
leaq -0xd0(%rbp), %r9
xorl %eax, %eax
callq 0x32b0
movq %rbx, %rdi
movq -0x38(%rbp), %rsi
callq 0x8aa8
jmp 0x9a45
leaq 0xb34e(%rip), %rax      # 0x14c8b
movq %rax, -0x48(%rbp)
leaq 0xb2ff(%rip), %rsi      # 0x14c47
movq -0x38(%rbp), %rax
movl 0x4(%r14), %ecx
movl (%rax), %r8d
movq %rbx, %rdi
movq %r12, %rdx
movq -0x30(%rbp), %r9
xorl %eax, %eax
callq 0x32b0
movq 0x10(%r14), %r15
movl 0x4(%r14), %r13d
leaq -0xd0(%rbp), %rsi
movq %r14, %rdi
callq 0x769c
movq %rbx, %rdi
movq -0x48(%rbp), %rsi
movq %r12, %rdx
movq %r15, %rcx
movl %r13d, %r8d
leaq -0xd0(%rbp), %r9
xorl %eax, %eax
callq 0x32b0
movq -0x38(%rbp), %rax
movl (%rax), %edx
leaq 0xb3e5(%rip), %rsi      # 0x14d8b
movq %rbx, %rdi
xorl %eax, %eax
callq 0x32b0
jmp 0x9a45
leaq 0xb2cf(%rip), %rax      # 0x14c8b
movq %rax, -0x40(%rbp)
leaq 0xb33c(%rip), %rsi      # 0x14d03
movl 0x4(%r14), %ecx
movq -0x38(%rbp), %r12
movl (%r12), %r8d
movl (%r15), %r9d
movq -0x30(%rbp), %rax
movq %rax, (%rsp)
movq %rbx, %rdi
movq -0x48(%rbp), %r15
movq %r15, %rdx
xorl %eax, %eax
callq 0x32b0
movq 0x10(%r14), %rax
movq %rax, -0x30(%rbp)
movl 0x4(%r14), %r13d
leaq -0xd0(%rbp), %rsi
movq %r14, %rdi
callq 0x769c
movq %rbx, %rdi
movq -0x40(%rbp), %rsi
movq %r15, %rdx
movq -0x30(%rbp), %rcx
movl %r13d, %r8d
leaq -0xd0(%rbp), %r9
xorl %eax, %eax
callq 0x32b0
movl (%r12), %edx
movq 0x10(%r12), %rax
movl (%rax), %ecx
leaq 0xb349(%rip), %rsi      # 0x14d84
movq %rbx, %rdi
xorl %eax, %eax
callq 0x32b0
leaq 0xbeaf(%rip), %rdi      # 0x158fb
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x33a0
cmpl $0x5, 0x20(%r14)
jne 0x9a76
leaq 0xaef8(%rip), %rdi      # 0x14960
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x33a0
cmpb $0x67, 0x9(%r14)
jne 0x9abc
movb 0x8(%r14), %al
cmpb $0x62, %al
jne 0x9aa1
movl (%r14), %ecx
movl 0x4(%r14), %edx
leaq 0xb346(%rip), %rsi      # 0x14dd9
movq %rbx, %rdi
xorl %eax, %eax
callq 0x32b0
movb 0x8(%r14), %al
cmpb $0x6f, %al
jne 0x9abc
movl 0x4(%r14), %ecx
leaq 0xb343(%rip), %rsi      # 0x14df3
movq %rbx, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x32b0
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq