/* Include files */

#include <stddef.h>
#include "blas.h"
#include "diffserv_model_sfun.h"
#include "c33_diffserv_model.h"
#define CHARTINSTANCE_CHARTNUMBER      (chartInstance->chartNumber)
#define CHARTINSTANCE_INSTANCENUMBER   (chartInstance->instanceNumber)
#include "diffserv_model_sfun_debug_macros.h"
#define _SF_MEX_LISTEN_FOR_CTRL_C(S)   sf_mex_listen_for_ctrl_c(sfGlobalDebugInstanceStruct,S);

/* Type Definitions */

/* Named Constants */
#define c33_event_Next_packet          (0)
#define CALL_EVENT                     (-1)

/* Variable Declarations */

/* Variable Definitions */
static const char * c33_debug_family_names[18] = { "nargin", "nargout",
  "Q1_pending", "Q2_pending", "Q3_pending", "prioritization", "weighting",
  "Q1_weight", "Q2_weight", "Q3_weight", "preemption", "workConservation",
  "Queue_select", "last_was_expedited", "last_Q_served", "Q_before_expediting",
  "current_Q_finished", "packets_served" };

/* Function Declarations */
static void initialize_c33_diffserv_model(SFc33_diffserv_modelInstanceStruct
  *chartInstance);
static void initialize_params_c33_diffserv_model
  (SFc33_diffserv_modelInstanceStruct *chartInstance);
static void enable_c33_diffserv_model(SFc33_diffserv_modelInstanceStruct
  *chartInstance);
static void disable_c33_diffserv_model(SFc33_diffserv_modelInstanceStruct
  *chartInstance);
static void c33_update_debugger_state_c33_diffserv_model
  (SFc33_diffserv_modelInstanceStruct *chartInstance);
static const mxArray *get_sim_state_c33_diffserv_model
  (SFc33_diffserv_modelInstanceStruct *chartInstance);
static void set_sim_state_c33_diffserv_model(SFc33_diffserv_modelInstanceStruct *
  chartInstance, const mxArray *c33_st);
static void finalize_c33_diffserv_model(SFc33_diffserv_modelInstanceStruct
  *chartInstance);
static void sf_c33_diffserv_model(SFc33_diffserv_modelInstanceStruct
  *chartInstance);
static void c33_chartstep_c33_diffserv_model(SFc33_diffserv_modelInstanceStruct *
  chartInstance);
static void initSimStructsc33_diffserv_model(SFc33_diffserv_modelInstanceStruct *
  chartInstance);
static void registerMessagesc33_diffserv_model
  (SFc33_diffserv_modelInstanceStruct *chartInstance);
static void init_script_number_translation(uint32_T c33_machineNumber, uint32_T
  c33_chartNumber);
static const mxArray *c33_sf_marshallOut(void *chartInstanceVoid, void
  *c33_inData);
static real_T c33_emlrt_marshallIn(SFc33_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c33_packets_served, const char_T
  *c33_identifier);
static real_T c33_b_emlrt_marshallIn(SFc33_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c33_u, const emlrtMsgIdentifier *c33_parentId);
static void c33_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c33_mxArrayInData, const char_T *c33_varName, void *c33_outData);
static const mxArray *c33_b_sf_marshallOut(void *chartInstanceVoid, void
  *c33_inData);
static boolean_T c33_c_emlrt_marshallIn(SFc33_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c33_u, const emlrtMsgIdentifier *c33_parentId);
static void c33_b_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c33_mxArrayInData, const char_T *c33_varName, void *c33_outData);
static const mxArray *c33_c_sf_marshallOut(void *chartInstanceVoid, void
  *c33_inData);
static int8_T c33_d_emlrt_marshallIn(SFc33_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c33_u, const emlrtMsgIdentifier *c33_parentId);
static void c33_c_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c33_mxArrayInData, const char_T *c33_varName, void *c33_outData);
static const mxArray *c33_d_sf_marshallOut(void *chartInstanceVoid, void
  *c33_inData);
static int32_T c33_e_emlrt_marshallIn(SFc33_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c33_u, const emlrtMsgIdentifier *c33_parentId);
static void c33_d_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c33_mxArrayInData, const char_T *c33_varName, void *c33_outData);
static uint8_T c33_f_emlrt_marshallIn(SFc33_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c33_b_is_active_c33_diffserv_model, const
  char_T *c33_identifier);
static uint8_T c33_g_emlrt_marshallIn(SFc33_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c33_u, const emlrtMsgIdentifier *c33_parentId);
static real_T c33_get_Q_before_expediting(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b);
static void c33_set_Q_before_expediting(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b, real_T c33_c);
static real_T *c33_access_Q_before_expediting(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b);
static boolean_T c33_get_current_Q_finished(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b);
static void c33_set_current_Q_finished(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b, boolean_T c33_c);
static boolean_T *c33_access_current_Q_finished
  (SFc33_diffserv_modelInstanceStruct *chartInstance, uint32_T c33_b);
static real_T c33_get_last_Q_served(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b);
static void c33_set_last_Q_served(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b, real_T c33_c);
static real_T *c33_access_last_Q_served(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b);
static boolean_T c33_get_last_was_expedited(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b);
static void c33_set_last_was_expedited(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b, boolean_T c33_c);
static boolean_T *c33_access_last_was_expedited
  (SFc33_diffserv_modelInstanceStruct *chartInstance, uint32_T c33_b);
static real_T c33_get_packets_served(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b);
static void c33_set_packets_served(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b, real_T c33_c);
static real_T *c33_access_packets_served(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b);
static void init_dsm_address_info(SFc33_diffserv_modelInstanceStruct
  *chartInstance);

/* Function Definitions */
static void initialize_c33_diffserv_model(SFc33_diffserv_modelInstanceStruct
  *chartInstance)
{
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
  chartInstance->c33_is_active_c33_diffserv_model = 0U;
}

static void initialize_params_c33_diffserv_model
  (SFc33_diffserv_modelInstanceStruct *chartInstance)
{
  real_T c33_d0;
  real_T c33_d1;
  real_T c33_d2;
  real_T c33_d3;
  real_T c33_d4;
  real_T c33_d5;
  real_T c33_d6;
  sf_set_error_prefix_string(
    "Error evaluating data 'prioritization' in the parent workspace.\n");
  sf_mex_import_named("prioritization", sf_mex_get_sfun_param(chartInstance->S,
    4, 0), &c33_d0, 0, 0, 0U, 0, 0U, 0);
  chartInstance->c33_prioritization = c33_d0;
  sf_set_error_prefix_string("Stateflow Runtime Error (chart): ");
  sf_set_error_prefix_string(
    "Error evaluating data 'weighting' in the parent workspace.\n");
  sf_mex_import_named("weighting", sf_mex_get_sfun_param(chartInstance->S, 5, 0),
                      &c33_d1, 0, 0, 0U, 0, 0U, 0);
  chartInstance->c33_weighting = c33_d1;
  sf_set_error_prefix_string("Stateflow Runtime Error (chart): ");
  sf_set_error_prefix_string(
    "Error evaluating data 'Q1_weight' in the parent workspace.\n");
  sf_mex_import_named("Q1_weight", sf_mex_get_sfun_param(chartInstance->S, 0, 0),
                      &c33_d2, 0, 0, 0U, 0, 0U, 0);
  chartInstance->c33_Q1_weight = c33_d2;
  sf_set_error_prefix_string("Stateflow Runtime Error (chart): ");
  sf_set_error_prefix_string(
    "Error evaluating data 'Q2_weight' in the parent workspace.\n");
  sf_mex_import_named("Q2_weight", sf_mex_get_sfun_param(chartInstance->S, 1, 0),
                      &c33_d3, 0, 0, 0U, 0, 0U, 0);
  chartInstance->c33_Q2_weight = c33_d3;
  sf_set_error_prefix_string("Stateflow Runtime Error (chart): ");
  sf_set_error_prefix_string(
    "Error evaluating data 'Q3_weight' in the parent workspace.\n");
  sf_mex_import_named("Q3_weight", sf_mex_get_sfun_param(chartInstance->S, 2, 0),
                      &c33_d4, 0, 0, 0U, 0, 0U, 0);
  chartInstance->c33_Q3_weight = c33_d4;
  sf_set_error_prefix_string("Stateflow Runtime Error (chart): ");
  sf_set_error_prefix_string(
    "Error evaluating data 'preemption' in the parent workspace.\n");
  sf_mex_import_named("preemption", sf_mex_get_sfun_param(chartInstance->S, 3, 0),
                      &c33_d5, 0, 0, 0U, 0, 0U, 0);
  chartInstance->c33_preemption = c33_d5;
  sf_set_error_prefix_string("Stateflow Runtime Error (chart): ");
  sf_set_error_prefix_string(
    "Error evaluating data 'workConservation' in the parent workspace.\n");
  sf_mex_import_named("workConservation", sf_mex_get_sfun_param(chartInstance->S,
    6, 0), &c33_d6, 0, 0, 0U, 0, 0U, 0);
  chartInstance->c33_workConservation = c33_d6;
  sf_set_error_prefix_string("Stateflow Runtime Error (chart): ");
}

static void enable_c33_diffserv_model(SFc33_diffserv_modelInstanceStruct
  *chartInstance)
{
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
}

static void disable_c33_diffserv_model(SFc33_diffserv_modelInstanceStruct
  *chartInstance)
{
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
}

static void c33_update_debugger_state_c33_diffserv_model
  (SFc33_diffserv_modelInstanceStruct *chartInstance)
{
}

static const mxArray *get_sim_state_c33_diffserv_model
  (SFc33_diffserv_modelInstanceStruct *chartInstance)
{
  const mxArray *c33_st;
  const mxArray *c33_y = NULL;
  real_T c33_hoistedGlobal;
  real_T c33_u;
  const mxArray *c33_b_y = NULL;
  uint8_T c33_b_hoistedGlobal;
  uint8_T c33_b_u;
  const mxArray *c33_c_y = NULL;
  real_T *c33_Queue_select;
  c33_Queue_select = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  c33_st = NULL;
  c33_st = NULL;
  c33_y = NULL;
  sf_mex_assign(&c33_y, sf_mex_createcellarray(2), FALSE);
  c33_hoistedGlobal = *c33_Queue_select;
  c33_u = c33_hoistedGlobal;
  c33_b_y = NULL;
  sf_mex_assign(&c33_b_y, sf_mex_create("y", &c33_u, 0, 0U, 0U, 0U, 0), FALSE);
  sf_mex_setcell(c33_y, 0, c33_b_y);
  c33_b_hoistedGlobal = chartInstance->c33_is_active_c33_diffserv_model;
  c33_b_u = c33_b_hoistedGlobal;
  c33_c_y = NULL;
  sf_mex_assign(&c33_c_y, sf_mex_create("y", &c33_b_u, 3, 0U, 0U, 0U, 0), FALSE);
  sf_mex_setcell(c33_y, 1, c33_c_y);
  sf_mex_assign(&c33_st, c33_y, FALSE);
  return c33_st;
}

