/*
**
** The C code is generated by ATS/Anairiats
** The compilation time is: 2020-11-4: 18h:10m
**
*/

/* include some .h files */
#ifndef _ATS_HEADER_NONE
#include "ats_config.h"
#include "ats_basics.h"
#include "ats_types.h"
#include "ats_exception.h"
#include "ats_memory.h"
#endif /* _ATS_HEADER_NONE */

/* include some .cats files */
#ifndef _ATS_PRELUDE_NONE
#include "prelude/CATS/basics.cats"
#include "prelude/CATS/bool.cats"
#include "prelude/CATS/char.cats"
#include "prelude/CATS/byte.cats"
#include "prelude/CATS/float.cats"
#include "prelude/CATS/integer.cats"
#include "prelude/CATS/integer_ptr.cats"
#include "prelude/CATS/integer_fixed.cats"
#include "prelude/CATS/sizetype.cats"
#include "prelude/CATS/pointer.cats"
#include "prelude/CATS/reference.cats"
#include "prelude/CATS/string.cats"
#include "prelude/CATS/lazy.cats"
#include "prelude/CATS/lazy_vt.cats"
#include "prelude/CATS/printf.cats"
#include "prelude/CATS/list.cats"
#include "prelude/CATS/option.cats"
#include "prelude/CATS/array.cats"
#include "prelude/CATS/matrix.cats"
#endif /* _ATS_PRELUDE_NONE */
/* prologues from statically loaded files */
/* external codes at top */

#include "prelude/CATS/array.cats"

/* type definitions */
typedef
struct {
ats_ptr_type atslab_3 ;
ats_ptr_type atslab_4 ;
} anairiats_rec_0 ;

typedef
struct {
ats_ptr_type atslab_2 ;
ats_size_type atslab_3 ;
} anairiats_rec_1 ;

/* external typedefs */
/* external dynamic constructor declarations */
/* external dynamic constant declarations */
ATSextern_fun(ats_void_type, atspre_vbox_make_view_ptr) (ats_ptr_type) ;
ATSextern_fun(ats_size_type, atspre_size1_of_int1) (ats_int_type) ;
ATSextern_fun(ats_size_type, atspre_add_size1_int1) (ats_size_type, ats_int_type) ;
ATSextern_fun(ats_size_type, atspre_sub_size1_int1) (ats_size_type, ats_int_type) ;
ATSextern_fun(ats_size_type, atspre_mul2_size1_size1) (ats_size_type, ats_size_type) ;
ATSextern_fun(ats_bool_type, atspre_lt_size1_size1) (ats_size_type, ats_size_type) ;
ATSextern_fun(ats_bool_type, atspre_gt_size1_int1) (ats_size_type, ats_int_type) ;
ATSextern_fun(ats_bool_type, atspre_neq_size1_size1) (ats_size_type, ats_size_type) ;
ATSextern_fun(ats_ptr_type, atspre_array_ptr_alloc_tsz) (ats_size_type, ats_size_type) ;
ATSextern_fun(ats_void_type, atspre_array_ptr_free) (ats_ptr_type) ;
ATSextern_fun(ats_void_type, atspre_array_ptr_initialize_funenv_tsz) (ats_ref_type, ats_size_type, ats_ptr_type, ats_size_type, ats_ptr_type) ;
ATSextern_fun(ats_void_type, atspre_array_ptr_initialize_cloenv_tsz) (ats_ref_type, ats_size_type, ats_ref_type, ats_size_type, ats_ptr_type) ;
ATSextern_fun(ats_ptr_type, atspre_array_ptr_split_tsz) (ats_ptr_type, ats_size_type, ats_size_type) ;
ATSextern_fun(ats_ptr_type, atspre_array_ptr_takeout_tsz) (ats_ptr_type, ats_size_type, ats_size_type) ;
ATSextern_fun(anairiats_rec_0, atspre_array_ptr_takeout2_tsz) (ats_ptr_type, ats_size_type, ats_size_type, ats_size_type) ;
ATSextern_fun(ats_void_type, atspre_array_ptr_foreach_funenv_tsz) (ats_ref_type, ats_ptr_type, ats_size_type, ats_size_type, ats_ptr_type) ;
ATSextern_fun(ats_void_type, atspre_array_ptr_iforeach_funenv_tsz) (ats_ref_type, ats_ptr_type, ats_size_type, ats_size_type, ats_ptr_type) ;
ATSextern_fun(ats_ptr_type, atspre_array2_ptr_takeout_tsz) (ats_ptr_type, ats_size_type, ats_size_type, ats_size_type) ;

