/*
** Automatically generated from `sym_name.m'
** by the Mercury compiler,
** version rotd-2023-09-20
** configured for x86_64-pc-linux-gnu.
** Do not edit.
**
** The autoconfigured grade settings governing
** the generation of this C file were
**
** TAG_BITS=2
** UNBOXED_FLOAT=no
** UNBOXED_INT64S=no
** PREGENERATED_DIST=yes
** HIGHLEVEL_CODE=yes
**
** END_OF_C_GRADE_INFO
*/


// :- module mdbcomp.sym_name.
// :- implementation.

/*
INIT mercury__mdbcomp__sym_name__init
ENDINIT
*/

#include "mdbcomp.sym_name.mih"


#include "array.mih"
#include "assoc_list.mih"
#include "bool.mih"
#include "builtin.mih"
#include "char.mih"
#include "construct.mih"
#include "deconstruct.mih"
#include "enum.mih"
#include "int.mih"
#include "integer.mih"
#include "list.mih"
#include "map.mih"
#include "maybe.mih"
#include "mdbcomp.mih"
#include "ops.mih"
#include "pair.mih"
#include "pretty_printer.mih"
#include "private_builtin.mih"
#include "require.mih"
#include "set.mih"
#include "set_ordlist.mih"
#include "string.mih"
#include "term.mih"
#include "term_context.mih"
#include "tree234.mih"
#include "type_desc.mih"
#include "univ.mih"




static const MR_PseudoTypeInfo mdbcomp__sym_name__mdbcomp__sym_name__field_types_sym_name_0_0[1];

static const MR_DuFunctorDesc mdbcomp__sym_name__mdbcomp__sym_name__du_functor_desc_sym_name_0_0;

static const MR_PseudoTypeInfo mdbcomp__sym_name__mdbcomp__sym_name__field_types_sym_name_0_1[2];

static const MR_DuFunctorDesc mdbcomp__sym_name__mdbcomp__sym_name__du_functor_desc_sym_name_0_1;

static const MR_DuFunctorDescPtr mdbcomp__sym_name__mdbcomp__sym_name__du_stag_ordered_sym_name_0_0[1];

static const MR_DuFunctorDescPtr mdbcomp__sym_name__mdbcomp__sym_name__du_stag_ordered_sym_name_0_1[1];

static const MR_DuPtagLayout mdbcomp__sym_name__mdbcomp__sym_name__du_ptag_ordered_sym_name_0[2];

static const MR_DuFunctorDescPtr mdbcomp__sym_name__mdbcomp__sym_name__du_name_ordered_sym_name_0[2];

static const MR_Integer mdbcomp__sym_name__mdbcomp__sym_name__functor_number_map_sym_name_0[2];

static void MR_CALL 
mdbcomp__sym_name__f_85_110_117_115_101_100_65_114_103_115_95_95_112_114_101_100_95_95_97_100_100_95_113_117_97_108_105_102_105_101_114_115_95_116_111_95_116_101_114_109_95_95_91_49_93_95_48_4_p_0(
  MR_Word HeadVar__1_1,
  MR_Word HeadVar__2_2,
  MR_Word HeadVar__3_3,
  MR_Word * Term_4);

static MR_bool MR_CALL 
mdbcomp__sym_name__list_to_sym_name_loop_2_p_0(
  MR_Word RevNames_3,
  MR_Word * SymName_4);

static void MR_CALL 
mdbcomp__sym_name__get_ancestors_loop_3_p_0(
  MR_Word HeadVar__1_1,
  MR_Word STATE_VARIABLE_Ancestors_0_2,
  MR_Word * STATE_VARIABLE_Ancestors_3);

static MR_bool MR_CALL 
mdbcomp__sym_name____Unify____module_name_0_0_10001(
  MR_Box wrapper_arg_1,
  MR_Box wrapper_arg_2);

static void MR_CALL 
mdbcomp__sym_name____Compare____module_name_0_0_10001(
  MR_Box * wrapper_arg_1,
  MR_Box wrapper_arg_2,
  MR_Box wrapper_arg_3);

static MR_bool MR_CALL 
mdbcomp__sym_name____Unify____sym_name_0_0_10001(
  MR_Box wrapper_arg_1,
  MR_Box wrapper_arg_2);

static void MR_CALL 
mdbcomp__sym_name____Compare____sym_name_0_0_10001(
  MR_Box * wrapper_arg_1,
  MR_Box wrapper_arg_2,
  MR_Box wrapper_arg_3);


static /* final */ const MR_Box mdbcomp__sym_name_scalar_common_1[1][1];




static /* final */ const MR_Box mdbcomp__sym_name_scalar_common_1[1][1] = {
  /* row   0 */
  { ((MR_Box) ((MR_String) ".")) },
};



#include "array.mh"
#include "mdbcomp.mh"


const MR_TypeCtorInfo_Struct mdbcomp__sym_name__mdbcomp__sym_name__type_ctor_info_module_name_0 = {
  (MR_Integer) 0,
  UINT8_C(18),
  INT8_C(-1),
  MR_TYPECTOR_REP_EQUIV_GROUND,
  ((MR_Box) (mdbcomp__sym_name____Unify____module_name_0_0_10001)),
  ((MR_Box) (mdbcomp__sym_name____Compare____module_name_0_0_10001)),
  (MR_String) "mdbcomp.sym_name",
  (MR_String) "module_name",
  { NULL },
  { (MR_PseudoTypeInfo) (&mdbcomp__sym_name__mdbcomp__sym_name__type_ctor_info_sym_name_0) },
  (MR_Integer) -1,
  UINT16_C(0),
  NULL,

};

static const MR_PseudoTypeInfo mdbcomp__sym_name__mdbcomp__sym_name__field_types_sym_name_0_0[1] = { (MR_PseudoTypeInfo) (&mercury__builtin__builtin__type_ctor_info_string_0) };

static const MR_DuFunctorDesc mdbcomp__sym_name__mdbcomp__sym_name__du_functor_desc_sym_name_0_0 = {
  (MR_String) "unqualified",
  INT16_C(1),
  UINT16_C(0),
  MR_SECTAG_NONE,
  UINT8_C(0),
  (MR_Integer) -1,
  INT32_C(0),
  mdbcomp__sym_name__mdbcomp__sym_name__field_types_sym_name_0_0,
  NULL,
  NULL,
  NULL,
  MR_FUNCTOR_SUBTYPE_NONE,
  UINT8_C(0)
};

static const MR_PseudoTypeInfo mdbcomp__sym_name__mdbcomp__sym_name__field_types_sym_name_0_1[2] = {
  (MR_PseudoTypeInfo) (&mdbcomp__sym_name__mdbcomp__sym_name__type_ctor_info_sym_name_0),
  (MR_PseudoTypeInfo) (&mercury__builtin__builtin__type_ctor_info_string_0)
};

static const MR_DuFunctorDesc mdbcomp__sym_name__mdbcomp__sym_name__du_functor_desc_sym_name_0_1 = {
  (MR_String) "qualified",
  INT16_C(2),
  UINT16_C(0),
  MR_SECTAG_NONE,
  UINT8_C(1),
  (MR_Integer) -1,
  INT32_C(1),
  mdbcomp__sym_name__mdbcomp__sym_name__field_types_sym_name_0_1,
  NULL,
  NULL,
  NULL,
  MR_FUNCTOR_SUBTYPE_NONE,
  UINT8_C(0)
};