static void set_sim_state_c33_diffserv_model(SFc33_diffserv_modelInstanceStruct *
  chartInstance, const mxArray *c33_st)
{
  const mxArray *c33_u;
  real_T *c33_Queue_select;
  c33_Queue_select = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  chartInstance->c33_doneDoubleBufferReInit = TRUE;
  c33_u = sf_mex_dup(c33_st);
  *c33_Queue_select = c33_emlrt_marshallIn(chartInstance, sf_mex_dup
    (sf_mex_getcell(c33_u, 0)), "Queue_select");
  chartInstance->c33_is_active_c33_diffserv_model = c33_f_emlrt_marshallIn
    (chartInstance, sf_mex_dup(sf_mex_getcell(c33_u, 1)),
     "is_active_c33_diffserv_model");
  sf_mex_destroy(&c33_u);
  c33_update_debugger_state_c33_diffserv_model(chartInstance);
  sf_mex_destroy(&c33_st);
}

static void finalize_c33_diffserv_model(SFc33_diffserv_modelInstanceStruct
  *chartInstance)
{
}

static void sf_c33_diffserv_model(SFc33_diffserv_modelInstanceStruct
  *chartInstance)
{
  real_T *c33_Q1_pending;
  real_T *c33_Q2_pending;
  real_T *c33_Q3_pending;
  real_T *c33_Queue_select;
  c33_Queue_select = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  c33_Q3_pending = (real_T *)ssGetInputPortSignal(chartInstance->S, 2);
  c33_Q2_pending = (real_T *)ssGetInputPortSignal(chartInstance->S, 1);
  c33_Q1_pending = (real_T *)ssGetInputPortSignal(chartInstance->S, 0);
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
  _SFD_CC_CALL(CHART_ENTER_SFUNCTION_TAG, 32U, chartInstance->c33_sfEvent);
  _SFD_DATA_RANGE_CHECK(*c33_Q1_pending, 0U);
  _SFD_DATA_RANGE_CHECK(*c33_Q2_pending, 1U);
  _SFD_DATA_RANGE_CHECK(*c33_Q3_pending, 2U);
  _SFD_DATA_RANGE_CHECK(chartInstance->c33_prioritization, 3U);
  _SFD_DATA_RANGE_CHECK(chartInstance->c33_weighting, 4U);
  _SFD_DATA_RANGE_CHECK(*c33_Queue_select, 5U);
  _SFD_DATA_RANGE_CHECK(chartInstance->c33_Q1_weight, 8U);
  _SFD_DATA_RANGE_CHECK(chartInstance->c33_Q2_weight, 9U);
  _SFD_DATA_RANGE_CHECK(chartInstance->c33_Q3_weight, 10U);
  _SFD_DATA_RANGE_CHECK(chartInstance->c33_preemption, 14U);
  _SFD_DATA_RANGE_CHECK(chartInstance->c33_workConservation, 15U);
  chartInstance->c33_sfEvent = c33_event_Next_packet;
  _SFD_CE_CALL(EVENT_BEFORE_BROADCAST_TAG, c33_event_Next_packet,
               chartInstance->c33_sfEvent);
  c33_chartstep_c33_diffserv_model(chartInstance);
  _SFD_CE_CALL(EVENT_AFTER_BROADCAST_TAG, c33_event_Next_packet,
               chartInstance->c33_sfEvent);
  _SFD_CHECK_FOR_STATE_INCONSISTENCY(_diffserv_modelMachineNumber_,
    chartInstance->chartNumber, chartInstance->instanceNumber);
}

