/*
**
** The C code is generated by ATS/Anairiats
** The compilation time is: 2020-11-6:  1h:51m
**
*/

/* 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 */

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_lexbuf.cats"

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_lexbuf.cats"

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_lexbuf.cats"

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_lexbuf.cats"

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_location.cats"

#include "pats_lexbuf.cats"

#include "pats_location.cats"

#include "pats_location.cats"
/* external codes at top */
/* type definitions */
typedef struct {
ats_ptr_type atslab_0 ;
ats_ptr_type atslab_1 ;
} anairiats_sum_0 ;

typedef
struct {
ats_ptr_type atslab_s2exp_srt ;
ats_ptr_type atslab_s2exp_node ;
} anairiats_rec_1 ;

typedef struct {
int tag ;
ats_ptr_type atslab_0 ;
ats_ptr_type atslab_1 ;
} anairiats_sum_2 ;

typedef struct {
int tag ;
ats_ptr_type atslab_0 ;
ats_int_type atslab_1 ;
ats_ptr_type atslab_2 ;
} anairiats_sum_3 ;

typedef struct {
ats_ptr_type atslab_0 ;
ats_ptr_type atslab_1 ;
ats_ptr_type atslab_2 ;
} anairiats_sum_4 ;

typedef struct {
ats_ptr_type atslab_0 ;
} anairiats_sum_5 ;

/* external typedefs */
/* external dynamic constructor declarations */
ATSextern_val(ats_sum_type, ATS_2d0_2e2_2e12_2prelude_2basics_sta_2esats__list_cons_0) ;
ATSextern_val(ats_sum_type, ATS_2d0_2e2_2e12_2prelude_2basics_sta_2esats__list_nil_1) ;
ATSextern_val(ats_sum_type, ATS_2d0_2e2_2e12_2prelude_2basics_sta_2esats__None_0) ;
ATSextern_val(ats_sum_type, ATS_2d0_2e2_2e12_2prelude_2basics_sta_2esats__Some_1) ;
ATSextern_val(ats_sum_type, _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_2esats__SLABELED_0) ;
ATSextern_val(ats_sum_type, _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_2esats__S2Ehole_9) ;
ATSextern_val(ats_sum_type, _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_2esats__S2Eat_12) ;
ATSextern_val(ats_sum_type, _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_2esats__S2Etyrec_25) ;
ATSextern_val(ats_sum_type, _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__S2CTXT_0) ;

/* external dynamic constant declarations */
ATSextern_fun(ats_int_type, atspre_add_int_int) (ats_int_type, ats_int_type) ;
ATSextern_fun(ats_bool_type, atspre_gt_int_int) (ats_int_type, ats_int_type) ;
ATSextern_fun(ats_ptr_type, _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_2esats__s2exp_at) (ats_ptr_type, ats_ptr_type) ;
ATSextern_fun(ats_ptr_type, _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_2esats__s2exp_tyrec_srt) (ats_ptr_type, ats_ptr_type, ats_int_type, ats_ptr_type) ;
ATSextern_fun(ats_bool_type, _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_2esats__s2exp_is_lin) (ats_ptr_type) ;
ATSextern_fun(ats_ptr_type, _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_util_2esats__s2rt_linearize) (ats_ptr_type) ;
ATSextern_fun(ats_ptr_type, _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_util_2esats__s2ctxt_hrepl) (ats_ptr_type, ats_ptr_type) ;
ATSextern_fun(ats_ptr_type, _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__s2exp_hrepl_flag) (ats_ptr_type, ats_ptr_type, ats_ref_type) ;
ATSextern_fun(ats_ptr_type, _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__labs2explst_hrepl_flag) (ats_ptr_type, ats_ptr_type, ats_ref_type) ;

/* external dynamic terminating constant declarations */
#ifdef _ATS_PROOFCHECK
#endif /* _ATS_PROOFCHECK */

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

/* sum constructor declarations */
ATSglobal(ats_sum_type, _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__S2CTXT_0) ;

/* exn constructor declarations */
/* global dynamic (non-functional) constant declarations */
/* internal function declarations */

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

/* function implementations */

/*
// /tmp/ATS-Postiats/src/pats_staexp2_ctxt.dats: 1613(line=48, offs=13) -- 1643(line=48, offs=43)
*/
ATSglobaldec()
ats_ptr_type
_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_2esats__s2ctxt_make (ats_ptr_type arg0, ats_ptr_type arg1) {
/* local vardec */
ATSlocal (ats_ptr_type, tmp0) ;

__ats_lab__2tmp_2ATS_2dPostiats_2src_2pats_staexp2_2esats__s2ctxt_make:
tmp0 = ATS_MALLOC(sizeof(anairiats_sum_0)) ;
ats_selptrset_mac(anairiats_sum_0, tmp0, atslab_0, arg0) ;
ats_selptrset_mac(anairiats_sum_0, tmp0, atslab_1, arg1) ;
return (tmp0) ;
} /* end of [_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_2esats__s2ctxt_make] */

/*
// /tmp/ATS-Postiats/src/pats_staexp2_ctxt.dats: 1929(line=65, offs=1) -- 2727(line=101, offs=4)
*/
ATSglobaldec()
ats_ptr_type
_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__s2exp_hrepl_flag (ats_ptr_type arg0, ats_ptr_type arg1, ats_ref_type arg2) {
/* local vardec */
ATSlocal (ats_ptr_type, tmp1) ;
ATSlocal (ats_ptr_type, tmp2) ;
ATSlocal (ats_int_type, tmp3) ;
ATSlocal (ats_ptr_type, tmp4) ;
ATSlocal (ats_ptr_type, tmp5) ;
ATSlocal (ats_int_type, tmp6) ;
ATSlocal (ats_ptr_type, tmp7) ;
ATSlocal (ats_bool_type, tmp8) ;
ATSlocal (ats_ptr_type, tmp9) ;
ATSlocal (ats_int_type, tmp10) ;
ATSlocal (ats_ptr_type, tmp11) ;
ATSlocal (ats_int_type, tmp12) ;
ATSlocal (ats_ptr_type, tmp13) ;
ATSlocal (ats_bool_type, tmp14) ;
ATSlocal (ats_ptr_type, tmp15) ;
ATSlocal (ats_bool_type, tmp16) ;
ATSlocal (ats_ptr_type, tmp17) ;

__ats_lab__2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__s2exp_hrepl_flag:
tmp2 = ats_selbox_mac(ats_castptr_mac(anairiats_rec_1, arg0), atslab_s2exp_node) ;
do {
/* branch: __ats_lab_0 */
__ats_lab_0_0:
if (((ats_sum_ptr_type)tmp2)->tag != 9) { goto __ats_lab_1_0 ; }
__ats_lab_0_1:
tmp3 = atspre_add_int_int (ats_ptrget_mac(ats_int_type, arg2), 1) ;
ats_ptrget_mac(ats_int_type, arg2) = tmp3 ;
tmp1 = arg1 ;
break ;

/* branch: __ats_lab_1 */
__ats_lab_1_0:
if (((ats_sum_ptr_type)tmp2)->tag != 12) { goto __ats_lab_2_0 ; }
__ats_lab_1_1:
tmp4 = ats_caselptrlab_mac(anairiats_sum_2, tmp2, atslab_0) ;
tmp5 = ats_caselptrlab_mac(anairiats_sum_2, tmp2, atslab_1) ;
tmp6 = ats_ptrget_mac(ats_int_type, arg2) ;
tmp7 = _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__s2exp_hrepl_flag (tmp4, arg1, arg2) ;
tmp8 = atspre_gt_int_int (ats_ptrget_mac(ats_int_type, arg2), tmp6) ;
if (tmp8) {
tmp1 = _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_2esats__s2exp_at (tmp7, tmp5) ;
} else {
tmp1 = arg0 ;
} /* end of [if] */
break ;

/* branch: __ats_lab_2 */
__ats_lab_2_0:
if (((ats_sum_ptr_type)tmp2)->tag != 25) { goto __ats_lab_3_0 ; }
__ats_lab_2_1:
tmp9 = ats_caselptrlab_mac(anairiats_sum_3, tmp2, atslab_0) ;
tmp10 = ats_caselptrlab_mac(anairiats_sum_3, tmp2, atslab_1) ;
tmp11 = ats_caselptrlab_mac(anairiats_sum_3, tmp2, atslab_2) ;
tmp12 = ats_ptrget_mac(ats_int_type, arg2) ;
tmp13 = _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__labs2explst_hrepl_flag (tmp11, arg1, arg2) ;
tmp14 = atspre_gt_int_int (ats_ptrget_mac(ats_int_type, arg2), tmp12) ;
if (tmp14) {
tmp16 = _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_2esats__s2exp_is_lin (arg1) ;
if (tmp16) {
tmp17 = ats_selbox_mac(ats_castptr_mac(anairiats_rec_1, arg0), atslab_s2exp_srt) ;
tmp15 = _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_util_2esats__s2rt_linearize (tmp17) ;
} else {
tmp15 = ats_selbox_mac(ats_castptr_mac(anairiats_rec_1, arg0), atslab_s2exp_srt) ;
} /* end of [if] */
tmp1 = _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_2esats__s2exp_tyrec_srt (tmp15, tmp9, tmp10, tmp13) ;
} else {
tmp1 = arg0 ;
} /* end of [if] */
break ;

/* branch: __ats_lab_3 */
__ats_lab_3_0:
__ats_lab_3_1:
tmp1 = arg0 ;
break ;
} while (0) ;
return (tmp1) ;
} /* end of [_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__s2exp_hrepl_flag] */