static const MR_DuFunctorDescPtr mdbcomp__sym_name__mdbcomp__sym_name__du_stag_ordered_sym_name_0_0[1] = { &mdbcomp__sym_name__mdbcomp__sym_name__du_functor_desc_sym_name_0_0 };

static const MR_DuFunctorDescPtr mdbcomp__sym_name__mdbcomp__sym_name__du_stag_ordered_sym_name_0_1[1] = { &mdbcomp__sym_name__mdbcomp__sym_name__du_functor_desc_sym_name_0_1 };

static const MR_DuPtagLayout mdbcomp__sym_name__mdbcomp__sym_name__du_ptag_ordered_sym_name_0[2] = {
  {
    UINT32_C(1),
    MR_SECTAG_NONE,
    mdbcomp__sym_name__mdbcomp__sym_name__du_stag_ordered_sym_name_0_0,
    INT8_C(-1),
    UINT8_C(0),
    UINT8_C(1)
  },
  {
    UINT32_C(1),
    MR_SECTAG_NONE,
    mdbcomp__sym_name__mdbcomp__sym_name__du_stag_ordered_sym_name_0_1,
    INT8_C(-1),
    UINT8_C(1),
    UINT8_C(1)
  }
};

static const MR_DuFunctorDescPtr mdbcomp__sym_name__mdbcomp__sym_name__du_name_ordered_sym_name_0[2] = {
  &mdbcomp__sym_name__mdbcomp__sym_name__du_functor_desc_sym_name_0_1,
  &mdbcomp__sym_name__mdbcomp__sym_name__du_functor_desc_sym_name_0_0
};

static const MR_Integer mdbcomp__sym_name__mdbcomp__sym_name__functor_number_map_sym_name_0[2] = {
  (MR_Integer) 1,
  (MR_Integer) 0
};

const MR_TypeCtorInfo_Struct mdbcomp__sym_name__mdbcomp__sym_name__type_ctor_info_sym_name_0 = {
  (MR_Integer) 0,
  UINT8_C(18),
  INT8_C(2),
  MR_TYPECTOR_REP_DU,
  ((MR_Box) (mdbcomp__sym_name____Unify____sym_name_0_0_10001)),
  ((MR_Box) (mdbcomp__sym_name____Compare____sym_name_0_0_10001)),
  (MR_String) "mdbcomp.sym_name",
  (MR_String) "sym_name",
  { mdbcomp__sym_name__mdbcomp__sym_name__du_name_ordered_sym_name_0 },
  { mdbcomp__sym_name__mdbcomp__sym_name__du_ptag_ordered_sym_name_0 },
  (MR_Integer) 2,
  UINT16_C(12),
  mdbcomp__sym_name__mdbcomp__sym_name__functor_number_map_sym_name_0,

};

void MR_CALL 
mdbcomp__sym_name____Compare____module_name_0_0(
  MR_Word * HeadVar__1_1,
  MR_Word HeadVar__2_2,
  MR_Word HeadVar__3_3)
{
  MR_Word Cast_HeadVar1_4 = HeadVar__2_2;
  MR_Word Cast_HeadVar2_5 = HeadVar__3_3;

  mdbcomp__sym_name____Compare____sym_name_0_0(HeadVar__1_1, Cast_HeadVar1_4, Cast_HeadVar2_5);
}

void MR_CALL 
mdbcomp__sym_name____Compare____sym_name_0_0(
  MR_Word * HeadVar__1_1,
  MR_Word HeadVar__2_2,
  MR_Word HeadVar__3_3)
{
  MR_bool succeeded;
  MR_Integer CastX_17 = (MR_Integer) (HeadVar__2_2);
  MR_Integer CastY_18 = (MR_Integer) (HeadVar__3_3);

  succeeded = (CastX_17 == CastY_18);
  if (succeeded)
    *HeadVar__1_1 = (MR_Integer) 0;
  else
  if (((MR_tag((MR_Word) HeadVar__2_2)) == (MR_Integer) 1))
  {
    MR_String Var_22 = ((MR_String) ((MR_hl_field(1, HeadVar__2_2, (MR_Integer) 1))));
    MR_Word Var_23 = ((MR_Word) ((MR_hl_field(1, HeadVar__2_2, (MR_Integer) 0))));

    if (((MR_tag((MR_Word) HeadVar__3_3)) == (MR_Integer) 1))
    {
      MR_Word ArgY1_13 = ((MR_Word) ((MR_hl_field(1, HeadVar__3_3, (MR_Integer) 0))));
      MR_String ArgY2_16 = ((MR_String) ((MR_hl_field(1, HeadVar__3_3, (MR_Integer) 1))));
      MR_Word SubResult1_14;

      mdbcomp__sym_name____Compare____sym_name_0_0(&SubResult1_14, Var_23, ArgY1_13);
      succeeded = (SubResult1_14 != (MR_Integer) 0);
      if (succeeded)
        *HeadVar__1_1 = SubResult1_14;
      else
        mercury__private_builtin__builtin_compare_string_3_p_0(HeadVar__1_1, Var_22, ArgY2_16);
    }
    else
      *HeadVar__1_1 = (MR_Integer) 2;
  }
  else
  {
    MR_String Var_24 = ((MR_String) ((MR_hl_field(0, HeadVar__2_2, (MR_Integer) 0))));

    if (((MR_tag((MR_Word) HeadVar__3_3)) == (MR_Integer) 1))
      *HeadVar__1_1 = (MR_Integer) 1;
    else
    {
      MR_String ArgY1_5 = ((MR_String) ((MR_hl_field(0, HeadVar__3_3, (MR_Integer) 0))));

      mercury__private_builtin__builtin_compare_string_3_p_0(HeadVar__1_1, Var_24, ArgY1_5);
    }
  }
}

MR_bool MR_CALL 
mdbcomp__sym_name____Unify____module_name_0_0(
  MR_Word HeadVar__1_1,
  MR_Word HeadVar__2_2)
{
  MR_bool succeeded;
  MR_Word Cast_HeadVar1_3 = HeadVar__1_1;
  MR_Word Cast_HeadVar2_4 = HeadVar__2_2;

  succeeded = mdbcomp__sym_name____Unify____sym_name_0_0(Cast_HeadVar1_3, Cast_HeadVar2_4);
  return succeeded;
}