static void c33_chartstep_c33_diffserv_model(SFc33_diffserv_modelInstanceStruct *
  chartInstance)
{
  real_T c33_hoistedGlobal;
  real_T c33_b_hoistedGlobal;
  real_T c33_c_hoistedGlobal;
  real_T c33_d_hoistedGlobal;
  real_T c33_e_hoistedGlobal;
  real_T c33_f_hoistedGlobal;
  real_T c33_g_hoistedGlobal;
  real_T c33_h_hoistedGlobal;
  real_T c33_i_hoistedGlobal;
  real_T c33_j_hoistedGlobal;
  real_T c33_Q1_pending;
  real_T c33_Q2_pending;
  real_T c33_Q3_pending;
  real_T c33_b_prioritization;
  real_T c33_b_weighting;
  real_T c33_b_Q1_weight;
  real_T c33_b_Q2_weight;
  real_T c33_b_Q3_weight;
  real_T c33_b_preemption;
  real_T c33_b_workConservation;
  uint32_T c33_debug_family_var_map[18];
  real_T c33_nargin = 10.0;
  real_T c33_nargout = 1.0;
  real_T c33_Queue_select;
  const mxArray *c33_y = NULL;
  char_T c33_u[36];
  static char_T c33_cv0[36] = { 'P', 'l', '\xe1', 'n', 'o', 'v', 'a', '\xe8',
    ' ', 'v', 'y', 'b', 'r', 'a', 'l', ' ', 'n', 'e', 'e', 'x', 'i', 's', 't',
    'u', 'j', '\xed', 'c', '\xed', ' ', 'f', 'r', 'o', 'n', 't', 'u', '!' };

  int32_T c33_i0;
  real_T *c33_b_Queue_select;
  real_T *c33_b_Q1_pending;
  real_T *c33_b_Q2_pending;
  real_T *c33_b_Q3_pending;
  boolean_T guard1 = FALSE;
  boolean_T guard2 = FALSE;
  boolean_T guard3 = FALSE;
  boolean_T guard4 = FALSE;
  boolean_T guard5 = FALSE;
  boolean_T guard6 = FALSE;
  boolean_T guard7 = FALSE;
  boolean_T guard8 = FALSE;
  boolean_T guard9 = FALSE;
  boolean_T guard10 = FALSE;
  boolean_T guard11 = FALSE;
  boolean_T guard12 = FALSE;
  boolean_T guard13 = FALSE;
  boolean_T guard14 = FALSE;
  boolean_T guard15 = FALSE;
  c33_b_Queue_select = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  c33_b_Q3_pending = (real_T *)ssGetInputPortSignal(chartInstance->S, 2);
  c33_b_Q2_pending = (real_T *)ssGetInputPortSignal(chartInstance->S, 1);
  c33_b_Q1_pending = (real_T *)ssGetInputPortSignal(chartInstance->S, 0);
  _SFD_CC_CALL(CHART_ENTER_DURING_FUNCTION_TAG, 32U, chartInstance->c33_sfEvent);
  c33_hoistedGlobal = *c33_b_Q1_pending;
  c33_b_hoistedGlobal = *c33_b_Q2_pending;
  c33_c_hoistedGlobal = *c33_b_Q3_pending;
  c33_d_hoistedGlobal = chartInstance->c33_prioritization;
  c33_e_hoistedGlobal = chartInstance->c33_weighting;
  c33_f_hoistedGlobal = chartInstance->c33_Q1_weight;
  c33_g_hoistedGlobal = chartInstance->c33_Q2_weight;
  c33_h_hoistedGlobal = chartInstance->c33_Q3_weight;
  c33_i_hoistedGlobal = chartInstance->c33_preemption;
  c33_j_hoistedGlobal = chartInstance->c33_workConservation;
  c33_Q1_pending = c33_hoistedGlobal;
  c33_Q2_pending = c33_b_hoistedGlobal;
  c33_Q3_pending = c33_c_hoistedGlobal;
  c33_b_prioritization = c33_d_hoistedGlobal;
  c33_b_weighting = c33_e_hoistedGlobal;
  c33_b_Q1_weight = c33_f_hoistedGlobal;
  c33_b_Q2_weight = c33_g_hoistedGlobal;
  c33_b_Q3_weight = c33_h_hoistedGlobal;
  c33_b_preemption = c33_i_hoistedGlobal;
  c33_b_workConservation = c33_j_hoistedGlobal;
  _SFD_SYMBOL_SCOPE_PUSH_EML(0U, 18U, 18U, c33_debug_family_names,
    c33_debug_family_var_map);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c33_nargin, 0U, c33_sf_marshallOut,
    c33_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c33_nargout, 1U, c33_sf_marshallOut,
    c33_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML(&c33_Q1_pending, 2U, c33_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML(&c33_Q2_pending, 3U, c33_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML(&c33_Q3_pending, 4U, c33_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c33_b_prioritization, 5U,
    c33_sf_marshallOut, c33_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c33_b_weighting, 6U, c33_sf_marshallOut,
    c33_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c33_b_Q1_weight, 7U, c33_sf_marshallOut,
    c33_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c33_b_Q2_weight, 8U, c33_sf_marshallOut,
    c33_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c33_b_Q3_weight, 9U, c33_sf_marshallOut,
    c33_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c33_b_preemption, 10U,
    c33_sf_marshallOut, c33_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c33_b_workConservation, 11U,
    c33_sf_marshallOut, c33_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c33_Queue_select, 12U,
    c33_sf_marshallOut, c33_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE
    (chartInstance->c33_last_was_expedited_address, 13U, c33_b_sf_marshallOut,
     c33_b_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(chartInstance->c33_last_Q_served_address,
    14U, c33_sf_marshallOut, c33_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE
    (chartInstance->c33_Q_before_expediting_address, 15U, c33_sf_marshallOut,
     c33_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE
    (chartInstance->c33_current_Q_finished_address, 16U, c33_b_sf_marshallOut,
     c33_b_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(chartInstance->c33_packets_served_address,
    17U, c33_sf_marshallOut, c33_sf_marshallIn);
  CV_EML_FCN(0, 0);
  _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 2);
  _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 3);
  _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 4);
  _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 5);
  _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 6);
  _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 8);
  _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 13);
  if (CV_EML_IF(0, 1, 0, c33_get_last_was_expedited(chartInstance, 0))) {
    _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 14);
    c33_set_last_Q_served(chartInstance, 0, c33_get_Q_before_expediting
                          (chartInstance, 0));
    ssUpdateDataStoreLog(chartInstance->S, 2);
    _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 15);
    c33_set_last_was_expedited(chartInstance, 0, FALSE);
    ssUpdateDataStoreLog(chartInstance->S, 3);
  }

  _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 21);
  guard1 = FALSE;
  guard2 = FALSE;
  guard3 = FALSE;
  guard4 = FALSE;
  guard5 = FALSE;
  guard6 = FALSE;
  if (CV_EML_COND(0, 1, 0, c33_b_prioritization == 1.0)) {
    if (CV_EML_COND(0, 1, 1, c33_Q1_pending != 0.0) != 0.0) {
      if (CV_EML_COND(0, 1, 2, c33_b_preemption != 0.0) != 0.0) {
        guard2 = TRUE;
      } else {
        guard5 = TRUE;
      }
    } else {
      guard6 = TRUE;
    }
  } else {
    guard6 = TRUE;
  }

  if (guard6 == TRUE) {
    guard5 = TRUE;
  }

  if (guard5 == TRUE) {
    if (CV_EML_COND(0, 1, 3, c33_b_prioritization == 1.0)) {
      if (CV_EML_COND(0, 1, 4, c33_Q1_pending != 0.0) != 0.0) {
        if (!(CV_EML_COND(0, 1, 5, c33_b_preemption != 0.0) != 0.0)) {
          if (CV_EML_COND(0, 1, 6, c33_get_current_Q_finished(chartInstance, 0)))
          {
            guard2 = TRUE;
          } else {
            guard1 = TRUE;
          }
        } else {
          guard3 = TRUE;
        }
      } else {
        guard4 = TRUE;
      }
    } else {
      guard4 = TRUE;
    }
  }

  if (guard4 == TRUE) {
    guard3 = TRUE;
  }

  if (guard3 == TRUE) {
    guard1 = TRUE;
  }

  if (guard2 == TRUE) {
    CV_EML_MCDC(0, 1, 0, TRUE);
    CV_EML_IF(0, 1, 1, TRUE);
    _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 22);
    c33_set_last_was_expedited(chartInstance, 0, TRUE);
    ssUpdateDataStoreLog(chartInstance->S, 3);
    _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 23);
    c33_set_Q_before_expediting(chartInstance, 0, c33_get_last_Q_served
      (chartInstance, 0));
    ssUpdateDataStoreLog(chartInstance->S, 0);
    _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 24);
    c33_Queue_select = 1.0;
  }

  if (guard1 == TRUE) {
    CV_EML_MCDC(0, 1, 0, FALSE);
    CV_EML_IF(0, 1, 1, FALSE);
    _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 26);
    switch ((int16_T)_SFD_INTEGER_CHECK("last_Q_served", c33_get_last_Q_served
             (chartInstance, 0))) {
     case 3:
      CV_EML_SWITCH(0, 1, 0, 1);
      _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 28);
      guard13 = FALSE;
      if (CV_EML_COND(0, 1, 7, c33_b_weighting == 1.0)) {
        if (CV_EML_COND(0, 1, 8, c33_get_packets_served(chartInstance, 0) <
                        c33_b_Q3_weight)) {
          CV_EML_MCDC(0, 1, 1, TRUE);
          CV_EML_IF(0, 1, 2, TRUE);
          _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 29);
          c33_set_packets_served(chartInstance, 0, c33_get_packets_served
            (chartInstance, 0) + 1.0);
          ssUpdateDataStoreLog(chartInstance->S, 4);
          _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 30);
          c33_set_current_Q_finished(chartInstance, 0, FALSE);
          ssUpdateDataStoreLog(chartInstance->S, 1);
          _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 31);
          guard14 = FALSE;
          if (!(CV_EML_COND(0, 1, 9, c33_b_workConservation != 0.0) != 0.0)) {
            guard14 = TRUE;
          } else if (CV_EML_COND(0, 1, 10, c33_Q3_pending != 0.0) != 0.0) {
            guard14 = TRUE;
          } else {
            CV_EML_MCDC(0, 1, 2, FALSE);
            CV_EML_IF(0, 1, 3, FALSE);
            _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 33);
            if (CV_EML_IF(0, 1, 4, c33_Q1_pending != 0.0) != 0.0) {
              _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 34);
              c33_Queue_select = 1.0;
            } else {
              _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 36);
              c33_Queue_select = 2.0;
            }
          }

          if (guard14 == TRUE) {
            CV_EML_MCDC(0, 1, 2, TRUE);
            CV_EML_IF(0, 1, 3, TRUE);
            _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 32);
            c33_Queue_select = 3.0;
          }
        } else {
          guard13 = TRUE;
        }
      } else {
        guard13 = TRUE;
      }

      if (guard13 == TRUE) {
        CV_EML_MCDC(0, 1, 1, FALSE);
        CV_EML_IF(0, 1, 2, FALSE);
        _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 40);
        guard15 = FALSE;
        if (!(CV_EML_COND(0, 1, 11, c33_b_workConservation != 0.0) != 0.0)) {
          guard15 = TRUE;
        } else if (CV_EML_COND(0, 1, 12, c33_Q1_pending != 0.0) != 0.0) {
          guard15 = TRUE;
        } else {
          CV_EML_MCDC(0, 1, 3, FALSE);
          CV_EML_IF(0, 1, 5, FALSE);
          _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 42);
          if (CV_EML_IF(0, 1, 6, c33_Q2_pending != 0.0) != 0.0) {
            _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 43);
            c33_Queue_select = 2.0;
          } else {
            _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 45);
            c33_Queue_select = 3.0;
          }
        }

        if (guard15 == TRUE) {
          CV_EML_MCDC(0, 1, 3, TRUE);
          CV_EML_IF(0, 1, 5, TRUE);
          _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 41);
          c33_Queue_select = 1.0;
        }

        _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 48);
        c33_set_packets_served(chartInstance, 0, 1.0);
        ssUpdateDataStoreLog(chartInstance->S, 4);
        _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 49);
        c33_set_current_Q_finished(chartInstance, 0, TRUE);
        ssUpdateDataStoreLog(chartInstance->S, 1);
      }
      break;

     case 1:
      CV_EML_SWITCH(0, 1, 0, 2);
      _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 54);
      guard10 = FALSE;
      if (CV_EML_COND(0, 1, 13, c33_b_weighting == 1.0)) {
        if (CV_EML_COND(0, 1, 14, c33_get_packets_served(chartInstance, 0) <
                        c33_b_Q1_weight)) {
          CV_EML_MCDC(0, 1, 4, TRUE);
          CV_EML_IF(0, 1, 7, TRUE);
          _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 55);
          c33_set_packets_served(chartInstance, 0, c33_get_packets_served
            (chartInstance, 0) + 1.0);
          ssUpdateDataStoreLog(chartInstance->S, 4);
          _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 56);
          c33_set_current_Q_finished(chartInstance, 0, FALSE);
          ssUpdateDataStoreLog(chartInstance->S, 1);
          _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 57);
          guard11 = FALSE;
          if (!(CV_EML_COND(0, 1, 15, c33_b_workConservation != 0.0) != 0.0)) {
            guard11 = TRUE;
          } else if (CV_EML_COND(0, 1, 16, c33_Q1_pending != 0.0) != 0.0) {
            guard11 = TRUE;
          } else {
            CV_EML_MCDC(0, 1, 5, FALSE);
            CV_EML_IF(0, 1, 8, FALSE);
            _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 59);
            if (CV_EML_IF(0, 1, 9, c33_Q2_pending != 0.0) != 0.0) {
              _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 60);
              c33_Queue_select = 2.0;
            } else {
              _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 62);
              c33_Queue_select = 3.0;
            }
          }

          if (guard11 == TRUE) {
            CV_EML_MCDC(0, 1, 5, TRUE);
            CV_EML_IF(0, 1, 8, TRUE);
            _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 58);
            c33_Queue_select = 1.0;
          }
        } else {
          guard10 = TRUE;
        }
      } else {
        guard10 = TRUE;
      }

      if (guard10 == TRUE) {
        CV_EML_MCDC(0, 1, 4, FALSE);
        CV_EML_IF(0, 1, 7, FALSE);
        _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 66);
        guard12 = FALSE;
        if (!(CV_EML_COND(0, 1, 17, c33_b_workConservation != 0.0) != 0.0)) {
          guard12 = TRUE;
        } else if (CV_EML_COND(0, 1, 18, c33_Q2_pending != 0.0) != 0.0) {
          guard12 = TRUE;
        } else {
          CV_EML_MCDC(0, 1, 6, FALSE);
          CV_EML_IF(0, 1, 10, FALSE);
          _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 68);
          if (CV_EML_IF(0, 1, 11, c33_Q3_pending != 0.0) != 0.0) {
            _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 69);
            c33_Queue_select = 3.0;
          } else {
            _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 71);
            c33_Queue_select = 1.0;
          }
        }

        if (guard12 == TRUE) {
          CV_EML_MCDC(0, 1, 6, TRUE);
          CV_EML_IF(0, 1, 10, TRUE);
          _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 67);
          c33_Queue_select = 2.0;
        }

        _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 74);
        c33_set_packets_served(chartInstance, 0, 1.0);
        ssUpdateDataStoreLog(chartInstance->S, 4);
        _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 75);
        c33_set_current_Q_finished(chartInstance, 0, TRUE);
        ssUpdateDataStoreLog(chartInstance->S, 1);
      }
      break;

     case 2:
      CV_EML_SWITCH(0, 1, 0, 3);
      _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 79);
      guard7 = FALSE;
      if (CV_EML_COND(0, 1, 19, c33_b_weighting == 1.0)) {
        if (CV_EML_COND(0, 1, 20, c33_get_packets_served(chartInstance, 0) <
                        c33_b_Q2_weight)) {
          CV_EML_MCDC(0, 1, 7, TRUE);
          CV_EML_IF(0, 1, 12, TRUE);
          _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 80);
          c33_set_packets_served(chartInstance, 0, c33_get_packets_served
            (chartInstance, 0) + 1.0);
          ssUpdateDataStoreLog(chartInstance->S, 4);
          _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 81);
          c33_set_current_Q_finished(chartInstance, 0, FALSE);
          ssUpdateDataStoreLog(chartInstance->S, 1);
          _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 82);
          guard8 = FALSE;
          if (!(CV_EML_COND(0, 1, 21, c33_b_workConservation != 0.0) != 0.0)) {
            guard8 = TRUE;
          } else if (CV_EML_COND(0, 1, 22, c33_Q2_pending != 0.0) != 0.0) {
            guard8 = TRUE;
          } else {
            CV_EML_MCDC(0, 1, 8, FALSE);
            CV_EML_IF(0, 1, 13, FALSE);
            _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 84);
            if (CV_EML_IF(0, 1, 14, c33_Q3_pending != 0.0) != 0.0) {
              _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 85);
              c33_Queue_select = 3.0;
            } else {
              _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 87);
              c33_Queue_select = 1.0;
            }
          }

          if (guard8 == TRUE) {
            CV_EML_MCDC(0, 1, 8, TRUE);
            CV_EML_IF(0, 1, 13, TRUE);
            _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 83);
            c33_Queue_select = 2.0;
          }
        } else {
          guard7 = TRUE;
        }
      } else {
        guard7 = TRUE;
      }

      if (guard7 == TRUE) {
        CV_EML_MCDC(0, 1, 7, FALSE);
        CV_EML_IF(0, 1, 12, FALSE);
        _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 91);
        guard9 = FALSE;
        if (!(CV_EML_COND(0, 1, 23, c33_b_workConservation != 0.0) != 0.0)) {
          guard9 = TRUE;
        } else if (CV_EML_COND(0, 1, 24, c33_Q3_pending != 0.0) != 0.0) {
          guard9 = TRUE;
        } else {
          CV_EML_MCDC(0, 1, 9, FALSE);
          CV_EML_IF(0, 1, 15, FALSE);
          _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 93);
          if (CV_EML_IF(0, 1, 16, c33_Q1_pending != 0.0) != 0.0) {
            _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 94);
            c33_Queue_select = 1.0;
          } else {
            _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 96);
            c33_Queue_select = 2.0;
          }
        }

        if (guard9 == TRUE) {
          CV_EML_MCDC(0, 1, 9, TRUE);
          CV_EML_IF(0, 1, 15, TRUE);
          _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 92);
          c33_Queue_select = 3.0;
        }

        _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 99);
        c33_set_packets_served(chartInstance, 0, 1.0);
        ssUpdateDataStoreLog(chartInstance->S, 4);
        _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 100);
        c33_set_current_Q_finished(chartInstance, 0, TRUE);
        ssUpdateDataStoreLog(chartInstance->S, 1);
      }
      break;

     default:
      CV_EML_SWITCH(0, 1, 0, 0);
      _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 104);
      for (c33_i0 = 0; c33_i0 < 36; c33_i0++) {
        c33_u[c33_i0] = c33_cv0[c33_i0];
      }

      c33_y = NULL;
      sf_mex_assign(&c33_y, sf_mex_create("y", c33_u, 10, 0U, 1U, 0U, 2, 1, 36),
                    FALSE);
      sf_mex_call_debug("errordlg", 0U, 1U, 14, c33_y);
      _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, 105);
      c33_Queue_select = 1.0;
      break;
    }
  }

  _SFD_EML_CALL(0U, chartInstance->c33_sfEvent, -105);
  _SFD_SYMBOL_SCOPE_POP();
  *c33_b_Queue_select = c33_Queue_select;
  _SFD_CC_CALL(EXIT_OUT_OF_FUNCTION_TAG, 32U, chartInstance->c33_sfEvent);
}

