/* TargetManagement_pkg::TargetManagement */
void TargetManagement_TargetManagement_pkg(
  /* TargetManagement_pkg::TargetManagement::MRSP */MRSP_internal_T_TargetManagement_types *MRSP,
  /* TargetManagement_pkg::TargetManagement::MRSP_updated */kcg_bool MRSP_updated,
  /* TargetManagement_pkg::TargetManagement::MA */MA_section_real_T_TargetManagement_types *MA,
  /* TargetManagement_pkg::TargetManagement::MA_updated */kcg_bool MA_updated,
  /* TargetManagement_pkg::TargetManagement::trainLocations */TrainLocations_real_T_SDM_Types_Pkg *trainLocations,
  outC_TargetManagement_TargetManagement_pkg *outC)
{
  static struct__130782 tmp;
  static kcg_int i;
  static Target_list_MRSP_real_T_TargetManagement_types tmp3;
  static extractTargetsMRSPACC_TargetManagement_pkg tmp2;
  static array__130570 tmp1;
  static array__130570 tmp4;
  /* TargetManagement_pkg::TargetManagement::_L88 */
  static kcg_bool _L88;
  
  if (MA_updated) {
    /* 1 */
    calcMATargets_TargetManagement_pkg_internalOperators(
      MA,
      &outC->_L12,
      &outC->_L93);
  }
  else if (outC->init) {
    kcg_copy_Target_real_T_TargetManagement_types(
      &outC->_L93,
      (Target_real_T_TargetManagement_types *)
        &emptyTarget_TargetManagement_pkg);
    kcg_copy_Target_real_T_TargetManagement_types(
      &outC->_L12,
      (Target_real_T_TargetManagement_types *)
        &emptyTarget_TargetManagement_pkg);
  }
  kcg_copy_Target_real_T_TargetManagement_types(
    &outC->targetCollection.SvL_LoA_target,
    &outC->_L93);
  for (i = 0; i < 110; i++) {
    kcg_copy_Target_real_T_TargetManagement_types(
      &tmp4[i],
      (Target_real_T_TargetManagement_types *)
        &emptyTarget_TargetManagement_pkg);
  }
  if (MRSP_updated) {
    /* 1 */
    extractTargetsFromMRSP_TargetManagement_pkg_internalOperators(MRSP, &tmp2);
    kcg_copy_Target_list_MRSP_real_T_TargetManagement_types(
      &tmp3,
      &tmp2.targetList);
  }
  else {
    if (outC->init) {
      kcg_copy_array__130570(&tmp1, &tmp4);
    }
    else {
      kcg_copy_Target_list_MRSP_real_T_TargetManagement_types(
        &tmp1,
        &outC->rem_MRSPTargetList);
    }
    kcg_copy_array__130570(&tmp.targetList, &tmp1);
    tmp.lastInsertedTargetIndex = - 1;
    kcg_copy_Target_list_MRSP_real_T_TargetManagement_types(
      &tmp3,
      &tmp.targetList);
  }
  /* 1 */
  removeOverpassedMRSP_TargetManagement_pkg_internalOperators(
    &tmp3,
    (*trainLocations).d_maxSafeFrontEndPos,
    &outC->rem_MRSPTargetList,
    &_L88);
  outC->targetCollection.updatedTargetList = MRSP_updated | MA_updated | _L88;
  kcg_copy_Target_list_MRSP_real_T_TargetManagement_types(
    &outC->targetCollection.MRSP_targetList,
    &outC->rem_MRSPTargetList);
  outC->init = kcg_false;
  kcg_copy_Target_real_T_TargetManagement_types(
    &outC->targetCollection.EOA_target,
    &outC->_L12);
}
/* TargetManagement_pkg::TargetManagement */
void TargetManagement_TargetManagement_pkg(
  /* TargetManagement_pkg::TargetManagement::MRSP */ MRSP_internal_T_TargetManagement_types *MRSP,
  /* TargetManagement_pkg::TargetManagement::MRSP_updated */ kcg_bool MRSP_updated,
  /* TargetManagement_pkg::TargetManagement::MA */ MA_section_real_T_TargetManagement_types *MA,
  /* TargetManagement_pkg::TargetManagement::MA_updated */ kcg_bool MA_updated,
  /* TargetManagement_pkg::TargetManagement::trainLocations */ TrainLocations_real_T_SDM_Types_Pkg *trainLocations,
  outC_TargetManagement_TargetManagement_pkg *outC)
{
  /* TargetManagement_pkg::TargetManagement */ Target_list_MRSP_real_T_TargetManagement_types tmp1;
  /* TargetManagement_pkg::TargetManagement */ extractTargetsMRSPACC_TargetManagement_pkg tmp;
  /* TargetManagement_pkg::TargetManagement::_L88 */ kcg_bool _L88;
  kcg_int i;
  
  /* ck_MA_updated */ if (MA_updated) {
    /* 1 */
    calcMATargets_TargetManagement_pkg_internalOperators(
      MA,
      &outC->_L12,
      &outC->_L93);
  }
  else if (outC->init) {
    kcg_copy_Target_real_T_TargetManagement_types(
      &outC->_L93,
      (Target_real_T_TargetManagement_types *)
        &emptyTarget_TargetManagement_pkg);
    kcg_copy_Target_real_T_TargetManagement_types(
      &outC->_L12,
      (Target_real_T_TargetManagement_types *)
        &emptyTarget_TargetManagement_pkg);
  }
  kcg_copy_Target_real_T_TargetManagement_types(
    &outC->targetCollection.EOA_target,
    &outC->_L12);
  kcg_copy_Target_real_T_TargetManagement_types(
    &outC->targetCollection.SvL_LoA_target,
    &outC->_L93);
  /* ck_MRSP_updated */ if (MRSP_updated) {
    /* 1 */
    extractTargetsFromMRSP_TargetManagement_pkg_internalOperators(MRSP, &tmp);
    kcg_copy_Target_list_MRSP_real_T_TargetManagement_types(
      &tmp1,
      &tmp.targetList);
  }
  else /* last_init_ck_MRSPTargetList */ if (outC->init) {
    for (i = 0; i < 110; i++) {
      kcg_copy_Target_real_T_TargetManagement_types(
        &tmp1[i],
        (Target_real_T_TargetManagement_types *)
          &emptyTarget_TargetManagement_pkg);
    }
  }
  else {
    kcg_copy_Target_list_MRSP_real_T_TargetManagement_types(
      &tmp1,
      &outC->rem_MRSPTargetList);
  }
  outC->init = kcg_false;
  /* 1 */
  removeOverpassedMRSP_TargetManagement_pkg_internalOperators(
    &tmp1,
    (*trainLocations).d_maxSafeFrontEndPos,
    &outC->rem_MRSPTargetList,
    &_L88);
  outC->targetCollection.updatedTargetList = MRSP_updated | MA_updated | _L88;
  kcg_copy_Target_list_MRSP_real_T_TargetManagement_types(
    &outC->targetCollection.MRSP_targetList,
    &outC->rem_MRSPTargetList);
}
/* TargetManagement_pkg::TargetManagement */
void TargetManagement_TargetManagement_pkg(
  /* TargetManagement_pkg::TargetManagement::MRSP */ MRSP_internal_T_TargetManagement_types *MRSP,
  /* TargetManagement_pkg::TargetManagement::MRSP_updated */ kcg_bool MRSP_updated,
  /* TargetManagement_pkg::TargetManagement::MA */ MAs_real_T_TargetManagement_types *MA,
  /* TargetManagement_pkg::TargetManagement::MA_updated */ kcg_bool MA_updated,
  /* TargetManagement_pkg::TargetManagement::trainLocations */ TrainLocations_real_T_SDM_Types_Pkg *trainLocations,
  outC_TargetManagement_TargetManagement_pkg *outC)
{
  kcg_int i;
  Target_list_LOA_real_T_TargetManagement_types tmp6;
  extractTargetsLOAACC_TargetManagement_pkg tmp5;
  Target_list_LOA_real_T_TargetManagement_types tmp4;
  Target_list_MRSP_real_T_TargetManagement_types tmp3;
  extractTargetsMRSPACC_TargetManagement_pkg tmp2;
  Target_list_MRSP_real_T_TargetManagement_types tmp1;
  kcg_real tmp;
  /* TargetManagement_pkg::TargetManagement::_L88 */ kcg_bool _L88;
  /* TargetManagement_pkg::TargetManagement::_L92 */ kcg_bool _L92;
  
  if (MA_updated) {
    /* 1 */
    extractLOATargetsFromMA_TargetManagement_pkg_internalOperators(MA, &tmp5);
    kcg_copy_Target_list_LOA_real_T_TargetManagement_types(
      &tmp6,
      &tmp5.targetList);
    /* 1 */
    extractEOASvLTargetFromMA_TargetManagement_pkg_internalOperators(
      MA,
      &outC->_L12,
      &outC->_L93,
      &outC->V_releaseFromMA,
      &outC->V_releaseFromMAValid);
  }
  else {
    if (outC->init) {
      for (i = 0; i < 10; i++) {
        kcg_copy_Target_real_T_TargetManagement_types(
          &tmp4[i],
          (Target_real_T_TargetManagement_types *)
            &emptyTargetLOA_TargetManagement_pkg);
      }
      kcg_copy_Target_real_T_TargetManagement_types(
        &outC->_L12,
        (Target_real_T_TargetManagement_types *)
          &emptyTargetEOA_TargetManagement_pkg);
      kcg_copy_Target_real_T_TargetManagement_types(
        &outC->_L93,
        (Target_real_T_TargetManagement_types *)
          &emptyTargetSvL_TargetManagement_pkg);
      tmp = 0.0;
      outC->V_releaseFromMAValid = kcg_false;
    }
    else {
      kcg_copy_Target_list_LOA_real_T_TargetManagement_types(
        &tmp4,
        &outC->rem_LOATargetList);
      tmp = outC->V_releaseFromMA;
    }
    kcg_copy_Target_list_LOA_real_T_TargetManagement_types(&tmp6, &tmp4);
    outC->V_releaseFromMA = tmp;
  }
  /* 1 */
  removeOverpassedLOA_TargetManagement_pkg_internalOperators(
    &tmp6,
    (*trainLocations).d_maxSafeFrontEndPos,
    &outC->rem_LOATargetList,
    &_L92);
  kcg_copy_Target_list_LOA_real_T_TargetManagement_types(
    &outC->targetCollection.LOA_targetList,
    &outC->rem_LOATargetList);
  if (MRSP_updated) {
    /* 1 */
    extractTargetsFromMRSP_TargetManagement_pkg_internalOperators(MRSP, &tmp2);
    kcg_copy_Target_list_MRSP_real_T_TargetManagement_types(
      &tmp3,
      &tmp2.targetList);
  }
  else {
    if (outC->init) {
      for (i = 0; i < 200; i++) {
        kcg_copy_Target_real_T_TargetManagement_types(
          &tmp1[i],
          (Target_real_T_TargetManagement_types *)
            &emptyTargetMRSP_TargetManagement_pkg);
      }
    }
    else {
      kcg_copy_Target_list_MRSP_real_T_TargetManagement_types(
        &tmp1,
        &outC->rem_MRSPTargetList);
    }
    kcg_copy_Target_list_MRSP_real_T_TargetManagement_types(&tmp3, &tmp1);
  }
  /* 1 */
  removeOverpassedMRSP_TargetManagement_pkg_internalOperators(
    &tmp3,
    (*trainLocations).d_maxSafeFrontEndPos,
    &outC->rem_MRSPTargetList,
    &_L88);
  outC->targetCollection.updatedTargetList = _L92 | MRSP_updated | MA_updated |
    _L88;
  kcg_copy_Target_list_MRSP_real_T_TargetManagement_types(
    &outC->targetCollection.MRSP_targetList,
    &outC->rem_MRSPTargetList);
  kcg_copy_Target_real_T_TargetManagement_types(
    &outC->targetCollection.EOA_target,
    &outC->_L12);
  kcg_copy_Target_real_T_TargetManagement_types(
    &outC->targetCollection.SvL_target,
    &outC->_L93);
  outC->init = kcg_false;
}