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

/*
INIT mercury__version_array2d__init
ENDINIT
*/

#include "version_array2d.mih"


#include "array.mih"
#include "assoc_list.mih"
#include "benchmarking.mih"
#include "bitmap.mih"
#include "bool.mih"
#include "builtin.mih"
#include "calendar.mih"
#include "char.mih"
#include "construct.mih"
#include "cord.mih"
#include "counter.mih"
#include "deconstruct.mih"
#include "dir.mih"
#include "enum.mih"
#include "exception.mih"
#include "float.mih"
#include "int.mih"
#include "int16.mih"
#include "int32.mih"
#include "int64.mih"
#include "int8.mih"
#include "integer.mih"
#include "io.mih"
#include "list.mih"
#include "map.mih"
#include "maybe.mih"
#include "mercury_term_lexer.mih"
#include "mercury_term_parser.mih"
#include "mutvar.mih"
#include "one_or_more.mih"
#include "ops.mih"
#include "pair.mih"
#include "pretty_printer.mih"
#include "private_builtin.mih"
#include "require.mih"
#include "rtti_implementation.mih"
#include "set.mih"
#include "set_ordlist.mih"
#include "set_tree234.mih"
#include "solutions.mih"
#include "stm_builtin.mih"
#include "store.mih"
#include "stream.mih"
#include "string.mih"
#include "table_builtin.mih"
#include "term.mih"
#include "term_context.mih"
#include "term_conversion.mih"
#include "term_int.mih"
#include "term_io.mih"
#include "term_subst.mih"
#include "term_unify.mih"
#include "term_vars.mih"
#include "time.mih"
#include "tree234.mih"
#include "type_desc.mih"
#include "uint.mih"
#include "uint16.mih"
#include "uint32.mih"
#include "uint64.mih"
#include "uint8.mih"
#include "unit.mih"
#include "univ.mih"
#include "varset.mih"
#include "version_array.mih"
#include "io.call_system.mih"
#include "io.environment.mih"
#include "io.error_util.mih"
#include "io.file.mih"
#include "io.primitives_read.mih"
#include "io.primitives_write.mih"
#include "io.stream_db.mih"
#include "io.stream_ops.mih"
#include "io.text_read.mih"
#include "stream.string_writer.mih"
#include "string.builder.mih"
#include "string.format.mih"
#include "string.parse_runtime.mih"
#include "string.parse_util.mih"
#include "string.to_string.mih"



struct mercury__version_array2d__version_array2d_2_f_0_env_0_s {
  MR_Word mercury__version_array2d__version_array2d_2_f_0_env_0__TypeInfo_for_T_18;
  MR_Word mercury__version_array2d__version_array2d_2_f_0_env_0__HeadVar__1_1;
  MR_bool mercury__version_array2d__version_array2d_2_f_0_env_0__succeeded;
  MR_Word mercury__version_array2d__version_array2d_2_f_0_env_0__TypeInfo_9_27;
  MR_Integer mercury__version_array2d__version_array2d_2_f_0_env_0__N_12;
  jmp_buf mercury__version_array2d__version_array2d_2_f_0_env_0__commit_0;
  MR_Word mercury__version_array2d__version_array2d_2_f_0_env_0__Ys_14;
  MR_Box mercury__version_array2d__version_array2d_2_f_0_env_0__conv1_Ys_14;
};


static const MR_FA_PseudoTypeInfo_Struct1 mercury__version_array2d__version_array__pti_version_array_1__pseudo_1;

static const MR_PseudoTypeInfo mercury__version_array2d__version_array2d__field_types_version_array2d_1_0[3];

static const MR_DuFunctorDesc mercury__version_array2d__version_array2d__du_functor_desc_version_array2d_1_0;

static const MR_DuFunctorDescPtr mercury__version_array2d__version_array2d__du_stag_ordered_version_array2d_1_0[1];

static const MR_DuPtagLayout mercury__version_array2d__version_array2d__du_ptag_ordered_version_array2d_1[1];

static const MR_DuFunctorDescPtr mercury__version_array2d__version_array2d__du_name_ordered_version_array2d_1[1];

static const MR_Integer mercury__version_array2d__version_array2d__functor_number_map_version_array2d_1[1];

static MR_Word MR_CALL 
mercury__version_array2d__f_85_110_117_115_101_100_65_114_103_115_95_95_102_117_110_99_95_95_108_105_115_116_115_95_50_95_95_91_49_93_95_48_6_f_0(
  MR_Integer IJ_8,
  MR_Integer J_9,
  MR_Integer N_10,
  MR_Box VA_11,
  MR_Word Xs_12,
  MR_Word Xss_13);

static void MR_CALL 
mercury__version_array2d__version_array2d_1_f_0_1(
  void * env_ptr_arg);

static void MR_CALL 
mercury__version_array2d__version_array2d_1_f_0_3(
  void * env_ptr_arg);

static void MR_CALL 
mercury__version_array2d__version_array2d_1_f_0_2(
  void * env_ptr_arg);

static void MR_CALL 
mercury__version_array2d__version_array2d_1_f_0_4(
  void * env_ptr_arg);

static MR_bool MR_CALL 
mercury__version_array2d____Unify____version_array2d_1_0_10001(
  MR_Box wrapper_arg_1,
  MR_Box wrapper_arg_2,
  MR_Box wrapper_arg_3);

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


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

static /* final */ const MR_Box mercury__version_array2d_scalar_common_2[1][4];

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




static /* final */ const MR_Box mercury__version_array2d_scalar_common_1[1][3] = {
  /* row   0 */
  {
    ((MR_Box) (base_typeclass_info_stream__stream__arity2__io__text_output_stream__arity0__io__state__arity0__)),
    ((MR_Box) (&mercury__io__io__type_ctor_info_text_output_stream_0)),
    ((MR_Box) (&mercury__io__io__type_ctor_info_state_0))
  },
};

static /* final */ const MR_Box mercury__version_array2d_scalar_common_2[1][4] = {
  /* row   0 */
  {
    ((MR_Box) (base_typeclass_info_stream__output__arity2__io__text_output_stream__arity0__io__state__arity0__)),
    ((MR_Box) (&mercury__version_array2d_scalar_common_1[0])),
    ((MR_Box) (&mercury__io__io__type_ctor_info_text_output_stream_0)),
    ((MR_Box) (&mercury__io__io__type_ctor_info_state_0))
  },
};

static /* final */ const MR_Box mercury__version_array2d_scalar_common_3[1][5] = {
  /* row   0 */
  {
    ((MR_Box) (base_typeclass_info_stream__writer__arity3__io__text_output_stream__arity0__string__arity0__io__state__arity0__)),
    ((MR_Box) (&mercury__version_array2d_scalar_common_2[0])),
    ((MR_Box) (&mercury__io__io__type_ctor_info_text_output_stream_0)),
    ((MR_Box) (&mercury__builtin__builtin__type_ctor_info_string_0)),
    ((MR_Box) (&mercury__io__io__type_ctor_info_state_0))
  },
};



#include "array.mh"
#include "benchmarking.mh"
#include "bitmap.mh"
#include "builtin.mh"
#include "char.mh"
#include "construct.mh"
#include "dir.mh"
#include "exception.mh"
#include "float.mh"
#include "int.mh"
#include "int16.mh"
#include "int32.mh"
#include "int64.mh"
#include "int8.mh"
#include "io.mh"
#include "pretty_printer.mh"
#include "private_builtin.mh"
#include "rtti_implementation.mh"
#include "stm_builtin.mh"
#include "store.mh"
#include "string.mh"
#include "table_builtin.mh"
#include "time.mh"
#include "type_desc.mh"
#include "uint.mh"
#include "uint16.mh"
#include "uint32.mh"
#include "uint64.mh"
#include "uint8.mh"
#include "version_array.mh"
#include "io.environment.mh"
#include "io.error_util.mh"
#include "io.file.mh"
#include "io.primitives_read.mh"
#include "io.primitives_write.mh"
#include "io.stream_db.mh"
#include "io.stream_ops.mh"
#include "io.text_read.mh"


static const MR_FA_PseudoTypeInfo_Struct1 mercury__version_array2d__version_array__pti_version_array_1__pseudo_1 = {
  &mercury__version_array__version_array__type_ctor_info_version_array_1,
  { (MR_PseudoTypeInfo) ((MR_Integer) 1) }
};

static const MR_PseudoTypeInfo mercury__version_array2d__version_array2d__field_types_version_array2d_1_0[3] = {
  (MR_PseudoTypeInfo) (&mercury__builtin__builtin__type_ctor_info_int_0),
  (MR_PseudoTypeInfo) (&mercury__builtin__builtin__type_ctor_info_int_0),
  (MR_PseudoTypeInfo) (&mercury__version_array2d__version_array__pti_version_array_1__pseudo_1)
};

static const MR_DuFunctorDesc mercury__version_array2d__version_array2d__du_functor_desc_version_array2d_1_0 = {
  (MR_String) "version_array2d",
  INT16_C(3),
  UINT16_C(4),
  MR_SECTAG_NONE,
  UINT8_C(0),
  (MR_Integer) -1,
  INT32_C(0),
  mercury__version_array2d__version_array2d__field_types_version_array2d_1_0,
  NULL,
  NULL,
  NULL,
  MR_FUNCTOR_SUBTYPE_NONE,
  UINT8_C(0)
};

static const MR_DuFunctorDescPtr mercury__version_array2d__version_array2d__du_stag_ordered_version_array2d_1_0[1] = { &mercury__version_array2d__version_array2d__du_functor_desc_version_array2d_1_0 };

static const MR_DuPtagLayout mercury__version_array2d__version_array2d__du_ptag_ordered_version_array2d_1[1] = {
  {
    UINT32_C(1),
    MR_SECTAG_NONE,
    mercury__version_array2d__version_array2d__du_stag_ordered_version_array2d_1_0,
    INT8_C(-1),
    UINT8_C(0),
    UINT8_C(1)
  }
};

static const MR_DuFunctorDescPtr mercury__version_array2d__version_array2d__du_name_ordered_version_array2d_1[1] = { &mercury__version_array2d__version_array2d__du_functor_desc_version_array2d_1_0 };

static const MR_Integer mercury__version_array2d__version_array2d__functor_number_map_version_array2d_1[1] = { (MR_Integer) 0 };

const MR_TypeCtorInfo_Struct mercury__version_array2d__version_array2d__type_ctor_info_version_array2d_1 = {
  (MR_Integer) 1,
  UINT8_C(18),
  INT8_C(1),
  MR_TYPECTOR_REP_DU,
  ((MR_Box) (mercury__version_array2d____Unify____version_array2d_1_0_10001)),
  ((MR_Box) (mercury__version_array2d____Compare____version_array2d_1_0_10001)),
  (MR_String) "version_array2d",
  (MR_String) "version_array2d",
  { mercury__version_array2d__version_array2d__du_name_ordered_version_array2d_1 },
  { mercury__version_array2d__version_array2d__du_ptag_ordered_version_array2d_1 },
  (MR_Integer) 1,
  UINT16_C(12),
  mercury__version_array2d__version_array2d__functor_number_map_version_array2d_1,

};