static void initSimStructsc33_diffserv_model(SFc33_diffserv_modelInstanceStruct *
  chartInstance)
{
}

static void registerMessagesc33_diffserv_model
  (SFc33_diffserv_modelInstanceStruct *chartInstance)
{
}

static void init_script_number_translation(uint32_T c33_machineNumber, uint32_T
  c33_chartNumber)
{
}

static const mxArray *c33_sf_marshallOut(void *chartInstanceVoid, void
  *c33_inData)
{
  const mxArray *c33_mxArrayOutData = NULL;
  real_T c33_u;
  const mxArray *c33_y = NULL;
  SFc33_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc33_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c33_mxArrayOutData = NULL;
  c33_u = *(real_T *)c33_inData;
  c33_y = NULL;
  sf_mex_assign(&c33_y, sf_mex_create("y", &c33_u, 0, 0U, 0U, 0U, 0), FALSE);
  sf_mex_assign(&c33_mxArrayOutData, c33_y, FALSE);
  return c33_mxArrayOutData;
}

static real_T c33_emlrt_marshallIn(SFc33_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c33_packets_served, const char_T
  *c33_identifier)
{
  real_T c33_y;
  emlrtMsgIdentifier c33_thisId;
  c33_thisId.fIdentifier = c33_identifier;
  c33_thisId.fParent = NULL;
  c33_y = c33_b_emlrt_marshallIn(chartInstance, sf_mex_dup(c33_packets_served),
    &c33_thisId);
  sf_mex_destroy(&c33_packets_served);
  return c33_y;
}

static real_T c33_b_emlrt_marshallIn(SFc33_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c33_u, const emlrtMsgIdentifier *c33_parentId)
{
  real_T c33_y;
  real_T c33_d7;
  sf_mex_import(c33_parentId, sf_mex_dup(c33_u), &c33_d7, 1, 0, 0U, 0, 0U, 0);
  c33_y = c33_d7;
  sf_mex_destroy(&c33_u);
  return c33_y;
}

static void c33_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c33_mxArrayInData, const char_T *c33_varName, void *c33_outData)
{
  const mxArray *c33_packets_served;
  const char_T *c33_identifier;
  emlrtMsgIdentifier c33_thisId;
  real_T c33_y;
  SFc33_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc33_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c33_packets_served = sf_mex_dup(c33_mxArrayInData);
  c33_identifier = c33_varName;
  c33_thisId.fIdentifier = c33_identifier;
  c33_thisId.fParent = NULL;
  c33_y = c33_b_emlrt_marshallIn(chartInstance, sf_mex_dup(c33_packets_served),
    &c33_thisId);
  sf_mex_destroy(&c33_packets_served);
  *(real_T *)c33_outData = c33_y;
  sf_mex_destroy(&c33_mxArrayInData);
}

static const mxArray *c33_b_sf_marshallOut(void *chartInstanceVoid, void
  *c33_inData)
{
  const mxArray *c33_mxArrayOutData = NULL;
  boolean_T c33_u;
  const mxArray *c33_y = NULL;
  SFc33_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc33_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c33_mxArrayOutData = NULL;
  c33_u = *(boolean_T *)c33_inData;
  c33_y = NULL;
  sf_mex_assign(&c33_y, sf_mex_create("y", &c33_u, 11, 0U, 0U, 0U, 0), FALSE);
  sf_mex_assign(&c33_mxArrayOutData, c33_y, FALSE);
  return c33_mxArrayOutData;
}

static boolean_T c33_c_emlrt_marshallIn(SFc33_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c33_u, const emlrtMsgIdentifier *c33_parentId)
{
  boolean_T c33_y;
  boolean_T c33_b0;
  sf_mex_import(c33_parentId, sf_mex_dup(c33_u), &c33_b0, 1, 11, 0U, 0, 0U, 0);
  c33_y = c33_b0;
  sf_mex_destroy(&c33_u);
  return c33_y;
}

static void c33_b_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c33_mxArrayInData, const char_T *c33_varName, void *c33_outData)
{
  const mxArray *c33_current_Q_finished;
  const char_T *c33_identifier;
  emlrtMsgIdentifier c33_thisId;
  boolean_T c33_y;
  SFc33_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc33_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c33_current_Q_finished = sf_mex_dup(c33_mxArrayInData);
  c33_identifier = c33_varName;
  c33_thisId.fIdentifier = c33_identifier;
  c33_thisId.fParent = NULL;
  c33_y = c33_c_emlrt_marshallIn(chartInstance, sf_mex_dup
    (c33_current_Q_finished), &c33_thisId);
  sf_mex_destroy(&c33_current_Q_finished);
  *(boolean_T *)c33_outData = c33_y;
  sf_mex_destroy(&c33_mxArrayInData);
}

const mxArray *sf_c33_diffserv_model_get_eml_resolved_functions_info(void)
{
  const mxArray *c33_nameCaptureInfo = NULL;
  c33_nameCaptureInfo = NULL;
  sf_mex_assign(&c33_nameCaptureInfo, sf_mex_create("nameCaptureInfo", NULL, 0,
    0U, 1U, 0U, 2, 0, 1), FALSE);
  return c33_nameCaptureInfo;
}

static const mxArray *c33_c_sf_marshallOut(void *chartInstanceVoid, void
  *c33_inData)
{
  const mxArray *c33_mxArrayOutData = NULL;
  int8_T c33_u;
  const mxArray *c33_y = NULL;
  SFc33_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc33_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c33_mxArrayOutData = NULL;
  c33_u = *(int8_T *)c33_inData;
  c33_y = NULL;
  sf_mex_assign(&c33_y, sf_mex_create("y", &c33_u, 2, 0U, 0U, 0U, 0), FALSE);
  sf_mex_assign(&c33_mxArrayOutData, c33_y, FALSE);
  return c33_mxArrayOutData;
}

static int8_T c33_d_emlrt_marshallIn(SFc33_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c33_u, const emlrtMsgIdentifier *c33_parentId)
{
  int8_T c33_y;
  int8_T c33_i1;
  sf_mex_import(c33_parentId, sf_mex_dup(c33_u), &c33_i1, 1, 2, 0U, 0, 0U, 0);
  c33_y = c33_i1;
  sf_mex_destroy(&c33_u);
  return c33_y;
}

static void c33_c_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c33_mxArrayInData, const char_T *c33_varName, void *c33_outData)
{
  const mxArray *c33_Next_packet;
  const char_T *c33_identifier;
  emlrtMsgIdentifier c33_thisId;
  int8_T c33_y;
  SFc33_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc33_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c33_Next_packet = sf_mex_dup(c33_mxArrayInData);
  c33_identifier = c33_varName;
  c33_thisId.fIdentifier = c33_identifier;
  c33_thisId.fParent = NULL;
  c33_y = c33_d_emlrt_marshallIn(chartInstance, sf_mex_dup(c33_Next_packet),
    &c33_thisId);
  sf_mex_destroy(&c33_Next_packet);
  *(int8_T *)c33_outData = c33_y;
  sf_mex_destroy(&c33_mxArrayInData);
}