void MR_CALL 
mdbcomp__sym_name__sym_name_to_term_4_p_0(
  MR_Word TypeInfo_for_T_14,
  MR_Word Context_5,
  MR_Word SymName_6,
  MR_Word ArgTerms_7,
  MR_Word * Term_8)
{
  MR_Word Qualifiers_9;
  MR_String Name_10;
  MR_Word BaseTerm_11;
  MR_Word RevQualifiers_12;
  MR_Word Var_13;

  if (((MR_tag((MR_Word) SymName_6)) == (MR_Integer) 1))
  {
    MR_Word Module_17 = ((MR_Word) ((MR_hl_field(1, SymName_6, (MR_Integer) 0))));

    Name_10 = ((MR_String) ((MR_hl_field(1, SymName_6, (MR_Integer) 1))));
    Qualifiers_9 = mdbcomp__sym_name__sym_name_to_list_1_f_0(Module_17);
  }
  else
  {
    Name_10 = ((MR_String) ((MR_hl_field(0, SymName_6, (MR_Integer) 0))));
    Qualifiers_9 = (MR_Word) ((MR_Unsigned) 0U);
  }
  {
    Var_13 = (MR_Word) MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL);
    MR_hl_field(0, Var_13, 0) = ((MR_Box) (Name_10));
  }
  {
    BaseTerm_11 = (MR_Word) MR_new_object(MR_Word, (3 * sizeof(MR_Word)), NULL, NULL);
    MR_hl_field(0, BaseTerm_11, 0) = ((MR_Box) (Var_13));
    MR_hl_field(0, BaseTerm_11, 1) = ((MR_Box) (ArgTerms_7));
    MR_hl_field(0, BaseTerm_11, 2) = ((MR_Box) (Context_5));
  }
  mercury__list__reverse_2_p_0((MR_Word) (&mercury__builtin__builtin__type_ctor_info_string_0), Qualifiers_9, &RevQualifiers_12);
  mdbcomp__sym_name__f_85_110_117_115_101_100_65_114_103_115_95_95_112_114_101_100_95_95_97_100_100_95_113_117_97_108_105_102_105_101_114_115_95_116_111_95_116_101_114_109_95_95_91_49_93_95_48_4_p_0(RevQualifiers_12, Context_5, BaseTerm_11, Term_8);
}

static void MR_CALL 
mdbcomp__sym_name__f_85_110_117_115_101_100_65_114_103_115_95_95_112_114_101_100_95_95_97_100_100_95_113_117_97_108_105_102_105_101_114_115_95_116_111_95_116_101_114_109_95_95_91_49_93_95_48_4_p_0(
  MR_Word HeadVar__1_1,
  MR_Word HeadVar__2_2,
  MR_Word HeadVar__3_3,
  MR_Word * Term_4)
{
  while (MR_TRUE)
  {
    // setup for model_det tailcalls optimized into a loop
    ;
    if ((HeadVar__1_1 == (MR_Word) ((MR_Unsigned) 0U)))
      *Term_4 = HeadVar__3_3;
    else
    {
      MR_String Qualifier_7 = ((MR_String) ((MR_hl_field(1, HeadVar__1_1, (MR_Integer) 0))));
      MR_Word Qualifiers_8 = ((MR_Word) ((MR_hl_field(1, HeadVar__1_1, (MR_Integer) 1))));
      MR_Word QualifierTerm_12;
      MR_Word Term1_13;
      MR_Word Var_14;
      MR_Word Var_18;
      MR_Word Var_19;
      MR_Word next_value_of_HeadVar__1_1;
      MR_Word next_value_of_HeadVar__3_3;

      {
        Var_14 = (MR_Word) MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL);
        MR_hl_field(0, Var_14, 0) = ((MR_Box) (Qualifier_7));
      }
      {
        QualifierTerm_12 = (MR_Word) MR_new_object(MR_Word, (3 * sizeof(MR_Word)), NULL, NULL);
        MR_hl_field(0, QualifierTerm_12, 0) = ((MR_Box) (Var_14));
        MR_hl_field(0, QualifierTerm_12, 1) = ((MR_Box) ((MR_Unsigned) 0U));
        MR_hl_field(0, QualifierTerm_12, 2) = ((MR_Box) (HeadVar__2_2));
      }
      {
        Var_19 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
        MR_hl_field(1, Var_19, 0) = ((MR_Box) (HeadVar__3_3));
        MR_hl_field(1, Var_19, 1) = ((MR_Box) ((MR_Unsigned) 0U));
      }
      {
        Var_18 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
        MR_hl_field(1, Var_18, 0) = ((MR_Box) (QualifierTerm_12));
        MR_hl_field(1, Var_18, 1) = ((MR_Box) (Var_19));
      }
      {
        Term1_13 = (MR_Word) MR_new_object(MR_Word, (3 * sizeof(MR_Word)), NULL, NULL);
        MR_hl_field(0, Term1_13, 0) = ((MR_Box) (&mdbcomp__sym_name_scalar_common_1[0]));
        MR_hl_field(0, Term1_13, 1) = ((MR_Box) (Var_18));
        MR_hl_field(0, Term1_13, 2) = ((MR_Box) (HeadVar__2_2));
      }
      // direct tailcall eliminated
      ;
      next_value_of_HeadVar__1_1 = Qualifiers_8;
      next_value_of_HeadVar__3_3 = Term1_13;
      HeadVar__1_1 = next_value_of_HeadVar__1_1;
      HeadVar__3_3 = next_value_of_HeadVar__3_3;
      continue;
    }
    break;
  }
}

MR_bool MR_CALL 
mdbcomp__sym_name__strip_outermost_qualifier_3_p_0(
  MR_Word SymName0_4,
  MR_String * OuterModuleName_5,
  MR_Word * SymName_6)
{
  MR_bool succeeded = ((MR_tag((MR_Word) SymName0_4)) == (MR_Integer) 1);
  MR_Word ModuleSymName0_7;
  MR_String Name_8;

  if (succeeded)
  {
    ModuleSymName0_7 = ((MR_Word) ((MR_hl_field(1, SymName0_4, (MR_Integer) 0))));
    Name_8 = ((MR_String) ((MR_hl_field(1, SymName0_4, (MR_Integer) 1))));
    if (((MR_tag((MR_Word) ModuleSymName0_7)) == (MR_Integer) 1))
    {
      MR_Word ModuleSymName_11;

      succeeded = mdbcomp__sym_name__strip_outermost_qualifier_3_p_0(ModuleSymName0_7, OuterModuleName_5, &ModuleSymName_11);
      if (succeeded)
      {
        {
          MR_Word base;
          base = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
          *SymName_6 = base;
          MR_hl_field(1, base, 0) = ((MR_Box) (ModuleSymName_11));
          MR_hl_field(1, base, 1) = ((MR_Box) (Name_8));
        }
        succeeded = MR_TRUE;
      }
    }
    else
    {
      *OuterModuleName_5 = ((MR_String) ((MR_hl_field(0, ModuleSymName0_7, (MR_Integer) 0))));
      {
        MR_Word base;
        base = (MR_Word) MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL);
        *SymName_6 = base;
        MR_hl_field(0, base, 0) = ((MR_Box) (Name_8));
      }
      succeeded = MR_TRUE;
    }
  }
  return succeeded;
}

MR_String MR_CALL 
mdbcomp__sym_name__outermost_qualifier_1_f_0(
  MR_Word SymName_3)
{
  while (MR_TRUE)
  {
    MR_String Name_4;

    // setup for model_det tailcalls optimized into a loop
    ;
    if (((MR_tag((MR_Word) SymName_3)) == (MR_Integer) 1))
    {
      MR_Word ModuleSymName_5 = ((MR_Word) ((MR_hl_field(1, SymName_3, (MR_Integer) 0))));
      MR_Word next_value_of_SymName_3 = ModuleSymName_5;

      // direct tailcall eliminated
      ;
      SymName_3 = next_value_of_SymName_3;
      continue;
    }
    else
      Name_4 = ((MR_String) ((MR_hl_field(0, SymName_3, (MR_Integer) 0))));
    return Name_4;
    break;
  }
}

MR_Word MR_CALL 
mdbcomp__sym_name__transform_sym_base_name_2_f_0(
  MR_Word TransformFunc_4,
  MR_Word SymName0_5)
{
  MR_Word SymName_6;

  if (((MR_tag((MR_Word) SymName0_5)) == (MR_Integer) 1))
  {
    MR_Word Module_8 = ((MR_Word) ((MR_hl_field(1, SymName0_5, (MR_Integer) 0))));
    MR_String Var_10;
    MR_String Name0_11 = ((MR_String) ((MR_hl_field(1, SymName0_5, (MR_Integer) 1))));
    MR_Box MR_CALL (* func_0)(MR_Box, MR_Box) = ((MR_Box MR_CALL (*)(MR_Box, MR_Box)) ((MR_hl_field(0, TransformFunc_4, (MR_Integer) 1))));
    MR_Box conv1_Var_10;

    conv1_Var_10 = func_0(((MR_Box) (TransformFunc_4)), ((MR_Box) (Name0_11)));
    Var_10 = ((MR_String) (conv1_Var_10));
    {
      SymName_6 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
      MR_hl_field(1, SymName_6, 0) = ((MR_Box) (Module_8));
      MR_hl_field(1, SymName_6, 1) = ((MR_Box) (Var_10));
    }
  }
  else
  {
    MR_String Name0_7 = ((MR_String) ((MR_hl_field(0, SymName0_5, (MR_Integer) 0))));
    MR_String Var_9;
    MR_Box MR_CALL (* func_2)(MR_Box, MR_Box) = ((MR_Box MR_CALL (*)(MR_Box, MR_Box)) ((MR_hl_field(0, TransformFunc_4, (MR_Integer) 1))));
    MR_Box conv3_Var_9;

    conv3_Var_9 = func_2(((MR_Box) (TransformFunc_4)), ((MR_Box) (Name0_7)));
    Var_9 = ((MR_String) (conv3_Var_9));
    {
      SymName_6 = (MR_Word) MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL);
      MR_hl_field(0, SymName_6, 0) = ((MR_Box) (Var_9));
    }
  }
  return SymName_6;
}

void MR_CALL 
mdbcomp__sym_name__add_sym_name_suffix_3_p_0(
  MR_Word SymName0_4,
  MR_String Suffix_5,
  MR_Word * SymName_6)
{
  if (((MR_tag((MR_Word) SymName0_4)) == (MR_Integer) 1))
  {
    MR_Word Module_9 = ((MR_Word) ((MR_hl_field(1, SymName0_4, (MR_Integer) 0))));
    MR_String Name0_10 = ((MR_String) ((MR_hl_field(1, SymName0_4, (MR_Integer) 1))));
    MR_String Name_11;

    mercury__string__append_3_p_2(Name0_10, Suffix_5, &Name_11);
    {
      MR_Word base;
      base = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
      *SymName_6 = base;
      MR_hl_field(1, base, 0) = ((MR_Box) (Module_9));
      MR_hl_field(1, base, 1) = ((MR_Box) (Name_11));
    }
  }
  else
  {
    MR_String Name0_7 = ((MR_String) ((MR_hl_field(0, SymName0_4, (MR_Integer) 0))));
    MR_String Name_8;

    mercury__string__append_3_p_2(Name0_7, Suffix_5, &Name_8);
    {
      MR_Word base;
      base = (MR_Word) MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL);
      *SymName_6 = base;
      MR_hl_field(0, base, 0) = ((MR_Box) (Name_8));
    }
  }
}

MR_bool MR_CALL 
mdbcomp__sym_name__remove_sym_name_suffix_3_p_0(
  MR_Word SymName0_4,
  MR_String Suffix_5,
  MR_Word * SymName_6)
{
  MR_bool succeeded;

  if (((MR_tag((MR_Word) SymName0_4)) == (MR_Integer) 1))
  {
    MR_Word Module_9 = ((MR_Word) ((MR_hl_field(1, SymName0_4, (MR_Integer) 0))));
    MR_String Name0_10 = ((MR_String) ((MR_hl_field(1, SymName0_4, (MR_Integer) 1))));
    MR_String Name_11;

    succeeded = mercury__string__remove_suffix_3_p_0(Name0_10, Suffix_5, &Name_11);
    if (succeeded)
    {
      {
        MR_Word base;
        base = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
        *SymName_6 = base;
        MR_hl_field(1, base, 0) = ((MR_Box) (Module_9));
        MR_hl_field(1, base, 1) = ((MR_Box) (Name_11));
      }
      succeeded = MR_TRUE;
    }
  }
  else
  {
    MR_String Name0_7 = ((MR_String) ((MR_hl_field(0, SymName0_4, (MR_Integer) 0))));
    MR_String Name_8;

    succeeded = mercury__string__remove_suffix_3_p_0(Name0_7, Suffix_5, &Name_8);
    if (succeeded)
    {
      {
        MR_Word base;
        base = (MR_Word) MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL);
        *SymName_6 = base;
        MR_hl_field(0, base, 0) = ((MR_Box) (Name_8));
      }
      succeeded = MR_TRUE;
    }
  }
  return succeeded;
}

void MR_CALL 
mdbcomp__sym_name__remove_sym_name_prefix_3_p_1(
  MR_Word * SymName0_4,
  MR_String Prefix_5,
  MR_Word SymName_6)
{
  if (((MR_tag((MR_Word) SymName_6)) == (MR_Integer) 1))
  {
    MR_Word Module_9 = ((MR_Word) ((MR_hl_field(1, SymName_6, (MR_Integer) 0))));
    MR_String Name0_10;
    MR_String Name_11 = ((MR_String) ((MR_hl_field(1, SymName_6, (MR_Integer) 1))));

    mercury__string__append_3_p_2(Prefix_5, Name_11, &Name0_10);
    {
      MR_Word base;
      base = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
      *SymName0_4 = base;
      MR_hl_field(1, base, 0) = ((MR_Box) (Module_9));
      MR_hl_field(1, base, 1) = ((MR_Box) (Name0_10));
    }
  }
  else
  {
    MR_String Name0_7;
    MR_String Name_8 = ((MR_String) ((MR_hl_field(0, SymName_6, (MR_Integer) 0))));

    mercury__string__append_3_p_2(Prefix_5, Name_8, &Name0_7);
    {
      MR_Word base;
      base = (MR_Word) MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL);
      *SymName0_4 = base;
      MR_hl_field(0, base, 0) = ((MR_Box) (Name0_7));
    }
  }
}

MR_bool MR_CALL 
mdbcomp__sym_name__remove_sym_name_prefix_3_p_0(
  MR_Word SymName0_4,
  MR_String Prefix_5,
  MR_Word * SymName_6)
{
  MR_bool succeeded;

  if (((MR_tag((MR_Word) SymName0_4)) == (MR_Integer) 1))
  {
    MR_Word Module_9 = ((MR_Word) ((MR_hl_field(1, SymName0_4, (MR_Integer) 0))));
    MR_String Name0_10 = ((MR_String) ((MR_hl_field(1, SymName0_4, (MR_Integer) 1))));
    MR_String Name_11;

    succeeded = mercury__string__append_3_p_1(Prefix_5, &Name_11, Name0_10);
    if (succeeded)
    {
      {
        MR_Word base;
        base = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
        *SymName_6 = base;
        MR_hl_field(1, base, 0) = ((MR_Box) (Module_9));
        MR_hl_field(1, base, 1) = ((MR_Box) (Name_11));
      }
      succeeded = MR_TRUE;
    }
  }
  else
  {
    MR_String Name0_7 = ((MR_String) ((MR_hl_field(0, SymName0_4, (MR_Integer) 0))));
    MR_String Name_8;

    succeeded = mercury__string__append_3_p_1(Prefix_5, &Name_8, Name0_7);
    if (succeeded)
    {
      {
        MR_Word base;
        base = (MR_Word) MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL);
        *SymName_6 = base;
        MR_hl_field(0, base, 0) = ((MR_Box) (Name_8));
      }
      succeeded = MR_TRUE;
    }
  }
  return succeeded;
}

MR_bool MR_CALL 
mdbcomp__sym_name__partial_sym_name_is_part_of_full_2_p_0(
  MR_Word PartialSymName_3,
  MR_Word FullSymName_4)
{
  MR_bool succeeded;
  MR_Word TypeCtorInfo_9_9;
  MR_Word PartialQualifiers_5;
  MR_String PartialBaseName_6;
  MR_Word FullQualifiers_7;

  if (((MR_tag((MR_Word) PartialSymName_3)) == (MR_Integer) 1))
  {
    MR_Word Module_11 = ((MR_Word) ((MR_hl_field(1, PartialSymName_3, (MR_Integer) 0))));

    PartialBaseName_6 = ((MR_String) ((MR_hl_field(1, PartialSymName_3, (MR_Integer) 1))));
    PartialQualifiers_5 = mdbcomp__sym_name__sym_name_to_list_1_f_0(Module_11);
  }
  else
  {
    PartialBaseName_6 = ((MR_String) ((MR_hl_field(0, PartialSymName_3, (MR_Integer) 0))));
    PartialQualifiers_5 = (MR_Word) ((MR_Unsigned) 0U);
  }
  if (((MR_tag((MR_Word) FullSymName_4)) == (MR_Integer) 1))
  {
    MR_String FullBaseName_8 = ((MR_String) ((MR_hl_field(1, FullSymName_4, (MR_Integer) 1))));
    MR_Word Module_15 = ((MR_Word) ((MR_hl_field(1, FullSymName_4, (MR_Integer) 0))));

    FullQualifiers_7 = mdbcomp__sym_name__sym_name_to_list_1_f_0(Module_15);
    succeeded = (strcmp(PartialBaseName_6, FullBaseName_8) == 0);
  }
  else
  {
    MR_String FullBaseName_18 = ((MR_String) ((MR_hl_field(0, FullSymName_4, (MR_Integer) 0))));

    succeeded = (strcmp(PartialBaseName_6, FullBaseName_18) == 0);
    if (succeeded)
    {
      FullQualifiers_7 = (MR_Word) ((MR_Unsigned) 0U);
      succeeded = MR_TRUE;
    }
  }
  if (succeeded)
  {
    TypeCtorInfo_9_9 = (MR_Word) (&mercury__builtin__builtin__type_ctor_info_string_0);
    succeeded = mercury__list__sublist_2_p_0(TypeCtorInfo_9_9, PartialQualifiers_5, FullQualifiers_7);
  }
  return succeeded;
}

MR_bool MR_CALL 
mdbcomp__sym_name__partial_sym_name_matches_full_2_p_0(
  MR_Word Partial_3,
  MR_Word Full_4)
{
  while (MR_TRUE)
  {
    MR_bool succeeded;

    // setup for model_semi tailcalls optimized into a loop
    ;
    if (((MR_tag((MR_Word) Partial_3)) == (MR_Integer) 1))
    {
      MR_Word PartialModule_5 = ((MR_Word) ((MR_hl_field(1, Partial_3, (MR_Integer) 0))));
      MR_String Name_6 = ((MR_String) ((MR_hl_field(1, Partial_3, (MR_Integer) 1))));
      MR_Word FullModule_7;
      MR_String Var_10;
      MR_Word next_value_of_Partial_3;
      MR_Word next_value_of_Full_4;

      succeeded = ((MR_tag((MR_Word) Full_4)) == (MR_Integer) 1);
      if (succeeded)
      {
        FullModule_7 = ((MR_Word) ((MR_hl_field(1, Full_4, (MR_Integer) 0))));
        Var_10 = ((MR_String) ((MR_hl_field(1, Full_4, (MR_Integer) 1))));
        succeeded = (strcmp(Name_6, Var_10) == 0);
        if (succeeded)
        {
          // direct tailcall eliminated
          ;
          next_value_of_Partial_3 = PartialModule_5;
          next_value_of_Full_4 = FullModule_7;
          Partial_3 = next_value_of_Partial_3;
          Full_4 = next_value_of_Full_4;
          continue;
        }
      }
    }
    else
    {
      MR_String Name_9 = ((MR_String) ((MR_hl_field(0, Partial_3, (MR_Integer) 0))));

      if (((MR_tag((MR_Word) Full_4)) == (MR_Integer) 1))
      {
        MR_String Var_12 = ((MR_String) ((MR_hl_field(1, Full_4, (MR_Integer) 1))));

        succeeded = (strcmp(Name_9, Var_12) == 0);
      }
      else
      {
        MR_String Var_11 = ((MR_String) ((MR_hl_field(0, Full_4, (MR_Integer) 0))));

        succeeded = (strcmp(Name_9, Var_11) == 0);
      }
    }
    return succeeded;
    break;
  }
}

void MR_CALL 
mdbcomp__sym_name__sym_name_get_module_name_default_name_4_p_0(
  MR_Word SymName_5,
  MR_Word DefaultModuleName_6,
  MR_Word * ModuleName_7,
  MR_String * Name_8)
{
  if (((MR_tag((MR_Word) SymName_5)) == (MR_Integer) 1))
  {
    *ModuleName_7 = ((MR_Word) ((MR_hl_field(1, SymName_5, (MR_Integer) 0))));
    *Name_8 = ((MR_String) ((MR_hl_field(1, SymName_5, (MR_Integer) 1))));
  }
  else
  {
    *Name_8 = ((MR_String) ((MR_hl_field(0, SymName_5, (MR_Integer) 0))));
    *ModuleName_7 = DefaultModuleName_6;
  }
}

void MR_CALL 
mdbcomp__sym_name__sym_name_get_module_name_default_3_p_0(
  MR_Word SymName_4,
  MR_Word DefaultModuleName_5,
  MR_Word * ModuleName_6)
{
  if (((MR_tag((MR_Word) SymName_4)) == (MR_Integer) 1))
    *ModuleName_6 = ((MR_Word) ((MR_hl_field(1, SymName_4, (MR_Integer) 0))));
  else
    *ModuleName_6 = DefaultModuleName_5;
}

void MR_CALL 
mdbcomp__sym_name__det_sym_name_get_module_name_2_p_0(
  MR_Word HeadVar__1_1,
  MR_Word * ModuleName_2)
{
  if (((MR_tag((MR_Word) HeadVar__1_1)) == (MR_Integer) 1))
    *ModuleName_2 = ((MR_Word) ((MR_hl_field(1, HeadVar__1_1, (MR_Integer) 0))));
  else
    {
      mercury__require__unexpected_2_p_0((MR_String) "predicate \140mdbcomp.sym_name.det_sym_name_get_module_name\'/2", (MR_String) "unqualified sym_name");
      return;
    }
}

MR_bool MR_CALL 
mdbcomp__sym_name__sym_name_get_module_name_2_p_0(
  MR_Word HeadVar__1_1,
  MR_Word * ModuleName_2)
{
  MR_bool succeeded = ((MR_tag((MR_Word) HeadVar__1_1)) == (MR_Integer) 1);

  if (succeeded)
    *ModuleName_2 = ((MR_Word) ((MR_hl_field(1, HeadVar__1_1, (MR_Integer) 0))));
  return succeeded;
}

MR_String MR_CALL 
mdbcomp__sym_name__unqualify_name_1_f_0(
  MR_Word HeadVar__1_1)
{
  MR_String Name_2;

  if (((MR_tag((MR_Word) HeadVar__1_1)) == (MR_Integer) 1))
    Name_2 = ((MR_String) ((MR_hl_field(1, HeadVar__1_1, (MR_Integer) 1))));
  else
    Name_2 = ((MR_String) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 0))));
  return Name_2;
}

MR_bool MR_CALL 
mdbcomp__sym_name__is_submodule_2_p_0(
  MR_Word HeadVar__1_1,
  MR_Word HeadVar__2_2)
{
  while (MR_TRUE)
  {
    MR_bool succeeded;

    // setup for model_semi tailcalls optimized into a loop
    ;
    succeeded = mdbcomp__sym_name____Unify____sym_name_0_0(HeadVar__2_2, HeadVar__1_1);
    if (!(succeeded))
    {
      MR_Word SymNameA_4;
      MR_Word next_value_of_HeadVar__1_1;

      succeeded = ((MR_tag((MR_Word) HeadVar__1_1)) == (MR_Integer) 1);
      if (succeeded)
      {
        SymNameA_4 = ((MR_Word) ((MR_hl_field(1, HeadVar__1_1, (MR_Integer) 0))));
        // direct tailcall eliminated
        ;
        next_value_of_HeadVar__1_1 = SymNameA_4;
        HeadVar__1_1 = next_value_of_HeadVar__1_1;
        continue;
      }
    }
    return succeeded;
    break;
  }
}

MR_bool MR_CALL 
mdbcomp__sym_name____Unify____sym_name_0_0(
  MR_Word HeadVar__1_1,
  MR_Word HeadVar__2_2)
{
  MR_bool succeeded;
  MR_Integer CastX_9 = (MR_Integer) (HeadVar__1_1);
  MR_Integer CastY_10 = (MR_Integer) (HeadVar__2_2);

  succeeded = (CastX_9 == CastY_10);
  if (succeeded)
    succeeded = MR_TRUE;
  else
  if (((MR_tag((MR_Word) HeadVar__1_1)) == (MR_Integer) 1))
  {
    MR_Word ArgX1_5 = ((MR_Word) ((MR_hl_field(1, HeadVar__1_1, (MR_Integer) 0))));
    MR_Word ArgY1_6;
    MR_String ArgX2_7 = ((MR_String) ((MR_hl_field(1, HeadVar__1_1, (MR_Integer) 1))));
    MR_String ArgY2_8;

    succeeded = ((MR_tag((MR_Word) HeadVar__2_2)) == (MR_Integer) 1);
    if (succeeded)
    {
      ArgY1_6 = ((MR_Word) ((MR_hl_field(1, HeadVar__2_2, (MR_Integer) 0))));
      ArgY2_8 = ((MR_String) ((MR_hl_field(1, HeadVar__2_2, (MR_Integer) 1))));
      succeeded = mdbcomp__sym_name____Unify____sym_name_0_0(ArgX1_5, ArgY1_6);
      if (succeeded)
        succeeded = (strcmp(ArgX2_7, ArgY2_8) == 0);
    }
  }
  else
  {
    MR_String ArgX1_3 = ((MR_String) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 0))));
    MR_String ArgY1_4;

    succeeded = ((MR_tag((MR_Word) HeadVar__2_2)) == (MR_Integer) 0);
    if (succeeded)
    {
      ArgY1_4 = ((MR_String) ((MR_hl_field(0, HeadVar__2_2, (MR_Integer) 0))));
      succeeded = (strcmp(ArgX1_3, ArgY1_4) == 0);
    }
  }
  return succeeded;
}

void MR_CALL 
mdbcomp__sym_name__det_list_to_sym_name_2_p_0(
  MR_Word Names_3,
  MR_Word * SymName_4)
{
  MR_bool succeeded;
  MR_Word RevNames_5;
  MR_Word SymNamePrime_6;

  mercury__list__reverse_2_p_0((MR_Word) (&mercury__builtin__builtin__type_ctor_info_string_0), Names_3, &RevNames_5);
  succeeded = mdbcomp__sym_name__list_to_sym_name_loop_2_p_0(RevNames_5, &SymNamePrime_6);
  if (succeeded)
    *SymName_4 = SymNamePrime_6;
  else
    {
      mercury__require__unexpected_2_p_0((MR_String) "predicate \140mdbcomp.sym_name.det_list_to_sym_name\'/2", (MR_String) "the list of names is empty");
      return;
    }
}

MR_bool MR_CALL 
mdbcomp__sym_name__list_to_sym_name_2_p_0(
  MR_Word Names_3,
  MR_Word * SymName_4)
{
  MR_bool succeeded;
  MR_Word RevNames_5;

  mercury__list__reverse_2_p_0((MR_Word) (&mercury__builtin__builtin__type_ctor_info_string_0), Names_3, &RevNames_5);
  succeeded = mdbcomp__sym_name__list_to_sym_name_loop_2_p_0(RevNames_5, SymName_4);
  return succeeded;
}

static MR_bool MR_CALL 
mdbcomp__sym_name__list_to_sym_name_loop_2_p_0(
  MR_Word RevNames_3,
  MR_Word * SymName_4)
{
  MR_bool succeeded = (RevNames_3 != (MR_Word) ((MR_Unsigned) 0U));
  MR_String Var_14;
  MR_Word Var_15;

  if (succeeded)
  {
    Var_14 = ((MR_String) ((MR_hl_field(1, RevNames_3, (MR_Integer) 0))));
    Var_15 = ((MR_Word) ((MR_hl_field(1, RevNames_3, (MR_Integer) 1))));
    if ((Var_15 == (MR_Word) ((MR_Unsigned) 0U)))
    {
      {
        MR_Word base;
        base = (MR_Word) MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL);
        *SymName_4 = base;
        MR_hl_field(0, base, 0) = ((MR_Box) (Var_14));
      }
      succeeded = MR_TRUE;
    }
    else
    {
      MR_Word ModuleQualifier_10;

      succeeded = mdbcomp__sym_name__list_to_sym_name_loop_2_p_0(Var_15, &ModuleQualifier_10);
      if (succeeded)
      {
        {
          MR_Word base;
          base = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
          *SymName_4 = base;
          MR_hl_field(1, base, 0) = ((MR_Box) (ModuleQualifier_10));
          MR_hl_field(1, base, 1) = ((MR_Box) (Var_14));
        }
        succeeded = MR_TRUE;
      }
    }
  }
  return succeeded;
}

