/* Include files */

#include <stddef.h>
#include "blas.h"
#include "diffserv_model_sfun.h"
#include "c58_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 c58_event_Next_packet          (0)
#define CALL_EVENT                     (-1)

/* Variable Declarations */

/* Variable Definitions */
static const char * c58_debug_family_names[17] = { "nargin", "nargout",
  "Q1_stacking", "Q2_stacking", "Q3_stacking", "prioritization", "weighting",
  "Q1_weight", "Q2_weight", "Q3_weight", "preemption", "Queue_select",
  "last_was_expedited", "last_Q_served", "Q_before_expediting",
  "current_Q_finished", "packets_served" };

/* Function Declarations */
static void initialize_c58_diffserv_model(SFc58_diffserv_modelInstanceStruct
  *chartInstance);
static void initialize_params_c58_diffserv_model
  (SFc58_diffserv_modelInstanceStruct *chartInstance);
static void enable_c58_diffserv_model(SFc58_diffserv_modelInstanceStruct
  *chartInstance);
static void disable_c58_diffserv_model(SFc58_diffserv_modelInstanceStruct
  *chartInstance);
static void c58_update_debugger_state_c58_diffserv_model
  (SFc58_diffserv_modelInstanceStruct *chartInstance);
static const mxArray *get_sim_state_c58_diffserv_model
  (SFc58_diffserv_modelInstanceStruct *chartInstance);
static void set_sim_state_c58_diffserv_model(SFc58_diffserv_modelInstanceStruct *
  chartInstance, const mxArray *c58_st);
static void finalize_c58_diffserv_model(SFc58_diffserv_modelInstanceStruct
  *chartInstance);
static void sf_c58_diffserv_model(SFc58_diffserv_modelInstanceStruct
  *chartInstance);
static void c58_chartstep_c58_diffserv_model(SFc58_diffserv_modelInstanceStruct *
  chartInstance);
static void initSimStructsc58_diffserv_model(SFc58_diffserv_modelInstanceStruct *
  chartInstance);
static void registerMessagesc58_diffserv_model
  (SFc58_diffserv_modelInstanceStruct *chartInstance);
static void init_script_number_translation(uint32_T c58_machineNumber, uint32_T
  c58_chartNumber);
static const mxArray *c58_sf_marshallOut(void *chartInstanceVoid, void
  *c58_inData);
static real_T c58_emlrt_marshallIn(SFc58_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c58_packets_served, const char_T
  *c58_identifier);
static real_T c58_b_emlrt_marshallIn(SFc58_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c58_u, const emlrtMsgIdentifier *c58_parentId);
static void c58_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c58_mxArrayInData, const char_T *c58_varName, void *c58_outData);
static const mxArray *c58_b_sf_marshallOut(void *chartInstanceVoid, void
  *c58_inData);
static boolean_T c58_c_emlrt_marshallIn(SFc58_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c58_u, const emlrtMsgIdentifier *c58_parentId);
static void c58_b_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c58_mxArrayInData, const char_T *c58_varName, void *c58_outData);
static const mxArray *c58_c_sf_marshallOut(void *chartInstanceVoid, void
  *c58_inData);
static int8_T c58_d_emlrt_marshallIn(SFc58_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c58_u, const emlrtMsgIdentifier *c58_parentId);
static void c58_c_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c58_mxArrayInData, const char_T *c58_varName, void *c58_outData);
static const mxArray *c58_d_sf_marshallOut(void *chartInstanceVoid, void
  *c58_inData);
static int32_T c58_e_emlrt_marshallIn(SFc58_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c58_u, const emlrtMsgIdentifier *c58_parentId);
static void c58_d_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c58_mxArrayInData, const char_T *c58_varName, void *c58_outData);
static uint8_T c58_f_emlrt_marshallIn(SFc58_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c58_b_is_active_c58_diffserv_model, const
  char_T *c58_identifier);
static uint8_T c58_g_emlrt_marshallIn(SFc58_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c58_u, const emlrtMsgIdentifier *c58_parentId);
static real_T c58_get_Q_before_expediting(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b);
static void c58_set_Q_before_expediting(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b, real_T c58_c);
static real_T *c58_access_Q_before_expediting(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b);
static boolean_T c58_get_current_Q_finished(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b);
static void c58_set_current_Q_finished(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b, boolean_T c58_c);
static boolean_T *c58_access_current_Q_finished
  (SFc58_diffserv_modelInstanceStruct *chartInstance, uint32_T c58_b);
static real_T c58_get_last_Q_served(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b);
static void c58_set_last_Q_served(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b, real_T c58_c);
static real_T *c58_access_last_Q_served(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b);
static boolean_T c58_get_last_was_expedited(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b);
static void c58_set_last_was_expedited(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b, boolean_T c58_c);
static boolean_T *c58_access_last_was_expedited
  (SFc58_diffserv_modelInstanceStruct *chartInstance, uint32_T c58_b);
static real_T c58_get_packets_served(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b);
static void c58_set_packets_served(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b, real_T c58_c);
static real_T *c58_access_packets_served(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b);
static void init_dsm_address_info(SFc58_diffserv_modelInstanceStruct
  *chartInstance);

/* Function Definitions */
static void initialize_c58_diffserv_model(SFc58_diffserv_modelInstanceStruct
  *chartInstance)
{
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
  chartInstance->c58_is_active_c58_diffserv_model = 0U;
}

static void initialize_params_c58_diffserv_model
  (SFc58_diffserv_modelInstanceStruct *chartInstance)
{
  real_T c58_d0;
  real_T c58_d1;
  real_T c58_d2;
  real_T c58_d3;
  real_T c58_d4;
  real_T c58_d5;
  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), &c58_d0, 0, 0, 0U, 0, 0U, 0);
  chartInstance->c58_prioritization = c58_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),
                      &c58_d1, 0, 0, 0U, 0, 0U, 0);
  chartInstance->c58_weighting = c58_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),
                      &c58_d2, 0, 0, 0U, 0, 0U, 0);
  chartInstance->c58_Q1_weight = c58_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),
                      &c58_d3, 0, 0, 0U, 0, 0U, 0);
  chartInstance->c58_Q2_weight = c58_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),
                      &c58_d4, 0, 0, 0U, 0, 0U, 0);
  chartInstance->c58_Q3_weight = c58_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),
                      &c58_d5, 0, 0, 0U, 0, 0U, 0);
  chartInstance->c58_preemption = c58_d5;
  sf_set_error_prefix_string("Stateflow Runtime Error (chart): ");
}

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

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

