// File: /workspace/github_cpp_makefile_star2_O1/zgimbutas[P]mwrap/src/mwrap-cgen.cc
// Function: mex_alloc_output(_IO_FILE*, Var*, bool)
void mex_alloc_output(FILE* fp, Var* v, bool return_flag)
{
    if (!v)
        return;
    if (v->iospec == 'o') {
        if (v->devicespec != 'g'){
        if (!return_flag && is_obj(v->tinfo) && is_mxarray_type(v->basetype)) {
            fprintf(fp, "    out%d_ = mxWrapAlloc_%s();\n",
                    v->output_label, v->basetype);
        } else if (is_array(v->tinfo)) {
            fprintf(fp, "    out%d_ = (%s*) mxMalloc(",
                    v->output_label, v->basetype);
            mex_alloc_size(fp, v->qual->args);
            fprintf(fp, "*sizeof(%s));\n", v->basetype);
        } else if (v->tinfo == VT_rarray) {
            fprintf(fp, "    out%d_ = (%s*) NULL;\n",
                    v->output_label, v->basetype);
        } else if (v->tinfo == VT_string) {
            fprintf(fp, "    out%d_ = (char*) mxMalloc(", v->output_label);
            mex_alloc_size(fp, v->qual->args);
            fprintf(fp, "*sizeof(char));\n");
        }
        }
        if (v->devicespec == 'g') {
            // need to allocate
            Expr* e = v->qual->args;
            int ndims = 0;
            if (e && e->next && !e->next->next) {
                ndims = 2;
            } else {
                ndims = 1;
            }
            const char* mtype = complex_tinfo(v) ? "mxCOMPLEX" : "mxREAL";
            const char* mxclassid = basetype_to_mxclassid(v->basetype);
            if (ndims == 2) {
                fprintf(fp, "    gpu_outdims%d_[0] = dim%d_; gpu_outdims%d_[1] = dim%d_;\n", v->output_label, e->input_label, v->output_label, e->next->input_label);
            }
            if (ndims == 1) {
                fprintf(fp, "    gpu_outdims%d_[0] = dim%d_;\n", v->output_label, e->input_label);
            }
            fprintf(fp, "    mxGPUArray_out%d_ = mxGPUCreateGPUArray(%d, gpu_outdims%d_, %s, %s, MX_GPU_DO_NOT_INITIALIZE);\n", v->output_label, ndims, v->output_label, mxclassid, mtype);
            fprintf(fp, "    out%d_ = (%s *)mxGPUGetData(mxGPUArray_out%d_);\n\n", v->output_label, basetype_to_cucomplex(v->basetype), v->output_label);
        }
    }
    mex_alloc_output(fp, v->next, return_flag);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, -0x34(%rbp)
movq %rsi, %r14
movq %rdi, %r15
movq %rdi, -0x40(%rbp)
testq %r14, %r14
je 0x9dec
cmpb $0x6f, 0x8(%r14)
jne 0x9dcd
cmpb $0x67, 0x9(%r14)
je 0x9cd6
cmpb $0x0, -0x34(%rbp)
jne 0x9c27
movl 0x20(%r14), %eax
cmpl $0xf, %eax
ja 0x9c27
movl $0x8802, %ecx           # imm = 0x8802
btl %eax, %ecx
jae 0x9c27
movq 0x10(%r14), %rdi
callq 0x608e
testb %al, %al
je 0x9c27
movl 0x4(%r14), %edx
movq 0x10(%r14), %rcx
movq %r15, %rdi
leaq 0xbb1e(%rip), %rsi      # 0x15740
jmp 0x9ccf
movl 0x20(%r14), %eax
leal -0x2(%rax), %ecx
cmpl $0x3, %ecx
jae 0x9c73
movl 0x4(%r14), %edx
movq 0x10(%r14), %rcx
movq %r15, %rdi
leaq 0xbb1b(%rip), %rsi      # 0x15760
xorl %eax, %eax
callq 0x3270
movq 0x18(%r14), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0x9747
movq 0x10(%r14), %rdx
movq %r15, %rdi
leaq 0xbb13(%rip), %rsi      # 0x1577d
xorl %eax, %eax
callq 0x3270
jmp 0x9cd6
cmpl $0x5, %eax
je 0x9cbd
cmpl $0x9, %eax
jne 0x9cd6
movl 0x4(%r14), %edx
movq %r15, %rdi
leaq 0xbb1b(%rip), %rsi      # 0x157a6
xorl %eax, %eax
callq 0x3270
movq 0x18(%r14), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0x9747
movl $0x10, %esi
movl $0x1, %edx
leaq 0xb494(%rip), %rdi      # 0x15147
movq %r15, %rcx
callq 0x3370
jmp 0x9cd6
movl 0x4(%r14), %edx
movq 0x10(%r14), %rcx
movq %r15, %rdi
leaq 0xbabd(%rip), %rsi      # 0x1578c
xorl %eax, %eax
callq 0x3270
cmpb $0x67, 0x9(%r14)
jne 0x9dcd
movq 0x18(%r14), %rax
movq 0x8(%rax), %rbx
testq %rbx, %rbx
je 0x9d02
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x9d02
cmpq $0x0, 0x10(%rax)
je 0x9dd6
movl $0x1, -0x30(%rbp)
movb $0x1, %al
movl %eax, -0x2c(%rbp)
xorl %r15d, %r15d
movl 0x20(%r14), %eax
addl $-0x3, %eax
leaq 0xbab0(%rip), %r12      # 0x157cf
cmpl $0xf, %eax
ja 0x9d31
movl %eax, %eax
leaq 0x11ff3(%rip), %rcx     # 0x1bd20
movq (%rcx,%rax,8), %r12
movq 0x10(%r14), %rdi
callq 0x7e90
movq %rax, %r13
testb %r15b, %r15b
movq -0x40(%rbp), %r15
je 0x9d67
movl 0x4(%r14), %edx
movl (%rbx), %ecx
movq 0x10(%rbx), %rax
movl (%rax), %r9d
movq %r15, %rdi
leaq 0xba79(%rip), %rsi      # 0x157d6
movl %edx, %r8d
xorl %eax, %eax
callq 0x3270
cmpb $0x0, -0x2c(%rbp)
je 0x9d84
movl 0x4(%r14), %edx
movl (%rbx), %ecx
movq %r15, %rdi
leaq 0xba96(%rip), %rsi      # 0x15813
xorl %eax, %eax
callq 0x3270
movl 0x4(%r14), %edx
movq %r12, (%rsp)
movq %r15, %rdi
leaq 0xba9e(%rip), %rsi      # 0x15834
movl -0x30(%rbp), %ecx
movl %edx, %r8d
movq %r13, %r9
xorl %eax, %eax
callq 0x3270
movl 0x4(%r14), %r12d
movq 0x10(%r14), %rdi
callq 0x7e44
movq %r15, %rdi
leaq 0xbadb(%rip), %rsi      # 0x15898
movl %r12d, %edx
movq %rax, %rcx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3270
movq 0x30(%r14), %r14
jmp 0x9bcb
movl $0x2, -0x30(%rbp)
movb $0x1, %r15b
movl $0x0, -0x2c(%rbp)
jmp 0x9d11
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq