// File: /workspace/github_cpp_makefile_star2_O3/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)
testq %rsi, %rsi
je 0x9cc7
movq %rsi, %r14
movq %rdi, %r15
movq %rdi, -0x40(%rbp)
cmpb $0x6f, 0x8(%r14)
jne 0x9ca2
cmpb $0x67, 0x9(%r14)
je 0x9bb6
cmpb $0x0, -0x34(%rbp)
jne 0x9afc
movl 0x20(%r14), %eax
cmpl $0xf, %eax
ja 0x9afc
movl $0x8802, %ecx           # imm = 0x8802
btl %eax, %ecx
jae 0x9afc
movq 0x10(%r14), %rdi
callq 0x5f6f
testb %al, %al
je 0x9afc
movl 0x4(%r14), %edx
movq 0x10(%r14), %rcx
movq %r15, %rdi
leaq 0xbc29(%rip), %rsi      # 0x15720
jmp 0x9ba4
movl 0x20(%r14), %eax
leal -0x2(%rax), %ecx
cmpl $0x3, %ecx
jae 0x9b48
movl 0x4(%r14), %edx
movq 0x10(%r14), %rcx
movq %r15, %rdi
leaq 0xbc26(%rip), %rsi      # 0x15740
xorl %eax, %eax
callq 0x3270
movq 0x18(%r14), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0x9615
movq 0x10(%r14), %rdx
movq %r15, %rdi
leaq 0xbc1e(%rip), %rsi      # 0x1575d
xorl %eax, %eax
callq 0x3270
jmp 0x9bab
cmpl $0x5, %eax
je 0x9b92
cmpl $0x9, %eax
jne 0x9bab
movl 0x4(%r14), %edx
movq %r15, %rdi
leaq 0xbc26(%rip), %rsi      # 0x15786
xorl %eax, %eax
callq 0x3270
movq 0x18(%r14), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0x9615
movl $0x10, %esi
movl $0x1, %edx
leaq 0xb59f(%rip), %rdi      # 0x15127
movq %r15, %rcx
callq 0x3370
jmp 0x9bab
movl 0x4(%r14), %edx
movq 0x10(%r14), %rcx
movq %r15, %rdi
leaq 0xbbc8(%rip), %rsi      # 0x1576c
xorl %eax, %eax
callq 0x3270
cmpb $0x67, 0x9(%r14)
jne 0x9ca2
movq 0x18(%r14), %rax
movq 0x8(%rax), %rbx
testq %rbx, %rbx
je 0x9bd7
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x9bd7
cmpq $0x0, 0x10(%rax)
je 0x9cb1
movl $0x1, -0x30(%rbp)
movb $0x1, %al
movl %eax, -0x2c(%rbp)
xorl %r15d, %r15d
movl 0x20(%r14), %eax
addl $-0x3, %eax
leaq 0xbbbb(%rip), %r12      # 0x157af
cmpl $0xf, %eax
ja 0x9c06
movl %eax, %eax
leaq 0x1211e(%rip), %rcx     # 0x1bd20
movq (%rcx,%rax,8), %r12
movq 0x10(%r14), %rdi
callq 0x7e0c
movq %rax, %r13
testb %r15b, %r15b
movq -0x40(%rbp), %r15
je 0x9c3c
movl 0x4(%r14), %edx
movl (%rbx), %ecx
movq 0x10(%rbx), %rax
movl (%rax), %r9d
movq %r15, %rdi
leaq 0xbb84(%rip), %rsi      # 0x157b6
movl %edx, %r8d
xorl %eax, %eax
callq 0x3270
cmpb $0x0, -0x2c(%rbp)
je 0x9c59
movl 0x4(%r14), %edx
movl (%rbx), %ecx
movq %r15, %rdi
leaq 0xbba1(%rip), %rsi      # 0x157f3
xorl %eax, %eax
callq 0x3270
movl 0x4(%r14), %edx
movq %r12, (%rsp)
movq %r15, %rdi
leaq 0xbba9(%rip), %rsi      # 0x15814
movl -0x30(%rbp), %ecx
movl %edx, %r8d
movq %r13, %r9
xorl %eax, %eax
callq 0x3270
movl 0x4(%r14), %r12d
movq 0x10(%r14), %rdi
callq 0x7dc0
movq %r15, %rdi
leaq 0xbbe6(%rip), %rsi      # 0x15878
movl %r12d, %edx
movq %rax, %rcx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x3270
movq 0x30(%r14), %r14
testq %r14, %r14
jne 0x9aa9
jmp 0x9cc7
movl $0x2, -0x30(%rbp)
movb $0x1, %r15b
movl $0x0, -0x2c(%rbp)
jmp 0x9be6
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq