/*
** Automatically generated from `unify_gen_test.m'
** by the Mercury compiler,
** version rotd-2026-07-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 ll_backend.unify_gen_test.
// :- implementation.

/*
INIT mercury__ll_backend__unify_gen_test__init
ENDINIT
*/

#include "ll_backend.unify_gen_test.mih"


#include "analysis.mih"
#include "array.mih"
#include "assoc_list.mih"
#include "backend_libs.mih"
#include "bimap.mih"
#include "bitmap.mih"
#include "bool.mih"
#include "builtin.mih"
#include "char.mih"
#include "check_hlds.mih"
#include "construct.mih"
#include "cord.mih"
#include "counter.mih"
#include "deconstruct.mih"
#include "enum.mih"
#include "getopt.mih"
#include "hlds.mih"
#include "integer.mih"
#include "io.mih"
#include "libs.mih"
#include "list.mih"
#include "ll_backend.mih"
#include "map.mih"
#include "maybe.mih"
#include "mdbcomp.mih"
#include "mode_robdd.mih"
#include "one_or_more.mih"
#include "one_or_more_map.mih"
#include "ops.mih"
#include "pair.mih"
#include "parse_tree.mih"
#include "pretty_printer.mih"
#include "private_builtin.mih"
#include "require.mih"
#include "robdd.mih"
#include "set.mih"
#include "set_ordlist.mih"
#include "set_tree234.mih"
#include "sparse_bitset.mih"
#include "stack.mih"
#include "stream.mih"
#include "string.mih"
#include "term.mih"
#include "term_context.mih"
#include "time.mih"
#include "transform_hlds.mih"
#include "tree234.mih"
#include "type_desc.mih"
#include "uint.mih"
#include "uint8.mih"
#include "unit.mih"
#include "univ.mih"
#include "varset.mih"
#include "analysis.framework.mih"
#include "backend_libs.builtin_ops.mih"
#include "backend_libs.rtti.mih"
#include "check_hlds.mode_constraint_robdd.mih"
#include "hlds.code_model.mih"
#include "hlds.goal_mode.mih"
#include "hlds.hlds_class.mih"
#include "hlds.hlds_clauses.mih"
#include "hlds.hlds_code_util.mih"
#include "hlds.hlds_cons.mih"
#include "hlds.hlds_data.mih"
#include "hlds.hlds_goal.mih"
#include "hlds.hlds_llds.mih"
#include "hlds.hlds_markers.mih"
#include "hlds.hlds_module.mih"
#include "hlds.hlds_out.mih"
#include "hlds.hlds_pred.mih"
#include "hlds.hlds_promise.mih"
#include "hlds.hlds_rtti.mih"
#include "hlds.inst_graph.mih"
#include "hlds.instmap.mih"
#include "hlds.pred_name.mih"
#include "hlds.pred_table.mih"
#include "hlds.status.mih"
#include "libs.file_util.mih"
#include "libs.globals.mih"
#include "libs.indent.mih"
#include "libs.op_mode.mih"
#include "libs.optimization_options.mih"
#include "libs.options.mih"
#include "libs.polyhedron.mih"
#include "libs.trace_params.mih"
#include "ll_backend.code_info.mih"
#include "ll_backend.code_util.mih"
#include "ll_backend.continuation_info.mih"
#include "ll_backend.global_data.mih"
#include "ll_backend.layout.mih"
#include "ll_backend.llds.mih"
#include "ll_backend.trace_gen.mih"
#include "ll_backend.unify_gen_util.mih"
#include "mdbcomp.feedback.mih"
#include "mdbcomp.goal_path.mih"
#include "mdbcomp.prim_data.mih"
#include "mdbcomp.program_representation.mih"
#include "mdbcomp.sym_name.mih"
#include "mode_robdd.tfeirn.mih"
#include "parse_tree.error_spec.mih"
#include "parse_tree.parse_tree_out_cons_id.mih"
#include "parse_tree.parse_tree_out_info.mih"
#include "parse_tree.parse_tree_output.mih"
#include "parse_tree.prog_data.mih"
#include "parse_tree.prog_data_foreign.mih"
#include "parse_tree.prog_data_pragma.mih"
#include "parse_tree.prog_foreign.mih"
#include "parse_tree.prog_item.mih"
#include "parse_tree.prog_rename.mih"
#include "parse_tree.prog_type.mih"
#include "parse_tree.prog_util.mih"
#include "parse_tree.set_of_var.mih"
#include "parse_tree.var_db.mih"
#include "parse_tree.var_table.mih"
#include "string.builder.mih"
#include "transform_hlds.term_constr_errors.mih"
#include "transform_hlds.term_constr_main_types.mih"
#include "transform_hlds.term_errors.mih"
#include "transform_hlds.term_util.mih"
#include "hlds.hlds_out.hlds_out_goal.mih"
#include "hlds.hlds_out.hlds_out_util.mih"
#include "mdbcomp.feedback.feedback_info.mih"




static const MR_EnumFunctorDesc ll_backend__unify_gen_test__ll_backend__unify_gen_test__enum_functor_desc_test_sense_0_0;

static const MR_EnumFunctorDesc ll_backend__unify_gen_test__ll_backend__unify_gen_test__enum_functor_desc_test_sense_0_1;

static const MR_EnumFunctorDescPtr ll_backend__unify_gen_test__ll_backend__unify_gen_test__enum_ordinal_ordered_test_sense_0[2];

static const MR_EnumFunctorDescPtr ll_backend__unify_gen_test__ll_backend__unify_gen_test__enum_name_ordered_test_sense_0[2];

static const MR_Integer ll_backend__unify_gen_test__ll_backend__unify_gen_test__functor_number_map_test_sense_0[2];

static MR_bool MR_CALL 
ll_backend__unify_gen_test__IntroducedFrom__pred__generate_test_rval_has_cons_tag__198__1_2_p_0(
  MR_Word ForeignLang_14,
  MR_Word HeadVar__2_79);

static void MR_CALL 
ll_backend__unify_gen_test__generate_test_rval_has_tagged_cons_id_4_p_0(
  MR_Word CI_5,
  MR_Word VarRval_6,
  MR_Word TaggedConsId_7,
  MR_Word * TestRval_8);

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

static void MR_CALL 
ll_backend__unify_gen_test__generate_test_var_has_one_tagged_cons_id_10_p_0_1(
  MR_Box closure_arg,
  MR_Box wrapper_arg_1,
  MR_Box * wrapper_arg_2);

static void MR_CALL 
ll_backend__unify_gen_test__logical_or_rvals_3_p_0(
  MR_Word CurTestRval_4,
  MR_Word OtherTestRvals_5,
  MR_Word * TestRval_6);

static MR_bool MR_CALL 
ll_backend__unify_gen_test__generate_test_rval_has_cons_tag_4_p_0_1(
  MR_Box closure_arg);

static void MR_CALL 
ll_backend__unify_gen_test__generate_test_rval_has_cons_tag_4_p_0(
  MR_Word CI_5,
  MR_Word VarRval_6,
  MR_Word ConsTag_7,
  MR_Word * TestRval_8);

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

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


static /* final */ const MR_Box ll_backend__unify_gen_test_scalar_common_1[7][2];

static /* final */ const MR_Box ll_backend__unify_gen_test_scalar_common_2[2][1];

static /* final */ const MR_Box ll_backend__unify_gen_test_scalar_common_3[1][5];

static /* final */ const MR_Box ll_backend__unify_gen_test_scalar_common_4[1][7];

static /* final */ const MR_Box ll_backend__unify_gen_test_scalar_common_5[1][6];

static /* final */ const MR_Box ll_backend__unify_gen_test_scalar_common_6[1][3];




static /* final */ const MR_Box ll_backend__unify_gen_test_scalar_common_1[7][2] = {
  /* row   0 */
  {
    ((MR_Box) (MR_Word) ((MR_Unsigned) 4U)),
    (MR_Box) (((MR_Unsigned) 0U << 3))
  },
  /* row   1 */
  {
    ((MR_Box) (MR_Word) ((MR_Unsigned) 1U)),
    ((MR_Box) ((MR_Unsigned) 0U))
  },
  /* row   2 */
  {
    ((MR_Box) (MR_Word) ((MR_Unsigned) 10U)),
    (MR_Box) ((MR_Unsigned) 0U)
  },
  /* row   3 */
  {
    ((MR_Box) (MR_Word) ((MR_Unsigned) 1U)),
    (MR_Box) ((MR_Unsigned) 1U)
  },
  /* row   4 */
  {
    ((MR_Box) (MR_Word) ((MR_Unsigned) 4U)),
    (MR_Box) (((MR_Unsigned) 1U << 3))
  },
  /* row   5 */
  {
    ((MR_Box) (MR_Word) ((MR_Unsigned) 1U)),
    ((MR_Box) (MR_mkword(1, &ll_backend__unify_gen_test_scalar_common_2[1])))
  },
  /* row   6 */
  {
    ((MR_Box) (MR_Word) ((MR_Unsigned) 6U)),
    (MR_Box) ((MR_Unsigned) 0U)
  },
};

static /* final */ const MR_Box ll_backend__unify_gen_test_scalar_common_2[2][1] = {
  /* row   0 */
  { (MR_Box) ((MR_Unsigned) 0U) },
  /* row   1 */
  { ((MR_Box) ((MR_Integer) 0)) },
};

static /* final */ const MR_Box ll_backend__unify_gen_test_scalar_common_3[1][5] = {
  /* row   0 */
  {
    NULL,
    ((MR_Box) (NULL)),
    ((MR_Box) ((MR_Integer) 2)),
    ((MR_Box) (&libs__globals__libs__globals__type_ctor_info_foreign_language_0)),
    ((MR_Box) (&libs__globals__libs__globals__type_ctor_info_foreign_language_0))
  },
};

static /* final */ const MR_Box ll_backend__unify_gen_test_scalar_common_4[1][7] = {
  /* row   0 */
  {
    NULL,
    ((MR_Box) (NULL)),
    ((MR_Box) ((MR_Integer) 4)),
    ((MR_Box) (&ll_backend__code_info__ll_backend__code_info__type_ctor_info_code_info_0)),
    ((MR_Box) (&ll_backend__llds__ll_backend__llds__type_ctor_info_rval_0)),
    ((MR_Box) (&hlds__hlds_data__hlds__hlds_data__type_ctor_info_tagged_cons_id_0)),
    ((MR_Box) (&ll_backend__llds__ll_backend__llds__type_ctor_info_rval_0))
  },
};

static /* final */ const MR_Box ll_backend__unify_gen_test_scalar_common_5[1][6] = {
  /* row   0 */
  {
    NULL,
    ((MR_Box) (NULL)),
    ((MR_Box) ((MR_Integer) 3)),
    ((MR_Box) (&hlds__hlds_data__hlds__hlds_data__type_ctor_info_tagged_cons_id_0)),
    ((MR_Box) (&mercury__builtin__builtin__type_ctor_info_string_0)),
    ((MR_Box) (&hlds__hlds_data__hlds__hlds_data__type_ctor_info_cons_tag_0))
  },
};

static /* final */ const MR_Box ll_backend__unify_gen_test_scalar_common_6[1][3] = {
  /* row   0 */
  {
    ((MR_Box) (&ll_backend__unify_gen_test_scalar_common_5[0])),
    ((MR_Box) (ll_backend__unify_gen_test__generate_test_var_has_one_tagged_cons_id_10_p_0_2)),
    ((MR_Box) ((MR_Integer) 0))
  },
};



#include "array.mh"
#include "bitmap.mh"
#include "io.mh"
#include "string.mh"
#include "time.mh"
#include "io.stream_ops.mh"


static const MR_EnumFunctorDesc ll_backend__unify_gen_test__ll_backend__unify_gen_test__enum_functor_desc_test_sense_0_0 = {
  (MR_String) "branch_on_success",
  INT32_C(0)
};

static const MR_EnumFunctorDesc ll_backend__unify_gen_test__ll_backend__unify_gen_test__enum_functor_desc_test_sense_0_1 = {
  (MR_String) "branch_on_failure",
  INT32_C(1)
};

static const MR_EnumFunctorDescPtr ll_backend__unify_gen_test__ll_backend__unify_gen_test__enum_ordinal_ordered_test_sense_0[2] = {
  &ll_backend__unify_gen_test__ll_backend__unify_gen_test__enum_functor_desc_test_sense_0_0,
  &ll_backend__unify_gen_test__ll_backend__unify_gen_test__enum_functor_desc_test_sense_0_1
};

static const MR_EnumFunctorDescPtr ll_backend__unify_gen_test__ll_backend__unify_gen_test__enum_name_ordered_test_sense_0[2] = {
  &ll_backend__unify_gen_test__ll_backend__unify_gen_test__enum_functor_desc_test_sense_0_1,
  &ll_backend__unify_gen_test__ll_backend__unify_gen_test__enum_functor_desc_test_sense_0_0
};

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

const MR_TypeCtorInfo_Struct ll_backend__unify_gen_test__ll_backend__unify_gen_test__type_ctor_info_test_sense_0 = {
  (MR_Integer) 0,
  UINT8_C(18),
  INT8_C(-1),
  MR_TYPECTOR_REP_ENUM,
  ((MR_Box) (ll_backend__unify_gen_test____Unify____test_sense_0_0_10001)),
  ((MR_Box) (ll_backend__unify_gen_test____Compare____test_sense_0_0_10001)),
  (MR_String) "ll_backend.unify_gen_test",
  (MR_String) "test_sense",
  { ll_backend__unify_gen_test__ll_backend__unify_gen_test__enum_name_ordered_test_sense_0 },
  { ll_backend__unify_gen_test__ll_backend__unify_gen_test__enum_ordinal_ordered_test_sense_0 },
  (MR_Integer) 2,
  UINT16_C(12),
  ll_backend__unify_gen_test__ll_backend__unify_gen_test__functor_number_map_test_sense_0,

};

static MR_bool MR_CALL 
ll_backend__unify_gen_test__IntroducedFrom__pred__generate_test_rval_has_cons_tag__198__1_2_p_0(
  MR_Word ForeignLang_14,
  MR_Word HeadVar__2_79)
{
  MR_bool succeeded = (ForeignLang_14 == HeadVar__2_79);

  return succeeded;
}

void MR_CALL 
ll_backend__unify_gen_test____Compare____test_sense_0_0(
  MR_Word * HeadVar__1_1,
  MR_Word HeadVar__2_2,
  MR_Word HeadVar__3_3)
{
  MR_bool succeeded;
  MR_Integer Cast_HeadVar1_4 = (MR_Integer) (HeadVar__2_2);
  MR_Integer Cast_HeadVar2_5 = (MR_Integer) (HeadVar__3_3);

  succeeded = (Cast_HeadVar1_4 < Cast_HeadVar2_5);
  if (succeeded)
    *HeadVar__1_1 = (MR_Integer) 1;
  else
  {
    succeeded = (Cast_HeadVar1_4 > Cast_HeadVar2_5);
    if (succeeded)
      *HeadVar__1_1 = (MR_Integer) 2;
    else
      *HeadVar__1_1 = (MR_Integer) 0;
  }
}

MR_bool MR_CALL 
ll_backend__unify_gen_test____Unify____test_sense_0_0(
  MR_Word HeadVar__1_1,
  MR_Word HeadVar__2_2)
{
  MR_bool succeeded = (HeadVar__1_1 == HeadVar__2_2);

  return succeeded;
}

static void MR_CALL 
ll_backend__unify_gen_test__generate_test_rval_has_tagged_cons_id_4_p_0(
  MR_Word CI_5,
  MR_Word VarRval_6,
  MR_Word TaggedConsId_7,
  MR_Word * TestRval_8)
{
  MR_Word ConsTag_10 = ((MR_Word) ((MR_hl_field(0, TaggedConsId_7, 1))));

  ll_backend__unify_gen_test__generate_test_rval_has_cons_tag_4_p_0(CI_5, VarRval_6, ConsTag_10, TestRval_8);
}

static void MR_CALL 
ll_backend__unify_gen_test__generate_test_var_has_one_tagged_cons_id_10_p_0_2(
  MR_Box closure_arg,
  MR_Box wrapper_arg_1,
  MR_Box * wrapper_arg_2,
  MR_Box * wrapper_arg_3)
{
  MR_Box closure = closure_arg;
  MR_String conv2_HeadVar__2_2;
  MR_Word conv1_HeadVar__3_3;

  hlds__hlds_out__hlds_out_goal__project_cons_name_and_tag_3_p_0(((MR_Word) (wrapper_arg_1)), &conv2_HeadVar__2_2, &conv1_HeadVar__3_3);
  *wrapper_arg_2 = ((MR_Box) (conv2_HeadVar__2_2));
  *wrapper_arg_3 = ((MR_Box) (conv1_HeadVar__3_3));
}

static void MR_CALL 
ll_backend__unify_gen_test__generate_test_var_has_one_tagged_cons_id_10_p_0_1(
  MR_Box closure_arg,
  MR_Box wrapper_arg_1,
  MR_Box * wrapper_arg_2)
{
  MR_Box closure = closure_arg;
  MR_Word conv0_TestRval_8;

  ll_backend__unify_gen_test__generate_test_rval_has_tagged_cons_id_4_p_0(((MR_Word) ((MR_hl_field(0, closure, 3)))), ((MR_Word) ((MR_hl_field(0, closure, 4)))), ((MR_Word) (wrapper_arg_1)), &conv0_TestRval_8);
  *wrapper_arg_2 = ((MR_Box) (conv0_TestRval_8));
}

void MR_CALL 
ll_backend__unify_gen_test__generate_test_var_has_one_tagged_cons_id_10_p_0(
  MR_Word VarRval_11,
  MR_String VarName_12,
  MR_Word MainTaggedConsId_13,
  MR_Word OtherTaggedConsIds_14,
  MR_Word CheaperTagTest_15,
  MR_Word Sense_16,
  MR_Word * ElseLabel_17,
  MR_Word * Code_18,
  MR_Word STATE_VARIABLE_CI_0_32,
  MR_Word * STATE_VARIABLE_CI_33)
{
  MR_bool succeeded;

  if ((OtherTaggedConsIds_14 == (MR_Word) ((MR_Unsigned) 0U)))
  {
    MR_Word MainConsId_20 = ((MR_Word) ((MR_hl_field(0, MainTaggedConsId_13, 0))));
    MR_Word MainConsTag_21 = ((MR_Word) ((MR_hl_field(0, MainTaggedConsId_13, 1))));
    MR_String ConsIdName_48;
    MR_String Comment_53;
    MR_Word TestRval_55;
    MR_Word BranchRval_68;
    MR_Word Var_69;
    MR_Word Var_70;
    MR_Word Var_71;
    MR_Word CheapConsTag_52;
    MR_Word ExpensiveDuCtor_49;
    MR_Word Var_66;

    ConsIdName_48 = parse_tree__parse_tree_out_cons_id__cons_id_and_arity_to_string_1_f_0(MainConsId_20);
    succeeded = (CheaperTagTest_15 != (MR_Word) ((MR_Unsigned) 0U));
    if (succeeded)
    {
      ExpensiveDuCtor_49 = ((MR_Word) ((MR_hl_field(1, CheaperTagTest_15, 0))));
      CheapConsTag_52 = ((MR_Word) ((MR_hl_field(1, CheaperTagTest_15, 3))));
      succeeded = ((MR_tag((MR_Word) MainConsId_20)) == (MR_Integer) 1);
      if (succeeded)
      {
        Var_66 = (MR_Word) (MR_body((MR_Word) (MainConsId_20), (MR_Integer) 1));
        succeeded = parse_tree__prog_data____Unify____du_ctor_0_0(ExpensiveDuCtor_49, Var_66);
      }
    }
    if (succeeded)
    {
      MR_Word NegTestRval_54;
      MR_String Var_56;
      MR_String Var_57;
      MR_String Var_58;
      MR_String Var_60;

      switch (Sense_16) {
        default: /*NOTREACHED*/ MR_assert(0);
        case (MR_Integer) 1:
          Var_56 = (MR_String) "branch away unless ";
          break;
        case (MR_Integer) 0:
          Var_56 = (MR_String) "branch away if ";
          break;
      }
      Var_60 = mercury__string__f_43_43_2_f_0(ConsIdName_48, (MR_String) " (inverted test)");
      Var_58 = mercury__string__f_43_43_2_f_0((MR_String) " has functor ", Var_60);
      Var_57 = mercury__string__f_43_43_2_f_0(VarName_12, Var_58);
      Comment_53 = mercury__string__f_43_43_2_f_0(Var_56, Var_57);
      ll_backend__unify_gen_test__generate_test_rval_has_cons_tag_4_p_0(STATE_VARIABLE_CI_0_32, VarRval_11, CheapConsTag_52, &NegTestRval_54);
      ll_backend__code_util__negate_rval_2_p_0(NegTestRval_54, &TestRval_55);
    }
    else
    {
      MR_String Var_62;
      MR_String Var_63;
      MR_String Var_64;

      switch (Sense_16) {
        default: /*NOTREACHED*/ MR_assert(0);
        case (MR_Integer) 1:
          Var_62 = (MR_String) "branch away unless ";
          break;
        case (MR_Integer) 0:
          Var_62 = (MR_String) "branch away if ";
          break;
      }
      Var_64 = mercury__string__f_43_43_2_f_0((MR_String) " has functor ", ConsIdName_48);
      Var_63 = mercury__string__f_43_43_2_f_0(VarName_12, Var_64);
      Comment_53 = mercury__string__f_43_43_2_f_0(Var_62, Var_63);
      ll_backend__unify_gen_test__generate_test_rval_has_cons_tag_4_p_0(STATE_VARIABLE_CI_0_32, VarRval_11, MainConsTag_21, &TestRval_55);
    }
    ll_backend__code_info__get_next_label_3_p_0(ElseLabel_17, STATE_VARIABLE_CI_0_32, STATE_VARIABLE_CI_33);
    switch (Sense_16) {
      default: /*NOTREACHED*/ MR_assert(0);
      case (MR_Integer) 1:
        ll_backend__code_util__negate_rval_2_p_0(TestRval_55, &BranchRval_68);
        break;
      case (MR_Integer) 0:
        BranchRval_68 = TestRval_55;
        break;
    }
    {
      Var_71 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL));
      MR_hl_field(1, Var_71, 0) = ((MR_Box) (*ElseLabel_17));
    }
    {
      Var_70 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (3 * sizeof(MR_Word)), NULL, NULL));
      MR_hl_field(3, Var_70, 0) = ((MR_Box) ((MR_Unsigned) 9U));
      MR_hl_field(3, Var_70, 1) = ((MR_Box) (BranchRval_68));
      MR_hl_field(3, Var_70, 2) = ((MR_Box) (Var_71));
    }
    {
      Var_69 = (MR_Word) MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL);
      MR_hl_field(0, Var_69, 0) = ((MR_Box) (Var_70));
      MR_hl_field(0, Var_69, 1) = ((MR_Box) (Comment_53));
    }
    *Code_18 = mercury__cord__singleton_1_f_0((MR_Word) (&ll_backend__llds__ll_backend__llds__type_ctor_info_instruction_0), ((MR_Box) (Var_69)));
  }
  else
  {
    MR_Word MainTagTestRval_24;
    MR_Word OtherTagTestRvals_25;
    MR_Word TestRval_26;
    MR_String MainConsName_27;
    MR_Word OtherConsNames_29;
    MR_String Comment_31;
    MR_Word Var_35;
    MR_String Var_37;
    MR_String Var_38;
    MR_Word ConsTag_74 = ((MR_Word) ((MR_hl_field(0, MainTaggedConsId_13, 1))));
    MR_Word BranchRval_75;
    MR_Word Var_76;
    MR_Word Var_77;
    MR_Word Var_78;
    MR_Word Var_28;
    MR_Word Var_30;

    ll_backend__unify_gen_test__generate_test_rval_has_cons_tag_4_p_0(STATE_VARIABLE_CI_0_32, VarRval_11, ConsTag_74, &MainTagTestRval_24);
    {
      Var_35 = (MR_Word) MR_new_object(MR_Word, (5 * sizeof(MR_Word)), NULL, NULL);
      MR_hl_field(0, Var_35, 0) = ((MR_Box) (&ll_backend__unify_gen_test_scalar_common_4[0]));
      MR_hl_field(0, Var_35, 1) = ((MR_Box) (ll_backend__unify_gen_test__generate_test_var_has_one_tagged_cons_id_10_p_0_1));
      MR_hl_field(0, Var_35, 2) = ((MR_Box) ((MR_Integer) 2));
      MR_hl_field(0, Var_35, 3) = ((MR_Box) (STATE_VARIABLE_CI_0_32));
      MR_hl_field(0, Var_35, 4) = ((MR_Box) (VarRval_11));
    }
    mercury__list__map_3_p_0((MR_Word) (&hlds__hlds_data__hlds__hlds_data__type_ctor_info_tagged_cons_id_0), (MR_Word) (&ll_backend__llds__ll_backend__llds__type_ctor_info_rval_0), Var_35, OtherTaggedConsIds_14, &OtherTagTestRvals_25);
    ll_backend__unify_gen_test__logical_or_rvals_3_p_0(MainTagTestRval_24, OtherTagTestRvals_25, &TestRval_26);
    hlds__hlds_out__hlds_out_goal__project_cons_name_and_tag_3_p_0(MainTaggedConsId_13, &MainConsName_27, &Var_28);
    mercury__list__map2_4_p_0((MR_Word) (&hlds__hlds_data__hlds__hlds_data__type_ctor_info_tagged_cons_id_0), (MR_Word) (&mercury__builtin__builtin__type_ctor_info_string_0), (MR_Word) (&hlds__hlds_data__hlds__hlds_data__type_ctor_info_cons_tag_0), (MR_Word) (&ll_backend__unify_gen_test_scalar_common_6[0]), OtherTaggedConsIds_14, &OtherConsNames_29, &Var_30);
    Var_38 = hlds__hlds_out__hlds_out_goal__case_comment_3_f_0(VarName_12, MainConsName_27, OtherConsNames_29);
    ll_backend__code_info__get_next_label_3_p_0(ElseLabel_17, STATE_VARIABLE_CI_0_32, STATE_VARIABLE_CI_33);
    switch (Sense_16) {
      default: /*NOTREACHED*/ MR_assert(0);
      case (MR_Integer) 1:
        {
          Var_37 = (MR_String) "branch away unless ";
          ll_backend__code_util__negate_rval_2_p_0(TestRval_26, &BranchRval_75);
        }
        break;
      case (MR_Integer) 0:
        {
          Var_37 = (MR_String) "branch away if ";
          BranchRval_75 = TestRval_26;
        }
        break;
    }
    Comment_31 = mercury__string__f_43_43_2_f_0(Var_37, Var_38);
    {
      Var_78 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL));
      MR_hl_field(1, Var_78, 0) = ((MR_Box) (*ElseLabel_17));
    }
    {
      Var_77 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (3 * sizeof(MR_Word)), NULL, NULL));
      MR_hl_field(3, Var_77, 0) = ((MR_Box) ((MR_Unsigned) 9U));
      MR_hl_field(3, Var_77, 1) = ((MR_Box) (BranchRval_75));
      MR_hl_field(3, Var_77, 2) = ((MR_Box) (Var_78));
    }
    {
      Var_76 = (MR_Word) MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL);
      MR_hl_field(0, Var_76, 0) = ((MR_Box) (Var_77));
      MR_hl_field(0, Var_76, 1) = ((MR_Box) (Comment_31));
    }
    *Code_18 = mercury__cord__singleton_1_f_0((MR_Word) (&ll_backend__llds__ll_backend__llds__type_ctor_info_instruction_0), ((MR_Box) (Var_76)));
  }
}

static void MR_CALL 
ll_backend__unify_gen_test__logical_or_rvals_3_p_0(
  MR_Word CurTestRval_4,
  MR_Word OtherTestRvals_5,
  MR_Word * TestRval_6)
{
  while (MR_TRUE)
  {
    // setup for model_det tailcalls optimized into a loop
    ;
    if ((OtherTestRvals_5 == (MR_Word) ((MR_Unsigned) 0U)))
      *TestRval_6 = CurTestRval_4;
    else
    {
      MR_Word HeadTestRval_7 = ((MR_Word) ((MR_hl_field(1, OtherTestRvals_5, 0))));
      MR_Word TailTestRvals_8 = ((MR_Word) ((MR_hl_field(1, OtherTestRvals_5, 1))));
      MR_Word NextTestRval_9;
      MR_Word next_value_of_CurTestRval_4;
      MR_Word next_value_of_OtherTestRvals_5;

      {
        NextTestRval_9 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (4 * sizeof(MR_Word)), NULL, NULL));
        MR_hl_field(3, NextTestRval_9, 0) = ((MR_Box) ((MR_Unsigned) 4U));
        MR_hl_field(3, NextTestRval_9, 1) = ((MR_Box) ((MR_Unsigned) 4U));
        MR_hl_field(3, NextTestRval_9, 2) = ((MR_Box) (CurTestRval_4));
        MR_hl_field(3, NextTestRval_9, 3) = ((MR_Box) (HeadTestRval_7));
      }
      // direct tailcall eliminated
      ;
      next_value_of_CurTestRval_4 = NextTestRval_9;
      next_value_of_OtherTestRvals_5 = TailTestRvals_8;
      CurTestRval_4 = next_value_of_CurTestRval_4;
      OtherTestRvals_5 = next_value_of_OtherTestRvals_5;
      continue;
    }
    break;
  }
}