/*
// /tmp/ATS-Postiats/src/pats_staexp2_ctxt.dats: 2793(line=105, offs=3) -- 3333(line=126, offs=4)
*/
ATSglobaldec()
ats_ptr_type
_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__labs2explst_hrepl_flag (ats_ptr_type arg0, ats_ptr_type arg1, ats_ref_type arg2) {
/* local vardec */
ATSlocal (ats_ptr_type, tmp18) ;
ATSlocal (ats_ptr_type, tmp19) ;
ATSlocal (ats_ptr_type, tmp20) ;
ATSlocal (ats_int_type, tmp21) ;
ATSlocal (ats_ptr_type, tmp22) ;
ATSlocal (ats_ptr_type, tmp23) ;
ATSlocal (ats_ptr_type, tmp24) ;
ATSlocal (ats_ptr_type, tmp25) ;
ATSlocal (ats_bool_type, tmp26) ;
ATSlocal (ats_ptr_type, tmp27) ;
ATSlocal (ats_ptr_type, tmp28) ;
ATSlocal (ats_bool_type, tmp29) ;

__ats_lab__2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__labs2explst_hrepl_flag:
do {
/* branch: __ats_lab_4 */
__ats_lab_4_0:
if (arg0 == (ats_sum_ptr_type)0) { goto __ats_lab_5_0 ; }
__ats_lab_4_1:
tmp19 = ats_caselptrlab_mac(anairiats_sum_0, arg0, atslab_0) ;
tmp20 = ats_caselptrlab_mac(anairiats_sum_0, arg0, atslab_1) ;
tmp21 = ats_ptrget_mac(ats_int_type, arg2) ;

tmp22 = ats_caselptrlab_mac(anairiats_sum_4, tmp19, atslab_0) ;
tmp23 = ats_caselptrlab_mac(anairiats_sum_4, tmp19, atslab_1) ;
tmp24 = ats_caselptrlab_mac(anairiats_sum_4, tmp19, atslab_2) ;
tmp25 = _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__s2exp_hrepl_flag (tmp24, arg1, arg2) ;
tmp26 = atspre_gt_int_int (ats_ptrget_mac(ats_int_type, arg2), tmp21) ;
if (tmp26) {
tmp27 = ATS_MALLOC(sizeof(anairiats_sum_4)) ;
ats_selptrset_mac(anairiats_sum_4, tmp27, atslab_0, tmp22) ;
ats_selptrset_mac(anairiats_sum_4, tmp27, atslab_1, tmp23) ;
ats_selptrset_mac(anairiats_sum_4, tmp27, atslab_2, tmp25) ;
tmp18 = ATS_MALLOC(sizeof(anairiats_sum_0)) ;
ats_selptrset_mac(anairiats_sum_0, tmp18, atslab_0, tmp27) ;
ats_selptrset_mac(anairiats_sum_0, tmp18, atslab_1, tmp20) ;
} else {
tmp28 = _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__labs2explst_hrepl_flag (tmp20, arg1, arg2) ;
tmp29 = atspre_gt_int_int (ats_ptrget_mac(ats_int_type, arg2), tmp21) ;
if (tmp29) {
tmp18 = ATS_MALLOC(sizeof(anairiats_sum_0)) ;
ats_selptrset_mac(anairiats_sum_0, tmp18, atslab_0, tmp19) ;
ats_selptrset_mac(anairiats_sum_0, tmp18, atslab_1, tmp28) ;
} else {
tmp18 = arg0 ;
} /* end of [if] */
} /* end of [if] */
break ;

/* branch: __ats_lab_5 */
__ats_lab_5_0:
// if (arg0 != (ats_sum_ptr_type)0) { ats_deadcode_failure_handle () ; }
__ats_lab_5_1:
tmp18 = (ats_sum_ptr_type)0 ;
break ;
} while (0) ;
return (tmp18) ;
} /* end of [_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__labs2explst_hrepl_flag] */