void MR_CALL 
mdbcomp__sym_name__sym_name_to_qualifier_list_and_name_3_p_0(
  MR_Word HeadVar__1_1,
  MR_Word * HeadVar__2_2,
  MR_String * Name_3)
{
  if (((MR_tag((MR_Word) HeadVar__1_1)) == (MR_Integer) 1))
  {
    MR_Word Module_5 = ((MR_Word) ((MR_hl_field(1, HeadVar__1_1, (MR_Integer) 0))));

    *Name_3 = ((MR_String) ((MR_hl_field(1, HeadVar__1_1, (MR_Integer) 1))));
    *HeadVar__2_2 = mdbcomp__sym_name__sym_name_to_list_1_f_0(Module_5);
  }
  else
  {
    *Name_3 = ((MR_String) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 0))));
    *HeadVar__2_2 = (MR_Word) ((MR_Unsigned) 0U);
  }
}

MR_Word MR_CALL 
mdbcomp__sym_name__sym_name_to_list_1_f_0(
  MR_Word HeadVar__1_1)
{
  MR_Word HeadVar__2_2;

  if (((MR_tag((MR_Word) HeadVar__1_1)) == (MR_Integer) 1))
  {
    MR_Word Module_5 = ((MR_Word) ((MR_hl_field(1, HeadVar__1_1, (MR_Integer) 0))));
    MR_String Name_6 = ((MR_String) ((MR_hl_field(1, HeadVar__1_1, (MR_Integer) 1))));
    MR_Word Var_7;
    MR_Word Var_8;

    Var_7 = mdbcomp__sym_name__sym_name_to_list_1_f_0(Module_5);
    {
      Var_8 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
      MR_hl_field(1, Var_8, 0) = ((MR_Box) (Name_6));
      MR_hl_field(1, Var_8, 1) = ((MR_Box) ((MR_Unsigned) 0U));
    }
    HeadVar__2_2 = mercury__list__f_43_43_2_f_0((MR_Word) (&mercury__builtin__builtin__type_ctor_info_string_0), Var_7, Var_8);
  }
  else
  {
    MR_String Name_3 = ((MR_String) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 0))));

    {
      HeadVar__2_2 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
      MR_hl_field(1, HeadVar__2_2, 0) = ((MR_Box) (Name_3));
      MR_hl_field(1, HeadVar__2_2, 1) = ((MR_Box) ((MR_Unsigned) 0U));
    }
  }
  return HeadVar__2_2;
}

MR_String MR_CALL 
mdbcomp__sym_name__sym_name_to_string_1_f_0(
  MR_Word SymName_3)
{
  MR_String HeadVar__2_2;

  HeadVar__2_2 = mdbcomp__sym_name__sym_name_to_string_sep_2_f_0(SymName_3, (MR_String) ".");
  return HeadVar__2_2;
}

MR_String MR_CALL 
mdbcomp__sym_name__sym_name_to_string_sep_2_f_0(
  MR_Word HeadVar__1_1,
  MR_String HeadVar__2_2)
{
  MR_String HeadVar__3_3;

  if (((MR_tag((MR_Word) HeadVar__1_1)) == (MR_Integer) 1))
  {
    MR_Word ModuleSym_6 = ((MR_Word) ((MR_hl_field(1, HeadVar__1_1, (MR_Integer) 0))));
    MR_String Name_7 = ((MR_String) ((MR_hl_field(1, HeadVar__1_1, (MR_Integer) 1))));
    MR_String ModuleName_10;
    MR_Word Var_11;
    MR_Word Var_12;
    MR_Word Var_13;

    ModuleName_10 = mdbcomp__sym_name__sym_name_to_string_sep_2_f_0(ModuleSym_6, HeadVar__2_2);
    {
      Var_13 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
      MR_hl_field(1, Var_13, 0) = ((MR_Box) (Name_7));
      MR_hl_field(1, Var_13, 1) = ((MR_Box) ((MR_Unsigned) 0U));
    }
    {
      Var_12 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
      MR_hl_field(1, Var_12, 0) = ((MR_Box) (HeadVar__2_2));
      MR_hl_field(1, Var_12, 1) = ((MR_Box) (Var_13));
    }
    {
      Var_11 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
      MR_hl_field(1, Var_11, 0) = ((MR_Box) (ModuleName_10));
      MR_hl_field(1, Var_11, 1) = ((MR_Box) (Var_12));
    }
    mercury__string__append_list_2_p_0(Var_11, &HeadVar__3_3);
  }
  else
    HeadVar__3_3 = ((MR_String) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 0))));
  return HeadVar__3_3;
}

MR_Word MR_CALL 
mdbcomp__sym_name__string_to_sym_name_1_f_0(
  MR_String String_3)
{
  MR_Word HeadVar__2_2;

  HeadVar__2_2 = mdbcomp__sym_name__string_to_sym_name_sep_2_f_0(String_3, (MR_String) ".");
  return HeadVar__2_2;
}

MR_Word MR_CALL 
mdbcomp__sym_name__string_to_sym_name_sep_2_f_0(
  MR_String String_4,
  MR_String ModuleSeparator_5)
{
  MR_bool succeeded;
  MR_Word Result_6;
  MR_Integer LeftLength_7;
  MR_Integer Var_14;

  succeeded = mercury__string__sub_string_search_3_p_0(String_4, ModuleSeparator_5, &LeftLength_7);
  if (succeeded)
  {
    Var_14 = (MR_Integer) 0;
    succeeded = (LeftLength_7 > Var_14);
  }
  if (succeeded)
  {
    MR_String ModuleName_8;
    MR_Integer StringLength_9;
    MR_Integer SeparatorLength_10;
    MR_Integer RightLength_11;
    MR_String Name_12;
    MR_Word NameSym_13;
    MR_Integer Var_15;

    mercury__string__left_3_p_0(String_4, LeftLength_7, &ModuleName_8);
    mercury__string__length_2_p_0(String_4, &StringLength_9);
    mercury__string__length_2_p_0(ModuleSeparator_5, &SeparatorLength_10);
    Var_15 = (MR_Integer) ((MR_Unsigned) StringLength_9 - (MR_Unsigned) LeftLength_7);
    RightLength_11 = (MR_Integer) ((MR_Unsigned) Var_15 - (MR_Unsigned) SeparatorLength_10);
    mercury__string__right_3_p_0(String_4, RightLength_11, &Name_12);
    NameSym_13 = mdbcomp__sym_name__string_to_sym_name_sep_2_f_0(Name_12, ModuleSeparator_5);
    Result_6 = mdbcomp__sym_name__add_outermost_qualifier_2_f_0(ModuleName_8, NameSym_13);
  }
  else
    {
      Result_6 = (MR_Word) MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL);
      MR_hl_field(0, Result_6, 0) = ((MR_Box) (String_4));
    }
  return Result_6;
}