/* external dynamic terminating constant declarations */
#ifdef _ATS_PROOFCHECK
extern
ats_void_type ATS_2d0_2e2_2e12_2prelude_2SATS_2array_2esats__array_v_takeout2_prfck () ;
extern
ats_void_type ATS_2d0_2e2_2e12_2prelude_2DATS_2array_2edats____copy_prfck () ;
extern
ats_void_type ATS_2d0_2e2_2e12_2prelude_2DATS_2array_2edats____free_prfck () ;
extern
ats_void_type ATS_2d0_2e2_2e12_2prelude_2DATS_2array_2edats____assert_prfck () ;
extern
ats_void_type ATS_2d0_2e2_2e12_2prelude_2DATS_2array_2edats____assert_prfck () ;
#endif /* _ATS_PROOFCHECK */

/* assuming abstract types */
int ATS_2d0_2e2_2e12_2prelude_2basics_sta_2esats__sasp__array_viewt0ype_int_type = 0 ;

/* sum constructor declarations */
/* exn constructor declarations */
/* global dynamic (non-functional) constant declarations */
/* internal function declarations */
static
ats_void_type loop_1 (ats_ptr_type arg0, ats_size_type arg1, ats_size_type arg2, ats_ptr_type arg3, ats_size_type arg4, ats_ptr_type arg5) ;
static
ats_void_type loop_3 (ats_ptr_type arg0, ats_size_type arg1, ats_size_type arg2, ats_ref_type arg3, ats_size_type arg4, ats_ptr_type arg5) ;
static
ats_void_type loop_7 (ats_ptr_type arg0, ats_ptr_type arg1, ats_size_type arg2, ats_size_type arg3, ats_ptr_type arg4) ;
static
ats_void_type loop_9 (ats_ptr_type arg0, ats_ptr_type arg1, ats_size_type arg2, ats_size_type arg3, ats_size_type arg4, ats_ptr_type arg5) ;

/* partial value template declarations */
/* static temporary variable declarations */
/* external value variable declarations */

/* function implementations */

/*
// /nix/store/rfja8ixrs5wb4kj3kiwlch1apnh7qgvy-ats-0.2.12/lib/ats-anairiats-0.2.12/prelude/DATS/array.dats: 6600(line=234, offs=7) -- 7239(line=251, offs=8)
*/
ATSstaticdec()
ats_void_type
loop_1 (ats_ptr_type arg0, ats_size_type arg1, ats_size_type arg2, ats_ptr_type arg3, ats_size_type arg4, ats_ptr_type arg5) {
/* local vardec */
// ATSlocal_void (tmp1) ;
ATSlocal (ats_bool_type, tmp2) ;
// ATSlocal_void (tmp3) ;
ATSlocal (ats_ptr_type, tmp4) ;
ATSlocal (ats_size_type, tmp5) ;

__ats_lab_loop_1:
tmp2 = atspre_lt_size1_size1 (arg2, arg1) ;
if (tmp2) {
/* tmp3 = */ ((ats_void_type(*)(ats_size_type, ats_ref_type, ats_ptr_type))arg3) (arg2, arg0, arg5) ;
tmp4 = atspre_padd_size (arg0, arg4) ;
tmp5 = atspre_add_size1_int1 (arg2, 1) ;
arg0 = tmp4 ;
arg1 = arg1 ;
arg2 = tmp5 ;
arg3 = arg3 ;
arg4 = arg4 ;
arg5 = arg5 ;
goto __ats_lab_loop_1 ; // tail call
} else {
/* empty */
} /* end of [if] */
return /* (tmp1) */ ;
} /* end of [loop_1] */

/*
// /nix/store/rfja8ixrs5wb4kj3kiwlch1apnh7qgvy-ats-0.2.12/lib/ats-anairiats-0.2.12/prelude/DATS/array.dats: 6558(line=233, offs=3) -- 7333(line=255, offs=4)
*/
ATSglobaldec()
ats_void_type
atspre_array_ptr_initialize_funenv_tsz (ats_ref_type arg0, ats_size_type arg1, ats_ptr_type arg2, ats_size_type arg3, ats_ptr_type arg4) {
/* local vardec */
// ATSlocal_void (tmp0) ;

__ats_lab_atspre_array_ptr_initialize_funenv_tsz:
/* tmp0 = */ loop_1 (arg0, arg1, 0, arg2, arg3, arg4) ;
return /* (tmp0) */ ;
} /* end of [atspre_array_ptr_initialize_funenv_tsz] */

/*
// /nix/store/rfja8ixrs5wb4kj3kiwlch1apnh7qgvy-ats-0.2.12/lib/ats-anairiats-0.2.12/prelude/DATS/array.dats: 8023(line=282, offs=7) -- 8675(line=299, offs=8)
*/
ATSstaticdec()
ats_void_type
loop_3 (ats_ptr_type arg0, ats_size_type arg1, ats_size_type arg2, ats_ref_type arg3, ats_size_type arg4, ats_ptr_type arg5) {
/* local vardec */
// ATSlocal_void (tmp7) ;
ATSlocal (ats_bool_type, tmp8) ;
// ATSlocal_void (tmp9) ;
ATSlocal (ats_ptr_type, tmp10) ;
ATSlocal (ats_size_type, tmp11) ;

__ats_lab_loop_3:
tmp8 = atspre_lt_size1_size1 (arg2, arg1) ;
if (tmp8) {
/* tmp9 = */ ((ats_void_type(*)(ats_clo_ptr_type, ats_size_type, ats_ref_type, ats_ptr_type))(ats_closure_fun(arg3))) (arg3, arg2, arg0, arg5) ;
tmp10 = atspre_padd_size (arg0, arg4) ;
tmp11 = atspre_add_size1_int1 (arg2, 1) ;
arg0 = tmp10 ;
arg1 = arg1 ;
arg2 = tmp11 ;
arg3 = arg3 ;
arg4 = arg4 ;
arg5 = arg5 ;
goto __ats_lab_loop_3 ; // tail call
} else {
/* empty */
} /* end of [if] */
return /* (tmp7) */ ;
} /* end of [loop_3] */

/*
// /nix/store/rfja8ixrs5wb4kj3kiwlch1apnh7qgvy-ats-0.2.12/lib/ats-anairiats-0.2.12/prelude/DATS/array.dats: 7981(line=281, offs=3) -- 8769(line=303, offs=4)
*/
ATSglobaldec()
ats_void_type
atspre_array_ptr_initialize_cloenv_tsz (ats_ref_type arg0, ats_size_type arg1, ats_ref_type arg2, ats_size_type arg3, ats_ptr_type arg4) {
/* local vardec */
// ATSlocal_void (tmp6) ;

__ats_lab_atspre_array_ptr_initialize_cloenv_tsz:
/* tmp6 = */ loop_3 (arg0, arg1, 0, arg2, arg3, arg4) ;
return /* (tmp6) */ ;
} /* end of [atspre_array_ptr_initialize_cloenv_tsz] */

/*
// /nix/store/rfja8ixrs5wb4kj3kiwlch1apnh7qgvy-ats-0.2.12/lib/ats-anairiats-0.2.12/prelude/DATS/array.dats: 10828(line=379, offs=24) -- 11091(line=385, offs=4)
*/
ATSglobaldec()
anairiats_rec_0
atspre_array_ptr_takeout2_tsz (ats_ptr_type arg0, ats_size_type arg1, ats_size_type arg2, ats_size_type arg3) {
/* local vardec */
ATSlocal (anairiats_rec_0, tmp12) ;
ATSlocal (ats_size_type, tmp13) ;
ATSlocal (ats_size_type, tmp14) ;
ATSlocal (ats_size_type, tmp15) ;
ATSlocal (ats_size_type, tmp16) ;
ATSlocal (ats_ptr_type, tmp17) ;
ATSlocal (ats_ptr_type, tmp18) ;

__ats_lab_atspre_array_ptr_takeout2_tsz:
tmp13 = atspre_mul2_size1_size1 (arg1, arg3) ;
tmp14 = ats_selsin_mac(tmp13, atslab_1) ;
tmp15 = atspre_mul2_size1_size1 (arg2, arg3) ;
tmp16 = ats_selsin_mac(tmp15, atslab_1) ;
tmp17 = atspre_padd_size (arg0, tmp14) ;
tmp18 = atspre_padd_size (arg0, tmp16) ;
tmp12.atslab_3 = tmp17 ;
tmp12.atslab_4 = tmp18 ;

return (tmp12) ;
} /* end of [atspre_array_ptr_takeout2_tsz] */