static const mxArray *c33_d_sf_marshallOut(void *chartInstanceVoid, void
  *c33_inData)
{
  const mxArray *c33_mxArrayOutData = NULL;
  int32_T c33_u;
  const mxArray *c33_y = NULL;
  SFc33_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc33_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c33_mxArrayOutData = NULL;
  c33_u = *(int32_T *)c33_inData;
  c33_y = NULL;
  sf_mex_assign(&c33_y, sf_mex_create("y", &c33_u, 6, 0U, 0U, 0U, 0), FALSE);
  sf_mex_assign(&c33_mxArrayOutData, c33_y, FALSE);
  return c33_mxArrayOutData;
}

static int32_T c33_e_emlrt_marshallIn(SFc33_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c33_u, const emlrtMsgIdentifier *c33_parentId)
{
  int32_T c33_y;
  int32_T c33_i2;
  sf_mex_import(c33_parentId, sf_mex_dup(c33_u), &c33_i2, 1, 6, 0U, 0, 0U, 0);
  c33_y = c33_i2;
  sf_mex_destroy(&c33_u);
  return c33_y;
}

static void c33_d_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c33_mxArrayInData, const char_T *c33_varName, void *c33_outData)
{
  const mxArray *c33_b_sfEvent;
  const char_T *c33_identifier;
  emlrtMsgIdentifier c33_thisId;
  int32_T c33_y;
  SFc33_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc33_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c33_b_sfEvent = sf_mex_dup(c33_mxArrayInData);
  c33_identifier = c33_varName;
  c33_thisId.fIdentifier = c33_identifier;
  c33_thisId.fParent = NULL;
  c33_y = c33_e_emlrt_marshallIn(chartInstance, sf_mex_dup(c33_b_sfEvent),
    &c33_thisId);
  sf_mex_destroy(&c33_b_sfEvent);
  *(int32_T *)c33_outData = c33_y;
  sf_mex_destroy(&c33_mxArrayInData);
}

static uint8_T c33_f_emlrt_marshallIn(SFc33_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c33_b_is_active_c33_diffserv_model, const
  char_T *c33_identifier)
{
  uint8_T c33_y;
  emlrtMsgIdentifier c33_thisId;
  c33_thisId.fIdentifier = c33_identifier;
  c33_thisId.fParent = NULL;
  c33_y = c33_g_emlrt_marshallIn(chartInstance, sf_mex_dup
    (c33_b_is_active_c33_diffserv_model), &c33_thisId);
  sf_mex_destroy(&c33_b_is_active_c33_diffserv_model);
  return c33_y;
}

static uint8_T c33_g_emlrt_marshallIn(SFc33_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c33_u, const emlrtMsgIdentifier *c33_parentId)
{
  uint8_T c33_y;
  uint8_T c33_u0;
  sf_mex_import(c33_parentId, sf_mex_dup(c33_u), &c33_u0, 1, 3, 0U, 0, 0U, 0);
  c33_y = c33_u0;
  sf_mex_destroy(&c33_u);
  return c33_y;
}

static real_T c33_get_Q_before_expediting(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b)
{
  ssReadFromDataStoreElement(chartInstance->S, 0, NULL, c33_b);
  if (chartInstance->c33_Q_before_expediting_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'Q_before_expediting\' (#306) in the initialization routine of the chart.\n");
  }

  return *chartInstance->c33_Q_before_expediting_address;
}

static void c33_set_Q_before_expediting(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b, real_T c33_c)
{
  ssWriteToDataStoreElement(chartInstance->S, 0, NULL, c33_b);
  if (chartInstance->c33_Q_before_expediting_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'Q_before_expediting\' (#306) in the initialization routine of the chart.\n");
  }

  *chartInstance->c33_Q_before_expediting_address = c33_c;
}

static real_T *c33_access_Q_before_expediting(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b)
{
  real_T *c33_c;
  ssReadFromDataStore(chartInstance->S, 0, NULL);
  if (chartInstance->c33_Q_before_expediting_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'Q_before_expediting\' (#306) in the initialization routine of the chart.\n");
  }

  c33_c = chartInstance->c33_Q_before_expediting_address;
  if (c33_b == 0) {
    ssWriteToDataStore(chartInstance->S, 0, NULL);
  }

  return c33_c;
}

static boolean_T c33_get_current_Q_finished(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b)
{
  ssReadFromDataStoreElement(chartInstance->S, 1, NULL, c33_b);
  if (chartInstance->c33_current_Q_finished_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'current_Q_finished\' (#307) in the initialization routine of the chart.\n");
  }

  return *chartInstance->c33_current_Q_finished_address;
}

static void c33_set_current_Q_finished(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b, boolean_T c33_c)
{
  ssWriteToDataStoreElement(chartInstance->S, 1, NULL, c33_b);
  if (chartInstance->c33_current_Q_finished_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'current_Q_finished\' (#307) in the initialization routine of the chart.\n");
  }

  *chartInstance->c33_current_Q_finished_address = c33_c;
}

static boolean_T *c33_access_current_Q_finished
  (SFc33_diffserv_modelInstanceStruct *chartInstance, uint32_T c33_b)
{
  boolean_T *c33_c;
  ssReadFromDataStore(chartInstance->S, 1, NULL);
  if (chartInstance->c33_current_Q_finished_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'current_Q_finished\' (#307) in the initialization routine of the chart.\n");
  }

  c33_c = chartInstance->c33_current_Q_finished_address;
  if (c33_b == 0) {
    ssWriteToDataStore(chartInstance->S, 1, NULL);
  }

  return c33_c;
}

static real_T c33_get_last_Q_served(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b)
{
  ssReadFromDataStoreElement(chartInstance->S, 2, NULL, c33_b);
  if (chartInstance->c33_last_Q_served_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'last_Q_served\' (#301) in the initialization routine of the chart.\n");
  }

  return *chartInstance->c33_last_Q_served_address;
}

static void c33_set_last_Q_served(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b, real_T c33_c)
{
  ssWriteToDataStoreElement(chartInstance->S, 2, NULL, c33_b);
  if (chartInstance->c33_last_Q_served_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'last_Q_served\' (#301) in the initialization routine of the chart.\n");
  }

  *chartInstance->c33_last_Q_served_address = c33_c;
}

static real_T *c33_access_last_Q_served(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b)
{
  real_T *c33_c;
  ssReadFromDataStore(chartInstance->S, 2, NULL);
  if (chartInstance->c33_last_Q_served_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'last_Q_served\' (#301) in the initialization routine of the chart.\n");
  }

  c33_c = chartInstance->c33_last_Q_served_address;
  if (c33_b == 0) {
    ssWriteToDataStore(chartInstance->S, 2, NULL);
  }

  return c33_c;
}

static boolean_T c33_get_last_was_expedited(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b)
{
  ssReadFromDataStoreElement(chartInstance->S, 3, NULL, c33_b);
  if (chartInstance->c33_last_was_expedited_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'last_was_expedited\' (#305) in the initialization routine of the chart.\n");
  }

  return *chartInstance->c33_last_was_expedited_address;
}

static void c33_set_last_was_expedited(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b, boolean_T c33_c)
{
  ssWriteToDataStoreElement(chartInstance->S, 3, NULL, c33_b);
  if (chartInstance->c33_last_was_expedited_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'last_was_expedited\' (#305) in the initialization routine of the chart.\n");
  }

  *chartInstance->c33_last_was_expedited_address = c33_c;
}

static boolean_T *c33_access_last_was_expedited
  (SFc33_diffserv_modelInstanceStruct *chartInstance, uint32_T c33_b)
{
  boolean_T *c33_c;
  ssReadFromDataStore(chartInstance->S, 3, NULL);
  if (chartInstance->c33_last_was_expedited_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'last_was_expedited\' (#305) in the initialization routine of the chart.\n");
  }

  c33_c = chartInstance->c33_last_was_expedited_address;
  if (c33_b == 0) {
    ssWriteToDataStore(chartInstance->S, 3, NULL);
  }

  return c33_c;
}

static real_T c33_get_packets_served(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b)
{
  ssReadFromDataStoreElement(chartInstance->S, 4, NULL, c33_b);
  if (chartInstance->c33_packets_served_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'packets_served\' (#300) in the initialization routine of the chart.\n");
  }

  return *chartInstance->c33_packets_served_address;
}

static void c33_set_packets_served(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b, real_T c33_c)
{
  ssWriteToDataStoreElement(chartInstance->S, 4, NULL, c33_b);
  if (chartInstance->c33_packets_served_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'packets_served\' (#300) in the initialization routine of the chart.\n");
  }

  *chartInstance->c33_packets_served_address = c33_c;
}

static real_T *c33_access_packets_served(SFc33_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c33_b)
{
  real_T *c33_c;
  ssReadFromDataStore(chartInstance->S, 4, NULL);
  if (chartInstance->c33_packets_served_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'packets_served\' (#300) in the initialization routine of the chart.\n");
  }

  c33_c = chartInstance->c33_packets_served_address;
  if (c33_b == 0) {
    ssWriteToDataStore(chartInstance->S, 4, NULL);
  }

  return c33_c;
}

static void init_dsm_address_info(SFc33_diffserv_modelInstanceStruct
  *chartInstance)
{
  ssGetSFcnDataStoreNameAddrIdx(chartInstance->S, "Q_before_expediting", (void **)
    &chartInstance->c33_Q_before_expediting_address,
    &chartInstance->c33_Q_before_expediting_index);
  ssGetSFcnDataStoreNameAddrIdx(chartInstance->S, "current_Q_finished", (void **)
    &chartInstance->c33_current_Q_finished_address,
    &chartInstance->c33_current_Q_finished_index);
  ssGetSFcnDataStoreNameAddrIdx(chartInstance->S, "last_Q_served", (void **)
    &chartInstance->c33_last_Q_served_address,
    &chartInstance->c33_last_Q_served_index);
  ssGetSFcnDataStoreNameAddrIdx(chartInstance->S, "last_was_expedited", (void **)
    &chartInstance->c33_last_was_expedited_address,
    &chartInstance->c33_last_was_expedited_index);
  ssGetSFcnDataStoreNameAddrIdx(chartInstance->S, "packets_served", (void **)
    &chartInstance->c33_packets_served_address,
    &chartInstance->c33_packets_served_index);
}

/* SFunction Glue Code */
#ifdef utFree
#undef utFree
#endif

#ifdef utMalloc
#undef utMalloc
#endif

#ifdef __cplusplus

extern "C" void *utMalloc(size_t size);
extern "C" void utFree(void*);

#else

extern void *utMalloc(size_t size);
extern void utFree(void*);

#endif

void sf_c33_diffserv_model_get_check_sum(mxArray *plhs[])
{
  ((real_T *)mxGetPr((plhs[0])))[0] = (real_T)(3373378641U);
  ((real_T *)mxGetPr((plhs[0])))[1] = (real_T)(449403993U);
  ((real_T *)mxGetPr((plhs[0])))[2] = (real_T)(201359331U);
  ((real_T *)mxGetPr((plhs[0])))[3] = (real_T)(2430090211U);
}

mxArray *sf_c33_diffserv_model_get_autoinheritance_info(void)
{
  const char *autoinheritanceFields[] = { "checksum", "inputs", "parameters",
    "outputs", "locals" };

  mxArray *mxAutoinheritanceInfo = mxCreateStructMatrix(1,1,5,
    autoinheritanceFields);

  {
    mxArray *mxChecksum = mxCreateString("uJCNVtXPq0IPrhGim13T0G");
    mxSetField(mxAutoinheritanceInfo,0,"checksum",mxChecksum);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,3,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }

    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"inputs",mxData);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,7,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,1,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,1,"type",mxType);
    }

    mxSetField(mxData,1,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,2,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,2,"type",mxType);
    }

    mxSetField(mxData,2,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,3,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,3,"type",mxType);
    }

    mxSetField(mxData,3,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,4,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,4,"type",mxType);
    }

    mxSetField(mxData,4,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,5,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,5,"type",mxType);
    }

    mxSetField(mxData,5,"complexity",mxCreateDoubleScalar(0));

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,6,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,6,"type",mxType);
    }

    mxSetField(mxData,6,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"parameters",mxData);
  }

  {
    const char *dataFields[] = { "size", "type", "complexity" };

    mxArray *mxData = mxCreateStructMatrix(1,1,3,dataFields);

    {
      mxArray *mxSize = mxCreateDoubleMatrix(1,2,mxREAL);
      double *pr = mxGetPr(mxSize);
      pr[0] = (double)(1);
      pr[1] = (double)(1);
      mxSetField(mxData,0,"size",mxSize);
    }

    {
      const char *typeFields[] = { "base", "fixpt" };

      mxArray *mxType = mxCreateStructMatrix(1,1,2,typeFields);
      mxSetField(mxType,0,"base",mxCreateDoubleScalar(10));
      mxSetField(mxType,0,"fixpt",mxCreateDoubleMatrix(0,0,mxREAL));
      mxSetField(mxData,0,"type",mxType);
    }

    mxSetField(mxData,0,"complexity",mxCreateDoubleScalar(0));
    mxSetField(mxAutoinheritanceInfo,0,"outputs",mxData);
  }

  {
    mxSetField(mxAutoinheritanceInfo,0,"locals",mxCreateDoubleMatrix(0,0,mxREAL));
  }

  return(mxAutoinheritanceInfo);
}

mxArray *sf_c33_diffserv_model_third_party_uses_info(void)
{
  mxArray * mxcell3p = mxCreateCellMatrix(1,0);
  return(mxcell3p);
}

static const mxArray *sf_get_sim_state_info_c33_diffserv_model(void)
{
  const char *infoFields[] = { "chartChecksum", "varInfo" };

  mxArray *mxInfo = mxCreateStructMatrix(1, 1, 2, infoFields);
  const char *infoEncStr[] = {
    "100 S1x2'type','srcId','name','auxInfo'{{M[1],M[8],T\"Queue_select\",},{M[8],M[0],T\"is_active_c33_diffserv_model\",}}"
  };

  mxArray *mxVarInfo = sf_mex_decode_encoded_mx_struct_array(infoEncStr, 2, 10);
  mxArray *mxChecksum = mxCreateDoubleMatrix(1, 4, mxREAL);
  sf_c33_diffserv_model_get_check_sum(&mxChecksum);
  mxSetField(mxInfo, 0, infoFields[0], mxChecksum);
  mxSetField(mxInfo, 0, infoFields[1], mxVarInfo);
  return mxInfo;
}

