// File: /workspace/github_cpp_makefile_star2_O3/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 0xa5ed
movq 0x18(%r14), %rax
movl 0x20(%r14), %ecx
leal -0x3(%rcx), %edx
cmpl $0xf, %edx
ja 0xa1c9
movl %edx, %edx
leaq 0x11b5d(%rip), %rsi     # 0x1bd20
movq (%rsi,%rdx,8), %r13
jmp 0xa1d0
leaq 0xb5df(%rip), %r13      # 0x157af
movq 0x8(%rax), %r15
cmpl $0x5, %ecx
jne 0xa225
movl 0x4(%r14), %edx
leaq 0xb8ed(%rip), %rsi      # 0x15ad1
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
movl 0x4(%r14), %edx
leaq 0xb8f3(%rip), %rsi      # 0x15aec
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
leaq 0xb919(%rip), %rdi      # 0x15b23
movl $0xd, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
leaq 0xb8a5(%rip), %r12      # 0x15ac8
jmp 0xa22c
leaq 0xb745(%rip), %r12      # 0x15971
testq %r15, %r15
je 0xa2d3
movq %r13, -0x30(%rbp)
movq %r15, -0x38(%rbp)
movq 0x10(%r15), %r15
testq %r15, %r15
je 0xa32b
movq %r12, -0x48(%rbp)
movq 0x10(%r15), %r12
movq 0x10(%r14), %r13
leaq 0x3852(%rip), %rsi      # 0xdaaf
movq %r13, %rdi
callq 0x3260
testq %r12, %r12
je 0xa384
leaq 0xba16(%rip), %r12      # 0x15c8b
leaq 0xb9f4(%rip), %rcx      # 0x15c70
movq %rcx, -0x40(%rbp)
leaq 0xbb0b(%rip), %rsi      # 0x15d92
testl %eax, %eax
movq -0x48(%rbp), %r15
je 0xa422
leaq 0x319c(%rip), %rsi      # 0xd436
movq %r13, %rdi
callq 0x3260
leaq 0xbae9(%rip), %rsi      # 0x15d92
testl %eax, %eax
movq -0x38(%rbp), %r13
je 0xa426
leaq 0xba28(%rip), %r12      # 0x15ce4
leaq 0xba16(%rip), %rax      # 0x15cd9
movq %rax, -0x40(%rbp)
leaq 0xbae8(%rip), %rsi      # 0x15db6
jmp 0xa426
movq %r12, %r15
movq 0x10(%r14), %r12
leaq 0x37ce(%rip), %rsi      # 0xdaaf
movq %r12, %rdi
callq 0x3260
testl %eax, %eax
je 0xa3ca
leaq 0x313e(%rip), %rsi      # 0xd436
movq %r12, %rdi
callq 0x3260
testl %eax, %eax
leaq 0xb828(%rip), %rax      # 0x15b31
leaq 0xb8a7(%rip), %rsi      # 0x15bb7
cmoveq %rax, %rsi
leaq 0xb873(%rip), %rax      # 0x15b8e
leaq 0xb8e1(%rip), %r12      # 0x15c03
cmoveq %rax, %r12
jmp 0xa3d8
movq 0x10(%r14), %r13
leaq 0x3779(%rip), %rsi      # 0xdaaf
movq %r13, %rdi
callq 0x3260
testl %eax, %eax
je 0xa49e
leaq 0x30e9(%rip), %rsi      # 0xd436
movq %r13, %rdi
callq 0x3260
testl %eax, %eax
leaq 0xb8e9(%rip), %rax      # 0x15c47
leaq 0xb94c(%rip), %rsi      # 0x15cb1
cmoveq %rax, %rsi
leaq 0xb91b(%rip), %rax      # 0x15c8b
leaq 0xb96d(%rip), %rcx      # 0x15ce4
cmoveq %rax, %rcx
movq %rcx, -0x48(%rbp)
jmp 0xa4b0
testl %eax, %eax
je 0xa51d
leaq 0x30a3(%rip), %rsi      # 0xd436
movq %r13, %rdi
callq 0x3260
testl %eax, %eax
leaq 0xb95f(%rip), %rax      # 0x15d03
leaq 0xb9a1(%rip), %rsi      # 0x15d4c
cmoveq %rax, %rsi
leaq 0xb8d5(%rip), %rax      # 0x15c8b
leaq 0xb927(%rip), %rcx      # 0x15ce4
cmoveq %rax, %rcx
movq %rcx, -0x40(%rbp)
jmp 0xa52f
leaq 0xb7bd(%rip), %r12      # 0x15b8e
leaq 0xb759(%rip), %rsi      # 0x15b31
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 0xb80d(%rip), %rsi      # 0x15c25
movq %rbx, %rdi
movl %ecx, %edx
jmp 0xa5a6
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 0x95c2
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 0x7f5c
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 0x95c2
jmp 0xa5ad
leaq 0xb7e6(%rip), %rax      # 0x15c8b
movq %rax, -0x48(%rbp)
leaq 0xb797(%rip), %rsi      # 0x15c47
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 0x7f5c
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 0xb87d(%rip), %rsi      # 0x15d8b
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
jmp 0xa5ad
leaq 0xb767(%rip), %rax      # 0x15c8b
movq %rax, -0x40(%rbp)
leaq 0xb7d4(%rip), %rsi      # 0x15d03
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 0x7f5c
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 0xb7e1(%rip), %rsi      # 0x15d84
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
leaq 0xc347(%rip), %rdi      # 0x168fb
movl $0x3, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
cmpl $0x5, 0x20(%r14)
jne 0xa5e6
leaq 0xb38c(%rip), %rdi      # 0x15960
movl $0x6, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
cmpb $0x67, 0x9(%r14)
jne 0xa62c
movb 0x8(%r14), %al
cmpb $0x62, %al
jne 0xa611
movl (%r14), %ecx
movl 0x4(%r14), %edx
leaq 0xb7d6(%rip), %rsi      # 0x15dd9
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
movb 0x8(%r14), %al
cmpb $0x6f, %al
jne 0xa62c
movl 0x4(%r14), %ecx
leaq 0xb7d3(%rip), %rsi      # 0x15df3
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