/*
// /nix/store/rfja8ixrs5wb4kj3kiwlch1apnh7qgvy-ats-0.2.12/lib/ats-anairiats-0.2.12/prelude/DATS/array.dats: 11822(line=417, offs=10) -- 11993(line=422, offs=4)
*/
ATSglobaldec()
ats_ptr_type
ATS_2d0_2e2_2e12_2prelude_2SATS_2array_2esats__array_make_arrpsz (anairiats_rec_1 arg0) {
/* local vardec */
ATSlocal (ats_ptr_type, tmp19) ;
// ATSlocal_void (tmp20) ;
ATSlocal (ats_ptr_type, tmp21) ;
// ATSlocal_void (tmp22) ;

__ats_lab_ATS_2d0_2e2_2e12_2prelude_2SATS_2array_2esats__array_make_arrpsz:
tmp21 = ats_select_mac(arg0, atslab_2) ;
/* tmp20 = */ atspre_vbox_make_view_ptr (tmp21) ;
/* tmp22 = ats_selsin_mac(tmp20, atslab_1) */ ;
tmp19 = ats_select_mac(arg0, atslab_2) ;
return (tmp19) ;
} /* end of [ATS_2d0_2e2_2e12_2prelude_2SATS_2array_2esats__array_make_arrpsz] */

/*
// /nix/store/rfja8ixrs5wb4kj3kiwlch1apnh7qgvy-ats-0.2.12/lib/ats-anairiats-0.2.12/prelude/DATS/array.dats: 16203(line=590, offs=7) -- 16815(line=608, offs=8)
*/
ATSstaticdec()
ats_void_type
loop_7 (ats_ptr_type arg0, ats_ptr_type arg1, ats_size_type arg2, ats_size_type arg3, ats_ptr_type arg4) {
/* local vardec */
// ATSlocal_void (tmp24) ;
ATSlocal (ats_bool_type, tmp25) ;
// ATSlocal_void (tmp26) ;
ATSlocal (ats_ptr_type, tmp27) ;
ATSlocal (ats_size_type, tmp28) ;

__ats_lab_loop_7:
tmp25 = atspre_gt_size1_int1 (arg2, 0) ;
if (tmp25) {
/* tmp26 = */ ((ats_void_type(*)(ats_ref_type, ats_ptr_type))arg1) (arg0, arg4) ;
tmp27 = atspre_padd_size (arg0, arg3) ;
tmp28 = atspre_sub_size1_int1 (arg2, 1) ;
arg0 = tmp27 ;
arg1 = arg1 ;
arg2 = tmp28 ;
arg3 = arg3 ;
arg4 = arg4 ;
goto __ats_lab_loop_7 ; // tail call
} else {
/* empty */
} /* end of [if] */
return /* (tmp24) */ ;
} /* end of [loop_7] */

/*
// /nix/store/rfja8ixrs5wb4kj3kiwlch1apnh7qgvy-ats-0.2.12/lib/ats-anairiats-0.2.12/prelude/DATS/array.dats: 16161(line=589, offs=3) -- 16887(line=611, offs=4)
*/
ATSglobaldec()
ats_void_type
atspre_array_ptr_foreach_funenv_tsz (ats_ref_type arg0, ats_ptr_type arg1, ats_size_type arg2, ats_size_type arg3, ats_ptr_type arg4) {
/* local vardec */
// ATSlocal_void (tmp23) ;

__ats_lab_atspre_array_ptr_foreach_funenv_tsz:
/* tmp23 = */ loop_7 (arg0, arg1, arg2, arg3, arg4) ;
return /* (tmp23) */ ;
} /* end of [atspre_array_ptr_foreach_funenv_tsz] */

/*
// /nix/store/rfja8ixrs5wb4kj3kiwlch1apnh7qgvy-ats-0.2.12/lib/ats-anairiats-0.2.12/prelude/DATS/array.dats: 18160(line=663, offs=7) -- 18807(line=681, offs=8)
*/
ATSstaticdec()
ats_void_type
loop_9 (ats_ptr_type arg0, ats_ptr_type arg1, ats_size_type arg2, ats_size_type arg3, ats_size_type arg4, ats_ptr_type arg5) {
/* local vardec */
// ATSlocal_void (tmp30) ;
ATSlocal (ats_bool_type, tmp31) ;
// ATSlocal_void (tmp32) ;
ATSlocal (ats_ptr_type, tmp33) ;
ATSlocal (ats_size_type, tmp34) ;

__ats_lab_loop_9:
tmp31 = atspre_lt_size1_size1 (arg3, arg2) ;
if (tmp31) {
/* tmp32 = */ ((ats_void_type(*)(ats_size_type, ats_ref_type, ats_ptr_type))arg1) (arg3, arg0, arg5) ;
tmp33 = atspre_padd_size (arg0, arg4) ;
tmp34 = atspre_add_size1_int1 (arg3, 1) ;
arg0 = tmp33 ;
arg1 = arg1 ;
arg2 = arg2 ;
arg3 = tmp34 ;
arg4 = arg4 ;
arg5 = arg5 ;
goto __ats_lab_loop_9 ; // tail call
} else {
/* empty */
} /* end of [if] */
return /* (tmp30) */ ;
} /* end of [loop_9] */

