
#include <string.h>
#include "{{ filename }}.h"

int {{ function_name }}_init({{ function_name }}_arg_t* arg, {{ function_name }}_res_t* res, {{ function_name }}_work_t* work) {
    if (!arg || !res || !work) {
        return -1; // Invalid pointers
    }

    /* Initialize inputs */
    memset(arg, 0, sizeof({{ function_name }}_arg_t));

    /* Initialize outputs */
    memset(res, 0, sizeof({{ function_name }}_res_t));

    /* Nonzero assignments */
{% for assignment in assignments %}
    {{ assignment.path }} = {{ assignment.value }};
{% endfor %}

    return 0;
}

int {{ function_name }}_step({{ function_name }}_arg_t* arg, {{ function_name }}_res_t* res, {{ function_name }}_work_t* work) {
    if (!arg || !res || !work) {
        return -1; // Invalid pointers
    }

    // Marshal inputs to CasADi format
    const {{ float_type }}* kernel_arg[{{ function_name }}_SZ_ARG];
{% for assignment in marshalled_inputs %}
    kernel_arg[{{ loop.index0 }}] = {{ assignment.path }};
{% endfor %}
    
    // Marshal outputs to CasADi format
    {{ float_type }}* kernel_res[{{ function_name }}_SZ_RES];
{% for assignment in marshalled_outputs %}
    kernel_res[{{ loop.index0 }}] = {{ assignment.path }};
{% endfor %}
    
    // Call kernel function
    return {{ function_name }}(kernel_arg, kernel_res, work->iw, work->w, 0);
}