// File: /workspace/github_cpp_makefile_star2_O3/zgimbutas[P]mwrap/src/mwrap-cgen.cc
// Function: mex_make_stmt(_IO_FILE*, Func*)
void mex_make_stmt(FILE* fp, Func* f)
{
    if (!f)
        return;

    if (f->thisv)
        fprintf(fp,
                "    if (!in0_) {\n"
                "        mw_err_txt_ = \"Cannot dispatch to NULL\";\n"
                "        goto mw_err_label;\n"
                "    }\n");

    if (mw_generate_catch)
        fprintf(fp, "    try {\n    ");

    if (f->ret) {
        Var* v = f->ret;
        if (v->tinfo == VT_obj) {

            if (is_mxarray_type(v->basetype)) {
                fprintf(fp, "    plhs[0] = mxWrapSet_%s(&(", v->basetype);
                mex_make_call(fp, f);
                fprintf(fp ,"));\n");
            } else {
                fprintf(fp, "    out0_ = new %s(", v->basetype);
                mex_make_call(fp, f);
                fprintf(fp ,");\n");
            }

        } else if (is_array(v->tinfo)) {

            fprintf(fp, "    plhs[0] = mxWrapReturn_%s(", v->basetype);
            mex_make_call(fp, f);
            fprintf(fp, ", ");
            Expr* e = v->qual->args;
            if (e && e->next && !e->next->next) {
                fprintf(fp, " dim%d_, dim%d_);\n",
                        e->input_label, e->next->input_label);
            } else {
                mex_alloc_size(fp, v->qual->args);
                fprintf(fp, ", 1);\n");
            }

        } else if (v->tinfo == VT_scalar  || v->tinfo == VT_r_scalar  ||
                   v->tinfo == VT_cscalar || v->tinfo == VT_r_cscalar ||
                   v->tinfo == VT_zscalar || v->tinfo == VT_r_zscalar) {

            fprintf(fp, "    out0_ = ");
            mex_make_call(fp, f);
            fprintf(fp, ";\n");

        } else if (v->tinfo == VT_string) {

            fprintf(fp, "    plhs[0] = mxWrapStrncpy(");
            mex_make_call(fp, f);
            fprintf(fp, ");\n");

        } else if (v->tinfo == VT_mx) {

            fprintf(fp, "    plhs[0] = ");
            mex_make_call(fp, f);
            fprintf(fp, ";\n");

        } else if (v->tinfo == VT_p_obj) {

            if (is_mxarray_type(v->basetype)) {
                fprintf(fp, "    plhs[0] = mxWrapSet_%s(", v->basetype);
                mex_make_call(fp, f);
                fprintf(fp, ");\n");
            } else {
                fprintf(fp, "    out0_ = ");
                mex_make_call(fp, f);
                fprintf(fp, ";\n");
            }

        } else if (v->tinfo == VT_p_scalar ||
                   v->tinfo == VT_p_cscalar ||
                   v->tinfo == VT_p_zscalar) {

            fprintf(fp, "    plhs[0] = mxWrapReturn_%s(", v->basetype);
            mex_make_call(fp, f);
            fprintf(fp, ", 1, 1);\n");

        } else if (v->tinfo == VT_r_obj) {

            if (is_mxarray_type(v->basetype)) {
                fprintf(fp, "    plhs[0] = mxWrapSet_%s(&(", v->basetype);
                mex_make_call(fp, f);
                fprintf(fp, "));\n");
            } else {
                fprintf(fp, "    out0_ = &(");
                mex_make_call(fp, f);
                fprintf(fp, ");\n");
            }

        }
    } else {
        fprintf(fp, "    ");
        mex_make_call(fp, f);
        fprintf(fp, ";\n");
    }

    if (mw_generate_catch)
        fprintf(fp,
                "    } catch(...) {\n"
                "        mw_err_txt_ = \"Caught C++ exception from %s\";\n"
                "    }\n"
                "    if (mw_err_txt_)\n"
                "        goto mw_err_label;\n",
                f->funcv);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
testq %rsi, %rsi
je 0x9fe2
movq %rsi, %r14
movq %rdi, %rbx
cmpq $0x0, 0x30(%rsi)
je 0x9f29
leaq 0xb9ec(%rip), %rdi      # 0x15903
movl $0x63, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
leaq 0x12301(%rip), %r15     # 0x1c231
cmpb $0x1, (%r15)
jne 0x9f4f
leaq 0xba2a(%rip), %rdi      # 0x15967
movl $0xe, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
movq 0x50(%r14), %r12
testq %r12, %r12
je 0x9f82
movl 0x20(%r12), %eax
decl %eax
cmpl $0x11, %eax
ja 0x9fbf
leaq 0x40a9(%rip), %rcx      # 0xe014
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xba5f(%rip), %rdi      # 0x159da
movl $0xc, %esi
jmp 0x9f8e
leaq 0xb9e8(%rip), %rdi      # 0x15971
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9e38
leaq 0x3f9e(%rip), %rdi      # 0xdf4b
movl $0x2, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
cmpb $0x1, (%r15)
jne 0x9fe2
movq 0x40(%r14), %rdx
leaq 0xba78(%rip), %rsi      # 0x15a48
movq %rbx, %rdi
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x3270
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%r12), %rdx
leaq 0xb9b1(%rip), %rsi      # 0x159a8
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9e38
leaq 0xba1c(%rip), %rdi      # 0x15a2f
movl $0x9, %esi
jmp 0x9fb2
movq 0x10(%r12), %rdx
leaq 0xb982(%rip), %rsi      # 0x159a8
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9e38
leaq 0xbb72(%rip), %rdi      # 0x15bb4
movl $0x2, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
movq 0x18(%r12), %rax
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0xa076
movq 0x10(%rsi), %rax
testq %rax, %rax
je 0xa076
cmpq $0x0, 0x10(%rax)
je 0xa16c
movq %rbx, %rdi
callq 0x9615
leaq 0xb9ad(%rip), %rdi      # 0x15a32
movl $0x6, %esi
jmp 0x9fb2
leaq 0xb951(%rip), %rdi      # 0x159e7
movl $0x1c, %esi
jmp 0xa143
movq 0x10(%r12), %rdi
callq 0x5f6f
movq 0x10(%r12), %rdx
testb %al, %al
jne 0xa0cf
leaq 0xb8da(%rip), %rsi      # 0x15994
jmp 0xa12b
movq 0x10(%r12), %rdi
callq 0x5f6f
testb %al, %al
je 0xa137
movq 0x10(%r12), %rdx
leaq 0xb8a0(%rip), %rsi      # 0x15976
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9e38
leaq 0xb041(%rip), %rdi      # 0x15133
movl $0x4, %esi
jmp 0x9fb2
leaq 0xb901(%rip), %rdi      # 0x15a04
movl $0xe, %esi
jmp 0x9f8e
movq 0x10(%r12), %rdi
callq 0x5f6f
testb %al, %al
je 0x9f74
movq 0x10(%r12), %rdx
leaq 0xb8e8(%rip), %rsi      # 0x15a13
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
jmp 0xa150
leaq 0xb8fb(%rip), %rdi      # 0x15a39
movl $0xe, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9e38
leaq 0xc799(%rip), %rdi      # 0x168fb
movl $0x3, %esi
jmp 0x9fb2
movl (%rsi), %edx
movl (%rax), %ecx
leaq 0xb850(%rip), %rsi      # 0x159c7
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
jmp 0x9fbf