static void c58_update_debugger_state_c58_diffserv_model
  (SFc58_diffserv_modelInstanceStruct *chartInstance)
{
}

static const mxArray *get_sim_state_c58_diffserv_model
  (SFc58_diffserv_modelInstanceStruct *chartInstance)
{
  const mxArray *c58_st;
  const mxArray *c58_y = NULL;
  real_T c58_hoistedGlobal;
  real_T c58_u;
  const mxArray *c58_b_y = NULL;
  uint8_T c58_b_hoistedGlobal;
  uint8_T c58_b_u;
  const mxArray *c58_c_y = NULL;
  real_T *c58_Queue_select;
  c58_Queue_select = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  c58_st = NULL;
  c58_st = NULL;
  c58_y = NULL;
  sf_mex_assign(&c58_y, sf_mex_createcellarray(2), FALSE);
  c58_hoistedGlobal = *c58_Queue_select;
  c58_u = c58_hoistedGlobal;
  c58_b_y = NULL;
  sf_mex_assign(&c58_b_y, sf_mex_create("y", &c58_u, 0, 0U, 0U, 0U, 0), FALSE);
  sf_mex_setcell(c58_y, 0, c58_b_y);
  c58_b_hoistedGlobal = chartInstance->c58_is_active_c58_diffserv_model;
  c58_b_u = c58_b_hoistedGlobal;
  c58_c_y = NULL;
  sf_mex_assign(&c58_c_y, sf_mex_create("y", &c58_b_u, 3, 0U, 0U, 0U, 0), FALSE);
  sf_mex_setcell(c58_y, 1, c58_c_y);
  sf_mex_assign(&c58_st, c58_y, FALSE);
  return c58_st;
}

static void set_sim_state_c58_diffserv_model(SFc58_diffserv_modelInstanceStruct *
  chartInstance, const mxArray *c58_st)
{
  const mxArray *c58_u;
  real_T *c58_Queue_select;
  c58_Queue_select = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  chartInstance->c58_doneDoubleBufferReInit = TRUE;
  c58_u = sf_mex_dup(c58_st);
  *c58_Queue_select = c58_emlrt_marshallIn(chartInstance, sf_mex_dup
    (sf_mex_getcell(c58_u, 0)), "Queue_select");
  chartInstance->c58_is_active_c58_diffserv_model = c58_f_emlrt_marshallIn
    (chartInstance, sf_mex_dup(sf_mex_getcell(c58_u, 1)),
     "is_active_c58_diffserv_model");
  sf_mex_destroy(&c58_u);
  c58_update_debugger_state_c58_diffserv_model(chartInstance);
  sf_mex_destroy(&c58_st);
}

static void finalize_c58_diffserv_model(SFc58_diffserv_modelInstanceStruct
  *chartInstance)
{
}

static void sf_c58_diffserv_model(SFc58_diffserv_modelInstanceStruct
  *chartInstance)
{
  real_T *c58_Q1_stacking;
  real_T *c58_Q2_stacking;
  real_T *c58_Q3_stacking;
  real_T *c58_Queue_select;
  c58_Queue_select = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  c58_Q3_stacking = (real_T *)ssGetInputPortSignal(chartInstance->S, 2);
  c58_Q2_stacking = (real_T *)ssGetInputPortSignal(chartInstance->S, 1);
  c58_Q1_stacking = (real_T *)ssGetInputPortSignal(chartInstance->S, 0);
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
  _SFD_CC_CALL(CHART_ENTER_SFUNCTION_TAG, 49U, chartInstance->c58_sfEvent);
  _SFD_DATA_RANGE_CHECK(*c58_Q1_stacking, 0U);
  _SFD_DATA_RANGE_CHECK(*c58_Q2_stacking, 1U);
  _SFD_DATA_RANGE_CHECK(*c58_Q3_stacking, 2U);
  _SFD_DATA_RANGE_CHECK(chartInstance->c58_prioritization, 3U);
  _SFD_DATA_RANGE_CHECK(chartInstance->c58_weighting, 4U);
  _SFD_DATA_RANGE_CHECK(*c58_Queue_select, 5U);
  _SFD_DATA_RANGE_CHECK(chartInstance->c58_Q1_weight, 8U);
  _SFD_DATA_RANGE_CHECK(chartInstance->c58_Q2_weight, 9U);
  _SFD_DATA_RANGE_CHECK(chartInstance->c58_Q3_weight, 10U);
  _SFD_DATA_RANGE_CHECK(chartInstance->c58_preemption, 14U);
  chartInstance->c58_sfEvent = c58_event_Next_packet;
  _SFD_CE_CALL(EVENT_BEFORE_BROADCAST_TAG, c58_event_Next_packet,
               chartInstance->c58_sfEvent);
  c58_chartstep_c58_diffserv_model(chartInstance);
  _SFD_CE_CALL(EVENT_AFTER_BROADCAST_TAG, c58_event_Next_packet,
               chartInstance->c58_sfEvent);
  _SFD_CHECK_FOR_STATE_INCONSISTENCY(_diffserv_modelMachineNumber_,
    chartInstance->chartNumber, chartInstance->instanceNumber);
}