void MR_CALL 
ll_backend__unify_gen_test__generate_test_var_has_cons_id_9_p_0(
  MR_Word VarRval_10,
  MR_String VarName_11,
  MR_Word ConsId_12,
  MR_Word CheaperTagTest_13,
  MR_Word Sense_14,
  MR_Word * ElseLabel_15,
  MR_Word * Code_16,
  MR_Word STATE_VARIABLE_CI_0_20,
  MR_Word * STATE_VARIABLE_CI_21)
{
  MR_bool succeeded;
  MR_Word ModuleInfo_18;
  MR_Word ConsTag_19;
  MR_String ConsIdName_22;
  MR_String Comment_27;
  MR_Word TestRval_29;
  MR_Word BranchRval_42;
  MR_Word Var_43;
  MR_Word Var_44;
  MR_Word Var_45;
  MR_Word CheapConsTag_26;
  MR_Word ExpensiveDuCtor_23;
  MR_Word Var_40;

  ll_backend__code_info__get_module_info_2_p_0(STATE_VARIABLE_CI_0_20, &ModuleInfo_18);
  ConsTag_19 = hlds__hlds_code_util__cons_id_to_tag_2_f_0(ModuleInfo_18, ConsId_12);
  ConsIdName_22 = parse_tree__parse_tree_out_cons_id__cons_id_and_arity_to_string_1_f_0(ConsId_12);
  succeeded = (CheaperTagTest_13 != (MR_Word) ((MR_Unsigned) 0U));
  if (succeeded)
  {
    ExpensiveDuCtor_23 = ((MR_Word) ((MR_hl_field(1, CheaperTagTest_13, 0))));
    CheapConsTag_26 = ((MR_Word) ((MR_hl_field(1, CheaperTagTest_13, 3))));
    succeeded = ((MR_tag((MR_Word) ConsId_12)) == (MR_Integer) 1);
    if (succeeded)
    {
      Var_40 = (MR_Word) (MR_body((MR_Word) (ConsId_12), (MR_Integer) 1));
      succeeded = parse_tree__prog_data____Unify____du_ctor_0_0(ExpensiveDuCtor_23, Var_40);
    }
  }
  if (succeeded)
  {
    MR_Word NegTestRval_28;
    MR_String Var_30;
    MR_String Var_31;
    MR_String Var_32;
    MR_String Var_34;

    switch (Sense_14) {
      default: /*NOTREACHED*/ MR_assert(0);
      case (MR_Integer) 1:
        Var_30 = (MR_String) "branch away unless ";
        break;
      case (MR_Integer) 0:
        Var_30 = (MR_String) "branch away if ";
        break;
    }
    Var_34 = mercury__string__f_43_43_2_f_0(ConsIdName_22, (MR_String) " (inverted test)");
    Var_32 = mercury__string__f_43_43_2_f_0((MR_String) " has functor ", Var_34);
    Var_31 = mercury__string__f_43_43_2_f_0(VarName_11, Var_32);
    Comment_27 = mercury__string__f_43_43_2_f_0(Var_30, Var_31);
    ll_backend__unify_gen_test__generate_test_rval_has_cons_tag_4_p_0(STATE_VARIABLE_CI_0_20, VarRval_10, CheapConsTag_26, &NegTestRval_28);
    ll_backend__code_util__negate_rval_2_p_0(NegTestRval_28, &TestRval_29);
  }
  else
  {
    MR_String Var_36;
    MR_String Var_37;
    MR_String Var_38;

    switch (Sense_14) {
      default: /*NOTREACHED*/ MR_assert(0);
      case (MR_Integer) 1:
        Var_36 = (MR_String) "branch away unless ";
        break;
      case (MR_Integer) 0:
        Var_36 = (MR_String) "branch away if ";
        break;
    }
    Var_38 = mercury__string__f_43_43_2_f_0((MR_String) " has functor ", ConsIdName_22);
    Var_37 = mercury__string__f_43_43_2_f_0(VarName_11, Var_38);
    Comment_27 = mercury__string__f_43_43_2_f_0(Var_36, Var_37);
    ll_backend__unify_gen_test__generate_test_rval_has_cons_tag_4_p_0(STATE_VARIABLE_CI_0_20, VarRval_10, ConsTag_19, &TestRval_29);
  }
  ll_backend__code_info__get_next_label_3_p_0(ElseLabel_15, STATE_VARIABLE_CI_0_20, STATE_VARIABLE_CI_21);
  switch (Sense_14) {
    default: /*NOTREACHED*/ MR_assert(0);
    case (MR_Integer) 1:
      ll_backend__code_util__negate_rval_2_p_0(TestRval_29, &BranchRval_42);
      break;
    case (MR_Integer) 0:
      BranchRval_42 = TestRval_29;
      break;
  }
  {
    Var_45 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL));
    MR_hl_field(1, Var_45, 0) = ((MR_Box) (*ElseLabel_15));
  }
  {
    Var_44 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (3 * sizeof(MR_Word)), NULL, NULL));
    MR_hl_field(3, Var_44, 0) = ((MR_Box) ((MR_Unsigned) 9U));
    MR_hl_field(3, Var_44, 1) = ((MR_Box) (BranchRval_42));
    MR_hl_field(3, Var_44, 2) = ((MR_Box) (Var_45));
  }
  {
    Var_43 = (MR_Word) MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL);
    MR_hl_field(0, Var_43, 0) = ((MR_Box) (Var_44));
    MR_hl_field(0, Var_43, 1) = ((MR_Box) (Comment_27));
  }
  *Code_16 = mercury__cord__singleton_1_f_0((MR_Word) (&ll_backend__llds__ll_backend__llds__type_ctor_info_instruction_0), ((MR_Box) (Var_43)));
}

static MR_bool MR_CALL 
ll_backend__unify_gen_test__generate_test_rval_has_cons_tag_4_p_0_1(
  MR_Box closure_arg)
{
  MR_bool succeeded;
  MR_Box closure = closure_arg;

  succeeded = ll_backend__unify_gen_test__IntroducedFrom__pred__generate_test_rval_has_cons_tag__198__1_2_p_0(((MR_Word) ((MR_hl_field(0, closure, 3)))), ((MR_Word) ((MR_hl_field(0, closure, 4)))));
  return succeeded;
}

