// File: /workspace/github_cpp_makefile_star2_O1/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 0xa111
movq %rsi, %r14
movq %rdi, %rbx
cmpq $0x0, 0x30(%rsi)
je 0xa058
leaq 0xb8dd(%rip), %rdi      # 0x15923
movl $0x63, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
leaq 0x121d2(%rip), %r15     # 0x1c231
cmpb $0x1, (%r15)
jne 0xa07e
leaq 0xb91b(%rip), %rdi      # 0x15987
movl $0xe, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
movq 0x50(%r14), %r12
testq %r12, %r12
je 0xa0b1
movl 0x20(%r12), %eax
decl %eax
cmpl $0x11, %eax
ja 0xa0ee
leaq 0x3f9a(%rip), %rcx      # 0xe034
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xb950(%rip), %rdi      # 0x159fa
movl $0xc, %esi
jmp 0xa0bd
leaq 0xb8d9(%rip), %rdi      # 0x15991
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9f6a
leaq 0x3e8f(%rip), %rdi      # 0xdf6b
movl $0x2, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
cmpb $0x1, (%r15)
jne 0xa111
movq 0x40(%r14), %rdx
leaq 0xb969(%rip), %rsi      # 0x15a68
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 0xb8a2(%rip), %rsi      # 0x159c8
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9f6a
leaq 0xb90d(%rip), %rdi      # 0x15a4f
movl $0x9, %esi
jmp 0xa0e1
movq 0x10(%r12), %rdx
leaq 0xb873(%rip), %rsi      # 0x159c8
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9f6a
leaq 0xba63(%rip), %rdi      # 0x15bd4
movl $0x2, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
movq 0x18(%r12), %rax
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0xa1a5
movq 0x10(%rsi), %rax
testq %rax, %rax
je 0xa1a5
cmpq $0x0, 0x10(%rax)
je 0xa29b
movq %rbx, %rdi
callq 0x9747
leaq 0xb89e(%rip), %rdi      # 0x15a52
movl $0x6, %esi
jmp 0xa0e1
leaq 0xb842(%rip), %rdi      # 0x15a07
movl $0x1c, %esi
jmp 0xa272
movq 0x10(%r12), %rdi
callq 0x608e
movq 0x10(%r12), %rdx
testb %al, %al
jne 0xa1fe
leaq 0xb7cb(%rip), %rsi      # 0x159b4
jmp 0xa25a
movq 0x10(%r12), %rdi
callq 0x608e
testb %al, %al
je 0xa266
movq 0x10(%r12), %rdx
leaq 0xb791(%rip), %rsi      # 0x15996
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9f6a
leaq 0xaf32(%rip), %rdi      # 0x15153
movl $0x4, %esi
jmp 0xa0e1
leaq 0xb7f2(%rip), %rdi      # 0x15a24
movl $0xe, %esi
jmp 0xa0bd
movq 0x10(%r12), %rdi
callq 0x608e
testb %al, %al
je 0xa0a3
movq 0x10(%r12), %rdx
leaq 0xb7d9(%rip), %rsi      # 0x15a33
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
jmp 0xa27f
leaq 0xb7ec(%rip), %rdi      # 0x15a59
movl $0xe, %esi
movl $0x1, %edx
movq %rbx, %rcx
callq 0x3370
movq %rbx, %rdi
movq %r14, %rsi
callq 0x9f6a
leaq 0xc68a(%rip), %rdi      # 0x1691b
movl $0x3, %esi
jmp 0xa0e1
movl (%rsi), %edx
movl (%rax), %ecx
leaq 0xb741(%rip), %rsi      # 0x159e7
movq %rbx, %rdi
xorl %eax, %eax
callq 0x3270
jmp 0xa0ee