/*
// /tmp/ATS-Postiats/src/pats_staexp2_ctxt.dats: 3415(line=132, offs=3) -- 3496(line=136, offs=4)
*/
ATSglobaldec()
ats_ptr_type
_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_util_2esats__s2exp_hrepl (ats_ptr_type arg0, ats_ptr_type arg1) {
/* local vardec */
ATSlocal (ats_ptr_type, tmp30) ;
ATSlocal (ats_int_type, tmp31) ;

__ats_lab__2tmp_2ATS_2dPostiats_2src_2pats_staexp2_util_2esats__s2exp_hrepl:
/* ats_int_type tmp31 ; */
tmp31 = 0 ;
tmp30 = _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__s2exp_hrepl_flag (arg0, arg1, (&tmp31)) ;
return (tmp30) ;
} /* end of [_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_util_2esats__s2exp_hrepl] */

/*
// /tmp/ATS-Postiats/src/pats_staexp2_ctxt.dats: 3568(line=142, offs=3) -- 3705(line=148, offs=4)
*/
ATSglobaldec()
ats_ptr_type
_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_util_2esats__s2ctxt_hrepl (ats_ptr_type arg0, ats_ptr_type arg1) {
/* local vardec */
ATSlocal (ats_ptr_type, tmp32) ;
ATSlocal (ats_int_type, tmp33) ;
ATSlocal (ats_ptr_type, tmp34) ;

__ats_lab__2tmp_2ATS_2dPostiats_2src_2pats_staexp2_util_2esats__s2ctxt_hrepl:
/* ats_int_type tmp33 ; */
tmp33 = 0 ;
// 
tmp34 = ats_caselptrlab_mac(anairiats_sum_0, arg0, atslab_0) ;
tmp32 = _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__s2exp_hrepl_flag (tmp34, arg1, (&tmp33)) ;
return (tmp32) ;
} /* end of [_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_util_2esats__s2ctxt_hrepl] */

/*
// /tmp/ATS-Postiats/src/pats_staexp2_ctxt.dats: 3760(line=152, offs=3) -- 3869(line=156, offs=23)
*/
ATSglobaldec()
ats_ptr_type
_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_util_2esats__s2ctxtopt_hrepl (ats_ptr_type arg0, ats_ptr_type arg1) {
/* local vardec */
ATSlocal (ats_ptr_type, tmp35) ;
ATSlocal (ats_ptr_type, tmp36) ;
ATSlocal (ats_ptr_type, tmp37) ;

__ats_lab__2tmp_2ATS_2dPostiats_2src_2pats_staexp2_util_2esats__s2ctxtopt_hrepl:
do {
/* branch: __ats_lab_6 */
__ats_lab_6_0:
if (arg0 == (ats_sum_ptr_type)0) { goto __ats_lab_7_0 ; }
__ats_lab_6_1:
tmp36 = ats_caselptrlab_mac(anairiats_sum_5, arg0, atslab_0) ;
tmp37 = _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_util_2esats__s2ctxt_hrepl (tmp36, arg1) ;
tmp35 = ATS_MALLOC(sizeof(anairiats_sum_5)) ;
ats_selptrset_mac(anairiats_sum_5, tmp35, atslab_0, tmp37) ;
break ;

/* branch: __ats_lab_7 */
__ats_lab_7_0:
// if (arg0 != (ats_sum_ptr_type)0) { ats_deadcode_failure_handle () ; }
__ats_lab_7_1:
tmp35 = (ats_sum_ptr_type)0 ;
break ;
} while (0) ;
return (tmp35) ;
} /* end of [_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_util_2esats__s2ctxtopt_hrepl] */

/* static load function */

extern ats_void_type _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_2esats__staload (void) ;
extern ats_void_type _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_util_2esats__staload (void) ;

ats_void_type
_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__staload () {
static int _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__staload_flag = 0 ;
if (_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__staload_flag) return ;
_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__staload_flag = 1 ;

_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_2esats__staload () ;
_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_util_2esats__staload () ;

// _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__S2CTXT_0.tag = 0 ;
return ;
} /* staload function */

/* dynamic load function */

// dynload flag declaration
extern ats_int_type _2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__dynload_flag ;

ats_void_type
_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__dynload () {
_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__dynload_flag = 1 ;
_2tmp_2ATS_2dPostiats_2src_2pats_staexp2_ctxt_2edats__staload () ;

#ifdef _ATS_PROOFCHECK
#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 */

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

/* end of [pats_staexp2_ctxt_dats.c] */