/*
// /nix/store/rfja8ixrs5wb4kj3kiwlch1apnh7qgvy-ats-0.2.12/lib/ats-anairiats-0.2.12/prelude/DATS/array.dats: 18118(line=662, offs=3) -- 18882(line=684, offs=4)
*/
ATSglobaldec()
ats_void_type
atspre_array_ptr_iforeach_funenv_tsz (ats_ref_type arg0, ats_ptr_type arg1, ats_size_type arg2, ats_size_type arg3, ats_ptr_type arg4) {
/* local vardec */
// ATSlocal_void (tmp29) ;

__ats_lab_atspre_array_ptr_iforeach_funenv_tsz:
/* tmp29 = */ loop_9 (arg0, arg1, arg2, 0, arg3, arg4) ;
return /* (tmp29) */ ;
} /* end of [atspre_array_ptr_iforeach_funenv_tsz] */

/* static load function */

// extern ats_void_type ATS_2d0_2e2_2e12_2prelude_2SATS_2array_2esats__staload (void) ;
// extern ats_void_type ATS_2d0_2e2_2e12_2prelude_2SATS_2array_2esats__staload (void) ;

ats_void_type
ATS_2d0_2e2_2e12_2prelude_2DATS_2array_2edats__staload () {
static int ATS_2d0_2e2_2e12_2prelude_2DATS_2array_2edats__staload_flag = 0 ;
if (ATS_2d0_2e2_2e12_2prelude_2DATS_2array_2edats__staload_flag) return ;
ATS_2d0_2e2_2e12_2prelude_2DATS_2array_2edats__staload_flag = 1 ;

// ATS_2d0_2e2_2e12_2prelude_2SATS_2array_2esats__staload () ;
// ATS_2d0_2e2_2e12_2prelude_2SATS_2array_2esats__staload () ;

return ;
} /* staload function */

/* dynamic load function */

// dynload flag declaration
// extern ats_int_type ATS_2d0_2e2_2e12_2prelude_2DATS_2array_2edats__dynload_flag ;

ats_void_type
ATS_2d0_2e2_2e12_2prelude_2DATS_2array_2edats__dynload () {
// ATS_2d0_2e2_2e12_2prelude_2DATS_2array_2edats__dynload_flag = 1 ;
ATS_2d0_2e2_2e12_2prelude_2DATS_2array_2edats__staload () ;

#ifdef _ATS_PROOFCHECK
ATS_2d0_2e2_2e12_2prelude_2SATS_2array_2esats__array_v_takeout2_prfck () ;
ATS_2d0_2e2_2e12_2prelude_2DATS_2array_2edats____copy_prfck () ;
ATS_2d0_2e2_2e12_2prelude_2DATS_2array_2edats____free_prfck () ;
ATS_2d0_2e2_2e12_2prelude_2DATS_2array_2edats____assert_prfck () ;
ATS_2d0_2e2_2e12_2prelude_2DATS_2array_2edats____assert_prfck () ;
#endif /* _ATS_PROOFCHECK */

/* marking static variables for GC */

/* marking external values for GC */

/* code for dynamic loading */
return ;
} /* end of [dynload function] */

/* external codes at mid */
/* external codes at bot */


typedef unsigned char byte ;

//
// HX-2010-05-24
// In case 'memcpy' is already defined as a macro ...
//
#ifndef memcpy
extern void *memcpy (void *dst, const void* src, size_t n) ;
#endif // end of [memcpy]

ats_void_type
atspre_array_ptr_initialize_elt_tsz (
  ats_ptr_type A
, ats_size_type asz
, ats_ptr_type ini
, ats_size_type tsz
)  {
  int i, itsz ; int left ; ats_ptr_type p ;
  if (asz == 0) return ;
  memcpy (A, ini, tsz) ;
  i = 1 ; itsz = tsz ; left = asz - i ;
  while (left > 0) {
    p = (ats_ptr_type)(((byte*)A) + itsz) ;
    if (left <= i) { memcpy (p, A, left * tsz) ; return ; }
    memcpy (p, A, itsz);
    i = i + i ; itsz = itsz + itsz ; left = asz - i ;
  } /* end of [while] */
  return ;
} /* end of [atspre_array_ptr_initialize_elt_tsz] */



/* ****** ****** */

/* end of [DATS_array_dats.c] */