void MR_CALL 
mercury__version_array2d____Compare____version_array2d_1_0(
  MR_Word TypeInfo_for_T_14,
  MR_Word * HeadVar__1_1,
  MR_Word HeadVar__2_2,
  MR_Word HeadVar__3_3)
{
  MR_bool succeeded;
  MR_Integer CastX_12 = (MR_Integer) (HeadVar__2_2);
  MR_Integer CastY_13 = (MR_Integer) (HeadVar__3_3);

  succeeded = (CastX_12 == CastY_13);
  if (succeeded)
    *HeadVar__1_1 = (MR_Integer) 0;
  else
  {
    MR_Integer ArgX1_4 = ((MR_Integer) ((MR_hl_field(0, HeadVar__2_2, (MR_Integer) 0))));
    MR_Integer ArgY1_5 = ((MR_Integer) ((MR_hl_field(0, HeadVar__3_3, (MR_Integer) 0))));
    MR_Integer ArgX2_7 = ((MR_Integer) ((MR_hl_field(0, HeadVar__2_2, (MR_Integer) 1))));
    MR_Integer ArgY2_8 = ((MR_Integer) ((MR_hl_field(0, HeadVar__3_3, (MR_Integer) 1))));
    MR_Box ArgX3_10 = ((MR_Box) ((MR_hl_field(0, HeadVar__2_2, (MR_Integer) 2))));
    MR_Box ArgY3_11 = ((MR_Box) ((MR_hl_field(0, HeadVar__3_3, (MR_Integer) 2))));
    MR_Word SubResult1_6;

    succeeded = (ArgX1_4 < ArgY1_5);
    if (succeeded)
      SubResult1_6 = (MR_Integer) 1;
    else
    {
      succeeded = (ArgX1_4 == ArgY1_5);
      if (succeeded)
        SubResult1_6 = (MR_Integer) 0;
      else
        SubResult1_6 = (MR_Integer) 2;
    }
    succeeded = (SubResult1_6 != (MR_Integer) 0);
    if (succeeded)
      *HeadVar__1_1 = SubResult1_6;
    else
    {
      MR_Word SubResult2_9;

      succeeded = (ArgX2_7 < ArgY2_8);
      if (succeeded)
        SubResult2_9 = (MR_Integer) 1;
      else
      {
        succeeded = (ArgX2_7 == ArgY2_8);
        if (succeeded)
          SubResult2_9 = (MR_Integer) 0;
        else
          SubResult2_9 = (MR_Integer) 2;
      }
      succeeded = (SubResult2_9 != (MR_Integer) 0);
      if (succeeded)
        *HeadVar__1_1 = SubResult2_9;
      else
        mercury__version_array____Compare____version_array_1_0(TypeInfo_for_T_14, HeadVar__1_1, ArgX3_10, ArgY3_11);
    }
  }
}

MR_bool MR_CALL 
mercury__version_array2d____Unify____version_array2d_1_0(
  MR_Word TypeInfo_for_T_11,
  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
  {
    MR_Integer ArgX1_3 = ((MR_Integer) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 0))));
    MR_Integer ArgY1_4 = ((MR_Integer) ((MR_hl_field(0, HeadVar__2_2, (MR_Integer) 0))));
    MR_Integer ArgX2_5 = ((MR_Integer) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 1))));
    MR_Integer ArgY2_6 = ((MR_Integer) ((MR_hl_field(0, HeadVar__2_2, (MR_Integer) 1))));
    MR_Box ArgX3_7 = ((MR_Box) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 2))));
    MR_Box ArgY3_8 = ((MR_Box) ((MR_hl_field(0, HeadVar__2_2, (MR_Integer) 2))));

    succeeded = (ArgX1_3 == ArgY1_4);
    if (succeeded)
    {
      succeeded = (ArgX2_5 == ArgY2_6);
      if (succeeded)
        succeeded = mercury__version_array____Unify____version_array_1_0(TypeInfo_for_T_11, ArgX3_7, ArgY3_8);
    }
  }
  return succeeded;
}

MR_Word MR_CALL 
mercury__version_array2d__unsafe_rewind_1_f_0(
  MR_Word TypeInfo_for_T_7,
  MR_Word HeadVar__1_1)
{
  MR_Word HeadVar__2_2;
  MR_Integer M_3 = ((MR_Integer) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 0))));
  MR_Integer N_4 = ((MR_Integer) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 1))));
  MR_Box VA_5 = ((MR_Box) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 2))));
  MR_Box Var_6;

{
#define MR_PROC_LABEL mercury__version_array2d__unsafe_rewind_1_f_0

	struct ML_va * VA0;
	struct ML_va * VA;

	VA0 = (struct ML_va *)VA_5 ;
		{

    VA = ML_va_rewind_dolock(VA0, MR_ALLOC_ID);


		;}
#undef MR_PROC_LABEL
	Var_6  = (MR_Box) VA;
}
  {
    HeadVar__2_2 = (MR_Word) MR_new_object(MR_Word, (3 * sizeof(MR_Word)), NULL, NULL);
    MR_hl_field(0, HeadVar__2_2, 0) = ((MR_Box) (M_3));
    MR_hl_field(0, HeadVar__2_2, 1) = ((MR_Box) (N_4));
    MR_hl_field(0, HeadVar__2_2, 2) = ((MR_Box) (Var_6));
  }
  return HeadVar__2_2;
}

MR_Word MR_CALL 
mercury__version_array2d__resize_4_f_0(
  MR_Word TypeInfo_for_T_18,
  MR_Word VA2D0_6,
  MR_Integer M_7,
  MR_Integer N_8,
  MR_Box X_9)
{
  MR_bool succeeded;
  MR_Word VA2D_10;
  MR_Word VA2D1_11;
  MR_Integer M0_12;
  MR_Integer N0_13;
  MR_Integer M1_14;
  MR_Integer N1_15;

  VA2D1_11 = mercury__version_array2d__init_3_f_0(TypeInfo_for_T_18, M_7, N_8, X_9);
  M0_12 = ((MR_Integer) ((MR_hl_field(0, VA2D0_6, (MR_Integer) 0))));
  N0_13 = ((MR_Integer) ((MR_hl_field(0, VA2D0_6, (MR_Integer) 1))));
  succeeded = (M0_12 < M_7);
  if (succeeded)
    M1_14 = M0_12;
  else
    M1_14 = M_7;
  succeeded = (N0_13 < N_8);
  if (succeeded)
    N1_15 = N0_13;
  else
    N1_15 = N_8;
  VA2D_10 = mercury__version_array2d__resize_2_6_f_0(TypeInfo_for_T_18, (MR_Integer) 0, (MR_Integer) 0, M1_14, N1_15, VA2D0_6, VA2D1_11);
  return VA2D_10;
}

MR_Word MR_CALL 
mercury__version_array2d__resize_2_6_f_0(
  MR_Word TypeInfo_for_T_21,
  MR_Integer I_8,
  MR_Integer J_9,
  MR_Integer M_10,
  MR_Integer N_11,
  MR_Word SrcVA2D_12,
  MR_Word DestVA2D_13)
{
  while (MR_TRUE)
  {
    MR_bool succeeded = (I_8 >= M_10);
    MR_Word HeadVar__7_7;

    // setup for model_det tailcalls optimized into a loop
    ;
    if (succeeded)
      HeadVar__7_7 = DestVA2D_13;
    else
    {
      succeeded = (J_9 >= N_11);
      if (succeeded)
      {
        MR_Integer Var_14 = (MR_Integer) ((MR_Unsigned) I_8 + (MR_Unsigned) 1);
        MR_Integer next_value_of_I_8 = Var_14;

        // direct tailcall eliminated
        ;
        I_8 = next_value_of_I_8;
        J_9 = (MR_Integer) 0;
        continue;
      }
      else
      {
        MR_Integer Var_17 = (MR_Integer) ((MR_Unsigned) J_9 + (MR_Unsigned) 1);
        MR_Word Var_19;
        MR_Box Var_20;
        MR_Integer next_value_of_J_9;
        MR_Word next_value_of_DestVA2D_13;

        Var_20 = mercury__version_array2d__elem_3_f_0(TypeInfo_for_T_21, I_8, J_9, SrcVA2D_12);
        Var_19 = mercury__version_array2d__f_101_108_101_109_32_58_61_4_f_0(TypeInfo_for_T_21, I_8, J_9, DestVA2D_13, Var_20);
        // direct tailcall eliminated
        ;
        next_value_of_J_9 = Var_17;
        next_value_of_DestVA2D_13 = Var_19;
        J_9 = next_value_of_J_9;
        DestVA2D_13 = next_value_of_DestVA2D_13;
        continue;
      }
    }
    return HeadVar__7_7;
    break;
  }
}

MR_Word MR_CALL 
mercury__version_array2d__copy_1_f_0(
  MR_Word TypeInfo_for_T_7,
  MR_Word HeadVar__1_1)
{
  MR_Word HeadVar__2_2;
  MR_Integer M_3 = ((MR_Integer) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 0))));
  MR_Integer N_4 = ((MR_Integer) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 1))));
  MR_Box VA_5 = ((MR_Box) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 2))));
  MR_Box Var_6;

  Var_6 = mercury__version_array__copy_1_f_0(TypeInfo_for_T_7, VA_5);
  {
    HeadVar__2_2 = (MR_Word) MR_new_object(MR_Word, (3 * sizeof(MR_Word)), NULL, NULL);
    MR_hl_field(0, HeadVar__2_2, 0) = ((MR_Box) (M_3));
    MR_hl_field(0, HeadVar__2_2, 1) = ((MR_Box) (N_4));
    MR_hl_field(0, HeadVar__2_2, 2) = ((MR_Box) (Var_6));
  }
  return HeadVar__2_2;
}

MR_Word MR_CALL 
mercury__version_array2d__lists_1_f_0(
  MR_Word TypeInfo_for_T_13,
  MR_Word HeadVar__1_1)
{
  MR_Word HeadVar__2_2;
  MR_Integer M_3 = ((MR_Integer) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 0))));
  MR_Integer N_4 = ((MR_Integer) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 1))));
  MR_Box VA_5 = ((MR_Box) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 2))));
  MR_Integer Var_6;
  MR_Integer Var_7 = (MR_Integer) ((MR_Unsigned) M_3 * (MR_Unsigned) N_4);
  MR_Integer Var_9;

  Var_6 = (MR_Integer) ((MR_Unsigned) Var_7 - (MR_Unsigned) 1);
  Var_9 = (MR_Integer) ((MR_Unsigned) N_4 - (MR_Unsigned) 1);
  HeadVar__2_2 = mercury__version_array2d__f_85_110_117_115_101_100_65_114_103_115_95_95_102_117_110_99_95_95_108_105_115_116_115_95_50_95_95_91_49_93_95_48_6_f_0(Var_6, Var_9, N_4, VA_5, (MR_Word) ((MR_Unsigned) 0U), (MR_Word) ((MR_Unsigned) 0U));
  return HeadVar__2_2;
}