static void MR_CALL 
ll_backend__unify_gen_test__generate_test_rval_has_cons_tag_4_p_0(
  MR_Word CI_5,
  MR_Word VarRval_6,
  MR_Word ConsTag_7,
  MR_Word * TestRval_8)
{
  MR_bool succeeded;

  switch (MR_tag((MR_Word) ConsTag_7)) {
    default: /*NOTREACHED*/ MR_assert(0);
    case (MR_Integer) 0:
      *TestRval_8 = (MR_Word) (MR_mkword(3, &ll_backend__unify_gen_test_scalar_common_1[1]));
      break;
    case (MR_Integer) 1:
      {
        MR_Word IntTag_9 = ((MR_Word) ((MR_hl_field(1, ConsTag_7, 0))));
        MR_Word Const_10;
        MR_Word IntType_11;
        MR_Word Var_65;
        MR_Word Var_67;

        ll_backend__unify_gen_util__int_tag_to_const_and_int_type_3_p_0(IntTag_9, &Const_10, &IntType_11);
        {
          Var_65 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
          MR_hl_field(3, Var_65, 0) = ((MR_Box) ((MR_Unsigned) 4U));
          MR_hl_field(3, Var_65, 1) = (MR_Box) (((((MR_Unsigned) (IntType_11) << 3)) | (MR_Unsigned) ((MR_Integer) 0)));
        }
        {
          Var_67 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
          MR_hl_field(3, Var_67, 0) = ((MR_Box) ((MR_Unsigned) 1U));
          MR_hl_field(3, Var_67, 1) = ((MR_Box) (Const_10));
        }
        {
          MR_Word base;
          base = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (4 * sizeof(MR_Word)), NULL, NULL));
          *TestRval_8 = base;
          MR_hl_field(3, base, 0) = ((MR_Box) ((MR_Unsigned) 4U));
          MR_hl_field(3, base, 1) = ((MR_Box) (Var_65));
          MR_hl_field(3, base, 2) = ((MR_Box) (VarRval_6));
          MR_hl_field(3, base, 3) = ((MR_Box) (Var_67));
        }
      }
      break;
    case (MR_Integer) 2:
      {
        MR_Float Float_12 = MR_unbox_float((MR_hl_field(2, ConsTag_7, 0)));
        MR_Word Var_70;
        MR_Word Var_71;

        {
          Var_71 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
          MR_hl_field(3, Var_71, 0) = ((MR_Box) ((MR_Unsigned) 9U));
          MR_hl_field(3, Var_71, 1) = MR_box_float(Float_12);
        }
        {
          Var_70 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
          MR_hl_field(3, Var_70, 0) = ((MR_Box) ((MR_Unsigned) 1U));
          MR_hl_field(3, Var_70, 1) = ((MR_Box) (Var_71));
        }
        {
          MR_Word base;
          base = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (4 * sizeof(MR_Word)), NULL, NULL));
          *TestRval_8 = base;
          MR_hl_field(3, base, 0) = ((MR_Box) ((MR_Unsigned) 4U));
          MR_hl_field(3, base, 1) = ((MR_Box) (MR_mkword(3, &ll_backend__unify_gen_test_scalar_common_1[2])));
          MR_hl_field(3, base, 2) = ((MR_Box) (VarRval_6));
          MR_hl_field(3, base, 3) = ((MR_Box) (Var_70));
        }
      }
      break;
    case (MR_Integer) 3:
      switch (((MR_Integer) ((MR_hl_field(3, ConsTag_7, 0))))) {
        default: /*NOTREACHED*/ MR_assert(0);
        case (MR_Integer) 0:
          {
            MR_String String_13 = ((MR_String) ((MR_hl_field(3, ConsTag_7, 1))));
            MR_Word Var_74;
            MR_Word Var_75;

            {
              Var_75 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
              MR_hl_field(3, Var_75, 0) = ((MR_Box) ((MR_Unsigned) 10U));
              MR_hl_field(3, Var_75, 1) = ((MR_Box) (String_13));
            }
            {
              Var_74 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
              MR_hl_field(3, Var_74, 0) = ((MR_Box) ((MR_Unsigned) 1U));
              MR_hl_field(3, Var_74, 1) = ((MR_Box) (Var_75));
            }
            {
              MR_Word base;
              base = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (4 * sizeof(MR_Word)), NULL, NULL));
              *TestRval_8 = base;
              MR_hl_field(3, base, 0) = ((MR_Box) ((MR_Unsigned) 4U));
              MR_hl_field(3, base, 1) = ((MR_Box) (MR_mkword(3, &ll_backend__unify_gen_test_scalar_common_1[6])));
              MR_hl_field(3, base, 2) = ((MR_Box) (VarRval_6));
              MR_hl_field(3, base, 3) = ((MR_Box) (Var_74));
            }
          }
          break;
        case (MR_Integer) 1:
          {
            MR_Word ForeignLang_14 = ((MR_Unsigned) ((MR_hl_field(3, ConsTag_7, 1))) & (MR_Integer) 3);
            MR_String ForeignVal_15 = ((MR_String) ((MR_hl_field(3, ConsTag_7, 2))));
            MR_Word Var_76;
            MR_Word Var_83;
            MR_Word Var_84;

            {
              Var_76 = (MR_Word) MR_new_object(MR_Word, (5 * sizeof(MR_Word)), NULL, NULL);
              MR_hl_field(0, Var_76, 0) = ((MR_Box) (&ll_backend__unify_gen_test_scalar_common_3[0]));
              MR_hl_field(0, Var_76, 1) = ((MR_Box) (ll_backend__unify_gen_test__generate_test_rval_has_cons_tag_4_p_0_1));
              MR_hl_field(0, Var_76, 2) = ((MR_Box) ((MR_Integer) 2));
              MR_hl_field(0, Var_76, 3) = ((MR_Box) (ForeignLang_14));
              MR_hl_field(0, Var_76, 4) = ((MR_Box) ((MR_Integer) 0));
            }
            mercury__require__expect_3_p_0(Var_76, (MR_String) "predicate \140ll_backend.unify_gen_test.generate_test_rval_has_cons_tag\'/4", (MR_String) "foreign tag for language other than C");
            {
              Var_84 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (3 * sizeof(MR_Word)), NULL, NULL));
              MR_hl_field(3, Var_84, 0) = ((MR_Box) ((MR_Unsigned) 8U));
              MR_hl_field(3, Var_84, 1) = ((MR_Box) (ForeignVal_15));
              MR_hl_field(3, Var_84, 2) = ((MR_Box) (MR_mkword(2, &ll_backend__unify_gen_test_scalar_common_2[0])));
            }
            {
              Var_83 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
              MR_hl_field(3, Var_83, 0) = ((MR_Box) ((MR_Unsigned) 1U));
              MR_hl_field(3, Var_83, 1) = ((MR_Box) (Var_84));
            }
            {
              MR_Word base;
              base = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (4 * sizeof(MR_Word)), NULL, NULL));
              *TestRval_8 = base;
              MR_hl_field(3, base, 0) = ((MR_Box) ((MR_Unsigned) 4U));
              MR_hl_field(3, base, 1) = ((MR_Box) (MR_mkword(3, &ll_backend__unify_gen_test_scalar_common_1[0])));
              MR_hl_field(3, base, 2) = ((MR_Box) (VarRval_6));
              MR_hl_field(3, base, 3) = ((MR_Box) (Var_83));
            }
          }
          break;
        case (MR_Integer) 2:
          {
            MR_Word MustMask_46 = ((MR_Unsigned) ((MR_hl_field(3, ConsTag_7, 3))) & (MR_Integer) 1);
            MR_Word Var_137;
            MR_Integer Var_138;
            MR_Word SectagBits_188;
            MR_Word LocalSectag_190 = ((MR_Word) ((MR_hl_field(3, ConsTag_7, 2))));
            MR_Unsigned PrimSec_192 = ((MR_Unsigned) ((MR_hl_field(0, LocalSectag_190, 1))));
            MR_Word ConstPrimSecRval_193;

            SectagBits_188 = ((MR_Word) ((MR_hl_field(0, LocalSectag_190, 2))));
            Var_138 = mercury__uint__cast_to_int_1_f_0(PrimSec_192);
            {
              Var_137 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL));
              MR_hl_field(1, Var_137, 0) = ((MR_Box) (Var_138));
            }
            {
              ConstPrimSecRval_193 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
              MR_hl_field(3, ConstPrimSecRval_193, 0) = ((MR_Box) ((MR_Unsigned) 1U));
              MR_hl_field(3, ConstPrimSecRval_193, 1) = ((MR_Box) (Var_137));
            }
            switch (MustMask_46) {
              default: /*NOTREACHED*/ MR_assert(0);
              case (MR_Integer) 0:
                {
                  MR_Word base;
                  base = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (4 * sizeof(MR_Word)), NULL, NULL));
                  *TestRval_8 = base;
                  MR_hl_field(3, base, 0) = ((MR_Box) ((MR_Unsigned) 4U));
                  MR_hl_field(3, base, 1) = ((MR_Box) (MR_mkword(3, &ll_backend__unify_gen_test_scalar_common_1[0])));
                  MR_hl_field(3, base, 2) = ((MR_Box) (VarRval_6));
                  MR_hl_field(3, base, 3) = ((MR_Box) (ConstPrimSecRval_193));
                }
                break;
              case (MR_Integer) 1:
                {
                  uint8_t Var_142;
                  MR_Unsigned Var_143;
                  MR_Word Var_148;
                  MR_Word Var_149;
                  uint8_t NumPtagBits_176;
                  uint8_t NumSectagBits_177;
                  MR_Integer NumPtagSectagBits_179;
                  MR_Unsigned PrimSecMask_180;
                  MR_Word MaskedVarRval_181;

                  ll_backend__code_info__get_num_ptag_bits_2_p_0(CI_5, &NumPtagBits_176);
                  NumSectagBits_177 = ((uint8_t) (MR_Word) (MR_hl_field(0, SectagBits_188, 0)));
                  Var_142 = (NumPtagBits_176 + NumSectagBits_177);
                  NumPtagSectagBits_179 = mercury__uint8__cast_to_int_1_f_0(Var_142);
                  Var_143 = mercury__uint__f_60_60_2_f_0((MR_Unsigned) 1U, NumPtagSectagBits_179);
                  PrimSecMask_180 = (Var_143 - (MR_Unsigned) 1U);
                  {
                    Var_149 = (MR_Word) MR_mkword(2, MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL));
                    MR_hl_field(2, Var_149, 0) = ((MR_Box) (PrimSecMask_180));
                  }
                  {
                    Var_148 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
                    MR_hl_field(3, Var_148, 0) = ((MR_Box) ((MR_Unsigned) 1U));
                    MR_hl_field(3, Var_148, 1) = ((MR_Box) (Var_149));
                  }
                  {
                    MaskedVarRval_181 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (4 * sizeof(MR_Word)), NULL, NULL));
                    MR_hl_field(3, MaskedVarRval_181, 0) = ((MR_Box) ((MR_Unsigned) 4U));
                    MR_hl_field(3, MaskedVarRval_181, 1) = ((MR_Box) (MR_mkword(3, &ll_backend__unify_gen_test_scalar_common_1[3])));
                    MR_hl_field(3, MaskedVarRval_181, 2) = ((MR_Box) (VarRval_6));
                    MR_hl_field(3, MaskedVarRval_181, 3) = ((MR_Box) (Var_148));
                  }
                  {
                    MR_Word base;
                    base = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (4 * sizeof(MR_Word)), NULL, NULL));
                    *TestRval_8 = base;
                    MR_hl_field(3, base, 0) = ((MR_Box) ((MR_Unsigned) 4U));
                    MR_hl_field(3, base, 1) = ((MR_Box) (MR_mkword(3, &ll_backend__unify_gen_test_scalar_common_1[4])));
                    MR_hl_field(3, base, 2) = ((MR_Box) (MaskedVarRval_181));
                    MR_hl_field(3, base, 3) = ((MR_Box) (ConstPrimSecRval_193));
                  }
                }
                break;
            }
          }
          break;
        case (MR_Integer) 3:
        case (MR_Integer) 4:
        case (MR_Integer) 5:
        case (MR_Integer) 6:
        case (MR_Integer) 7:
        case (MR_Integer) 8:
        case (MR_Integer) 9:
        case (MR_Integer) 10:
        case (MR_Integer) 14:
          {
            mercury__require__unexpected_2_p_0((MR_String) "predicate \140ll_backend.unify_gen_test.generate_test_rval_has_cons_tag\'/4", (MR_String) "unexpected ConsTag");
            return;
          }
          break;
        case (MR_Integer) 11:
          {
            MR_Word RemoteArgsTagInfo_20 = ((MR_Word) ((MR_hl_field(3, ConsTag_7, 1))));

            switch (MR_tag((MR_Word) RemoteArgsTagInfo_20)) {
              default: /*NOTREACHED*/ MR_assert(0);
              case (MR_Integer) 0:
                *TestRval_8 = (MR_Word) (MR_mkword(3, &ll_backend__unify_gen_test_scalar_common_1[1]));
                break;
              case (MR_Integer) 1:
                {
                  MR_Word Var_96;
                  MR_Integer Var_97;
                  MR_Word Ptag_155 = ((MR_Word) ((MR_hl_field(1, RemoteArgsTagInfo_20, 0))));
                  MR_Word VarPtag_156;
                  uint8_t PtagUint8_157;
                  MR_Word PtagConstRval_158;

                  {
                    VarPtag_156 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (3 * sizeof(MR_Word)), NULL, NULL));
                    MR_hl_field(3, VarPtag_156, 0) = ((MR_Box) ((MR_Unsigned) 3U));
                    MR_hl_field(3, VarPtag_156, 1) = ((MR_Box) ((MR_Unsigned) 0U));
                    MR_hl_field(3, VarPtag_156, 2) = ((MR_Box) (VarRval_6));
                  }
                  PtagUint8_157 = (uint8_t) (Ptag_155);
                  Var_97 = mercury__uint8__cast_to_int_1_f_0(PtagUint8_157);
                  {
                    Var_96 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL));
                    MR_hl_field(1, Var_96, 0) = ((MR_Box) (Var_97));
                  }
                  {
                    PtagConstRval_158 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
                    MR_hl_field(3, PtagConstRval_158, 0) = ((MR_Box) ((MR_Unsigned) 1U));
                    MR_hl_field(3, PtagConstRval_158, 1) = ((MR_Box) (Var_96));
                  }
                  {
                    MR_Word base;
                    base = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (4 * sizeof(MR_Word)), NULL, NULL));
                    *TestRval_8 = base;
                    MR_hl_field(3, base, 0) = ((MR_Box) ((MR_Unsigned) 4U));
                    MR_hl_field(3, base, 1) = ((MR_Box) (MR_mkword(3, &ll_backend__unify_gen_test_scalar_common_1[0])));
                    MR_hl_field(3, base, 2) = ((MR_Box) (VarPtag_156));
                    MR_hl_field(3, base, 3) = ((MR_Box) (PtagConstRval_158));
                  }
                }
                break;
              case (MR_Integer) 2:
                {
                  MR_Word RemoteSectag_21 = ((MR_Word) ((MR_hl_field(2, RemoteArgsTagInfo_20, 1))));
                  MR_Word ConstPtagRval_22;
                  MR_Word PtagTestRval_23;
                  MR_Word VarSectagWordRval_24;
                  MR_Unsigned SecTagUint_25;
                  MR_Word SectagSize_26;
                  MR_Word VarSectagRval_27;
                  MR_Word ConstSectagRval_31;
                  MR_Word SectagTestRval_32;
                  MR_Word Var_102;
                  MR_Integer Var_103;
                  MR_Word Var_107;
                  MR_Word Var_108;
                  MR_Word Var_116;
                  MR_Integer Var_117;
                  MR_Word Ptag_159 = ((MR_Word) ((MR_hl_field(2, RemoteArgsTagInfo_20, 0))));
                  MR_Word VarPtag_160;
                  uint8_t PtagUint8_161;

                  {
                    VarPtag_160 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (3 * sizeof(MR_Word)), NULL, NULL));
                    MR_hl_field(3, VarPtag_160, 0) = ((MR_Box) ((MR_Unsigned) 3U));
                    MR_hl_field(3, VarPtag_160, 1) = ((MR_Box) ((MR_Unsigned) 0U));
                    MR_hl_field(3, VarPtag_160, 2) = ((MR_Box) (VarRval_6));
                  }
                  PtagUint8_161 = (uint8_t) (Ptag_159);
                  Var_103 = mercury__uint8__cast_to_int_1_f_0(PtagUint8_161);
                  {
                    Var_102 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL));
                    MR_hl_field(1, Var_102, 0) = ((MR_Box) (Var_103));
                  }
                  {
                    ConstPtagRval_22 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
                    MR_hl_field(3, ConstPtagRval_22, 0) = ((MR_Box) ((MR_Unsigned) 1U));
                    MR_hl_field(3, ConstPtagRval_22, 1) = ((MR_Box) (Var_102));
                  }
                  {
                    PtagTestRval_23 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (4 * sizeof(MR_Word)), NULL, NULL));
                    MR_hl_field(3, PtagTestRval_23, 0) = ((MR_Box) ((MR_Unsigned) 4U));
                    MR_hl_field(3, PtagTestRval_23, 1) = ((MR_Box) (MR_mkword(3, &ll_backend__unify_gen_test_scalar_common_1[0])));
                    MR_hl_field(3, PtagTestRval_23, 2) = ((MR_Box) (VarPtag_160));
                    MR_hl_field(3, PtagTestRval_23, 3) = ((MR_Box) (ConstPtagRval_22));
                  }
                  {
                    Var_108 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL));
                    MR_hl_field(1, Var_108, 0) = ((MR_Box) (Ptag_159));
                  }
                  {
                    Var_107 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (4 * sizeof(MR_Word)), NULL, NULL));
                    MR_hl_field(3, Var_107, 0) = ((MR_Box) ((MR_Unsigned) 9U));
                    MR_hl_field(3, Var_107, 1) = ((MR_Box) (Var_108));
                    MR_hl_field(3, Var_107, 2) = ((MR_Box) (VarRval_6));
                    MR_hl_field(3, Var_107, 3) = ((MR_Box) (MR_mkword(3, &ll_backend__unify_gen_test_scalar_common_1[5])));
                  }
                  {
                    VarSectagWordRval_24 = (MR_Word) MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL);
                    MR_hl_field(0, VarSectagWordRval_24, 0) = ((MR_Box) (Var_107));
                  }
                  SecTagUint_25 = ((MR_Unsigned) ((MR_hl_field(0, RemoteSectag_21, 0))));
                  SectagSize_26 = ((MR_Word) ((MR_hl_field(0, RemoteSectag_21, 1))));
                  if ((SectagSize_26 == (MR_Word) ((MR_Unsigned) 0U)))
                    VarSectagRval_27 = VarSectagWordRval_24;
                  else
                  {
                    MR_Word SectagBits_28 = (MR_Word) (MR_body((MR_Word) (SectagSize_26), (MR_Integer) 1));
                    MR_Unsigned SectagMask_30 = ((MR_Unsigned) ((MR_hl_field(0, SectagBits_28, 1))));
                    MR_Word Var_114;
                    MR_Word Var_115;

                    {
                      Var_115 = (MR_Word) MR_mkword(2, MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL));
                      MR_hl_field(2, Var_115, 0) = ((MR_Box) (SectagMask_30));
                    }
                    {
                      Var_114 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
                      MR_hl_field(3, Var_114, 0) = ((MR_Box) ((MR_Unsigned) 1U));
                      MR_hl_field(3, Var_114, 1) = ((MR_Box) (Var_115));
                    }
                    {
                      VarSectagRval_27 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (4 * sizeof(MR_Word)), NULL, NULL));
                      MR_hl_field(3, VarSectagRval_27, 0) = ((MR_Box) ((MR_Unsigned) 4U));
                      MR_hl_field(3, VarSectagRval_27, 1) = ((MR_Box) (MR_mkword(3, &ll_backend__unify_gen_test_scalar_common_1[3])));
                      MR_hl_field(3, VarSectagRval_27, 2) = ((MR_Box) (VarSectagWordRval_24));
                      MR_hl_field(3, VarSectagRval_27, 3) = ((MR_Box) (Var_114));
                    }
                  }
                  Var_117 = mercury__uint__cast_to_int_1_f_0(SecTagUint_25);
                  {
                    Var_116 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL));
                    MR_hl_field(1, Var_116, 0) = ((MR_Box) (Var_117));
                  }
                  {
                    ConstSectagRval_31 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
                    MR_hl_field(3, ConstSectagRval_31, 0) = ((MR_Box) ((MR_Unsigned) 1U));
                    MR_hl_field(3, ConstSectagRval_31, 1) = ((MR_Box) (Var_116));
                  }
                  {
                    SectagTestRval_32 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (4 * sizeof(MR_Word)), NULL, NULL));
                    MR_hl_field(3, SectagTestRval_32, 0) = ((MR_Box) ((MR_Unsigned) 4U));
                    MR_hl_field(3, SectagTestRval_32, 1) = ((MR_Box) (MR_mkword(3, &ll_backend__unify_gen_test_scalar_common_1[0])));
                    MR_hl_field(3, SectagTestRval_32, 2) = ((MR_Box) (VarSectagRval_27));
                    MR_hl_field(3, SectagTestRval_32, 3) = ((MR_Box) (ConstSectagRval_31));
                  }
                  {
                    MR_Word base;
                    base = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (4 * sizeof(MR_Word)), NULL, NULL));
                    *TestRval_8 = base;
                    MR_hl_field(3, base, 0) = ((MR_Box) ((MR_Unsigned) 4U));
                    MR_hl_field(3, base, 1) = ((MR_Box) ((MR_Unsigned) 0U));
                    MR_hl_field(3, base, 2) = ((MR_Box) (PtagTestRval_23));
                    MR_hl_field(3, base, 3) = ((MR_Box) (SectagTestRval_32));
                  }
                }
                break;
              case (MR_Integer) 3:
                {
                  mercury__require__unexpected_2_p_0((MR_String) "predicate \140ll_backend.unify_gen_test.generate_test_rval_has_cons_tag\'/4", (MR_String) "remote_args_ctor");
                  return;
                }
                break;
            }
          }
          break;
        case (MR_Integer) 12:
          {
            MR_Word LocalArgsTagInfo_34 = ((MR_Word) ((MR_hl_field(3, ConsTag_7, 1))));

            if ((LocalArgsTagInfo_34 == (MR_Word) ((MR_Unsigned) 0U)))
              *TestRval_8 = (MR_Word) (MR_mkword(3, &ll_backend__unify_gen_test_scalar_common_1[1]));
            else
            {
              MR_Word LocalSectag_36 = ((MR_Word) ((MR_hl_field(1, LocalArgsTagInfo_34, 1))));
              MR_Unsigned PrimSec_38 = ((MR_Unsigned) ((MR_hl_field(0, LocalSectag_36, 1))));
              MR_Word ConstPrimSecRval_39;
              uint8_t NumPtagBits_40;
              uint8_t NumSectagBits_41;
              MR_Integer NumPtagSectagBits_43;
              MR_Unsigned PrimSecMask_44;
              MR_Word MaskedVarRval_45;
              MR_Word Var_125;
              uint8_t Var_126;
              MR_Unsigned Var_127;
              MR_Word Var_132;
              MR_Word Var_133;
              MR_Word SectagBits_170 = ((MR_Word) ((MR_hl_field(0, LocalSectag_36, 2))));

              {
                Var_125 = (MR_Word) MR_mkword(2, MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL));
                MR_hl_field(2, Var_125, 0) = ((MR_Box) (PrimSec_38));
              }
              {
                ConstPrimSecRval_39 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
                MR_hl_field(3, ConstPrimSecRval_39, 0) = ((MR_Box) ((MR_Unsigned) 1U));
                MR_hl_field(3, ConstPrimSecRval_39, 1) = ((MR_Box) (Var_125));
              }
              ll_backend__code_info__get_num_ptag_bits_2_p_0(CI_5, &NumPtagBits_40);
              NumSectagBits_41 = ((uint8_t) (MR_Word) (MR_hl_field(0, SectagBits_170, 0)));
              Var_126 = (NumPtagBits_40 + NumSectagBits_41);
              NumPtagSectagBits_43 = mercury__uint8__cast_to_int_1_f_0(Var_126);
              Var_127 = mercury__uint__f_60_60_2_f_0((MR_Unsigned) 1U, NumPtagSectagBits_43);
              PrimSecMask_44 = (Var_127 - (MR_Unsigned) 1U);
              {
                Var_133 = (MR_Word) MR_mkword(2, MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL));
                MR_hl_field(2, Var_133, 0) = ((MR_Box) (PrimSecMask_44));
              }
              {
                Var_132 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
                MR_hl_field(3, Var_132, 0) = ((MR_Box) ((MR_Unsigned) 1U));
                MR_hl_field(3, Var_132, 1) = ((MR_Box) (Var_133));
              }
              {
                MaskedVarRval_45 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (4 * sizeof(MR_Word)), NULL, NULL));
                MR_hl_field(3, MaskedVarRval_45, 0) = ((MR_Box) ((MR_Unsigned) 4U));
                MR_hl_field(3, MaskedVarRval_45, 1) = ((MR_Box) (MR_mkword(3, &ll_backend__unify_gen_test_scalar_common_1[3])));
                MR_hl_field(3, MaskedVarRval_45, 2) = ((MR_Box) (VarRval_6));
                MR_hl_field(3, MaskedVarRval_45, 3) = ((MR_Box) (Var_132));
              }
              {
                MR_Word base;
                base = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (4 * sizeof(MR_Word)), NULL, NULL));
                *TestRval_8 = base;
                MR_hl_field(3, base, 0) = ((MR_Box) ((MR_Unsigned) 4U));
                MR_hl_field(3, base, 1) = ((MR_Box) (MR_mkword(3, &ll_backend__unify_gen_test_scalar_common_1[4])));
                MR_hl_field(3, base, 2) = ((MR_Box) (MaskedVarRval_45));
                MR_hl_field(3, base, 3) = ((MR_Box) (ConstPrimSecRval_39));
              }
            }
          }
          break;
        case (MR_Integer) 13:
          {
            MR_Word Ptag_16 = ((MR_Word) ((MR_hl_field(3, ConsTag_7, 1))));
            MR_Word VarPtag_17;
            uint8_t PtagUint8_18;
            MR_Word PtagConstRval_19;
            MR_Word Var_89;
            MR_Integer Var_90;

            {
              VarPtag_17 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (3 * sizeof(MR_Word)), NULL, NULL));
              MR_hl_field(3, VarPtag_17, 0) = ((MR_Box) ((MR_Unsigned) 3U));
              MR_hl_field(3, VarPtag_17, 1) = ((MR_Box) ((MR_Unsigned) 0U));
              MR_hl_field(3, VarPtag_17, 2) = ((MR_Box) (VarRval_6));
            }
            PtagUint8_18 = (uint8_t) (Ptag_16);
            Var_90 = mercury__uint8__cast_to_int_1_f_0(PtagUint8_18);
            {
              Var_89 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (1 * sizeof(MR_Word)), NULL, NULL));
              MR_hl_field(1, Var_89, 0) = ((MR_Box) (Var_90));
            }
            {
              PtagConstRval_19 = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
              MR_hl_field(3, PtagConstRval_19, 0) = ((MR_Box) ((MR_Unsigned) 1U));
              MR_hl_field(3, PtagConstRval_19, 1) = ((MR_Box) (Var_89));
            }
            {
              MR_Word base;
              base = (MR_Word) MR_mkword(3, MR_new_object(MR_Word, (4 * sizeof(MR_Word)), NULL, NULL));
              *TestRval_8 = base;
              MR_hl_field(3, base, 0) = ((MR_Box) ((MR_Unsigned) 4U));
              MR_hl_field(3, base, 1) = ((MR_Box) (MR_mkword(3, &ll_backend__unify_gen_test_scalar_common_1[0])));
              MR_hl_field(3, base, 2) = ((MR_Box) (VarPtag_17));
              MR_hl_field(3, base, 3) = ((MR_Box) (PtagConstRval_19));
            }
          }
          break;
      }
      break;
  }
}

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

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

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

  ll_backend__unify_gen_test____Compare____test_sense_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__ll_backend__unify_gen_test__init(void)
{
}

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

  MR_register_type_ctor_info(&ll_backend__unify_gen_test__ll_backend__unify_gen_test__type_ctor_info_test_sense_0);
}

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

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

// :- end_module ll_backend.unify_gen_test.
