// File: /workspace/github_cpp_makefile_star2_O2/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 0x9195
cmpb $0x6f, 0x8(%r14)
jne 0x917b
cmpb $0x67, 0x9(%r14)
je 0x9090
cmpb $0x0, -0x34(%rbp)
jne 0x8fda
movl 0x20(%r14), %eax
cmpl $0xf, %eax
ja 0x8fda
movl $0x8802, %ecx           # imm = 0x8802
btl %eax, %ecx
jae 0x8fda
movq 0x10(%r14), %rdi
callq 0x5781
testb %al, %al
je 0x8fda
movl 0x4(%r14), %edx
movq 0x10(%r14), %rcx
movq %r15, %rdi
leaq 0xb74b(%rip), %rsi      # 0x14720
jmp 0x907e
movl 0x20(%r14), %eax
leal -0x2(%rax), %ecx
cmpl $0x3, %ecx
jae 0x9026
movl 0x4(%r14), %edx
movq 0x10(%r14), %rcx
movq %r15, %rdi
leaq 0xb748(%rip), %rsi      # 0x14740
xorl %eax, %eax
callq 0x32b0
movq 0x18(%r14), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0x8af9
movq 0x10(%r14), %rdx
movq %r15, %rdi
leaq 0xb740(%rip), %rsi      # 0x1475d
xorl %eax, %eax
callq 0x32b0
jmp 0x9085
cmpl $0x5, %eax
je 0x906c
cmpl $0x9, %eax
jne 0x9085
movl 0x4(%r14), %edx
movq %r15, %rdi
leaq 0xb748(%rip), %rsi      # 0x14786
xorl %eax, %eax
callq 0x32b0
movq 0x18(%r14), %rax
movq 0x8(%rax), %rsi
movq %r15, %rdi
callq 0x8af9
leaq 0xb0cb(%rip), %rdi      # 0x14127
pushq $0x10
popq %rsi
pushq $0x1
popq %rdx
movq %r15, %rcx
callq 0x33a0
jmp 0x9085
movl 0x4(%r14), %edx
movq 0x10(%r14), %rcx
movq %r15, %rdi
leaq 0xb6ee(%rip), %rsi      # 0x1476c
xorl %eax, %eax
callq 0x32b0
cmpb $0x67, 0x9(%r14)
jne 0x917b
movq 0x18(%r14), %rax
movq 0x8(%rax), %rbx
testq %rbx, %rbx
je 0x90b1
movq 0x10(%rbx), %rax
testq %rax, %rax
je 0x90b1
cmpq $0x0, 0x10(%rax)
je 0x9184
movb $0x1, %al
movl %eax, -0x2c(%rbp)
xorl %r15d, %r15d
pushq $0x1
popq %rax
movl %eax, -0x30(%rbp)
movl 0x20(%r14), %eax
addl $-0x3, %eax
leaq 0xb6e2(%rip), %r12      # 0x147af
cmpl $0xf, %eax
ja 0x90df
movl %eax, %eax
leaq 0x11c45(%rip), %rcx     # 0x1ad20
movq (%rcx,%rax,8), %r12
movq 0x10(%r14), %rdi
callq 0x754c
movq %rax, %r13
testb %r15b, %r15b
movq -0x40(%rbp), %r15
je 0x9115
movl 0x4(%r14), %edx
movl (%rbx), %ecx
movq 0x10(%rbx), %rax
movl (%rax), %r9d
movq %r15, %rdi
leaq 0xb6ab(%rip), %rsi      # 0x147b6
movl %edx, %r8d
xorl %eax, %eax
callq 0x32b0
cmpb $0x0, -0x2c(%rbp)
je 0x9132
movl 0x4(%r14), %edx
movl (%rbx), %ecx
movq %r15, %rdi
leaq 0xb6c8(%rip), %rsi      # 0x147f3
xorl %eax, %eax
callq 0x32b0
movl 0x4(%r14), %edx
movq %r12, (%rsp)
movq %r15, %rdi
leaq 0xb6d0(%rip), %rsi      # 0x14814
movl -0x30(%rbp), %ecx
movl %edx, %r8d
movq %r13, %r9
xorl %eax, %eax
callq 0x32b0
movl 0x4(%r14), %r12d
movq 0x10(%r14), %rdi
callq 0x7500
movq %r15, %rdi
leaq 0xb70d(%rip), %rsi      # 0x14878
movl %r12d, %edx
movq %rax, %rcx
movl %r12d, %r8d
xorl %eax, %eax
callq 0x32b0
movq 0x30(%r14), %r14
jmp 0x8f7e
movb $0x1, %r15b
movl $0x0, -0x2c(%rbp)
pushq $0x2
jmp 0x90bb
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq