// File: zgimbutas[P]mwrap/src/mwrap-cgen.cc
// Function: mex_unpack_input_array(_IO_FILE*, Var*)
void mex_unpack_input_array(FILE* fp, Var* v)
{
    if (v->devicespec != 'g'){
    fprintf(fp, "    if (mxGetM(prhs[%d])*mxGetN(prhs[%d]) != 0) {\n",
            v->input_label, v->input_label);
    if (strcmp(v->basetype, "fcomplex") == 0)
      fprintf(fp,
	      "        if( mxGetClassID(prhs[%d]) != mxSINGLE_CLASS )\n"
	      "            mw_err_txt_ = \"Invalid array argument, mxSINGLE_CLASS expected\";\n"
	      "        if (mw_err_txt_) goto mw_err_label;\n"
	      "        in%d_ = mxWrapGetArray_single_%s(prhs[%d], &mw_err_txt_);\n"
	      "        if (mw_err_txt_)\n"
	      "            goto mw_err_label;\n",
	      v->input_label, v->input_label, v->basetype, v->input_label);
    else if (strcmp(v->basetype, "dcomplex") == 0)
      fprintf(fp,
	      "        if( mxGetClassID(prhs[%d]) != mxDOUBLE_CLASS )\n"
	      "            mw_err_txt_ = \"Invalid array argument, mxDOUBLE_CLASS expected\";\n"
	      "        if (mw_err_txt_) goto mw_err_label;\n"
	      "        in%d_ = mxWrapGetArray_%s(prhs[%d], &mw_err_txt_);\n"
	      "        if (mw_err_txt_)\n"
	      "            goto mw_err_label;\n",
	      v->input_label, v->input_label, v->basetype, v->input_label);
    else if (strcmp(v->basetype, "float") == 0)
      if (v->iospec == 'i')
        fprintf(fp,
		"        if( mxGetClassID(prhs[%d]) != mxSINGLE_CLASS )\n"
		"            mw_err_txt_ = \"Invalid array argument, mxSINGLE_CLASS expected\";\n"
		"        if (mw_err_txt_) goto mw_err_label;\n"
                "#if MX_HAS_INTERLEAVED_COMPLEX\n"
                "        in%d_ = mxGetSingles(prhs[%d]);\n"
                "#else\n"
                "        in%d_ = (float*) mxGetData(prhs[%d]);\n"
                "#endif\n",
                v->input_label, v->input_label, v->input_label, v->input_label, v->input_label);
      else
        fprintf(fp,
                "        in%d_ = mxWrapGetArray_single_%s(prhs[%d], &mw_err_txt_);\n"
                "        if (mw_err_txt_)\n"
                "            goto mw_err_label;\n",
                v->input_label, v->basetype, v->input_label);
    else if (strcmp(v->basetype, "double") == 0)
      if (v->iospec == 'i'){
		fprintf(fp,
		"        if( mxGetClassID(prhs[%d]) != mxDOUBLE_CLASS )\n"
		"            mw_err_txt_ = \"Invalid array argument, mxDOUBLE_CLASS expected\";\n"
		"        if (mw_err_txt_) goto mw_err_label;\n"
		"#if MX_HAS_INTERLEAVED_COMPLEX\n"
		"        in%d_ = mxGetDoubles(prhs[%d]);\n"
		"#else\n"
		"        in%d_ = mxGetPr(prhs[%d]);\n"
		"#endif\n",
		v->input_label, v->input_label, v->input_label, v->input_label, v->input_label);
      }
      else
		fprintf(fp,
		"        in%d_ = mxWrapGetArray_%s(prhs[%d], &mw_err_txt_);\n"
		"        if (mw_err_txt_)\n"
		"            goto mw_err_label;\n",
		v->input_label, v->basetype, v->input_label);
    else
      fprintf(fp,
	      "        in%d_ = mxWrapGetArray_%s(prhs[%d], &mw_err_txt_);\n"
	      "        if (mw_err_txt_)\n"
	      "            goto mw_err_label;\n",
	      v->input_label, v->basetype, v->input_label);
    fprintf(fp,
            "    } else\n"
            "        in%d_ = NULL;\n",
            v->input_label);
    fprintf(fp, "\n");
    }

    if (v->devicespec == 'g'){
      if (v->iospec == 'i' || v->iospec == 'b'){
        fprintf(fp,
        "    // extract input GPU array pointer\n"
        "    if(!(mxIsGPUArray(prhs[%d])))\n"
        "        mw_err_txt_ = \"Invalid array argument, gpuArray expected\";\n"
        "    if (mw_err_txt_) goto mw_err_label;\n"
        "    mxGPUArray_in%d_ = mxGPUCreateFromMxArray(prhs[%d]);\n"
        "    in%d_ = (%s *)mxGPUGetDataReadOnly(mxGPUArray_in%d_);\n\n",
        v->input_label, v->input_label, v->input_label, v->input_label, basetype_to_cucomplex(v->basetype), v->input_label);
        }
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movsbl 0x9(%rax), %eax
cmpl $0x67, %eax
je 0xf3bb
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %edx
movq -0x10(%rbp), %rax
movl (%rax), %ecx
leaq 0xc7d1(%rip), %rsi      # 0x1b989
movb $0x0, %al
callq 0x33a0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x52b7(%rip), %rsi      # 0x14485
callq 0x3390
cmpl $0x0, %eax
jne 0xf20a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %edx
movq -0x10(%rbp), %rax
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %r8
movq -0x10(%rbp), %rax
movl (%rax), %r9d
leaq 0xc7be(%rip), %rsi      # 0x1b9bc
movb $0x0, %al
callq 0x33a0
jmp 0xf391
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x5263(%rip), %rsi      # 0x1447c
callq 0x3390
cmpl $0x0, %eax
jne 0xf255
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %edx
movq -0x10(%rbp), %rax
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %r8
movq -0x10(%rbp), %rax
movl (%rax), %r9d
leaq 0xc89e(%rip), %rsi      # 0x1bae7
movb $0x0, %al
callq 0x33a0
jmp 0xf38f
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x58bf(%rip), %rsi      # 0x14b23
callq 0x3390
cmpl $0x0, %eax
jne 0xf2de
movq -0x10(%rbp), %rax
movsbl 0x8(%rax), %eax
cmpl $0x69, %eax
jne 0xf2b2
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %edx
movq -0x10(%rbp), %rax
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl (%rax), %r8d
movq -0x10(%rbp), %rax
movl (%rax), %r9d
movq -0x10(%rbp), %rax
movl (%rax), %eax
leaq 0xc965(%rip), %rsi      # 0x1bc0b
movl %eax, (%rsp)
movb $0x0, %al
callq 0x33a0
jmp 0xf2d9
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %edx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movl (%rax), %r8d
leaq 0xc79a(%rip), %rsi      # 0x1ba6c
movb $0x0, %al
callq 0x33a0
jmp 0xf38d
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
leaq 0x582f(%rip), %rsi      # 0x14b1c
callq 0x3390
cmpl $0x0, %eax
jne 0xf364
movq -0x10(%rbp), %rax
movsbl 0x8(%rax), %eax
cmpl $0x69, %eax
jne 0xf33b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %edx
movq -0x10(%rbp), %rax
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movl (%rax), %r8d
movq -0x10(%rbp), %rax
movl (%rax), %r9d
movq -0x10(%rbp), %rax
movl (%rax), %eax
leaq 0xca0f(%rip), %rsi      # 0x1bd3e
movl %eax, (%rsp)
movb $0x0, %al
callq 0x33a0
jmp 0xf362
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %edx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movl (%rax), %r8d
leaq 0xc83c(%rip), %rsi      # 0x1bb97
movb $0x0, %al
callq 0x33a0
jmp 0xf38b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %edx
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movl (%rax), %r8d
leaq 0xc813(%rip), %rsi      # 0x1bb97
movb $0x0, %al
callq 0x33a0
jmp 0xf38d
jmp 0xf38f
jmp 0xf391
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movl (%rax), %edx
leaq 0xcac4(%rip), %rsi      # 0x1be66
movb $0x0, %al
callq 0x33a0
movq -0x8(%rbp), %rdi
leaq 0xbdae(%rip), %rsi      # 0x1b162
movb $0x0, %al
callq 0x33a0
movq -0x10(%rbp), %rax
movsbl 0x9(%rax), %eax
cmpl $0x67, %eax
jne 0xf452
movq -0x10(%rbp), %rax
movsbl 0x8(%rax), %eax
cmpl $0x69, %eax
je 0xf3e6
movq -0x10(%rbp), %rax
movsbl 0x8(%rax), %eax
cmpl $0x62, %eax
jne 0xf450
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0xca70
movq -0x28(%rbp), %rdi
movl -0x20(%rbp), %edx
movl -0x1c(%rbp), %ecx
movl -0x18(%rbp), %r8d
movl -0x14(%rbp), %r9d
movq %rax, %r10
movq -0x10(%rbp), %rax
movl (%rax), %eax
leaq 0xca47(%rip), %rsi      # 0x1be88
movq %r10, (%rsp)
movl %eax, 0x8(%rsp)
movb $0x0, %al
callq 0x33a0
jmp 0xf452
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)