/* Include files */

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

/* Variable Declarations */

/* Variable Definitions */
static const char * c50_debug_family_names[4] = { "nargin", "nargout",
  "DestAddr", "NextHop" };

/* Function Declarations */
static void initialize_c50_diffserv_model(SFc50_diffserv_modelInstanceStruct
  *chartInstance);
static void initialize_params_c50_diffserv_model
  (SFc50_diffserv_modelInstanceStruct *chartInstance);
static void enable_c50_diffserv_model(SFc50_diffserv_modelInstanceStruct
  *chartInstance);
static void disable_c50_diffserv_model(SFc50_diffserv_modelInstanceStruct
  *chartInstance);
static void c50_update_debugger_state_c50_diffserv_model
  (SFc50_diffserv_modelInstanceStruct *chartInstance);
static const mxArray *get_sim_state_c50_diffserv_model
  (SFc50_diffserv_modelInstanceStruct *chartInstance);
static void set_sim_state_c50_diffserv_model(SFc50_diffserv_modelInstanceStruct *
  chartInstance, const mxArray *c50_st);
static void finalize_c50_diffserv_model(SFc50_diffserv_modelInstanceStruct
  *chartInstance);
static void sf_c50_diffserv_model(SFc50_diffserv_modelInstanceStruct
  *chartInstance);
static void initSimStructsc50_diffserv_model(SFc50_diffserv_modelInstanceStruct *
  chartInstance);
static void registerMessagesc50_diffserv_model
  (SFc50_diffserv_modelInstanceStruct *chartInstance);
static void init_script_number_translation(uint32_T c50_machineNumber, uint32_T
  c50_chartNumber);
static const mxArray *c50_sf_marshallOut(void *chartInstanceVoid, void
  *c50_inData);
static real_T c50_emlrt_marshallIn(SFc50_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c50_NextHop, const char_T *c50_identifier);
static real_T c50_b_emlrt_marshallIn(SFc50_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c50_u, const emlrtMsgIdentifier *c50_parentId);
static void c50_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c50_mxArrayInData, const char_T *c50_varName, void *c50_outData);
static const mxArray *c50_b_sf_marshallOut(void *chartInstanceVoid, void
  *c50_inData);
static int32_T c50_c_emlrt_marshallIn(SFc50_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c50_u, const emlrtMsgIdentifier *c50_parentId);
static void c50_b_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c50_mxArrayInData, const char_T *c50_varName, void *c50_outData);
static uint8_T c50_d_emlrt_marshallIn(SFc50_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c50_b_is_active_c50_diffserv_model, const
  char_T *c50_identifier);
static uint8_T c50_e_emlrt_marshallIn(SFc50_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c50_u, const emlrtMsgIdentifier *c50_parentId);
static void init_dsm_address_info(SFc50_diffserv_modelInstanceStruct
  *chartInstance);

/* Function Definitions */
static void initialize_c50_diffserv_model(SFc50_diffserv_modelInstanceStruct
  *chartInstance)
{
  chartInstance->c50_sfEvent = CALL_EVENT;
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
  chartInstance->c50_is_active_c50_diffserv_model = 0U;
}

static void initialize_params_c50_diffserv_model
  (SFc50_diffserv_modelInstanceStruct *chartInstance)
{
}

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

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

static void c50_update_debugger_state_c50_diffserv_model
  (SFc50_diffserv_modelInstanceStruct *chartInstance)
{
}

static const mxArray *get_sim_state_c50_diffserv_model
  (SFc50_diffserv_modelInstanceStruct *chartInstance)
{
  const mxArray *c50_st;
  const mxArray *c50_y = NULL;
  real_T c50_hoistedGlobal;
  real_T c50_u;
  const mxArray *c50_b_y = NULL;
  uint8_T c50_b_hoistedGlobal;
  uint8_T c50_b_u;
  const mxArray *c50_c_y = NULL;
  real_T *c50_NextHop;
  c50_NextHop = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  c50_st = NULL;
  c50_st = NULL;
  c50_y = NULL;
  sf_mex_assign(&c50_y, sf_mex_createcellarray(2), FALSE);
  c50_hoistedGlobal = *c50_NextHop;
  c50_u = c50_hoistedGlobal;
  c50_b_y = NULL;
  sf_mex_assign(&c50_b_y, sf_mex_create("y", &c50_u, 0, 0U, 0U, 0U, 0), FALSE);
  sf_mex_setcell(c50_y, 0, c50_b_y);
  c50_b_hoistedGlobal = chartInstance->c50_is_active_c50_diffserv_model;
  c50_b_u = c50_b_hoistedGlobal;
  c50_c_y = NULL;
  sf_mex_assign(&c50_c_y, sf_mex_create("y", &c50_b_u, 3, 0U, 0U, 0U, 0), FALSE);
  sf_mex_setcell(c50_y, 1, c50_c_y);
  sf_mex_assign(&c50_st, c50_y, FALSE);
  return c50_st;
}

static void set_sim_state_c50_diffserv_model(SFc50_diffserv_modelInstanceStruct *
  chartInstance, const mxArray *c50_st)
{
  const mxArray *c50_u;
  real_T *c50_NextHop;
  c50_NextHop = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  chartInstance->c50_doneDoubleBufferReInit = TRUE;
  c50_u = sf_mex_dup(c50_st);
  *c50_NextHop = c50_emlrt_marshallIn(chartInstance, sf_mex_dup(sf_mex_getcell
    (c50_u, 0)), "NextHop");
  chartInstance->c50_is_active_c50_diffserv_model = c50_d_emlrt_marshallIn
    (chartInstance, sf_mex_dup(sf_mex_getcell(c50_u, 1)),
     "is_active_c50_diffserv_model");
  sf_mex_destroy(&c50_u);
  c50_update_debugger_state_c50_diffserv_model(chartInstance);
  sf_mex_destroy(&c50_st);
}

static void finalize_c50_diffserv_model(SFc50_diffserv_modelInstanceStruct
  *chartInstance)
{
}

static void sf_c50_diffserv_model(SFc50_diffserv_modelInstanceStruct
  *chartInstance)
{
  real_T c50_hoistedGlobal;
  real_T c50_DestAddr;
  uint32_T c50_debug_family_var_map[4];
  real_T c50_nargin = 1.0;
  real_T c50_nargout = 1.0;
  real_T c50_NextHop;
  real_T *c50_b_DestAddr;
  real_T *c50_b_NextHop;
  c50_b_NextHop = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
  c50_b_DestAddr = (real_T *)ssGetInputPortSignal(chartInstance->S, 0);
  _sfTime_ = (real_T)ssGetT(chartInstance->S);
  _SFD_CC_CALL(CHART_ENTER_SFUNCTION_TAG, 49U, chartInstance->c50_sfEvent);
  _SFD_DATA_RANGE_CHECK(*c50_b_DestAddr, 0U);
  _SFD_DATA_RANGE_CHECK(*c50_b_NextHop, 1U);
  chartInstance->c50_sfEvent = CALL_EVENT;
  _SFD_CC_CALL(CHART_ENTER_DURING_FUNCTION_TAG, 49U, chartInstance->c50_sfEvent);
  c50_hoistedGlobal = *c50_b_DestAddr;
  c50_DestAddr = c50_hoistedGlobal;
  _SFD_SYMBOL_SCOPE_PUSH_EML(0U, 4U, 4U, c50_debug_family_names,
    c50_debug_family_var_map);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c50_nargin, 0U, c50_sf_marshallOut,
    c50_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c50_nargout, 1U, c50_sf_marshallOut,
    c50_sf_marshallIn);
  _SFD_SYMBOL_SCOPE_ADD_EML(&c50_DestAddr, 2U, c50_sf_marshallOut);
  _SFD_SYMBOL_SCOPE_ADD_EML_IMPORTABLE(&c50_NextHop, 3U, c50_sf_marshallOut,
    c50_sf_marshallIn);
  CV_EML_FCN(0, 0);
  _SFD_EML_CALL(0U, chartInstance->c50_sfEvent, 5);
  switch ((int16_T)_SFD_INTEGER_CHECK("DestAddr", c50_DestAddr)) {
   case 1:
    CV_EML_SWITCH(0, 1, 0, 1);
    _SFD_EML_CALL(0U, chartInstance->c50_sfEvent, 7);
    c50_NextHop = 3.0;
    break;

   case 2:
    CV_EML_SWITCH(0, 1, 0, 2);
    _SFD_EML_CALL(0U, chartInstance->c50_sfEvent, 10);
    c50_NextHop = 1.0;
    break;

   case 3:
    CV_EML_SWITCH(0, 1, 0, 3);
    _SFD_EML_CALL(0U, chartInstance->c50_sfEvent, 13);
    c50_NextHop = 2.0;
    break;

   case 4:
    CV_EML_SWITCH(0, 1, 0, 4);
    _SFD_EML_CALL(0U, chartInstance->c50_sfEvent, 16);
    c50_NextHop = 3.0;
    break;

   default:
    CV_EML_SWITCH(0, 1, 0, 0);
    _SFD_EML_CALL(0U, chartInstance->c50_sfEvent, 19);
    c50_NextHop = 3.0;
    break;
  }

  _SFD_EML_CALL(0U, chartInstance->c50_sfEvent, -19);
  _SFD_SYMBOL_SCOPE_POP();
  *c50_b_NextHop = c50_NextHop;
  _SFD_CC_CALL(EXIT_OUT_OF_FUNCTION_TAG, 49U, chartInstance->c50_sfEvent);
  _SFD_CHECK_FOR_STATE_INCONSISTENCY(_diffserv_modelMachineNumber_,
    chartInstance->chartNumber, chartInstance->instanceNumber);
}

static void initSimStructsc50_diffserv_model(SFc50_diffserv_modelInstanceStruct *
  chartInstance)
{
}

static void registerMessagesc50_diffserv_model
  (SFc50_diffserv_modelInstanceStruct *chartInstance)
{
}

static void init_script_number_translation(uint32_T c50_machineNumber, uint32_T
  c50_chartNumber)
{
}

static const mxArray *c50_sf_marshallOut(void *chartInstanceVoid, void
  *c50_inData)
{
  const mxArray *c50_mxArrayOutData = NULL;
  real_T c50_u;
  const mxArray *c50_y = NULL;
  SFc50_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc50_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c50_mxArrayOutData = NULL;
  c50_u = *(real_T *)c50_inData;
  c50_y = NULL;
  sf_mex_assign(&c50_y, sf_mex_create("y", &c50_u, 0, 0U, 0U, 0U, 0), FALSE);
  sf_mex_assign(&c50_mxArrayOutData, c50_y, FALSE);
  return c50_mxArrayOutData;
}

static real_T c50_emlrt_marshallIn(SFc50_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c50_NextHop, const char_T *c50_identifier)
{
  real_T c50_y;
  emlrtMsgIdentifier c50_thisId;
  c50_thisId.fIdentifier = c50_identifier;
  c50_thisId.fParent = NULL;
  c50_y = c50_b_emlrt_marshallIn(chartInstance, sf_mex_dup(c50_NextHop),
    &c50_thisId);
  sf_mex_destroy(&c50_NextHop);
  return c50_y;
}

static real_T c50_b_emlrt_marshallIn(SFc50_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c50_u, const emlrtMsgIdentifier *c50_parentId)
{
  real_T c50_y;
  real_T c50_d0;
  sf_mex_import(c50_parentId, sf_mex_dup(c50_u), &c50_d0, 1, 0, 0U, 0, 0U, 0);
  c50_y = c50_d0;
  sf_mex_destroy(&c50_u);
  return c50_y;
}

static void c50_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c50_mxArrayInData, const char_T *c50_varName, void *c50_outData)
{
  const mxArray *c50_NextHop;
  const char_T *c50_identifier;
  emlrtMsgIdentifier c50_thisId;
  real_T c50_y;
  SFc50_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc50_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c50_NextHop = sf_mex_dup(c50_mxArrayInData);
  c50_identifier = c50_varName;
  c50_thisId.fIdentifier = c50_identifier;
  c50_thisId.fParent = NULL;
  c50_y = c50_b_emlrt_marshallIn(chartInstance, sf_mex_dup(c50_NextHop),
    &c50_thisId);
  sf_mex_destroy(&c50_NextHop);
  *(real_T *)c50_outData = c50_y;
  sf_mex_destroy(&c50_mxArrayInData);
}

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

static const mxArray *c50_b_sf_marshallOut(void *chartInstanceVoid, void
  *c50_inData)
{
  const mxArray *c50_mxArrayOutData = NULL;
  int32_T c50_u;
  const mxArray *c50_y = NULL;
  SFc50_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc50_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c50_mxArrayOutData = NULL;
  c50_u = *(int32_T *)c50_inData;
  c50_y = NULL;
  sf_mex_assign(&c50_y, sf_mex_create("y", &c50_u, 6, 0U, 0U, 0U, 0), FALSE);
  sf_mex_assign(&c50_mxArrayOutData, c50_y, FALSE);
  return c50_mxArrayOutData;
}

static int32_T c50_c_emlrt_marshallIn(SFc50_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c50_u, const emlrtMsgIdentifier *c50_parentId)
{
  int32_T c50_y;
  int32_T c50_i0;
  sf_mex_import(c50_parentId, sf_mex_dup(c50_u), &c50_i0, 1, 6, 0U, 0, 0U, 0);
  c50_y = c50_i0;
  sf_mex_destroy(&c50_u);
  return c50_y;
}

static void c50_b_sf_marshallIn(void *chartInstanceVoid, const mxArray
  *c50_mxArrayInData, const char_T *c50_varName, void *c50_outData)
{
  const mxArray *c50_b_sfEvent;
  const char_T *c50_identifier;
  emlrtMsgIdentifier c50_thisId;
  int32_T c50_y;
  SFc50_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc50_diffserv_modelInstanceStruct *)chartInstanceVoid;
  c50_b_sfEvent = sf_mex_dup(c50_mxArrayInData);
  c50_identifier = c50_varName;
  c50_thisId.fIdentifier = c50_identifier;
  c50_thisId.fParent = NULL;
  c50_y = c50_c_emlrt_marshallIn(chartInstance, sf_mex_dup(c50_b_sfEvent),
    &c50_thisId);
  sf_mex_destroy(&c50_b_sfEvent);
  *(int32_T *)c50_outData = c50_y;
  sf_mex_destroy(&c50_mxArrayInData);
}

static uint8_T c50_d_emlrt_marshallIn(SFc50_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c50_b_is_active_c50_diffserv_model, const
  char_T *c50_identifier)
{
  uint8_T c50_y;
  emlrtMsgIdentifier c50_thisId;
  c50_thisId.fIdentifier = c50_identifier;
  c50_thisId.fParent = NULL;
  c50_y = c50_e_emlrt_marshallIn(chartInstance, sf_mex_dup
    (c50_b_is_active_c50_diffserv_model), &c50_thisId);
  sf_mex_destroy(&c50_b_is_active_c50_diffserv_model);
  return c50_y;
}

static uint8_T c50_e_emlrt_marshallIn(SFc50_diffserv_modelInstanceStruct
  *chartInstance, const mxArray *c50_u, const emlrtMsgIdentifier *c50_parentId)
{
  uint8_T c50_y;
  uint8_T c50_u0;
  sf_mex_import(c50_parentId, sf_mex_dup(c50_u), &c50_u0, 1, 3, 0U, 0, 0U, 0);
  c50_y = c50_u0;
  sf_mex_destroy(&c50_u);
  return c50_y;
}

static void init_dsm_address_info(SFc50_diffserv_modelInstanceStruct
  *chartInstance)
{
}

/* 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_c50_diffserv_model_get_check_sum(mxArray *plhs[])
{
  ((real_T *)mxGetPr((plhs[0])))[0] = (real_T)(2575691983U);
  ((real_T *)mxGetPr((plhs[0])))[1] = (real_T)(3380533375U);
  ((real_T *)mxGetPr((plhs[0])))[2] = (real_T)(309237204U);
  ((real_T *)mxGetPr((plhs[0])))[3] = (real_T)(2270939045U);
}

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

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

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

  {
    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,"inputs",mxData);
  }

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

  {
    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_c50_diffserv_model_third_party_uses_info(void)
{
  mxArray * mxcell3p = mxCreateCellMatrix(1,0);
  return(mxcell3p);
}

static const mxArray *sf_get_sim_state_info_c50_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[5],T\"NextHop\",},{M[8],M[0],T\"is_active_c50_diffserv_model\",}}"
  };

  mxArray *mxVarInfo = sf_mex_decode_encoded_mx_struct_array(infoEncStr, 2, 10);
  mxArray *mxChecksum = mxCreateDoubleMatrix(1, 4, mxREAL);
  sf_c50_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)) {
    SFc50_diffserv_modelInstanceStruct *chartInstance;
    chartInstance = (SFc50_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_,
           50,
           1,
           1,
           2,
           0,
           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,
            0,
            0,
            0);
          _SFD_SET_DATA_PROPS(0,1,1,0,"DestAddr");
          _SFD_SET_DATA_PROPS(1,2,0,1,"NextHop");
          _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,0,0,0,1,0,0,0,0);
        _SFD_CV_INIT_EML_FCN(0,0,"eML_blk_kernel",0,-1,336);

        {
          static int caseStart[] = { 272, 108, 149, 190, 231 };

          static int caseExprEnd[] = { 281, 114, 155, 196, 237 };

          _SFD_CV_INIT_EML_SWITCH(0,1,0,88,104,335,5,&(caseStart[0]),
            &(caseExprEnd[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)c50_sf_marshallOut,(MexInFcnForType)NULL);
        _SFD_SET_DATA_COMPILED_PROPS(1,SF_DOUBLE,0,NULL,0,0,0,0.0,1.0,0,0,
          (MexFcnForType)c50_sf_marshallOut,(MexInFcnForType)c50_sf_marshallIn);

        {
          real_T *c50_DestAddr;
          real_T *c50_NextHop;
          c50_NextHop = (real_T *)ssGetOutputPortSignal(chartInstance->S, 1);
          c50_DestAddr = (real_T *)ssGetInputPortSignal(chartInstance->S, 0);
          _SFD_SET_DATA_VALUE_PTR(0U, c50_DestAddr);
          _SFD_SET_DATA_VALUE_PTR(1U, c50_NextHop);
        }
      }
    } else {
      sf_debug_reset_current_state_configuration(sfGlobalDebugInstanceStruct,
        _diffserv_modelMachineNumber_,chartInstance->chartNumber,
        chartInstance->instanceNumber);
    }
  }
}

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

static void sf_opaque_initialize_c50_diffserv_model(void *chartInstanceVar)
{
  chart_debug_initialization(((SFc50_diffserv_modelInstanceStruct*)
    chartInstanceVar)->S,0);
  initialize_params_c50_diffserv_model((SFc50_diffserv_modelInstanceStruct*)
    chartInstanceVar);
  initialize_c50_diffserv_model((SFc50_diffserv_modelInstanceStruct*)
    chartInstanceVar);
}

static void sf_opaque_enable_c50_diffserv_model(void *chartInstanceVar)
{
  enable_c50_diffserv_model((SFc50_diffserv_modelInstanceStruct*)
    chartInstanceVar);
}

static void sf_opaque_disable_c50_diffserv_model(void *chartInstanceVar)
{
  disable_c50_diffserv_model((SFc50_diffserv_modelInstanceStruct*)
    chartInstanceVar);
}

static void sf_opaque_gateway_c50_diffserv_model(void *chartInstanceVar)
{
  sf_c50_diffserv_model((SFc50_diffserv_modelInstanceStruct*) chartInstanceVar);
}

extern const mxArray* sf_internal_get_sim_state_c50_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_c50_diffserv_model
    ((SFc50_diffserv_modelInstanceStruct*)chartInfo->chartInstance);/* raw sim ctx */
  prhs[3] = (mxArray*) sf_get_sim_state_info_c50_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_c50_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_c50_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_c50_diffserv_model((SFc50_diffserv_modelInstanceStruct*)
    chartInfo->chartInstance, mxDuplicateArray(plhs[0]));
  mxDestroyArray(plhs[0]);
}

static const mxArray* sf_opaque_get_sim_state_c50_diffserv_model(SimStruct* S)
{
  return sf_internal_get_sim_state_c50_diffserv_model(S);
}

static void sf_opaque_set_sim_state_c50_diffserv_model(SimStruct* S, const
  mxArray *st)
{
  sf_internal_set_sim_state_c50_diffserv_model(S, st);
}

static void sf_opaque_terminate_c50_diffserv_model(void *chartInstanceVar)
{
  if (chartInstanceVar!=NULL) {
    SimStruct *S = ((SFc50_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_c50_diffserv_model((SFc50_diffserv_modelInstanceStruct*)
      chartInstanceVar);
    utFree((void *)chartInstanceVar);
    ssSetUserData(S,NULL);
  }
}

static void sf_opaque_init_subchart_simstructs(void *chartInstanceVar)
{
  initSimStructsc50_diffserv_model((SFc50_diffserv_modelInstanceStruct*)
    chartInstanceVar);
}

extern unsigned int sf_machine_global_initializer_called(void);
static void mdlProcessParameters_c50_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_c50_diffserv_model((SFc50_diffserv_modelInstanceStruct*)
      (((ChartInfoStruct *)ssGetUserData(S))->chartInstance));
  }
}

static void mdlSetWorkWidths_c50_diffserv_model(SimStruct *S)
{
  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,
      50);
    ssSetStateflowIsInlinable(S,chartIsInlinable);
    ssSetRTWCG(S,sf_rtw_info_uint_prop(S,sf_get_instance_specialization(),
                infoStruct,50,"RTWCG"));
    ssSetEnableFcnIsTrivial(S,1);
    ssSetDisableFcnIsTrivial(S,1);
    ssSetNotMultipleInlinable(S,sf_rtw_info_uint_prop(S,
      sf_get_instance_specialization(),infoStruct,50,
      "gatewayCannotBeInlinedMultipleTimes"));
    sf_update_buildInfo(S,sf_get_instance_specialization(),infoStruct,50);
    if (chartIsInlinable) {
      ssSetInputPortOptimOpts(S, 0, SS_REUSABLE_AND_LOCAL);
      sf_mark_chart_expressionable_inputs(S,sf_get_instance_specialization(),
        infoStruct,50,1);
      sf_mark_chart_reusable_outputs(S,sf_get_instance_specialization(),
        infoStruct,50,1);
    }

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

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

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

  ssSetOptions(S,ssGetOptions(S)|SS_OPTION_WORKS_WITH_CODE_REUSE);
  ssSetChecksum0(S,(1045145232U));
  ssSetChecksum1(S,(1899835816U));
  ssSetChecksum2(S,(3003858152U));
  ssSetChecksum3(S,(360697521U));
  ssSetmdlDerivatives(S, NULL);
  ssSetExplicitFCSSCtrl(S,1);
  ssSupportsMultipleExecInstances(S,1);
}

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

static void mdlStart_c50_diffserv_model(SimStruct *S)
{
  SFc50_diffserv_modelInstanceStruct *chartInstance;
  chartInstance = (SFc50_diffserv_modelInstanceStruct *)utMalloc(sizeof
    (SFc50_diffserv_modelInstanceStruct));
  memset(chartInstance, 0, sizeof(SFc50_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_c50_diffserv_model;
  chartInstance->chartInfo.initializeChart =
    sf_opaque_initialize_c50_diffserv_model;
  chartInstance->chartInfo.terminateChart =
    sf_opaque_terminate_c50_diffserv_model;
  chartInstance->chartInfo.enableChart = sf_opaque_enable_c50_diffserv_model;
  chartInstance->chartInfo.disableChart = sf_opaque_disable_c50_diffserv_model;
  chartInstance->chartInfo.getSimState =
    sf_opaque_get_sim_state_c50_diffserv_model;
  chartInstance->chartInfo.setSimState =
    sf_opaque_set_sim_state_c50_diffserv_model;
  chartInstance->chartInfo.getSimStateInfo =
    sf_get_sim_state_info_c50_diffserv_model;
  chartInstance->chartInfo.zeroCrossings = NULL;
  chartInstance->chartInfo.outputs = NULL;
  chartInstance->chartInfo.derivatives = NULL;
  chartInstance->chartInfo.mdlRTW = mdlRTW_c50_diffserv_model;
  chartInstance->chartInfo.mdlStart = mdlStart_c50_diffserv_model;
  chartInstance->chartInfo.mdlSetWorkWidths =
    mdlSetWorkWidths_c50_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 c50_diffserv_model_method_dispatcher(SimStruct *S, int_T method, void *data)
{
  switch (method) {
   case SS_CALL_MDL_START:
    mdlStart_c50_diffserv_model(S);
    break;

   case SS_CALL_MDL_SET_WORK_WIDTHS:
    mdlSetWorkWidths_c50_diffserv_model(S);
    break;

   case SS_CALL_MDL_PROCESS_PARAMETERS:
    mdlProcessParameters_c50_diffserv_model(S);
    break;

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