static void c58_chartstep_c58_diffserv_model(SFc58_diffserv_modelInstanceStruct *
  chartInstance)
{
  real_T c58_hoistedGlobal;
  real_T c58_b_hoistedGlobal;
  real_T c58_c_hoistedGlobal;
  real_T c58_d_hoistedGlobal;
  real_T c58_e_hoistedGlobal;
  real_T c58_f_hoistedGlobal;
  real_T c58_g_hoistedGlobal;
  real_T c58_h_hoistedGlobal;
  real_T c58_i_hoistedGlobal;
  real_T c58_Q1_stacking;
  real_T c58_Q2_stacking;
  real_T c58_Q3_stacking;
  real_T c58_b_prioritization;
  real_T c58_b_weighting;
  real_T c58_b_Q1_weight;
  real_T c58_b_Q2_weight;
  real_T c58_b_Q3_weight;
  real_T c58_b_preemption;
  uint32_T c58_debug_family_var_map[17];
  real_T c58_nargin = 9.0;
  real_T c58_nargout = 1.0;
  real_T c58_Queue_select;
  const mxArray *c58_y = NULL;
  char_T c58_u[36];
  static char_T c58_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 c58_i0;
  real_T *c58_b_Queue_select;
  real_T *c58_b_Q1_stacking;
  real_T *c58_b_Q2_stacking;
  real_T *c58_b_Q3_stacking;
  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;
  c58_b_Queue_select = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  c58_b_Q3_stacking = (real_T *)ssGetInputPortSignal(chartInstance->S, 2);
  c58_b_Q2_stacking = (real_T *)ssGetInputPortSignal(chartInstance->S, 1);
  c58_b_Q1_stacking = (real_T *)ssGetInputPortSignal(chartInstance->S, 0);
  _SFD_CC_CALL(CHART_ENTER_DURING_FUNCTION_TAG, 49U, chartInstance->c58_sfEvent);
  c58_hoistedGlobal = *c58_b_Q1_stacking;
  c58_b_hoistedGlobal = *c58_b_Q2_stacking;
  c58_c_hoistedGlobal = *c58_b_Q3_stacking;
  c58_d_hoistedGlobal = chartInstance->c58_prioritization;
  c58_e_hoistedGlobal = chartInstance->c58_weighting;
  c58_f_hoistedGlobal = chartInstance->c58_Q1_weight;
  c58_g_hoistedGlobal = chartInstance->c58_Q2_weight;
  c58_h_hoistedGlobal = chartInstance->c58_Q3_weight;
  c58_i_hoistedGlobal = chartInstance->c58_preemption;
  c58_Q1_stacking = c58_hoistedGlobal;
  c58_Q2_stacking = c58_b_hoistedGlobal;
  c58_Q3_stacking = c58_c_hoistedGlobal;
  c58_b_prioritization = c58_d_hoistedGlobal;
  c58_b_weighting = c58_e_hoistedGlobal;
  c58_b_Q1_weight = c58_f_hoistedGlobal;
  c58_b_Q2_weight = c58_g_hoistedGlobal;
  c58_b_Q3_weight = c58_h_hoistedGlobal;
  c58_b_preemption = c58_i_hoistedGlobal;
  _SFD_SYMBOL_SCOPE_PUSH_EML(0U, 17U, 17U, c58_debug_family_names,
    c58_debug_family_var_map);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c58_nargin, 0U, c58_sf_marshallOut,
    c58_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c58_nargout, 1U, c58_sf_marshallOut,
    c58_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML(&c58_Q1_stacking, 2U, c58_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML(&c58_Q2_stacking, 3U, c58_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML(&c58_Q3_stacking, 4U, c58_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c58_b_prioritization, 5U,
    c58_sf_marshallOut, c58_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c58_b_weighting, 6U, c58_sf_marshallOut,
    c58_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c58_b_Q1_weight, 7U, c58_sf_marshallOut,
    c58_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c58_b_Q2_weight, 8U, c58_sf_marshallOut,
    c58_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c58_b_Q3_weight, 9U, c58_sf_marshallOut,
    c58_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c58_b_preemption, 10U,
    c58_sf_marshallOut, c58_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c58_Queue_select, 11U,
    c58_sf_marshallOut, c58_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE
    (chartInstance->c58_last_was_expedited_address, 12U, c58_b_sf_marshallOut,
     c58_b_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(chartInstance->c58_last_Q_served_address,
    13U, c58_sf_marshallOut, c58_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE
    (chartInstance->c58_Q_before_expediting_address, 14U, c58_sf_marshallOut,
     c58_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE
    (chartInstance->c58_current_Q_finished_address, 15U, c58_b_sf_marshallOut,
     c58_b_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(chartInstance->c58_packets_served_address,
    16U, c58_sf_marshallOut, c58_sf_marshallIn);
  CV_EML_FCN(0, 0);
  _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 2);
  _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 3);
  _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 4);
  _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 5);
  _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 6);
  _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 8);
  _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 10);
  if (CV_EML_IF(0, 1, 0, c58_get_last_was_expedited(chartInstance, 0))) {
    _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 11);
    c58_set_last_Q_served(chartInstance, 0, c58_get_Q_before_expediting
                          (chartInstance, 0));
    ssUpdateDataStoreLog(chartInstance->S, 2);
    _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 12);
    c58_set_last_was_expedited(chartInstance, 0, FALSE);
    ssUpdateDataStoreLog(chartInstance->S, 3);
  }

  _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 15);
  guard1 = FALSE;
  guard2 = FALSE;
  guard3 = FALSE;
  guard4 = FALSE;
  guard5 = FALSE;
  guard6 = FALSE;
  if (CV_EML_COND(0, 1, 0, c58_b_prioritization == 1.0)) {
    if (CV_EML_COND(0, 1, 1, c58_Q1_stacking > 0.0)) {
      if (CV_EML_COND(0, 1, 2, c58_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, c58_b_prioritization == 1.0)) {
      if (CV_EML_COND(0, 1, 4, c58_Q1_stacking > 0.0)) {
        if (!(CV_EML_COND(0, 1, 5, c58_b_preemption != 0.0) != 0.0)) {
          if (CV_EML_COND(0, 1, 6, c58_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->c58_sfEvent, 16);
    c58_set_last_was_expedited(chartInstance, 0, TRUE);
    ssUpdateDataStoreLog(chartInstance->S, 3);
    _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 17);
    c58_set_Q_before_expediting(chartInstance, 0, c58_get_last_Q_served
      (chartInstance, 0));
    ssUpdateDataStoreLog(chartInstance->S, 0);
    _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 18);
    c58_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->c58_sfEvent, 20);
    switch ((int16_T)_SFD_INTEGER_CHECK("last_Q_served", c58_get_last_Q_served
             (chartInstance, 0))) {
     case 3:
      CV_EML_SWITCH(0, 1, 0, 1);
      _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 22);
      guard9 = FALSE;
      if (CV_EML_COND(0, 1, 7, c58_b_weighting == 1.0)) {
        if (CV_EML_COND(0, 1, 8, c58_get_packets_served(chartInstance, 0) <
                        c58_b_Q3_weight)) {
          CV_EML_MCDC(0, 1, 1, TRUE);
          CV_EML_IF(0, 1, 2, TRUE);
          _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 23);
          c58_set_packets_served(chartInstance, 0, c58_get_packets_served
            (chartInstance, 0) + 1.0);
          ssUpdateDataStoreLog(chartInstance->S, 4);
          _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 24);
          c58_set_current_Q_finished(chartInstance, 0, FALSE);
          ssUpdateDataStoreLog(chartInstance->S, 1);
          _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 25);
          c58_Queue_select = 3.0;
        } else {
          guard9 = TRUE;
        }
      } else {
        guard9 = TRUE;
      }

      if (guard9 == TRUE) {
        CV_EML_MCDC(0, 1, 1, FALSE);
        CV_EML_IF(0, 1, 2, FALSE);
        _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 27);
        c58_Queue_select = 1.0;
        _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 28);
        c58_set_packets_served(chartInstance, 0, 1.0);
        ssUpdateDataStoreLog(chartInstance->S, 4);
        _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 29);
        c58_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->c58_sfEvent, 34);
      guard8 = FALSE;
      if (CV_EML_COND(0, 1, 9, c58_b_weighting == 1.0)) {
        if (CV_EML_COND(0, 1, 10, c58_get_packets_served(chartInstance, 0) <
                        c58_b_Q1_weight)) {
          CV_EML_MCDC(0, 1, 2, TRUE);
          CV_EML_IF(0, 1, 3, TRUE);
          _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 35);
          c58_set_packets_served(chartInstance, 0, c58_get_packets_served
            (chartInstance, 0) + 1.0);
          ssUpdateDataStoreLog(chartInstance->S, 4);
          _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 36);
          c58_set_current_Q_finished(chartInstance, 0, FALSE);
          ssUpdateDataStoreLog(chartInstance->S, 1);
          _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 37);
          c58_Queue_select = 1.0;
        } else {
          guard8 = TRUE;
        }
      } else {
        guard8 = TRUE;
      }

      if (guard8 == TRUE) {
        CV_EML_MCDC(0, 1, 2, FALSE);
        CV_EML_IF(0, 1, 3, FALSE);
        _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 39);
        c58_Queue_select = 2.0;
        _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 40);
        c58_set_packets_served(chartInstance, 0, 1.0);
        ssUpdateDataStoreLog(chartInstance->S, 4);
        _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 41);
        c58_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->c58_sfEvent, 45);
      guard7 = FALSE;
      if (CV_EML_COND(0, 1, 11, c58_b_weighting == 1.0)) {
        if (CV_EML_COND(0, 1, 12, c58_get_packets_served(chartInstance, 0) <
                        c58_b_Q2_weight)) {
          CV_EML_MCDC(0, 1, 3, TRUE);
          CV_EML_IF(0, 1, 4, TRUE);
          _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 46);
          c58_set_packets_served(chartInstance, 0, c58_get_packets_served
            (chartInstance, 0) + 1.0);
          ssUpdateDataStoreLog(chartInstance->S, 4);
          _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 47);
          c58_set_current_Q_finished(chartInstance, 0, FALSE);
          ssUpdateDataStoreLog(chartInstance->S, 1);
          _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 48);
          c58_Queue_select = 2.0;
        } else {
          guard7 = TRUE;
        }
      } else {
        guard7 = TRUE;
      }

      if (guard7 == TRUE) {
        CV_EML_MCDC(0, 1, 3, FALSE);
        CV_EML_IF(0, 1, 4, FALSE);
        _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 50);
        c58_Queue_select = 3.0;
        _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 51);
        c58_set_packets_served(chartInstance, 0, 1.0);
        ssUpdateDataStoreLog(chartInstance->S, 4);
        _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 52);
        c58_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->c58_sfEvent, 56);
      for (c58_i0 = 0; c58_i0 < 36; c58_i0++) {
        c58_u[c58_i0] = c58_cv0[c58_i0];
      }

      c58_y = NULL;
      sf_mex_assign(&c58_y, sf_mex_create("y", c58_u, 10, 0U, 1U, 0U, 2, 1, 36),
                    FALSE);
      sf_mex_call_debug("errordlg", 0U, 1U, 14, c58_y);
      _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, 57);
      c58_Queue_select = 1.0;
      break;
    }
  }

  _SFD_EML_CALL(0U, chartInstance->c58_sfEvent, -57);
  _SFD_SYMBOL_SCOPE_POP();
  *c58_b_Queue_select = c58_Queue_select;
  _SFD_CC_CALL(EXIT_OUT_OF_FUNCTION_TAG, 49U, chartInstance->c58_sfEvent);
}

static void initSimStructsc58_diffserv_model(SFc58_diffserv_modelInstanceStruct *
  chartInstance)
{
}

static void registerMessagesc58_diffserv_model
  (SFc58_diffserv_modelInstanceStruct *chartInstance)
{
}

static void init_script_number_translation(uint32_T c58_machineNumber, uint32_T
  c58_chartNumber)
{
}

static const mxArray *c58_sf_marshallOut(void *chartInstanceVoid, void
  *c58_inData)
{
  const mxArray *c58_mxArrayOutData = NULL;
  real_T c58_u;
  const mxArray *c58_y = NULL;
  SFc58_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc58_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c58_mxArrayOutData = NULL;
  c58_u = *(real_T *)c58_inData;
  c58_y = NULL;
  sf_mex_assign(&c58_y, sf_mex_create("y", &c58_u, 0, 0U, 0U, 0U, 0), FALSE);
  sf_mex_assign(&c58_mxArrayOutData, c58_y, FALSE);
  return c58_mxArrayOutData;
}

static real_T c58_emlrt_marshallIn(SFc58_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c58_packets_served, const char_T
  *c58_identifier)
{
  real_T c58_y;
  emlrtMsgIdentifier c58_thisId;
  c58_thisId.fIdentifier = c58_identifier;
  c58_thisId.fParent = NULL;
  c58_y = c58_b_emlrt_marshallIn(chartInstance, sf_mex_dup(c58_packets_served),
    &c58_thisId);
  sf_mex_destroy(&c58_packets_served);
  return c58_y;
}

static real_T c58_b_emlrt_marshallIn(SFc58_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c58_u, const emlrtMsgIdentifier *c58_parentId)
{
  real_T c58_y;
  real_T c58_d6;
  sf_mex_import(c58_parentId, sf_mex_dup(c58_u), &c58_d6, 1, 0, 0U, 0, 0U, 0);
  c58_y = c58_d6;
  sf_mex_destroy(&c58_u);
  return c58_y;
}

static void c58_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c58_mxArrayInData, const char_T *c58_varName, void *c58_outData)
{
  const mxArray *c58_packets_served;
  const char_T *c58_identifier;
  emlrtMsgIdentifier c58_thisId;
  real_T c58_y;
  SFc58_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc58_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c58_packets_served = sf_mex_dup(c58_mxArrayInData);
  c58_identifier = c58_varName;
  c58_thisId.fIdentifier = c58_identifier;
  c58_thisId.fParent = NULL;
  c58_y = c58_b_emlrt_marshallIn(chartInstance, sf_mex_dup(c58_packets_served),
    &c58_thisId);
  sf_mex_destroy(&c58_packets_served);
  *(real_T *)c58_outData = c58_y;
  sf_mex_destroy(&c58_mxArrayInData);
}

static const mxArray *c58_b_sf_marshallOut(void *chartInstanceVoid, void
  *c58_inData)
{
  const mxArray *c58_mxArrayOutData = NULL;
  boolean_T c58_u;
  const mxArray *c58_y = NULL;
  SFc58_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc58_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c58_mxArrayOutData = NULL;
  c58_u = *(boolean_T *)c58_inData;
  c58_y = NULL;
  sf_mex_assign(&c58_y, sf_mex_create("y", &c58_u, 11, 0U, 0U, 0U, 0), FALSE);
  sf_mex_assign(&c58_mxArrayOutData, c58_y, FALSE);
  return c58_mxArrayOutData;
}

static boolean_T c58_c_emlrt_marshallIn(SFc58_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c58_u, const emlrtMsgIdentifier *c58_parentId)
{
  boolean_T c58_y;
  boolean_T c58_b0;
  sf_mex_import(c58_parentId, sf_mex_dup(c58_u), &c58_b0, 1, 11, 0U, 0, 0U, 0);
  c58_y = c58_b0;
  sf_mex_destroy(&c58_u);
  return c58_y;
}

static void c58_b_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c58_mxArrayInData, const char_T *c58_varName, void *c58_outData)
{
  const mxArray *c58_current_Q_finished;
  const char_T *c58_identifier;
  emlrtMsgIdentifier c58_thisId;
  boolean_T c58_y;
  SFc58_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc58_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c58_current_Q_finished = sf_mex_dup(c58_mxArrayInData);
  c58_identifier = c58_varName;
  c58_thisId.fIdentifier = c58_identifier;
  c58_thisId.fParent = NULL;
  c58_y = c58_c_emlrt_marshallIn(chartInstance, sf_mex_dup
    (c58_current_Q_finished), &c58_thisId);
  sf_mex_destroy(&c58_current_Q_finished);
  *(boolean_T *)c58_outData = c58_y;
  sf_mex_destroy(&c58_mxArrayInData);
}

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

static const mxArray *c58_c_sf_marshallOut(void *chartInstanceVoid, void
  *c58_inData)
{
  const mxArray *c58_mxArrayOutData = NULL;
  int8_T c58_u;
  const mxArray *c58_y = NULL;
  SFc58_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc58_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c58_mxArrayOutData = NULL;
  c58_u = *(int8_T *)c58_inData;
  c58_y = NULL;
  sf_mex_assign(&c58_y, sf_mex_create("y", &c58_u, 2, 0U, 0U, 0U, 0), FALSE);
  sf_mex_assign(&c58_mxArrayOutData, c58_y, FALSE);
  return c58_mxArrayOutData;
}

static int8_T c58_d_emlrt_marshallIn(SFc58_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c58_u, const emlrtMsgIdentifier *c58_parentId)
{
  int8_T c58_y;
  int8_T c58_i1;
  sf_mex_import(c58_parentId, sf_mex_dup(c58_u), &c58_i1, 1, 2, 0U, 0, 0U, 0);
  c58_y = c58_i1;
  sf_mex_destroy(&c58_u);
  return c58_y;
}

static void c58_c_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c58_mxArrayInData, const char_T *c58_varName, void *c58_outData)
{
  const mxArray *c58_Next_packet;
  const char_T *c58_identifier;
  emlrtMsgIdentifier c58_thisId;
  int8_T c58_y;
  SFc58_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc58_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c58_Next_packet = sf_mex_dup(c58_mxArrayInData);
  c58_identifier = c58_varName;
  c58_thisId.fIdentifier = c58_identifier;
  c58_thisId.fParent = NULL;
  c58_y = c58_d_emlrt_marshallIn(chartInstance, sf_mex_dup(c58_Next_packet),
    &c58_thisId);
  sf_mex_destroy(&c58_Next_packet);
  *(int8_T *)c58_outData = c58_y;
  sf_mex_destroy(&c58_mxArrayInData);
}

static const mxArray *c58_d_sf_marshallOut(void *chartInstanceVoid, void
  *c58_inData)
{
  const mxArray *c58_mxArrayOutData = NULL;
  int32_T c58_u;
  const mxArray *c58_y = NULL;
  SFc58_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc58_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c58_mxArrayOutData = NULL;
  c58_u = *(int32_T *)c58_inData;
  c58_y = NULL;
  sf_mex_assign(&c58_y, sf_mex_create("y", &c58_u, 6, 0U, 0U, 0U, 0), FALSE);
  sf_mex_assign(&c58_mxArrayOutData, c58_y, FALSE);
  return c58_mxArrayOutData;
}

static int32_T c58_e_emlrt_marshallIn(SFc58_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c58_u, const emlrtMsgIdentifier *c58_parentId)
{
  int32_T c58_y;
  int32_T c58_i2;
  sf_mex_import(c58_parentId, sf_mex_dup(c58_u), &c58_i2, 1, 6, 0U, 0, 0U, 0);
  c58_y = c58_i2;
  sf_mex_destroy(&c58_u);
  return c58_y;
}

static void c58_d_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c58_mxArrayInData, const char_T *c58_varName, void *c58_outData)
{
  const mxArray *c58_b_sfEvent;
  const char_T *c58_identifier;
  emlrtMsgIdentifier c58_thisId;
  int32_T c58_y;
  SFc58_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc58_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c58_b_sfEvent = sf_mex_dup(c58_mxArrayInData);
  c58_identifier = c58_varName;
  c58_thisId.fIdentifier = c58_identifier;
  c58_thisId.fParent = NULL;
  c58_y = c58_e_emlrt_marshallIn(chartInstance, sf_mex_dup(c58_b_sfEvent),
    &c58_thisId);
  sf_mex_destroy(&c58_b_sfEvent);
  *(int32_T *)c58_outData = c58_y;
  sf_mex_destroy(&c58_mxArrayInData);
}

static uint8_T c58_f_emlrt_marshallIn(SFc58_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c58_b_is_active_c58_diffserv_model, const
  char_T *c58_identifier)
{
  uint8_T c58_y;
  emlrtMsgIdentifier c58_thisId;
  c58_thisId.fIdentifier = c58_identifier;
  c58_thisId.fParent = NULL;
  c58_y = c58_g_emlrt_marshallIn(chartInstance, sf_mex_dup
    (c58_b_is_active_c58_diffserv_model), &c58_thisId);
  sf_mex_destroy(&c58_b_is_active_c58_diffserv_model);
  return c58_y;
}

static uint8_T c58_g_emlrt_marshallIn(SFc58_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c58_u, const emlrtMsgIdentifier *c58_parentId)
{
  uint8_T c58_y;
  uint8_T c58_u0;
  sf_mex_import(c58_parentId, sf_mex_dup(c58_u), &c58_u0, 1, 3, 0U, 0, 0U, 0);
  c58_y = c58_u0;
  sf_mex_destroy(&c58_u);
  return c58_y;
}

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

  return *chartInstance->c58_Q_before_expediting_address;
}

static void c58_set_Q_before_expediting(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b, real_T c58_c)
{
  ssWriteToDataStoreElement(chartInstance->S, 0, NULL, c58_b);
  if (chartInstance->c58_Q_before_expediting_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'Q_before_expediting\' (#655) in the initialization routine of the chart.\n");
  }

  *chartInstance->c58_Q_before_expediting_address = c58_c;
}

static real_T *c58_access_Q_before_expediting(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b)
{
  real_T *c58_c;
  ssReadFromDataStore(chartInstance->S, 0, NULL);
  if (chartInstance->c58_Q_before_expediting_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'Q_before_expediting\' (#655) in the initialization routine of the chart.\n");
  }

  c58_c = chartInstance->c58_Q_before_expediting_address;
  if (c58_b == 0) {
    ssWriteToDataStore(chartInstance->S, 0, NULL);
  }

  return c58_c;
}

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

  return *chartInstance->c58_current_Q_finished_address;
}

static void c58_set_current_Q_finished(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b, boolean_T c58_c)
{
  ssWriteToDataStoreElement(chartInstance->S, 1, NULL, c58_b);
  if (chartInstance->c58_current_Q_finished_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'current_Q_finished\' (#656) in the initialization routine of the chart.\n");
  }

  *chartInstance->c58_current_Q_finished_address = c58_c;
}

static boolean_T *c58_access_current_Q_finished
  (SFc58_diffserv_modelInstanceStruct *chartInstance, uint32_T c58_b)
{
  boolean_T *c58_c;
  ssReadFromDataStore(chartInstance->S, 1, NULL);
  if (chartInstance->c58_current_Q_finished_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'current_Q_finished\' (#656) in the initialization routine of the chart.\n");
  }

  c58_c = chartInstance->c58_current_Q_finished_address;
  if (c58_b == 0) {
    ssWriteToDataStore(chartInstance->S, 1, NULL);
  }

  return c58_c;
}

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

  return *chartInstance->c58_last_Q_served_address;
}

static void c58_set_last_Q_served(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b, real_T c58_c)
{
  ssWriteToDataStoreElement(chartInstance->S, 2, NULL, c58_b);
  if (chartInstance->c58_last_Q_served_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'last_Q_served\' (#650) in the initialization routine of the chart.\n");
  }

  *chartInstance->c58_last_Q_served_address = c58_c;
}

static real_T *c58_access_last_Q_served(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b)
{
  real_T *c58_c;
  ssReadFromDataStore(chartInstance->S, 2, NULL);
  if (chartInstance->c58_last_Q_served_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'last_Q_served\' (#650) in the initialization routine of the chart.\n");
  }

  c58_c = chartInstance->c58_last_Q_served_address;
  if (c58_b == 0) {
    ssWriteToDataStore(chartInstance->S, 2, NULL);
  }

  return c58_c;
}

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

  return *chartInstance->c58_last_was_expedited_address;
}

static void c58_set_last_was_expedited(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b, boolean_T c58_c)
{
  ssWriteToDataStoreElement(chartInstance->S, 3, NULL, c58_b);
  if (chartInstance->c58_last_was_expedited_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'last_was_expedited\' (#654) in the initialization routine of the chart.\n");
  }

  *chartInstance->c58_last_was_expedited_address = c58_c;
}

static boolean_T *c58_access_last_was_expedited
  (SFc58_diffserv_modelInstanceStruct *chartInstance, uint32_T c58_b)
{
  boolean_T *c58_c;
  ssReadFromDataStore(chartInstance->S, 3, NULL);
  if (chartInstance->c58_last_was_expedited_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'last_was_expedited\' (#654) in the initialization routine of the chart.\n");
  }

  c58_c = chartInstance->c58_last_was_expedited_address;
  if (c58_b == 0) {
    ssWriteToDataStore(chartInstance->S, 3, NULL);
  }

  return c58_c;
}

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

  return *chartInstance->c58_packets_served_address;
}

static void c58_set_packets_served(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b, real_T c58_c)
{
  ssWriteToDataStoreElement(chartInstance->S, 4, NULL, c58_b);
  if (chartInstance->c58_packets_served_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'packets_served\' (#649) in the initialization routine of the chart.\n");
  }

  *chartInstance->c58_packets_served_address = c58_c;
}

static real_T *c58_access_packets_served(SFc58_diffserv_modelInstanceStruct
  *chartInstance, uint32_T c58_b)
{
  real_T *c58_c;
  ssReadFromDataStore(chartInstance->S, 4, NULL);
  if (chartInstance->c58_packets_served_address == 0) {
    sf_mex_error_message("Invalid access to Data Store Memory data \'packets_served\' (#649) in the initialization routine of the chart.\n");
  }

  c58_c = chartInstance->c58_packets_served_address;
  if (c58_b == 0) {
    ssWriteToDataStore(chartInstance->S, 4, NULL);
  }

  return c58_c;
}

static void init_dsm_address_info(SFc58_diffserv_modelInstanceStruct
  *chartInstance)
{
  ssGetSFcnDataStoreNameAddrIdx(chartInstance->S, "Q_before_expediting", (void **)
    &chartInstance->c58_Q_before_expediting_address,
    &chartInstance->c58_Q_before_expediting_index);
  ssGetSFcnDataStoreNameAddrIdx(chartInstance->S, "current_Q_finished", (void **)
    &chartInstance->c58_current_Q_finished_address,
    &chartInstance->c58_current_Q_finished_index);
  ssGetSFcnDataStoreNameAddrIdx(chartInstance->S, "last_Q_served", (void **)
    &chartInstance->c58_last_Q_served_address,
    &chartInstance->c58_last_Q_served_index);
  ssGetSFcnDataStoreNameAddrIdx(chartInstance->S, "last_was_expedited", (void **)
    &chartInstance->c58_last_was_expedited_address,
    &chartInstance->c58_last_was_expedited_index);
  ssGetSFcnDataStoreNameAddrIdx(chartInstance->S, "packets_served", (void **)
    &chartInstance->c58_packets_served_address,
    &chartInstance->c58_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_c58_diffserv_model_get_check_sum(mxArray *plhs[])
{
  ((real_T *)mxGetPr((plhs[0])))[0] = (real_T)(2716957501U);
  ((real_T *)mxGetPr((plhs[0])))[1] = (real_T)(2793679334U);
  ((real_T *)mxGetPr((plhs[0])))[2] = (real_T)(1551083950U);
  ((real_T *)mxGetPr((plhs[0])))[3] = (real_T)(219608307U);
}

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

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

  {
    mxArray *mxChecksum = mxCreateString("9l4oTjposp5UsDNZQw2u2G");
    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,6,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));
    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_c58_diffserv_model_third_party_uses_info(void)
{
  mxArray * mxcell3p = mxCreateCellMatrix(1,0);
  return(mxcell3p);
}

static const mxArray *sf_get_sim_state_info_c58_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_c58_diffserv_model\",}}"
  };

  mxArray *mxVarInfo = sf_mex_decode_encoded_mx_struct_array(infoEncStr, 2, 10);
  mxArray *mxChecksum = mxCreateDoubleMatrix(1, 4, mxREAL);
  sf_c58_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)) {
    SFc58_diffserv_modelInstanceStruct *chartInstance;
    chartInstance = (SFc58_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_,
           58,
           1,
           1,
           15,
           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_stacking");
          _SFD_SET_DATA_PROPS(1,1,1,0,"Q2_stacking");
          _SFD_SET_DATA_PROPS(2,1,1,0,"Q3_stacking");
          _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_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,5,0,0,1,0,0,13,4);
        _SFD_CV_INIT_EML_FCN(0,0,"eML_blk_kernel",0,-1,1924);
        _SFD_CV_INIT_EML_IF(0,1,0,293,314,-1,391);
        _SFD_CV_INIT_EML_IF(0,1,1,397,549,644,1913);
        _SFD_CV_INIT_EML_IF(0,1,2,701,752,896,1036);
        _SFD_CV_INIT_EML_IF(0,1,3,1073,1124,1268,1415);
        _SFD_CV_INIT_EML_IF(0,1,4,1452,1503,1647,1780);

        {
          static int caseStart[] = { 1798, 682, 1054, 1433 };

          static int caseExprEnd[] = { 1807, 688, 1060, 1439 };

          _SFD_CV_INIT_EML_SWITCH(0,1,0,653,674,1907,4,&(caseStart[0]),
            &(caseExprEnd[0]));
        }

        {
          static int condStart[] = { 402, 427, 448, 466, 491, 513, 529 };

          static int condEnd[] = { 421, 442, 458, 485, 506, 523, 547 };

          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,400,549,7,0,&(condStart[0]),&(condEnd[0]),
                                14,&(pfixExpr[0]));
        }

        {
          static int condStart[] = { 705, 725 };

          static int condEnd[] = { 719, 751 };

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

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

        {
          static int condStart[] = { 1077, 1097 };

          static int condEnd[] = { 1091, 1123 };

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

          _SFD_CV_INIT_EML_MCDC(0,1,2,1076,1124,2,9,&(condStart[0]),&(condEnd[0]),
                                3,&(pfixExpr[0]));
        }

        {
          static int condStart[] = { 1456, 1476 };

          static int condEnd[] = { 1470, 1502 };

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

          _SFD_CV_INIT_EML_MCDC(0,1,3,1455,1503,2,11,&(condStart[0]),&(condEnd[0]),
                                3,&(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)c58_sf_marshallOut,(MexInFcnForType)NULL);
        _SFD_SET_DATA_COMPILED_PROPS(1,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c58_sf_marshallOut,(MexInFcnForType)NULL);
        _SFD_SET_DATA_COMPILED_PROPS(2,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c58_sf_marshallOut,(MexInFcnForType)NULL);
        _SFD_SET_DATA_COMPILED_PROPS(3,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c58_sf_marshallOut,(MexInFcnForType)c58_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(4,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c58_sf_marshallOut,(MexInFcnForType)c58_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(5,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c58_sf_marshallOut,(MexInFcnForType)c58_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(6,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c58_sf_marshallOut,(MexInFcnForType)c58_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(7,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c58_sf_marshallOut,(MexInFcnForType)c58_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(8,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c58_sf_marshallOut,(MexInFcnForType)c58_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(9,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c58_sf_marshallOut,(MexInFcnForType)c58_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(10,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c58_sf_marshallOut,(MexInFcnForType)c58_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(11,SF_UINT8,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c58_b_sf_marshallOut,(MexInFcnForType)
          c58_b_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(12,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c58_sf_marshallOut,(MexInFcnForType)c58_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(13,SF_UINT8,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c58_b_sf_marshallOut,(MexInFcnForType)
          c58_b_sf_marshallIn);
        _SFD_SET_DATA_COMPILED_PROPS(14,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c58_sf_marshallOut,(MexInFcnForType)c58_sf_marshallIn);

        {
          real_T *c58_Q1_stacking;
          real_T *c58_Q2_stacking;
          real_T *c58_Q3_stacking;
          real_T *c58_Queue_select;
          c58_Queue_select = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
          c58_Q3_stacking = (real_T *)ssGetInputPortSignal(chartInstance->S, 2);
          c58_Q2_stacking = (real_T *)ssGetInputPortSignal(chartInstance->S, 1);
          c58_Q1_stacking = (real_T *)ssGetInputPortSignal(chartInstance->S, 0);
          _SFD_SET_DATA_VALUE_PTR(0U, c58_Q1_stacking);
          _SFD_SET_DATA_VALUE_PTR(1U, c58_Q2_stacking);
          _SFD_SET_DATA_VALUE_PTR(2U, c58_Q3_stacking);
          _SFD_SET_DATA_VALUE_PTR(3U, &chartInstance->c58_prioritization);
          _SFD_SET_DATA_VALUE_PTR(4U, &chartInstance->c58_weighting);
          _SFD_SET_DATA_VALUE_PTR(5U, c58_Queue_select);
          _SFD_SET_DATA_VALUE_PTR(6U, chartInstance->c58_packets_served_address);
          _SFD_SET_DATA_VALUE_PTR(7U, chartInstance->c58_last_Q_served_address);
          _SFD_SET_DATA_VALUE_PTR(8U, &chartInstance->c58_Q1_weight);
          _SFD_SET_DATA_VALUE_PTR(9U, &chartInstance->c58_Q2_weight);
          _SFD_SET_DATA_VALUE_PTR(10U, &chartInstance->c58_Q3_weight);
          _SFD_SET_DATA_VALUE_PTR(11U,
            chartInstance->c58_last_was_expedited_address);
          _SFD_SET_DATA_VALUE_PTR(12U,
            chartInstance->c58_Q_before_expediting_address);
          _SFD_SET_DATA_VALUE_PTR(13U,
            chartInstance->c58_current_Q_finished_address);
          _SFD_SET_DATA_VALUE_PTR(14U, &chartInstance->c58_preemption);
        }
      }
    } else {
      sf_debug_reset_current_state_configuration(sfGlobalDebugInstanceStruct,
        _diffserv_modelMachineNumber_,chartInstance->chartNumber,
        chartInstance->instanceNumber);
    }
  }
}

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

static void sf_opaque_initialize_c58_diffserv_model(void *chartInstanceVar)
{
  chart_debug_initialization(((SFc58_diffserv_modelInstanceStruct*)
    chartInstanceVar)->S,0);
  initialize_params_c58_diffserv_model((SFc58_diffserv_modelInstanceStruct*)
    chartInstanceVar);
  initialize_c58_diffserv_model((SFc58_diffserv_modelInstanceStruct*)
    chartInstanceVar);
}

static void sf_opaque_enable_c58_diffserv_model(void *chartInstanceVar)
{
  enable_c58_diffserv_model((SFc58_diffserv_modelInstanceStruct*)
    chartInstanceVar);
}

static void sf_opaque_disable_c58_diffserv_model(void *chartInstanceVar)
{
  disable_c58_diffserv_model((SFc58_diffserv_modelInstanceStruct*)
    chartInstanceVar);
}

static void sf_opaque_gateway_c58_diffserv_model(void *chartInstanceVar)
{
  sf_c58_diffserv_model((SFc58_diffserv_modelInstanceStruct*) chartInstanceVar);
}

extern const mxArray* sf_internal_get_sim_state_c58_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_c58_diffserv_model
    ((SFc58_diffserv_modelInstanceStruct*)chartInfo->chartInstance);/* raw sim ctx */
  prhs[3] = (mxArray*) sf_get_sim_state_info_c58_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_c58_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_c58_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_c58_diffserv_model((SFc58_diffserv_modelInstanceStruct*)
    chartInfo->chartInstance, mxDuplicateArray(plhs[0]));
  mxDestroyArray(plhs[0]);
}

static const mxArray* sf_opaque_get_sim_state_c58_diffserv_model(SimStruct* S)
{
  return sf_internal_get_sim_state_c58_diffserv_model(S);
}

static void sf_opaque_set_sim_state_c58_diffserv_model(SimStruct* S, const
  mxArray *st)
{
  sf_internal_set_sim_state_c58_diffserv_model(S, st);
}

static void sf_opaque_terminate_c58_diffserv_model(void *chartInstanceVar)
{
  if (chartInstanceVar!=NULL) {
    SimStruct *S = ((SFc58_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_c58_diffserv_model((SFc58_diffserv_modelInstanceStruct*)
      chartInstanceVar);
    utFree((void *)chartInstanceVar);
    ssSetUserData(S,NULL);
  }
}

static void sf_opaque_init_subchart_simstructs(void *chartInstanceVar)
{
  initSimStructsc58_diffserv_model((SFc58_diffserv_modelInstanceStruct*)
    chartInstanceVar);
}

extern unsigned int sf_machine_global_initializer_called(void);
static void mdlProcessParameters_c58_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_c58_diffserv_model((SFc58_diffserv_modelInstanceStruct*)
      (((ChartInfoStruct *)ssGetUserData(S))->chartInstance));
  }
}

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

  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);
  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,
      58);
    ssSetStateflowIsInlinable(S,chartIsInlinable);
    ssSetRTWCG(S,sf_rtw_info_uint_prop(S,sf_get_instance_specialization(),
                infoStruct,58,"RTWCG"));
    ssSetEnableFcnIsTrivial(S,1);
    ssSetDisableFcnIsTrivial(S,1);
    ssSetNotMultipleInlinable(S,sf_rtw_info_uint_prop(S,
      sf_get_instance_specialization(),infoStruct,58,
      "gatewayCannotBeInlinedMultipleTimes"));
    sf_update_buildInfo(S,sf_get_instance_specialization(),infoStruct,58);
    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,58,3);
      sf_mark_chart_reusable_outputs(S,sf_get_instance_specialization(),
        infoStruct,58,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,58);
    ssSetHasSubFunctions(S,!(chartIsInlinable));
  } else {
  }

  ssSetOptions(S,ssGetOptions(S)|SS_OPTION_WORKS_WITH_CODE_REUSE);
  ssSetChecksum0(S,(734493561U));
  ssSetChecksum1(S,(2303656086U));
  ssSetChecksum2(S,(3848768635U));
  ssSetChecksum3(S,(3927314283U));
  ssSetmdlDerivatives(S, NULL);
  ssSetExplicitFCSSCtrl(S,1);
  ssSupportsMultipleExecInstances(S,0);
}

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

static void mdlStart_c58_diffserv_model(SimStruct *S)
{
  SFc58_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc58_diffserv_modelInstanceStruct *)utMalloc(sizeof
    (SFc58_diffserv_modelInstanceStruct));
  memset(chartInstance, 0, sizeof(SFc58_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_c58_diffserv_model;
  chartInstance->chartInfo.initializeChart =
    sf_opaque_initialize_c58_diffserv_model;
  chartInstance->chartInfo.terminateChart =
    sf_opaque_terminate_c58_diffserv_model;
  chartInstance->chartInfo.enableChart = sf_opaque_enable_c58_diffserv_model;
  chartInstance->chartInfo.disableChart = sf_opaque_disable_c58_diffserv_model;
  chartInstance->chartInfo.getSimState =
    sf_opaque_get_sim_state_c58_diffserv_model;
  chartInstance->chartInfo.setSimState =
    sf_opaque_set_sim_state_c58_diffserv_model;
  chartInstance->chartInfo.getSimStateInfo =
    sf_get_sim_state_info_c58_diffserv_model;
  chartInstance->chartInfo.zeroCrossings = NULL;
  chartInstance->chartInfo.outputs = NULL;
  chartInstance->chartInfo.derivatives = NULL;
  chartInstance->chartInfo.mdlRTW = mdlRTW_c58_diffserv_model;
  chartInstance->chartInfo.mdlStart = mdlStart_c58_diffserv_model;
  chartInstance->chartInfo.mdlSetWorkWidths =
    mdlSetWorkWidths_c58_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 c58_diffserv_model_method_dispatcher(SimStruct *S, int_T method, void *data)
{
  switch (method) {
   case SS_CALL_MDL_START:
    mdlStart_c58_diffserv_model(S);
    break;

   case SS_CALL_MDL_SET_WORK_WIDTHS:
    mdlSetWorkWidths_c58_diffserv_model(S);
    break;

   case SS_CALL_MDL_PROCESS_PARAMETERS:
    mdlProcessParameters_c58_diffserv_model(S);
    break;

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