// File: /workspace/github_cpp_makefile_star2_O2/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 0x95d0
movq %rsi, %r14
movq %rdi, %rbx
cmpq $0x0, 0x30(%rsi)
je 0x93ce
leaq 0xb543(%rip), %rdi      # 0x14903
pushq $0x63
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x33a0
leaq 0x11e7c(%rip), %r12     # 0x1b251
cmpb $0x1, (%r12)
jne 0x93f1
leaq 0xb584(%rip), %rdi      # 0x14967
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x33a0
movq 0x50(%r14), %r15
testq %r15, %r15
je 0x9424
movl 0x20(%r15), %eax
decl %eax
cmpl $0x11, %eax
ja 0x95ac
leaq 0x3c04(%rip), %rcx      # 0xd014
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0xb5ba(%rip), %rdi      # 0x149da
pushq $0xc
jmp 0x942d
leaq 0xb546(%rip), %rdi      # 0x14971
pushq $0x4
popq %rsi
pushq $0x1
popq %r15
movq %r15, %rdx
movq %rbx, %rcx
callq 0x33a0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x92ed
leaq 0x3afc(%rip), %rdi      # 0xcf4b
pushq $0x2
popq %rsi
movq %r15, %rdx
jmp 0x95a4
movq 0x10(%r15), %rdx
leaq 0xb543(%rip), %rsi      # 0x149a8
movq %rbx, %rdi
xorl %eax, %eax
callq 0x32b0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x92ed
leaq 0xb5ae(%rip), %rdi      # 0x14a2f
pushq $0x9
jmp 0x95a0
movq 0x10(%r15), %rdx
leaq 0xb515(%rip), %rsi      # 0x149a8
movq %rbx, %rdi
xorl %eax, %eax
callq 0x32b0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x92ed
leaq 0xb705(%rip), %rdi      # 0x14bb4
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x33a0
movq 0x18(%r15), %rax
movq 0x8(%rax), %rsi
testq %rsi, %rsi
je 0x94de
movq 0x10(%rsi), %rax
testq %rax, %rax
je 0x94de
cmpq $0x0, 0x10(%rax)
je 0x960b
movq %rbx, %rdi
callq 0x8af9
leaq 0xb545(%rip), %rdi      # 0x14a32
pushq $0x6
jmp 0x95a0
leaq 0xb4ec(%rip), %rdi      # 0x149e7
pushq $0x1c
jmp 0x95e2
movq 0x10(%r15), %rdi
callq 0x5781
movq 0x10(%r15), %rdx
testb %al, %al
jne 0x9531
leaq 0xb47a(%rip), %rsi      # 0x14994
jmp 0x9582
movq 0x10(%r15), %rdi
callq 0x5781
testb %al, %al
je 0x95d9
movq 0x10(%r15), %rdx
leaq 0xb43e(%rip), %rsi      # 0x14976
movq %rbx, %rdi
xorl %eax, %eax
callq 0x32b0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x92ed
leaq 0xabdf(%rip), %rdi      # 0x14133
pushq $0x4
jmp 0x95a0
leaq 0xb4a5(%rip), %rdi      # 0x14a04
pushq $0xe
jmp 0x942d
movq 0x10(%r15), %rdi
callq 0x5781
testb %al, %al
je 0x9419
movq 0x10(%r15), %rdx
leaq 0xb491(%rip), %rsi      # 0x14a13
movq %rbx, %rdi
xorl %eax, %eax
callq 0x32b0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x92ed
leaq 0xc35d(%rip), %rdi      # 0x158fb
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq %rbx, %rcx
callq 0x33a0
cmpb $0x1, (%r12)
jne 0x95d0
movq 0x40(%r14), %rdx
leaq 0xb48a(%rip), %rsi      # 0x14a48
movq %rbx, %rdi
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x32b0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0xb459(%rip), %rdi      # 0x14a39
pushq $0xe
popq %rsi
pushq $0x1
popq %r15
movq %r15, %rdx
movq %rbx, %rcx
callq 0x33a0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x92ed
leaq 0xc2f7(%rip), %rdi      # 0x158fb
pushq $0x3
jmp 0x9451
movl (%rsi), %edx
movl (%rax), %ecx
leaq 0xb3b1(%rip), %rsi      # 0x149c7
movq %rbx, %rdi
xorl %eax, %eax
callq 0x32b0
jmp 0x95ac