MR_Word MR_CALL 
mdbcomp__sym_name__add_outermost_qualifier_2_f_0(
  MR_String ModuleName_4,
  MR_Word SymName0_5)
{
  MR_Word SymName_6;

  if (((MR_tag((MR_Word) SymName0_5)) == (MR_Integer) 1))
  {
    MR_Word ModuleSymName0_8 = ((MR_Word) ((MR_hl_field(1, SymName0_5, (MR_Integer) 0))));
    MR_Word ModuleSymName_9;
    MR_String Name_11 = ((MR_String) ((MR_hl_field(1, SymName0_5, (MR_Integer) 1))));

    ModuleSymName_9 = mdbcomp__sym_name__add_outermost_qualifier_2_f_0(ModuleName_4, ModuleSymName0_8);
    {
      SymName_6 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
      MR_hl_field(1, SymName_6, 0) = ((MR_Box) (ModuleSymName_9));
      MR_hl_field(1, SymName_6, 1) = ((MR_Box) (Name_11));
    }
  }
  else
  {
    MR_String Name_7 = ((MR_String) ((MR_hl_field(0, SymName0_5, (MR_Integer) 0))));
    MR_Word Var_10;

    {
      Var_10 = (MR_Word) MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL);
      MR_hl_field(0, Var_10, 0) = ((MR_Box) (ModuleName_4));
    }
    {
      SymName_6 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
      MR_hl_field(1, SymName_6, 0) = ((MR_Box) (Var_10));
      MR_hl_field(1, SymName_6, 1) = ((MR_Box) (Name_7));
    }
  }
  return SymName_6;
}

MR_Word MR_CALL 
mdbcomp__sym_name__get_ancestors_set_1_f_0(
  MR_Word ModuleName_3)
{
  MR_Word HeadVar__2_2;
  MR_Word Var_4;

  mdbcomp__sym_name__get_ancestors_loop_3_p_0(ModuleName_3, (MR_Word) ((MR_Unsigned) 0U), &Var_4);
  HeadVar__2_2 = mercury__set__list_to_set_1_f_0((MR_Word) (&mdbcomp__sym_name__mdbcomp__sym_name__type_ctor_info_sym_name_0), Var_4);
  return HeadVar__2_2;
}

MR_Word MR_CALL 
mdbcomp__sym_name__get_ancestors_1_f_0(
  MR_Word ModuleName_3)
{
  MR_Word Ancestors_4;

  mdbcomp__sym_name__get_ancestors_loop_3_p_0(ModuleName_3, (MR_Word) ((MR_Unsigned) 0U), &Ancestors_4);
  return Ancestors_4;
}

static void MR_CALL 
mdbcomp__sym_name__get_ancestors_loop_3_p_0(
  MR_Word HeadVar__1_1,
  MR_Word STATE_VARIABLE_Ancestors_0_2,
  MR_Word * STATE_VARIABLE_Ancestors_3)
{
  while (MR_TRUE)
  {
    // setup for model_det tailcalls optimized into a loop
    ;
    if (((MR_tag((MR_Word) HeadVar__1_1)) == (MR_Integer) 1))
    {
      MR_Word Parent_8 = ((MR_Word) ((MR_hl_field(1, HeadVar__1_1, (MR_Integer) 0))));
      MR_Word STATE_VARIABLE_Ancestors_13_13;
      MR_Word next_value_of_HeadVar__1_1;
      MR_Word next_value_of_STATE_VARIABLE_Ancestors_0_2;

      {
        STATE_VARIABLE_Ancestors_13_13 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
        MR_hl_field(1, STATE_VARIABLE_Ancestors_13_13, 0) = ((MR_Box) (Parent_8));
        MR_hl_field(1, STATE_VARIABLE_Ancestors_13_13, 1) = ((MR_Box) (STATE_VARIABLE_Ancestors_0_2));
      }
      // direct tailcall eliminated
      ;
      next_value_of_HeadVar__1_1 = Parent_8;
      next_value_of_STATE_VARIABLE_Ancestors_0_2 = STATE_VARIABLE_Ancestors_13_13;
      HeadVar__1_1 = next_value_of_HeadVar__1_1;
      STATE_VARIABLE_Ancestors_0_2 = next_value_of_STATE_VARIABLE_Ancestors_0_2;
      continue;
    }
    else
      *STATE_VARIABLE_Ancestors_3 = STATE_VARIABLE_Ancestors_0_2;
    break;
  }
}

static MR_bool MR_CALL 
mdbcomp__sym_name____Unify____module_name_0_0_10001(
  MR_Box wrapper_arg_1,
  MR_Box wrapper_arg_2)
{
  MR_bool succeeded;

  succeeded = mdbcomp__sym_name____Unify____module_name_0_0(((MR_Word) (wrapper_arg_1)), ((MR_Word) (wrapper_arg_2)));
  return succeeded;
}

static void MR_CALL 
mdbcomp__sym_name____Compare____module_name_0_0_10001(
  MR_Box * wrapper_arg_1,
  MR_Box wrapper_arg_2,
  MR_Box wrapper_arg_3)
{
  MR_Word conv0_HeadVar__1_1;

  mdbcomp__sym_name____Compare____module_name_0_0(&conv0_HeadVar__1_1, ((MR_Word) (wrapper_arg_2)), ((MR_Word) (wrapper_arg_3)));
  *wrapper_arg_1 = ((MR_Box) (conv0_HeadVar__1_1));
}

static MR_bool MR_CALL 
mdbcomp__sym_name____Unify____sym_name_0_0_10001(
  MR_Box wrapper_arg_1,
  MR_Box wrapper_arg_2)
{
  MR_bool succeeded;

  succeeded = mdbcomp__sym_name____Unify____sym_name_0_0(((MR_Word) (wrapper_arg_1)), ((MR_Word) (wrapper_arg_2)));
  return succeeded;
}

static void MR_CALL 
mdbcomp__sym_name____Compare____sym_name_0_0_10001(
  MR_Box * wrapper_arg_1,
  MR_Box wrapper_arg_2,
  MR_Box wrapper_arg_3)
{
  MR_Word conv0_HeadVar__1_1;

  mdbcomp__sym_name____Compare____sym_name_0_0(&conv0_HeadVar__1_1, ((MR_Word) (wrapper_arg_2)), ((MR_Word) (wrapper_arg_3)));
  *wrapper_arg_1 = ((MR_Box) (conv0_HeadVar__1_1));
}

void mercury__mdbcomp__sym_name__init(void)
{
}

void mercury__mdbcomp__sym_name__init_type_tables(void)
{
	static MR_bool initialised = MR_FALSE;
	if (initialised) return;
	initialised = MR_TRUE;

	MR_register_type_ctor_info(&mdbcomp__sym_name__mdbcomp__sym_name__type_ctor_info_module_name_0);
	MR_register_type_ctor_info(&mdbcomp__sym_name__mdbcomp__sym_name__type_ctor_info_sym_name_0);
}

void mercury__mdbcomp__sym_name__init_debugger(void)
{
	MR_fatal_error("debugger initialization in MLDS grade");
}

// Ensure everything is compiled with the same grade.
const char *mercury__mdbcomp__sym_name__grade_check(void)
{
    return &MR_GRADE_VAR;
}

// :- end_module mdbcomp.sym_name.
