// File: /workspace/github_cpp_makefile_star2_O1/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 0xa715
movq 0x18(%r14), %rax
movl 0x20(%r14), %ecx
leal -0x3(%rcx), %edx
cmpl $0xf, %edx
ja 0xa2f8
movl %edx, %edx
leaq 0x11a2e(%rip), %rsi     # 0x1bd20
movq (%rsi,%rdx,8), %r13
jmp 0xa2ff
leaq 0xb4d0(%rip), %r13      # 0x157cf
movq 0x8(%rax), %r15
cmpl $0x5, %ecx
jne 0xa354
movl 0x4(%r14), %edx
leaq 0xb7de(%rip), %rsi      # 0x15af1
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
movl 0x4(%r14), %edx
leaq 0xb7e4(%rip), %rsi      # 0x15b0c
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
leaq 0xb80a(%rip), %rdi      # 0x15b43
movl $0xd, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
leaq 0xb796(%rip), %r12      # 0x15ae8
jmp 0xa35b
leaq 0xb636(%rip), %r12      # 0x15991
testq %r15, %r15
je 0xa402
movq %r13, -0x30(%rbp)
movq %r15, -0x38(%rbp)
movq 0x10(%r15), %r15
testq %r15, %r15
je 0xa45a
movq %r12, -0x48(%rbp)
movq 0x10(%r15), %r12
movq 0x10(%r14), %r13
leaq 0x372b(%rip), %rsi      # 0xdab7
movq %r13, %rdi
callq 0x3260
testq %r12, %r12
je 0xa4b3
leaq 0xb907(%rip), %r12      # 0x15cab
leaq 0xb8e5(%rip), %rcx      # 0x15c90
movq %rcx, -0x40(%rbp)
leaq 0xb9fc(%rip), %rsi      # 0x15db2
testl %eax, %eax
movq -0x48(%rbp), %r15
je 0xa551
leaq 0x306d(%rip), %rsi      # 0xd436
movq %r13, %rdi
callq 0x3260
leaq 0xb9da(%rip), %rsi      # 0x15db2
testl %eax, %eax
movq -0x38(%rbp), %r13
je 0xa555
leaq 0xb919(%rip), %r12      # 0x15d04
leaq 0xb907(%rip), %rax      # 0x15cf9
movq %rax, -0x40(%rbp)
leaq 0xb9d9(%rip), %rsi      # 0x15dd6
jmp 0xa555
movq %r12, %r15
movq 0x10(%r14), %r12
leaq 0x36a7(%rip), %rsi      # 0xdab7
movq %r12, %rdi
callq 0x3260
testl %eax, %eax
je 0xa4f9
leaq 0x300f(%rip), %rsi      # 0xd436
movq %r12, %rdi
callq 0x3260
testl %eax, %eax
leaq 0xb719(%rip), %rax      # 0x15b51
leaq 0xb798(%rip), %rsi      # 0x15bd7
cmoveq %rax, %rsi
leaq 0xb764(%rip), %rax      # 0x15bae
leaq 0xb7d2(%rip), %r12      # 0x15c23
cmoveq %rax, %r12
jmp 0xa507
movq 0x10(%r14), %r13
leaq 0x3652(%rip), %rsi      # 0xdab7
movq %r13, %rdi
callq 0x3260
testl %eax, %eax
je 0xa5cd
leaq 0x2fba(%rip), %rsi      # 0xd436
movq %r13, %rdi
callq 0x3260
testl %eax, %eax
leaq 0xb7da(%rip), %rax      # 0x15c67
leaq 0xb83d(%rip), %rsi      # 0x15cd1
cmoveq %rax, %rsi
leaq 0xb80c(%rip), %rax      # 0x15cab
leaq 0xb85e(%rip), %rcx      # 0x15d04
cmoveq %rax, %rcx
movq %rcx, -0x48(%rbp)
jmp 0xa5df
testl %eax, %eax
je 0xa64c
leaq 0x2f74(%rip), %rsi      # 0xd436
movq %r13, %rdi
callq 0x3260
testl %eax, %eax
leaq 0xb850(%rip), %rax      # 0x15d23
leaq 0xb892(%rip), %rsi      # 0x15d6c
cmoveq %rax, %rsi
leaq 0xb7c6(%rip), %rax      # 0x15cab
leaq 0xb818(%rip), %rcx      # 0x15d04
cmoveq %rax, %rcx
movq %rcx, -0x40(%rbp)
jmp 0xa65e
leaq 0xb6ae(%rip), %r12      # 0x15bae
leaq 0xb64a(%rip), %rsi      # 0x15b51
movl (%r14), %r8d
movl 0x4(%r14), %ecx
movq %r13, (%rsp)
movq %rbx, %rdi
movq %r15, %rdx
movl %r8d, %r9d
xorl %eax, %eax
callq 0x3270
movq 0x10(%r14), %rcx
movl (%r14), %r9d
movl 0x4(%r14), %r8d
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
xorl %eax, %eax
callq 0x3270
movl (%r14), %ecx
leaq 0xb6fe(%rip), %rsi      # 0x15c45
movq %rbx, %rdi
movl %ecx, %edx
jmp 0xa6d5
movq -0x38(%rbp), %r13
movl 0x4(%r14), %ecx
movq %rbx, %rdi
movq %r15, %rdx
xorl %eax, %eax
callq 0x3270
movq %rbx, %rdi
movq %r13, %rsi
callq 0x96f7
movq %rbx, %rdi
movq -0x40(%rbp), %rsi
movq -0x30(%rbp), %rdx
xorl %eax, %eax
callq 0x3270
movq 0x10(%r14), %rax
movq %rax, -0x30(%rbp)
movl 0x4(%r14), %r13d
leaq -0xd0(%rbp), %rsi
movq %r14, %rdi
callq 0x7fe0
movq %rbx, %rdi
movq %r12, %rsi
movq %r15, %rdx
movq -0x30(%rbp), %rcx
movl %r13d, %r8d
leaq -0xd0(%rbp), %r9
xorl %eax, %eax
callq 0x3270
movq %rbx, %rdi
movq -0x38(%rbp), %rsi
callq 0x96f7
jmp 0xa6dc
leaq 0xb6d7(%rip), %rax      # 0x15cab
movq %rax, -0x48(%rbp)
leaq 0xb688(%rip), %rsi      # 0x15c67
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 0x3270
movq 0x10(%r14), %r15
movl 0x4(%r14), %r13d
leaq -0xd0(%rbp), %rsi
movq %r14, %rdi
callq 0x7fe0
movq %rbx, %rdi
movq -0x48(%rbp), %rsi
movq %r12, %rdx
movq %r15, %rcx
movl %r13d, %r8d
leaq -0xd0(%rbp), %r9
xorl %eax, %eax
callq 0x3270
movq -0x38(%rbp), %rax
movl (%rax), %edx
leaq 0xb76e(%rip), %rsi      # 0x15dab
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
jmp 0xa6dc
leaq 0xb658(%rip), %rax      # 0x15cab
movq %rax, -0x40(%rbp)
leaq 0xb6c5(%rip), %rsi      # 0x15d23
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 0x3270
movq 0x10(%r14), %rax
movq %rax, -0x30(%rbp)
movl 0x4(%r14), %r13d
leaq -0xd0(%rbp), %rsi
movq %r14, %rdi
callq 0x7fe0
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 0x3270
movl (%r12), %edx
movq 0x10(%r12), %rax
movl (%rax), %ecx
leaq 0xb6d2(%rip), %rsi      # 0x15da4
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
leaq 0xc238(%rip), %rdi      # 0x1691b
movl $0x3, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
cmpl $0x5, 0x20(%r14)
jne 0xa715
leaq 0xb27d(%rip), %rdi      # 0x15980
movl $0x6, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
cmpb $0x67, 0x9(%r14)
jne 0xa759
cmpb $0x62, 0x8(%r14)
jne 0xa73b
movl (%r14), %ecx
movl 0x4(%r14), %edx
leaq 0xb6c8(%rip), %rsi      # 0x15df9
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
cmpb $0x6f, 0x8(%r14)
jne 0xa759
movl 0x4(%r14), %ecx
leaq 0xb6c6(%rip), %rsi      # 0x15e13
movq %rbx, %rdi
movl %ecx, %edx
xorl %eax, %eax
callq 0x3270
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq