/* Receive_TrackSide_Msg_Pkg::checkTelegram */
void checkTelegram_Receive_TrackSide_Msg_Pkg(
  /* Receive_TrackSide_Msg_Pkg::checkTelegram::newTelegram */ Telegram_T_BG_Types_Pkg *newTelegram,
  /* Receive_TrackSide_Msg_Pkg::checkTelegram::inTelegramArray */ TelegramArray_T_BG_Types_Pkg *inTelegramArray,
  /* Receive_TrackSide_Msg_Pkg::checkTelegram::BGCollector */ BGCollector_T_Receive_TrackSide_Msg_Pkg *BGCollector,
  /* Receive_TrackSide_Msg_Pkg::checkTelegram::outCollector */ BGCollector_T_Receive_TrackSide_Msg_Pkg *outCollector,
  /* Receive_TrackSide_Msg_Pkg::checkTelegram::outTelegramArray */ TelegramArray_T_BG_Types_Pkg *outTelegramArray,
  /* Receive_TrackSide_Msg_Pkg::checkTelegram::outTelegramNotInGroup */ kcg_bool *outTelegramNotInGroup,
  /* Receive_TrackSide_Msg_Pkg::checkTelegram::outBGchangedEarly */ kcg_bool *outBGchangedEarly)
{
  /* Receive_TrackSide_Msg_Pkg::checkTelegram */ BGCollector_T_Receive_TrackSide_Msg_Pkg tmp;
  /* Receive_TrackSide_Msg_Pkg::checkTelegram::newBGInitNeeded */ kcg_bool newBGInitNeeded;
  /* Receive_TrackSide_Msg_Pkg::checkTelegram::_L36 */ kcg_bool _L36;
  /* Receive_TrackSide_Msg_Pkg::checkTelegram::_L63 */ kcg_bool _L63;
  
  _L36 = (*newTelegram).telegramheader.nid_bg == (*BGCollector).BG_ID;
  _L63 = !_L36 & ((*BGCollector).totalTelegrams > 0);
  newBGInitNeeded = _L63 & (*BGCollector).BGMessageSent;
  /* 2 */ if (newBGInitNeeded) {
    kcg_copy_TelegramArray_T_BG_Types_Pkg(
      outTelegramArray,
      (TelegramArray_T_BG_Types_Pkg *) &cEmptyTelegramArray_BG_Types_Pkg);
    /* 1 */
    initCollector_Receive_TrackSide_Msg_Pkg_BaliseSupport(newTelegram, &tmp);
  }
  else {
    kcg_copy_TelegramArray_T_BG_Types_Pkg(outTelegramArray, inTelegramArray);
    kcg_copy_BGCollector_T_Receive_TrackSide_Msg_Pkg(&tmp, BGCollector);
  }
  *outTelegramNotInGroup = !/* 1 */
    findTelegram_Receive_TrackSide_Msg_Pkg_BaliseSupport(
      (*newTelegram).telegramheader.n_pig,
      outTelegramArray,
      (kcg_bool) ((*newTelegram).valid & _L36));
  *outBGchangedEarly = _L63 & !(*BGCollector).BGMessageSent;
  /* 1 */
  checkSingleBB_Receive_TrackSide_Msg_Pkg_BaliseSupport(
    newTelegram,
    &tmp,
    outCollector);
}
/* Receive_TrackSide_Msg_Pkg::checkTelegram */
void checkTelegram_Receive_TrackSide_Msg_Pkg(
  /* Receive_TrackSide_Msg_Pkg::checkTelegram::newTelegram */ Telegram_T_BG_Types_Pkg *newTelegram,
  /* Receive_TrackSide_Msg_Pkg::checkTelegram::inTelegramArray */ TelegramArray_T_BG_Types_Pkg *inTelegramArray,
  /* Receive_TrackSide_Msg_Pkg::checkTelegram::BGCollector */ BGCollector_T_Receive_TrackSide_Msg_Pkg *BGCollector,
  outC_checkTelegram_Receive_TrackSide_Msg_Pkg *outC)
{
  kcg_copy_Telegram_T_BG_Types_Pkg(&outC->_L2, newTelegram);
  outC->_L4 = outC->_L2.valid;
  outC->_L32 = outC->_L2.telegramheader.nid_bg;
  kcg_copy_BGCollector_T_Receive_TrackSide_Msg_Pkg(&outC->_L56, BGCollector);
  outC->_L61 = outC->_L56.BG_ID;
  outC->_L36 = outC->_L32 == outC->_L61;
  outC->_L31 = outC->_L4 & outC->_L36;
  outC->_L55 = outC->_L2.telegramheader.n_pig;
  outC->_L62 = !outC->_L36;
  outC->_L64 = outC->_L56.totalTelegrams;
  outC->_L66 = 0;
  outC->_L65 = outC->_L64 > outC->_L66;
  outC->_L63 = outC->_L62 & outC->_L65;
  outC->_L67 = outC->_L56.BGMessageSent;
  outC->_L68 = outC->_L63 & outC->_L67;
  outC->newBGInitNeeded = outC->_L68;
  outC->_L70 = outC->newBGInitNeeded;
  kcg_copy_TelegramArray_T_BG_Types_Pkg(
    &outC->_L94,
    (TelegramArray_T_BG_Types_Pkg *) &cEmptyTelegramArray_BG_Types_Pkg);
  kcg_copy_TelegramArray_T_BG_Types_Pkg(&outC->_L40, inTelegramArray);
  /* 1 */ if (outC->_L70) {
    kcg_copy_TelegramArray_T_BG_Types_Pkg(&outC->_L69, &outC->_L94);
  }
  else {
    kcg_copy_TelegramArray_T_BG_Types_Pkg(&outC->_L69, &outC->_L40);
  }
  /* 1 */
  findTelegram_Receive_TrackSide_Msg_Pkg_BaliseSupport(
    outC->_L55,
    &outC->_L69,
    outC->_L31,
    &outC->Context_1);
  outC->_L41 = outC->Context_1.telegramAlreadyInGroup;
  outC->_L86 = !outC->_L41;
  outC->outTelegramNotInGroup = outC->_L86;
  outC->_L87 = !outC->_L67;
  outC->_L88 = outC->_L63 & outC->_L87;
  outC->outBGchangedEarly = outC->_L88;
  outC->_L73 = outC->newBGInitNeeded;
  /* 1 */
  initCollector_Receive_TrackSide_Msg_Pkg_BaliseSupport(
    &outC->_L2,
    &outC->_1_Context_1);
  kcg_copy_BGCollector_T_Receive_TrackSide_Msg_Pkg(
    &outC->_L92,
    &outC->_1_Context_1.outCollector);
  kcg_copy_BGCollector_T_Receive_TrackSide_Msg_Pkg(&outC->_L74, BGCollector);
  /* 2 */ if (outC->_L73) {
    kcg_copy_BGCollector_T_Receive_TrackSide_Msg_Pkg(&outC->_L72, &outC->_L92);
  }
  else {
    kcg_copy_BGCollector_T_Receive_TrackSide_Msg_Pkg(&outC->_L72, &outC->_L74);
  }
  /* 1 */
  checkSingleBB_Receive_TrackSide_Msg_Pkg_BaliseSupport(
    &outC->_L2,
    &outC->_L72,
    &outC->_2_Context_1);
  kcg_copy_BGCollector_T_Receive_TrackSide_Msg_Pkg(
    &outC->_L93,
    &outC->_2_Context_1.outCollector);
  kcg_copy_BGCollector_T_Receive_TrackSide_Msg_Pkg(
    &outC->outCollector,
    &outC->_L93);
  kcg_copy_TelegramArray_T_BG_Types_Pkg(&outC->outTelegramArray, &outC->_L69);
}