static void chart_debug_initialization(SimStruct *S, unsigned int
  fullDebuggerInitialization)
{
  if (!sim_mode_is_rtw_gen(S)) {
    SFc33_diffserv_modelInstanceStruct *chartInstance;
    chartInstance = (SFc33_diffserv_modelInstanceStruct *) ((ChartInfoStruct *)
      (ssGetUserData(S)))->chartInstance;
    if (ssIsFirstInitCond(S) && fullDebuggerInitialization==1) {
      /* do this only if simulation is starting */
      {
        unsigned int chartAlreadyPresent;
        chartAlreadyPresent = sf_debug_initialize_chart
          (sfGlobalDebugInstanceStruct,
           _diffserv_modelMachineNumber_,
           33,
           1,
           1,
           16,
           1,
           0,
           0,
           0,
           0,
           &(chartInstance->chartNumber),
           &(chartInstance->instanceNumber),
           ssGetPath(S),
           (void *)S);
        if (chartAlreadyPresent==0) {
          /* this is the first instance */
          init_script_number_translation(_diffserv_modelMachineNumber_,
            chartInstance->chartNumber);
          sf_debug_set_chart_disable_implicit_casting
            (sfGlobalDebugInstanceStruct,_diffserv_modelMachineNumber_,
             chartInstance->chartNumber,1);
          sf_debug_set_chart_event_thresholds(sfGlobalDebugInstanceStruct,
            _diffserv_modelMachineNumber_,
            chartInstance->chartNumber,
            1,
            1,
            1);
          _SFD_SET_DATA_PROPS(0,1,1,0,"Q1_pending");
          _SFD_SET_DATA_PROPS(1,1,1,0,"Q2_pending");
          _SFD_SET_DATA_PROPS(2,1,1,0,"Q3_pending");
          _SFD_SET_DATA_PROPS(3,10,0,0,"prioritization");
          _SFD_SET_DATA_PROPS(4,10,0,0,"weighting");
          _SFD_SET_DATA_PROPS(5,2,0,1,"Queue_select");
          _SFD_SET_DATA_PROPS(6,11,0,0,"packets_served");
          _SFD_SET_DATA_PROPS(7,11,0,0,"last_Q_served");
          _SFD_SET_DATA_PROPS(8,10,0,0,"Q1_weight");
          _SFD_SET_DATA_PROPS(9,10,0,0,"Q2_weight");
          _SFD_SET_DATA_PROPS(10,10,0,0,"Q3_weight");
          _SFD_SET_DATA_PROPS(11,11,0,0,"last_was_expedited");
          _SFD_SET_DATA_PROPS(12,11,0,0,"Q_before_expediting");
          _SFD_SET_DATA_PROPS(13,11,0,0,"current_Q_finished");
          _SFD_SET_DATA_PROPS(14,10,0,0,"preemption");
          _SFD_SET_DATA_PROPS(15,10,0,0,"workConservation");
          _SFD_EVENT_SCOPE(0,1);
          _SFD_STATE_INFO(0,0,2);
          _SFD_CH_SUBSTATE_COUNT(0);
          _SFD_CH_SUBSTATE_DECOMP(0);
        }

        _SFD_CV_INIT_CHART(0,0,0,0);

        {
          _SFD_CV_INIT_STATE(0,0,0,0,0,0,NULL,NULL);
        }

        _SFD_CV_INIT_TRANS(0,0,NULL,NULL,0,NULL);

        /* Initialization of MATLAB Function Model Coverage */
        _SFD_CV_INIT_EML(0,1,1,17,0,0,1,0,0,25,10);
        _SFD_CV_INIT_EML_FCN(0,0,"eML_blk_kernel",0,-1,4436);
        _SFD_CV_INIT_EML_IF(0,1,0,478,499,-1,576);
        _SFD_CV_INIT_EML_IF(0,1,1,839,981,1186,4425);
        _SFD_CV_INIT_EML_IF(0,1,2,1243,1294,2266,2634);
        _SFD_CV_INIT_EML_IF(0,1,3,1606,1644,1819,2235);
        _SFD_CV_INIT_EML_IF(0,1,4,1819,1836,2004,2235);
        _SFD_CV_INIT_EML_IF(0,1,5,2287,2325,2380,2514);
        _SFD_CV_INIT_EML_IF(0,1,6,2380,2397,2452,2514);
        _SFD_CV_INIT_EML_IF(0,1,7,2671,2722,3094,3469);
        _SFD_CV_INIT_EML_IF(0,1,8,2836,2874,2929,3063);
        _SFD_CV_INIT_EML_IF(0,1,9,2929,2946,3001,3063);
        _SFD_CV_INIT_EML_IF(0,1,10,3115,3153,3208,3342);
        _SFD_CV_INIT_EML_IF(0,1,11,3208,3225,3280,3342);
        _SFD_CV_INIT_EML_IF(0,1,12,3506,3557,3929,4292);
        _SFD_CV_INIT_EML_IF(0,1,13,3671,3709,3764,3898);
        _SFD_CV_INIT_EML_IF(0,1,14,3764,3781,3836,3898);
        _SFD_CV_INIT_EML_IF(0,1,15,3950,3988,4044,4179);
        _SFD_CV_INIT_EML_IF(0,1,16,4044,4061,4117,4179);

        {
          static int caseStart[] = { 4310, 1224, 2652, 3487 };

          static int caseExprEnd[] = { 4319, 1230, 2658, 3493 };

          _SFD_CV_INIT_EML_SWITCH(0,1,0,1195,1216,4419,4,&(caseStart[0]),
            &(caseExprEnd[0]));
        }

        {
          static int condStart[] = { 844, 869, 885, 903, 928, 945, 961 };

          static int condEnd[] = { 863, 879, 895, 922, 938, 955, 979 };

          static int pfixExpr[] = { 0, 1, -3, 2, -3, 3, 4, -3, 5, -1, -3, 6, -3,
            -2 };

          _SFD_CV_INIT_EML_MCDC(0,1,0,842,981,7,0,&(condStart[0]),&(condEnd[0]),
                                14,&(pfixExpr[0]));
        }

        {
          static int condStart[] = { 1247, 1267 };

          static int condEnd[] = { 1261, 1293 };

          static int pfixExpr[] = { 0, 1, -3 };

          _SFD_CV_INIT_EML_MCDC(0,1,1,1246,1294,2,7,&(condStart[0]),&(condEnd[0]),
                                3,&(pfixExpr[0]));
        }

        {
          static int condStart[] = { 1611, 1633 };

          static int condEnd[] = { 1627, 1643 };

          static int pfixExpr[] = { 0, -1, 1, -2 };

          _SFD_CV_INIT_EML_MCDC(0,1,2,1609,1644,2,9,&(condStart[0]),&(condEnd[0]),
                                4,&(pfixExpr[0]));
        }

        {
          static int condStart[] = { 2292, 2314 };

          static int condEnd[] = { 2308, 2324 };

          static int pfixExpr[] = { 0, -1, 1, -2 };

          _SFD_CV_INIT_EML_MCDC(0,1,3,2290,2325,2,11,&(condStart[0]),&(condEnd[0]),
                                4,&(pfixExpr[0]));
        }

        {
          static int condStart[] = { 2675, 2695 };

          static int condEnd[] = { 2689, 2721 };

          static int pfixExpr[] = { 0, 1, -3 };

          _SFD_CV_INIT_EML_MCDC(0,1,4,2674,2722,2,13,&(condStart[0]),&(condEnd[0]),
                                3,&(pfixExpr[0]));
        }

        {
          static int condStart[] = { 2841, 2863 };

          static int condEnd[] = { 2857, 2873 };

          static int pfixExpr[] = { 0, -1, 1, -2 };

          _SFD_CV_INIT_EML_MCDC(0,1,5,2839,2874,2,15,&(condStart[0]),&(condEnd[0]),
                                4,&(pfixExpr[0]));
        }

        {
          static int condStart[] = { 3120, 3142 };

          static int condEnd[] = { 3136, 3152 };

          static int pfixExpr[] = { 0, -1, 1, -2 };

          _SFD_CV_INIT_EML_MCDC(0,1,6,3118,3153,2,17,&(condStart[0]),&(condEnd[0]),
                                4,&(pfixExpr[0]));
        }

        {
          static int condStart[] = { 3510, 3530 };

          static int condEnd[] = { 3524, 3556 };

          static int pfixExpr[] = { 0, 1, -3 };

          _SFD_CV_INIT_EML_MCDC(0,1,7,3509,3557,2,19,&(condStart[0]),&(condEnd[0]),
                                3,&(pfixExpr[0]));
        }

        {
          static int condStart[] = { 3676, 3698 };

          static int condEnd[] = { 3692, 3708 };

          static int pfixExpr[] = { 0, -1, 1, -2 };

          _SFD_CV_INIT_EML_MCDC(0,1,8,3674,3709,2,21,&(condStart[0]),&(condEnd[0]),
                                4,&(pfixExpr[0]));
        }

        {
          static int condStart[] = { 3955, 3977 };

          static int condEnd[] = { 3971, 3987 };

          static int pfixExpr[] = { 0, -1, 1, -2 };

          _SFD_CV_INIT_EML_MCDC(0,1,9,3953,3988,2,23,&(condStart[0]),&(condEnd[0]),
                                4,&(pfixExpr[0]));
        }

        _SFD_TRANS_COV_WTS(0,0,0,1,0);
        if (chartAlreadyPresent==0) {
          _SFD_TRANS_COV_MAPS(0,
                              0,NULL,NULL,
                              0,NULL,NULL,
                              1,NULL,NULL,
                              0,NULL,NULL);
        }

        _SFD_SET_DATA_COMPILED_PROPS(0,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c33_sf_marshallOut,(MexInFcnForType)NULL);
        _SFD_SET_DATA_COMPILED_PROPS(1,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c33_sf_marshallOut,(MexInFcnForType)NULL);
        _SFD_SET_DATA_COMPILED_PROPS(2,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c33_sf_marshallOut,(MexInFcnForType)NULL);
        _SFD_SET_DATA_COMPILED_PROPS(3,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c33_sf_marshallOut,(MexInFcnForType)c33_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(4,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c33_sf_marshallOut,(MexInFcnForType)c33_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(5,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c33_sf_marshallOut,(MexInFcnForType)c33_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(6,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c33_sf_marshallOut,(MexInFcnForType)c33_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(7,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c33_sf_marshallOut,(MexInFcnForType)c33_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(8,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c33_sf_marshallOut,(MexInFcnForType)c33_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(9,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c33_sf_marshallOut,(MexInFcnForType)c33_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(10,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c33_sf_marshallOut,(MexInFcnForType)c33_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(11,SF_UINT8,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c33_b_sf_marshallOut,(MexInFcnForType)
          c33_b_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(12,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c33_sf_marshallOut,(MexInFcnForType)c33_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(13,SF_UINT8,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c33_b_sf_marshallOut,(MexInFcnForType)
          c33_b_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(14,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c33_sf_marshallOut,(MexInFcnForType)c33_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(15,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c33_sf_marshallOut,(MexInFcnForType)c33_sf_marshallIn);

        {
          real_T *c33_Q1_pending;
          real_T *c33_Q2_pending;
          real_T *c33_Q3_pending;
          real_T *c33_Queue_select;
          c33_Queue_select = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
          c33_Q3_pending = (real_T *)ssGetInputPortSignal(chartInstance->S, 2);
          c33_Q2_pending = (real_T *)ssGetInputPortSignal(chartInstance->S, 1);
          c33_Q1_pending = (real_T *)ssGetInputPortSignal(chartInstance->S, 0);
          _SFD_SET_DATA_VALUE_PTR(0U, c33_Q1_pending);
          _SFD_SET_DATA_VALUE_PTR(1U, c33_Q2_pending);
          _SFD_SET_DATA_VALUE_PTR(2U, c33_Q3_pending);
          _SFD_SET_DATA_VALUE_PTR(3U, &chartInstance->c33_prioritization);
          _SFD_SET_DATA_VALUE_PTR(4U, &chartInstance->c33_weighting);
          _SFD_SET_DATA_VALUE_PTR(5U, c33_Queue_select);
          _SFD_SET_DATA_VALUE_PTR(6U, chartInstance->c33_packets_served_address);
          _SFD_SET_DATA_VALUE_PTR(7U, chartInstance->c33_last_Q_served_address);
          _SFD_SET_DATA_VALUE_PTR(8U, &chartInstance->c33_Q1_weight);
          _SFD_SET_DATA_VALUE_PTR(9U, &chartInstance->c33_Q2_weight);
          _SFD_SET_DATA_VALUE_PTR(10U, &chartInstance->c33_Q3_weight);
          _SFD_SET_DATA_VALUE_PTR(11U,
            chartInstance->c33_last_was_expedited_address);
          _SFD_SET_DATA_VALUE_PTR(12U,
            chartInstance->c33_Q_before_expediting_address);
          _SFD_SET_DATA_VALUE_PTR(13U,
            chartInstance->c33_current_Q_finished_address);
          _SFD_SET_DATA_VALUE_PTR(14U, &chartInstance->c33_preemption);
          _SFD_SET_DATA_VALUE_PTR(15U, &chartInstance->c33_workConservation);
        }
      }
    } else {
      sf_debug_reset_current_state_configuration(sfGlobalDebugInstanceStruct,
        _diffserv_modelMachineNumber_,chartInstance->chartNumber,
        chartInstance->instanceNumber);
    }
  }
}

static const char* sf_get_instance_specialization(void)
{
  return "SOFhyw8lhhK1SqMOHaAnWG";
}

static void sf_opaque_initialize_c33_diffserv_model(void *chartInstanceVar)
{
  chart_debug_initialization(((SFc33_diffserv_modelInstanceStruct*)
    chartInstanceVar)->S,0);
  initialize_params_c33_diffserv_model((SFc33_diffserv_modelInstanceStruct*)
    chartInstanceVar);
  initialize_c33_diffserv_model((SFc33_diffserv_modelInstanceStruct*)
    chartInstanceVar);
}

static void sf_opaque_enable_c33_diffserv_model(void *chartInstanceVar)
{
  enable_c33_diffserv_model((SFc33_diffserv_modelInstanceStruct*)
    chartInstanceVar);
}

static void sf_opaque_disable_c33_diffserv_model(void *chartInstanceVar)
{
  disable_c33_diffserv_model((SFc33_diffserv_modelInstanceStruct*)
    chartInstanceVar);
}

static void sf_opaque_gateway_c33_diffserv_model(void *chartInstanceVar)
{
  sf_c33_diffserv_model((SFc33_diffserv_modelInstanceStruct*) chartInstanceVar);
}

extern const mxArray* sf_internal_get_sim_state_c33_diffserv_model(SimStruct* S)
{
  ChartInfoStruct *chartInfo = (ChartInfoStruct*) ssGetUserData(S);
  mxArray *plhs[1] = { NULL };

  mxArray *prhs[4];
  int mxError = 0;
  prhs[0] = mxCreateString("chart_simctx_raw2high");
  prhs[1] = mxCreateDoubleScalar(ssGetSFuncBlockHandle(S));
  prhs[2] = (mxArray*) get_sim_state_c33_diffserv_model
    ((SFc33_diffserv_modelInstanceStruct*)chartInfo->chartInstance);/* raw sim ctx */
  prhs[3] = (mxArray*) sf_get_sim_state_info_c33_diffserv_model();/* state var info */
  mxError = sf_mex_call_matlab(1, plhs, 4, prhs, "sfprivate");
  mxDestroyArray(prhs[0]);
  mxDestroyArray(prhs[1]);
  mxDestroyArray(prhs[2]);
  mxDestroyArray(prhs[3]);
  if (mxError || plhs[0] == NULL) {
    sf_mex_error_message("Stateflow Internal Error: \nError calling 'chart_simctx_raw2high'.\n");
  }

  return plhs[0];
}

extern void sf_internal_set_sim_state_c33_diffserv_model(SimStruct* S, const
  mxArray *st)
{
  ChartInfoStruct *chartInfo = (ChartInfoStruct*) ssGetUserData(S);
  mxArray *plhs[1] = { NULL };

  mxArray *prhs[4];
  int mxError = 0;
  prhs[0] = mxCreateString("chart_simctx_high2raw");
  prhs[1] = mxCreateDoubleScalar(ssGetSFuncBlockHandle(S));
  prhs[2] = mxDuplicateArray(st);      /* high level simctx */
  prhs[3] = (mxArray*) sf_get_sim_state_info_c33_diffserv_model();/* state var info */
  mxError = sf_mex_call_matlab(1, plhs, 4, prhs, "sfprivate");
  mxDestroyArray(prhs[0]);
  mxDestroyArray(prhs[1]);
  mxDestroyArray(prhs[2]);
  mxDestroyArray(prhs[3]);
  if (mxError || plhs[0] == NULL) {
    sf_mex_error_message("Stateflow Internal Error: \nError calling 'chart_simctx_high2raw'.\n");
  }

  set_sim_state_c33_diffserv_model((SFc33_diffserv_modelInstanceStruct*)
    chartInfo->chartInstance, mxDuplicateArray(plhs[0]));
  mxDestroyArray(plhs[0]);
}

static const mxArray* sf_opaque_get_sim_state_c33_diffserv_model(SimStruct* S)
{
  return sf_internal_get_sim_state_c33_diffserv_model(S);
}

static void sf_opaque_set_sim_state_c33_diffserv_model(SimStruct* S, const
  mxArray *st)
{
  sf_internal_set_sim_state_c33_diffserv_model(S, st);
}

static void sf_opaque_terminate_c33_diffserv_model(void *chartInstanceVar)
{
  if (chartInstanceVar!=NULL) {
    SimStruct *S = ((SFc33_diffserv_modelInstanceStruct*) chartInstanceVar)->S;
    if (sim_mode_is_rtw_gen(S) || sim_mode_is_external(S)) {
      sf_clear_rtw_identifier(S);
      unload_diffserv_model_optimization_info();
    }

    finalize_c33_diffserv_model((SFc33_diffserv_modelInstanceStruct*)
      chartInstanceVar);
    utFree((void *)chartInstanceVar);
    ssSetUserData(S,NULL);
  }
}

static void sf_opaque_init_subchart_simstructs(void *chartInstanceVar)
{
  initSimStructsc33_diffserv_model((SFc33_diffserv_modelInstanceStruct*)
    chartInstanceVar);
}

extern unsigned int sf_machine_global_initializer_called(void);
static void mdlProcessParameters_c33_diffserv_model(SimStruct *S)
{
  int i;
  for (i=0;i<ssGetNumRunTimeParams(S);i++) {
    if (ssGetSFcnParamTunable(S,i)) {
      ssUpdateDlgParamAsRunTimeParam(S,i);
    }
  }

  if (sf_machine_global_initializer_called()) {
    initialize_params_c33_diffserv_model((SFc33_diffserv_modelInstanceStruct*)
      (((ChartInfoStruct *)ssGetUserData(S))->chartInstance));
  }
}

static void mdlSetWorkWidths_c33_diffserv_model(SimStruct *S)
{
  /* Actual parameters from chart:
     Q1_weight Q2_weight Q3_weight preemption prioritization weighting workConservation
   */
  const char_T *rtParamNames[] = { "Q1_weight", "Q2_weight", "Q3_weight",
    "preemption", "prioritization", "weighting", "workConservation" };

  ssSetNumRunTimeParams(S,ssGetSFcnParamsCount(S));

  /* registration for Q1_weight*/
  ssRegDlgParamAsRunTimeParam(S, 0, 0, rtParamNames[0], SS_DOUBLE);

  /* registration for Q2_weight*/
  ssRegDlgParamAsRunTimeParam(S, 1, 1, rtParamNames[1], SS_DOUBLE);

  /* registration for Q3_weight*/
  ssRegDlgParamAsRunTimeParam(S, 2, 2, rtParamNames[2], SS_DOUBLE);

  /* registration for preemption*/
  ssRegDlgParamAsRunTimeParam(S, 3, 3, rtParamNames[3], SS_DOUBLE);

  /* registration for prioritization*/
  ssRegDlgParamAsRunTimeParam(S, 4, 4, rtParamNames[4], SS_DOUBLE);

  /* registration for weighting*/
  ssRegDlgParamAsRunTimeParam(S, 5, 5, rtParamNames[5], SS_DOUBLE);

  /* registration for workConservation*/
  ssRegDlgParamAsRunTimeParam(S, 6, 6, rtParamNames[6], SS_DOUBLE);
  if (sim_mode_is_rtw_gen(S) || sim_mode_is_external(S)) {
    mxArray *infoStruct = load_diffserv_model_optimization_info();
    int_T chartIsInlinable =
      (int_T)sf_is_chart_inlinable(S,sf_get_instance_specialization(),infoStruct,
      33);
    ssSetStateflowIsInlinable(S,chartIsInlinable);
    ssSetRTWCG(S,sf_rtw_info_uint_prop(S,sf_get_instance_specialization(),
                infoStruct,33,"RTWCG"));
    ssSetEnableFcnIsTrivial(S,1);
    ssSetDisableFcnIsTrivial(S,1);
    ssSetNotMultipleInlinable(S,sf_rtw_info_uint_prop(S,
      sf_get_instance_specialization(),infoStruct,33,
      "gatewayCannotBeInlinedMultipleTimes"));
    sf_update_buildInfo(S,sf_get_instance_specialization(),infoStruct,33);
    if (chartIsInlinable) {
      ssSetInputPortOptimOpts(S, 0, SS_REUSABLE_AND_LOCAL);
      ssSetInputPortOptimOpts(S, 1, SS_REUSABLE_AND_LOCAL);
      ssSetInputPortOptimOpts(S, 2, SS_REUSABLE_AND_LOCAL);
      sf_mark_chart_expressionable_inputs(S,sf_get_instance_specialization(),
        infoStruct,33,3);
      sf_mark_chart_reusable_outputs(S,sf_get_instance_specialization(),
        infoStruct,33,1);
    }

    ssSetInputPortOptimOpts(S, 3, SS_REUSABLE_AND_LOCAL);

    {
      unsigned int outPortIdx;
      for (outPortIdx=1; outPortIdx<=1; ++outPortIdx) {
        ssSetOutputPortOptimizeInIR(S, outPortIdx, 1U);
      }
    }

    {
      unsigned int inPortIdx;
      for (inPortIdx=0; inPortIdx < 3; ++inPortIdx) {
        ssSetInputPortOptimizeInIR(S, inPortIdx, 1U);
      }
    }

    sf_set_rtw_dwork_info(S,sf_get_instance_specialization(),infoStruct,33);
    ssSetHasSubFunctions(S,!(chartIsInlinable));
  } else {
  }

  ssSetOptions(S,ssGetOptions(S)|SS_OPTION_WORKS_WITH_CODE_REUSE);
  ssSetChecksum0(S,(1522137023U));
  ssSetChecksum1(S,(1079606867U));
  ssSetChecksum2(S,(2395090548U));
  ssSetChecksum3(S,(534198545U));
  ssSetmdlDerivatives(S, NULL);
  ssSetExplicitFCSSCtrl(S,1);
  ssSupportsMultipleExecInstances(S,0);
}

static void mdlRTW_c33_diffserv_model(SimStruct *S)
{
  if (sim_mode_is_rtw_gen(S)) {
    ssWriteRTWStrParam(S, "StateflowChartType", "Embedded MATLAB");
  }
}

static void mdlStart_c33_diffserv_model(SimStruct *S)
{
  SFc33_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc33_diffserv_modelInstanceStruct *)utMalloc(sizeof
    (SFc33_diffserv_modelInstanceStruct));
  memset(chartInstance, 0, sizeof(SFc33_diffserv_modelInstanceStruct));
  if (chartInstance==NULL) {
    sf_mex_error_message("Could not allocate memory for chart instance.");
  }

  chartInstance->chartInfo.chartInstance = chartInstance;
  chartInstance->chartInfo.isEMLChart = 1;
  chartInstance->chartInfo.chartInitialized = 0;
  chartInstance->chartInfo.sFunctionGateway =
    sf_opaque_gateway_c33_diffserv_model;
  chartInstance->chartInfo.initializeChart =
    sf_opaque_initialize_c33_diffserv_model;
  chartInstance->chartInfo.terminateChart =
    sf_opaque_terminate_c33_diffserv_model;
  chartInstance->chartInfo.enableChart = sf_opaque_enable_c33_diffserv_model;
  chartInstance->chartInfo.disableChart = sf_opaque_disable_c33_diffserv_model;
  chartInstance->chartInfo.getSimState =
    sf_opaque_get_sim_state_c33_diffserv_model;
  chartInstance->chartInfo.setSimState =
    sf_opaque_set_sim_state_c33_diffserv_model;
  chartInstance->chartInfo.getSimStateInfo =
    sf_get_sim_state_info_c33_diffserv_model;
  chartInstance->chartInfo.zeroCrossings = NULL;
  chartInstance->chartInfo.outputs = NULL;
  chartInstance->chartInfo.derivatives = NULL;
  chartInstance->chartInfo.mdlRTW = mdlRTW_c33_diffserv_model;
  chartInstance->chartInfo.mdlStart = mdlStart_c33_diffserv_model;
  chartInstance->chartInfo.mdlSetWorkWidths =
    mdlSetWorkWidths_c33_diffserv_model;
  chartInstance->chartInfo.extModeExec = NULL;
  chartInstance->chartInfo.restoreLastMajorStepConfiguration = NULL;
  chartInstance->chartInfo.restoreBeforeLastMajorStepConfiguration = NULL;
  chartInstance->chartInfo.storeCurrentConfiguration = NULL;
  chartInstance->S = S;
  ssSetUserData(S,(void *)(&(chartInstance->chartInfo)));/* register the chart instance with simstruct */
  init_dsm_address_info(chartInstance);
  if (!sim_mode_is_rtw_gen(S)) {
  }

  sf_opaque_init_subchart_simstructs(chartInstance->chartInfo.chartInstance);
  chart_debug_initialization(S,1);
}

void c33_diffserv_model_method_dispatcher(SimStruct *S, int_T method, void *data)
{
  switch (method) {
   case SS_CALL_MDL_START:
    mdlStart_c33_diffserv_model(S);
    break;

   case SS_CALL_MDL_SET_WORK_WIDTHS:
    mdlSetWorkWidths_c33_diffserv_model(S);
    break;

   case SS_CALL_MDL_PROCESS_PARAMETERS:
    mdlProcessParameters_c33_diffserv_model(S);
    break;

   default:
    /* Unhandled method */
    sf_mex_error_message("Stateflow Internal Error:\n"
                         "Error calling c33_diffserv_model_method_dispatcher.\n"
                         "Can't handle method %d.\n", method);
    break;
  }
}