static MR_Word MR_CALL 
mercury__version_array2d__f_85_110_117_115_101_100_65_114_103_115_95_95_102_117_110_99_95_95_108_105_115_116_115_95_50_95_95_91_49_93_95_48_6_f_0(
  MR_Integer IJ_8,
  MR_Integer J_9,
  MR_Integer N_10,
  MR_Box VA_11,
  MR_Word Xs_12,
  MR_Word Xss_13)
{
  while (MR_TRUE)
  {
    MR_bool succeeded = ((MR_Integer) 0 <= IJ_8);
    MR_Word HeadVar__7_7;

    // setup for model_det tailcalls optimized into a loop
    ;
    if (succeeded)
    {
      succeeded = ((MR_Integer) 0 <= J_9);
      if (succeeded)
      {
        MR_Integer Var_16 = (MR_Integer) ((MR_Unsigned) IJ_8 - (MR_Unsigned) 1);
        MR_Integer Var_18 = (MR_Integer) ((MR_Unsigned) J_9 - (MR_Unsigned) 1);
        MR_Word Var_20;
        MR_Box Var_21;
        MR_Box Var_27;
        MR_Integer next_value_of_IJ_8;
        MR_Integer next_value_of_J_9;
        MR_Word next_value_of_Xs_12;

{
#define MR_PROC_LABEL mercury__version_array2d__f_85_110_117_115_101_100_65_114_103_115_95_95_102_117_110_99_95_95_108_105_115_116_115_95_50_95_95_91_49_93_95_48_6_f_0

	struct ML_va * VA;
	MR_Integer I;
	MR_Word X;
	MR_bool SUCCESS_INDICATOR;

	VA = (struct ML_va *)VA_11 ;
	I = IJ_8 ;
		{

    SUCCESS_INDICATOR = ML_va_get_dolock(VA, I, &X);


		;}
#undef MR_PROC_LABEL
	if (SUCCESS_INDICATOR) {
	Var_27  = (MR_Box) X;
	}
succeeded  = SUCCESS_INDICATOR;
}
        if (succeeded)
          Var_21 = Var_27;
        else
        {
          MR_Integer Var_28;
          MR_Integer Var_30;

{
#define MR_PROC_LABEL mercury__version_array2d__f_85_110_117_115_101_100_65_114_103_115_95_95_102_117_110_99_95_95_108_105_115_116_115_95_50_95_95_91_49_93_95_48_6_f_0

	struct ML_va * VA;
	MR_Integer N;

	VA = (struct ML_va *)VA_11 ;
		{

    N = ML_va_size_dolock(VA);


		;}
#undef MR_PROC_LABEL
	Var_30  = N;
}
          Var_28 = (MR_Integer) ((MR_Unsigned) Var_30 - (MR_Unsigned) 1);
          mercury__version_array__out_of_bounds_error_3_p_0(IJ_8, Var_28, (MR_String) "version_array.lookup");
        }
        {
          Var_20 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
          MR_hl_field(1, Var_20, 0) = Var_21;
          MR_hl_field(1, Var_20, 1) = ((MR_Box) (Xs_12));
        }
        // direct tailcall eliminated
        ;
        next_value_of_IJ_8 = Var_16;
        next_value_of_J_9 = Var_18;
        next_value_of_Xs_12 = Var_20;
        IJ_8 = next_value_of_IJ_8;
        J_9 = next_value_of_J_9;
        Xs_12 = next_value_of_Xs_12;
        continue;
      }
      else
      {
        MR_Integer Var_22 = (MR_Integer) ((MR_Unsigned) N_10 - (MR_Unsigned) 1);
        MR_Word Var_25;
        MR_Integer next_value_of_J_9;
        MR_Word next_value_of_Xss_13;

        {
          Var_25 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
          MR_hl_field(1, Var_25, 0) = ((MR_Box) (Xs_12));
          MR_hl_field(1, Var_25, 1) = ((MR_Box) (Xss_13));
        }
        // direct tailcall eliminated
        ;
        next_value_of_J_9 = Var_22;
        next_value_of_Xss_13 = Var_25;
        J_9 = next_value_of_J_9;
        Xs_12 = (MR_Word) ((MR_Unsigned) 0U);
        Xss_13 = next_value_of_Xss_13;
        continue;
      }
    }
    else
      {
        HeadVar__7_7 = (MR_Word) MR_mkword(1, MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL));
        MR_hl_field(1, HeadVar__7_7, 0) = ((MR_Box) (Xs_12));
        MR_hl_field(1, HeadVar__7_7, 1) = ((MR_Box) (Xss_13));
      }
    return HeadVar__7_7;
    break;
  }
}

void MR_CALL 
mercury__version_array2d__set_5_p_0(
  MR_Word TypeInfo_for_T_10,
  MR_Integer I_6,
  MR_Integer J_7,
  MR_Box X_8,
  MR_Word VA2D_9,
  MR_Word * HeadVar__5_5)
{
  *HeadVar__5_5 = mercury__version_array2d__f_101_108_101_109_32_58_61_4_f_0(TypeInfo_for_T_10, I_6, J_7, VA2D_9, X_8);
}

MR_Word MR_CALL 
mercury__version_array2d__f_101_108_101_109_32_58_61_4_f_0(
  MR_Word TypeInfo_for_T_15,
  MR_Integer I_9,
  MR_Integer J_10,
  MR_Word HeadVar__3_3,
  MR_Box X_11)
{
  MR_bool succeeded;
  MR_Word HeadVar__5_5;
  MR_Integer M_6 = ((MR_Integer) ((MR_hl_field(0, HeadVar__3_3, (MR_Integer) 0))));
  MR_Integer N_7 = ((MR_Integer) ((MR_hl_field(0, HeadVar__3_3, (MR_Integer) 1))));
  MR_Box VA_8 = ((MR_Box) ((MR_hl_field(0, HeadVar__3_3, (MR_Integer) 2))));
  MR_Box Var_12;
  MR_Integer Var_13;
  MR_Integer Var_14 = (MR_Integer) ((MR_Unsigned) I_9 * (MR_Unsigned) N_7);
  MR_Box Var_16;

  Var_13 = (MR_Integer) ((MR_Unsigned) Var_14 + (MR_Unsigned) J_10);
{
#define MR_PROC_LABEL mercury__version_array2d__f_101_108_101_109_32_58_61_4_f_0

	MR_Integer I;
	MR_Word X;
	struct ML_va * VA0;
	struct ML_va * VA;
	MR_bool SUCCESS_INDICATOR;

	I = Var_13 ;
	X = (MR_Word) X_11 ;
	VA0 = (struct ML_va *)VA_8 ;
		{

    SUCCESS_INDICATOR = ML_va_set_dolock(VA0, I, X, &VA, MR_ALLOC_ID);


		;}
#undef MR_PROC_LABEL
	if (SUCCESS_INDICATOR) {
	Var_16  = (MR_Box) VA;
	}
succeeded  = SUCCESS_INDICATOR;
}
  if (succeeded)
    Var_12 = Var_16;
  else
  {
    MR_Integer Var_17;
    MR_Integer Var_19;

{
#define MR_PROC_LABEL mercury__version_array2d__f_101_108_101_109_32_58_61_4_f_0

	struct ML_va * VA;
	MR_Integer N;

	VA = (struct ML_va *)VA_8 ;
		{

    N = ML_va_size_dolock(VA);


		;}
#undef MR_PROC_LABEL
	Var_19  = N;
}
    Var_17 = (MR_Integer) ((MR_Unsigned) Var_19 - (MR_Unsigned) 1);
    mercury__version_array__out_of_bounds_error_3_p_0(Var_13, Var_17, (MR_String) "version_array.set");
  }
  {
    HeadVar__5_5 = (MR_Word) MR_new_object(MR_Word, (3 * sizeof(MR_Word)), NULL, NULL);
    MR_hl_field(0, HeadVar__5_5, 0) = ((MR_Box) (M_6));
    MR_hl_field(0, HeadVar__5_5, 1) = ((MR_Box) (N_7));
    MR_hl_field(0, HeadVar__5_5, 2) = ((MR_Box) (Var_12));
  }
  return HeadVar__5_5;
}

MR_Box MR_CALL 
mercury__version_array2d__elem_3_f_0(
  MR_Word TypeInfo_for_T_12,
  MR_Integer I_8,
  MR_Integer J_9,
  MR_Word HeadVar__3_3)
{
  MR_bool succeeded;
  MR_Box HeadVar__4_4;
  MR_Integer N_6 = ((MR_Integer) ((MR_hl_field(0, HeadVar__3_3, (MR_Integer) 1))));
  MR_Box VA_7 = ((MR_Box) ((MR_hl_field(0, HeadVar__3_3, (MR_Integer) 2))));
  MR_Integer Var_10;
  MR_Integer Var_11 = (MR_Integer) ((MR_Unsigned) I_8 * (MR_Unsigned) N_6);
  MR_Box Var_13;

  Var_10 = (MR_Integer) ((MR_Unsigned) Var_11 + (MR_Unsigned) J_9);
{
#define MR_PROC_LABEL mercury__version_array2d__elem_3_f_0

	struct ML_va * VA;
	MR_Integer I;
	MR_Word X;
	MR_bool SUCCESS_INDICATOR;

	VA = (struct ML_va *)VA_7 ;
	I = Var_10 ;
		{

    SUCCESS_INDICATOR = ML_va_get_dolock(VA, I, &X);


		;}
#undef MR_PROC_LABEL
	if (SUCCESS_INDICATOR) {
	Var_13  = (MR_Box) X;
	}
succeeded  = SUCCESS_INDICATOR;
}
  if (succeeded)
    HeadVar__4_4 = Var_13;
  else
  {
    MR_Integer Var_14;
    MR_Integer Var_16;

{
#define MR_PROC_LABEL mercury__version_array2d__elem_3_f_0

	struct ML_va * VA;
	MR_Integer N;

	VA = (struct ML_va *)VA_7 ;
		{

    N = ML_va_size_dolock(VA);


		;}
#undef MR_PROC_LABEL
	Var_16  = N;
}
    Var_14 = (MR_Integer) ((MR_Unsigned) Var_16 - (MR_Unsigned) 1);
    mercury__version_array__out_of_bounds_error_3_p_0(Var_10, Var_14, (MR_String) "version_array.lookup");
  }
  return HeadVar__4_4;
}

MR_bool MR_CALL 
mercury__version_array2d__in_bounds_3_p_0(
  MR_Word TypeInfo_for_T_11,
  MR_Word HeadVar__1_1,
  MR_Integer I_7,
  MR_Integer J_8)
{
  MR_bool succeeded = ((MR_Integer) 0 <= I_7);
  MR_Integer M_4 = ((MR_Integer) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 0))));
  MR_Integer N_5 = ((MR_Integer) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 1))));
  MR_Integer Var_10;

  if (succeeded)
  {
    succeeded = (I_7 < M_4);
    if (succeeded)
    {
      Var_10 = (MR_Integer) 0;
      succeeded = (Var_10 <= J_8);
      if (succeeded)
        succeeded = (J_8 < N_5);
    }
  }
  return succeeded;
}

