/* TM_trackside_baseline2::Write_P027V1 */
void Write_P027V1_TM_trackside_baseline2(
  /* TM_trackside_baseline2::Write_P027V1::Packet27V1 */P027V1_trackside_int_T_TM_baseline2 *Packet27V1,
  /* TM_trackside_baseline2::Write_P027V1::Packets */CompressedPackets_T_Common_Types_Pkg *Packets,
  /* TM_trackside_baseline2::Write_P027V1::Error */kcg_bool *Error,
  /* TM_trackside_baseline2::Write_P027V1::PacketsOut */CompressedPackets_T_Common_Types_Pkg *PacketsOut)
{
  struct__47107 tmp1;
  kcg_bool tmp;
  kcg_int i;
  /* TM_trackside_baseline2::Write_P027V1::_L21 */ kcg_int _L21;
  /* TM_trackside_baseline2::Write_P027V1::_L44 */ CompressedPacketData_T_Common_Types_Pkg _L44;
  /* TM_trackside_baseline2::Write_P027V1::_L43 */ MetadataElement_T_Common_Types_Pkg _L43;
  /* TM_trackside_baseline2::Write_P027V1::_L45 */ P027V1_OBU_sectionlist_int_T_TM_baseline2 _L45;
  /* TM_trackside_baseline2::Write_P027V1::_L46 */ kcg_int _L46;
  /* TM_trackside_baseline2::Write_P027V1::_L56 */ kcg_int _L56;
  /* TM_trackside_baseline2::Write_P027V1::_L59 */ Q_DIR _L59;
  
  *Error = kcg_false;
  /* 1 */
  C_P027V1_tracksim_compr_body_TM_conversions_baseline2(
    Packet27V1,
    &_L43,
    &_L44,
    &_L45,
    &_L46,
    &_L56,
    &_L59);
  /* 1 */
  SEND_WriteMessageHeader_TM_lib_internal(
    &(*Packets).PacketHeaders,
    &_L43,
    &(*PacketsOut).PacketHeaders,
    &_L21,
    &i);
  /* 1 */
  SEND_MessageData_TM_lib_internal(
    _L21,
    i,
    &(*Packets).PacketData,
    &_L44,
    &(*PacketsOut).PacketData);
  for (i = 0; i < 33; i++) {
    kcg_copy_CompressedPackets_T_Common_Types_Pkg(&tmp1, PacketsOut);
    /* 1 */
    C_P027V1_tracksim_merge_sections_TM_conversions_baseline2(
      i,
      &tmp1,
      &_L45[i],
      _L46,
      _L56,
      _L59,
      &tmp,
      PacketsOut);
    if (!tmp) {
      break;
    }
  }
}
/* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections */
void C_P027V1_tracksim_merge_sections_TM_conversions_baseline2(
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::i */kcg_int i,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::PacketStream_in */CompressedPackets_T_Common_Types_Pkg *PacketStream_in,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::P027V1_sections_from_track */P027V1_section_int_T_TM_baseline2 *P027V1_sections_from_track,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::n_iter */kcg_int n_iter,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::meta_first_section_in */kcg_int meta_first_section_in,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::cont */kcg_bool *cont,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::Packets_Out */CompressedPackets_T_Common_Types_Pkg *Packets_Out)
{
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::_L432 */
  static CompressedPacketData_T_Common_Types_Pkg _L432;
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::_L431 */
  static MetadataElement_T_Common_Types_Pkg _L431;
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::_L436 */
  static kcg_int _L436;
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::_L437 */
  static kcg_int _L437;
  
  *cont = n_iter > i;
  /* 2 */
  C_P027V1_tracksim_compr_one_section_TM_conversions_baseline2(
    i,
    P027V1_sections_from_track,
    meta_first_section_in,
    &_L431,
    &_L432);
  /* 1 */
  SEND_WriteMessageHeader_TM_lib_internal(
    &(*PacketStream_in).PacketHeaders,
    &_L431,
    &(*Packets_Out).PacketHeaders,
    &_L436,
    &_L437);
  /* 1 */
  SEND_MessageData_TM_lib_internal(
    _L436,
    _L437,
    &(*PacketStream_in).PacketData,
    &_L432,
    &(*Packets_Out).PacketData);
}
/* TM_trackside_baseline2::Write_P027V1 */
void Write_P027V1_TM_trackside_baseline2(
  /* TM_trackside_baseline2::Write_P027V1::Packet27V1 */P027V1_trackside_int_T_TM_baseline2 *Packet27V1,
  /* TM_trackside_baseline2::Write_P027V1::Packets */CompressedPackets_T_Common_Types_Pkg *Packets,
  outC_Write_P027V1_TM_trackside_baseline2 *outC)
{
  static kcg_int i2;
  static kcg_int i1;
  static CompressedPackets_T_Common_Types_Pkg tmp;
  static kcg_int i;
  static kcg_int noname;
  
  kcg_copy_CompressedPackets_T_Common_Types_Pkg(&outC->_L40, Packets);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L42,
    &outC->_L40.PacketData);
  kcg_copy_P027V1_trackside_int_T_TM_baseline2(&outC->_L1, Packet27V1);
  /* 1 */
  C_P027V1_tracksim_compr_body_TM_conversions_baseline2(
    &outC->_L1,
    &outC->Context_1);
  kcg_copy_MetadataElement_T_Common_Types_Pkg(
    &outC->_L43,
    &outC->Context_1.Header);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L44,
    &outC->Context_1.P027V1_body_compressed);
  kcg_copy__2_P027V1_OBU_sectionlist_int_T_TM_baseline2(
    &outC->_L45,
    &outC->Context_1.P027V1_sections);
  outC->_L46 = outC->Context_1.n_iter_k_out;
  outC->_L56 = outC->Context_1.meta_first_section;
  for (i2 = 0; i2 < 33; i2++) {
    outC->_L55[i2] = outC->_L56;
  }
  for (i1 = 0; i1 < 33; i1++) {
    outC->_L54[i1] = outC->_L46;
  }
  outC->_L52 = kcg_true;
  kcg_copy_Metadata_T_Common_Types_Pkg(&outC->_L41, &outC->_L40.PacketHeaders);
  /* 1 */
  SEND_WriteMessageHeader_TM_lib_internal(
    &outC->_L41,
    &outC->_L43,
    &outC->_1_Context_1);
  kcg_copy_Metadata_T_Common_Types_Pkg(
    &outC->_L4,
    &outC->_1_Context_1.HeadersOut);
  outC->_L21 = outC->_1_Context_1.NewStartAddr;
  outC->_L22 = outC->_1_Context_1.NewEndAddr;
  /* 1 */
  SEND_MessageData_TM_lib_internal(
    outC->_L21,
    outC->_L22,
    &outC->_L42,
    &outC->_L44,
    &outC->_2_Context_1);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L10,
    &outC->_2_Context_1.DataOut);
  kcg_copy_Metadata_T_Common_Types_Pkg(&outC->_L39.PacketHeaders, &outC->_L4);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L39.PacketData,
    &outC->_L10);
  kcg_copy_CompressedPackets_T_Common_Types_Pkg(&outC->_L51, &outC->_L39);
  if (outC->_L52) {
    for (i = 0; i < 33; i++) {
      kcg_copy_CompressedPackets_T_Common_Types_Pkg(&tmp, &outC->_L51);
      /* 1 */
      C_P027V1_tracksim_merge_s_TM_conversions_baseline2(
        i,
        &tmp,
        &outC->_L45[i],
        outC->_L54[i],
        outC->_L55[i],
        &outC->_3_Context_1[i]);
      kcg_copy_CompressedPackets_T_Common_Types_Pkg(
        &outC->_L51,
        &outC->_3_Context_1[i].Packets_Out);
      outC->_L50 = i + 1;
      if (!outC->_3_Context_1[i].cont) {
        break;
      }
    }
  }
  else {
    outC->_L50 = 0;
  }
  noname = outC->_L50;
  outC->_L18 = kcg_false;
  outC->Error = outC->_L18;
  kcg_copy_CompressedPackets_T_Common_Types_Pkg(&outC->PacketsOut, &outC->_L51);
}
/* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections */
void C_P027V1_tracksim_merge_s_TM_conversions_baseline2(
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::i */ kcg_int i,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::PacketStream_in */ CompressedPackets_T_Common_Types_Pkg *PacketStream_in,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::P027V1_sections_from_track */ P027V1_section_int_T_TM_baseline2 *P027V1_sections_from_track,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::n_iter */ kcg_int n_iter,
  /* TM_conversions_baseline2::C_P027V1_tracksim_merge_sections::meta_first_section_in */ kcg_int meta_first_section_in,
  outC_C_P027V1_tracksim_merge_s_TM_conversions_baseline2 *outC)
{
  outC->_L446 = i;
  kcg_copy_P027V1_section_int_T_TM_baseline2(
    &outC->_L440,
    P027V1_sections_from_track);
  outC->_L448 = meta_first_section_in;
  /* 2 */
  C_P027V1_tracksim_compr_o_TM_conversions_baseline2(
    outC->_L446,
    &outC->_L440,
    outC->_L448,
    &outC->Context_2);
  kcg_copy_MetadataElement_T_Common_Types_Pkg(
    &outC->_L431,
    &outC->Context_2.Header);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L432,
    &outC->Context_2.P027V1_sections_compressed);
  kcg_copy_CompressedPackets_T_Common_Types_Pkg(&outC->_L439, PacketStream_in);
  kcg_copy_Metadata_T_Common_Types_Pkg(
    &outC->_L442,
    &outC->_L439.PacketHeaders);
  /* 1 */
  SEND_WriteMessageHeader_TM_lib_internal(
    &outC->_L442,
    &outC->_L431,
    &outC->Context_1);
  kcg_copy_Metadata_T_Common_Types_Pkg(
    &outC->_L435,
    &outC->Context_1.HeadersOut);
  outC->_L436 = outC->Context_1.NewStartAddr;
  outC->_L437 = outC->Context_1.NewEndAddr;
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L443,
    &outC->_L439.PacketData);
  /* 1 */
  SEND_MessageData_TM_lib_internal(
    outC->_L436,
    outC->_L437,
    &outC->_L443,
    &outC->_L432,
    &outC->_1_Context_1);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L433,
    &outC->_1_Context_1.DataOut);
  kcg_copy_Metadata_T_Common_Types_Pkg(
    &outC->_L434.PacketHeaders,
    &outC->_L435);
  kcg_copy_CompressedPacketData_T_Common_Types_Pkg(
    &outC->_L434.PacketData,
    &outC->_L433);
  outC->_L438 = i;
  outC->_L441 = n_iter;
  outC->_L447 = outC->_L441 > outC->_L438;
  outC->cont = outC->_L447;
  kcg_copy_CompressedPackets_T_Common_Types_Pkg(
    &outC->Packets_Out,
    &outC->_L434);
}