void MR_CALL 
mercury__version_array2d__bounds_3_p_0(
  MR_Word TypeInfo_for_T_7,
  MR_Word HeadVar__1_1,
  MR_Integer * M_4,
  MR_Integer * N_5)
{
  *M_4 = ((MR_Integer) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 0))));
  *N_5 = ((MR_Integer) ((MR_hl_field(0, HeadVar__1_1, (MR_Integer) 1))));
}

MR_Word MR_CALL 
mercury__version_array2d__init_3_f_0(
  MR_Word TypeInfo_for_T_14,
  MR_Integer M_5,
  MR_Integer N_6,
  MR_Box X_7)
{
  MR_bool succeeded = (M_5 >= (MR_Integer) 0);
  MR_Word HeadVar__4_4;
  MR_Integer Var_9;

  if (succeeded)
  {
    Var_9 = (MR_Integer) 0;
    succeeded = (N_6 >= Var_9);
  }
  if (succeeded)
  {
    MR_Box Var_10;
    MR_Integer Var_11 = (MR_Integer) ((MR_Unsigned) M_5 * (MR_Unsigned) N_6);

    Var_10 = mercury__version_array__init_2_f_0(TypeInfo_for_T_14, Var_11, X_7);
    {
      HeadVar__4_4 = (MR_Word) MR_new_object(MR_Word, (3 * sizeof(MR_Word)), NULL, NULL);
      MR_hl_field(0, HeadVar__4_4, 0) = ((MR_Box) (M_5));
      MR_hl_field(0, HeadVar__4_4, 1) = ((MR_Box) (N_6));
      MR_hl_field(0, HeadVar__4_4, 2) = ((MR_Box) (Var_10));
    }
  }
  else
  {
    MR_Word TypeInfo_16_16;
    MR_Box conv0_HeadVar__4_4;

    {
      TypeInfo_16_16 = (MR_Word) MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL);
      MR_hl_field(0, TypeInfo_16_16, 0) = ((MR_Box) (&mercury__version_array2d__version_array2d__type_ctor_info_version_array2d_1));
      MR_hl_field(0, TypeInfo_16_16, 1) = ((MR_Box) (TypeInfo_for_T_14));
    }
    conv0_HeadVar__4_4 = mercury__require__func_error_2_f_0(TypeInfo_16_16, (MR_String) "function \140version_array2d.init\'/3", (MR_String) "bounds must be non-negative");
    HeadVar__4_4 = ((MR_Word) (conv0_HeadVar__4_4));
  }
  return HeadVar__4_4;
}

static void MR_CALL 
mercury__version_array2d__version_array2d_1_f_0_1(
  void * env_ptr_arg)
{
  struct mercury__version_array2d__version_array2d_2_f_0_env_0_s * env_ptr = (struct mercury__version_array2d__version_array2d_2_f_0_env_0_s *) (env_ptr_arg);

  MR_builtin_longjmp((env_ptr)->mercury__version_array2d__version_array2d_2_f_0_env_0__commit_0, 1);
}

static void MR_CALL 
mercury__version_array2d__version_array2d_1_f_0_3(
  void * env_ptr_arg)
{
  struct mercury__version_array2d__version_array2d_2_f_0_env_0_s * env_ptr = (struct mercury__version_array2d__version_array2d_2_f_0_env_0_s *) (env_ptr_arg);

  (env_ptr)->mercury__version_array2d__version_array2d_2_f_0_env_0__Ys_14 = ((MR_Word) ((env_ptr)->mercury__version_array2d__version_array2d_2_f_0_env_0__conv1_Ys_14));
  mercury__version_array2d__version_array2d_1_f_0_2(env_ptr);
}

static void MR_CALL 
mercury__version_array2d__version_array2d_1_f_0_2(
  void * env_ptr_arg)
{
  struct mercury__version_array2d__version_array2d_2_f_0_env_0_s * env_ptr = (struct mercury__version_array2d__version_array2d_2_f_0_env_0_s *) (env_ptr_arg);

  {
    MR_Integer Var_21;

    mercury__list__length_acc_3_p_0((env_ptr)->mercury__version_array2d__version_array2d_2_f_0_env_0__TypeInfo_for_T_18, (env_ptr)->mercury__version_array2d__version_array2d_2_f_0_env_0__Ys_14, (MR_Integer) 0, &Var_21);
    (env_ptr)->mercury__version_array2d__version_array2d_2_f_0_env_0__succeeded = ((env_ptr)->mercury__version_array2d__version_array2d_2_f_0_env_0__N_12 != Var_21);
    if ((env_ptr)->mercury__version_array2d__version_array2d_2_f_0_env_0__succeeded)
      mercury__version_array2d__version_array2d_1_f_0_1(env_ptr);
  }
}

static void MR_CALL 
mercury__version_array2d__version_array2d_1_f_0_4(
  void * env_ptr_arg)
{
  struct mercury__version_array2d__version_array2d_2_f_0_env_0_s * env_ptr = (struct mercury__version_array2d__version_array2d_2_f_0_env_0_s *) (env_ptr_arg);

  if (MR_builtin_setjmp((env_ptr)->mercury__version_array2d__version_array2d_2_f_0_env_0__commit_0) == 0)
    {
      mercury__list__member_2_p_1((env_ptr)->mercury__version_array2d__version_array2d_2_f_0_env_0__TypeInfo_9_27, &(env_ptr)->mercury__version_array2d__version_array2d_2_f_0_env_0__conv1_Ys_14, (MR_Word) ((env_ptr)->mercury__version_array2d__version_array2d_2_f_0_env_0__HeadVar__1_1), mercury__version_array2d__version_array2d_1_f_0_3, env_ptr);
      (env_ptr)->mercury__version_array2d__version_array2d_2_f_0_env_0__succeeded = MR_FALSE;
    }
  else
    (env_ptr)->mercury__version_array2d__version_array2d_2_f_0_env_0__succeeded = MR_TRUE;
}

MR_Word MR_CALL 
mercury__version_array2d__version_array2d_1_f_0(
  MR_Word TypeInfo_for_T_18,
  MR_Word HeadVar__1_1)
{
  struct mercury__version_array2d__version_array2d_2_f_0_env_0_s env;

  (env).mercury__version_array2d__version_array2d_2_f_0_env_0__TypeInfo_for_T_18 = TypeInfo_for_T_18;
  (env).mercury__version_array2d__version_array2d_2_f_0_env_0__HeadVar__1_1 = HeadVar__1_1;
  {
    MR_Word VA2D_2;

    if (((env).mercury__version_array2d__version_array2d_2_f_0_env_0__HeadVar__1_1 == (MR_Word) ((MR_Unsigned) 0U)))
    {
      MR_Box Var_5;

      Var_5 = mercury__version_array__version_array_1_f_0((env).mercury__version_array2d__version_array2d_2_f_0_env_0__TypeInfo_for_T_18, (MR_Word) ((MR_Unsigned) 0U));
      {
        VA2D_2 = (MR_Word) MR_new_object(MR_Word, (3 * sizeof(MR_Word)), NULL, NULL);
        MR_hl_field(0, VA2D_2, 0) = ((MR_Box) ((MR_Integer) 0));
        MR_hl_field(0, VA2D_2, 1) = ((MR_Box) ((MR_Integer) 0));
        MR_hl_field(0, VA2D_2, 2) = ((MR_Box) (Var_5));
      }
    }
    else
    {
      MR_Word Xs_8 = ((MR_Word) ((MR_hl_field(1, (env).mercury__version_array2d__version_array2d_2_f_0_env_0__HeadVar__1_1, (MR_Integer) 0))));
      MR_Integer M_11;
      MR_Box A_13;
      MR_Word Var_15;
      MR_Word Var_24;
      MR_Word Var_9 = ((MR_Word) ((MR_hl_field(1, (env).mercury__version_array2d__version_array2d_2_f_0_env_0__HeadVar__1_1, (MR_Integer) 1))));
      MR_Word conv0_Var_24;

      {
        MR_Word base;
        base = (MR_Word) MR_new_object(MR_Word, (2 * sizeof(MR_Word)), NULL, NULL);
        (env).mercury__version_array2d__version_array2d_2_f_0_env_0__TypeInfo_9_27 = base;
        MR_hl_field(0, base, 0) = ((MR_Box) (&mercury__list__list__type_ctor_info_list_1));
        MR_hl_field(0, base, 1) = ((MR_Box) ((env).mercury__version_array2d__version_array2d_2_f_0_env_0__TypeInfo_for_T_18));
      }
      mercury__list__length_acc_3_p_0((env).mercury__version_array2d__version_array2d_2_f_0_env_0__TypeInfo_9_27, (MR_Word) ((env).mercury__version_array2d__version_array2d_2_f_0_env_0__HeadVar__1_1), (MR_Integer) 0, &M_11);
      mercury__list__length_acc_3_p_0((env).mercury__version_array2d__version_array2d_2_f_0_env_0__TypeInfo_for_T_18, Xs_8, (MR_Integer) 0, &(env).mercury__version_array2d__version_array2d_2_f_0_env_0__N_12);
      mercury__list__reverse_2_p_0((env).mercury__version_array2d__version_array2d_2_f_0_env_0__TypeInfo_9_27, (MR_Word) ((env).mercury__version_array2d__version_array2d_2_f_0_env_0__HeadVar__1_1), &conv0_Var_24);
      Var_24 = (MR_Word) (conv0_Var_24);
      mercury__list__condense_acc_3_p_0((env).mercury__version_array2d__version_array2d_2_f_0_env_0__TypeInfo_for_T_18, Var_24, (MR_Word) ((MR_Unsigned) 0U), &Var_15);
      A_13 = mercury__version_array__version_array_1_f_0((env).mercury__version_array2d__version_array2d_2_f_0_env_0__TypeInfo_for_T_18, Var_15);
      mercury__version_array2d__version_array2d_1_f_0_4(&env);
      (env).mercury__version_array2d__version_array2d_2_f_0_env_0__succeeded = !((env).mercury__version_array2d__version_array2d_2_f_0_env_0__succeeded);
      if ((env).mercury__version_array2d__version_array2d_2_f_0_env_0__succeeded)
        {
          VA2D_2 = (MR_Word) MR_new_object(MR_Word, (3 * sizeof(MR_Word)), NULL, NULL);
          MR_hl_field(0, VA2D_2, 0) = ((MR_Box) (M_11));
          MR_hl_field(0, VA2D_2, 1) = ((MR_Box) ((env).mercury__version_array2d__version_array2d_2_f_0_env_0__N_12));
          MR_hl_field(0, VA2D_2, 2) = ((MR_Box) (A_13));
        }
      else
        mercury__require__error_2_p_0((MR_String) "function \140version_array2d.version_array2d\'/1", (MR_String) "non-rectangular list of lists");
    }
    return VA2D_2;
  }
}

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

  succeeded = mercury__version_array2d____Unify____version_array2d_1_0(((MR_Word) (wrapper_arg_1)), ((MR_Word) (wrapper_arg_2)), ((MR_Word) (wrapper_arg_3)));
  return succeeded;
}

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

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

void mercury__version_array2d__init(void)
{
}

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

	MR_register_type_ctor_info(&mercury__version_array2d__version_array2d__type_ctor_info_version_array2d_1);
}

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

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

// :- end_module version_array2d.
