

#include "BUILTIN.h"

#include "Nat.h"
extern OBJ __AOption_5;

#include "Bitset.h"

#include "Array.h"
extern OBJ _ACAST_3(OBJ);extern OBJ __ACAST_3;
extern OBJ _AIdentity_2(OBJ);extern OBJ __AIdentity_2;
extern OBJ _ADArray_2(OBJ,OBJ,OBJ);OBJ __ADArray_2; /* abs */
extern OBJ _ADArray_3(OBJ);OBJ __ADArray_3; /* abs? */
extern OBJ _ADArray_4(OBJ);OBJ __ADArray_4; /* new */
extern OBJ _ADArray_5(OBJ);OBJ __ADArray_5; /* occ */
extern OBJ _ADArray_6(OBJ);OBJ __ADArray_6; /* rep */
extern OBJ _ADArray_8(OBJ,OBJ);OBJ __ADArray_8; /* init */
extern OBJ _ADArray_9(OBJ,OBJ);OBJ __ADArray_9; /* init,1 */
extern OBJ _ADArray_10(OBJ,OBJ,OBJ);OBJ __ADArray_10; /* init,2 */
extern OBJ _ADArray_11(OBJ,OBJ,OBJ);OBJ __ADArray_11; /* init,3 */
OBJ __ADArray_12; /* empty */
extern OBJ _ADArray_13(OBJ);OBJ __ADArray_13; /* empty,1 */
extern OBJ _ADArray_14(OBJ,OBJ,OBJ);OBJ __ADArray_14; /* upd */
extern OBJ _ADArray_15(OBJ,OBJ,OBJ);OBJ __ADArray_15; /* := */
extern OBJ _ADArray_16(OBJ,OBJ,OBJ);OBJ __ADArray_16; /* upd,1 */
extern OBJ _ADArray_17(OBJ,OBJ,OBJ);OBJ __ADArray_17; /* swap */
extern OBJ _ADArray_18(OBJ,OBJ,OBJ);OBJ __ADArray_18; /* extend */
extern OBJ _ADArray_19(OBJ,OBJ,OBJ);OBJ __ADArray_19; /* extend,1 */
extern OBJ _ADArray_20(OBJ,OBJ);OBJ __ADArray_20; /* ! */
extern OBJ _ADArray_21(OBJ,OBJ);OBJ __ADArray_21; /* !? */
extern OBJ _ADArray_22(OBJ);OBJ __ADArray_22; /* # */
extern OBJ _ADArray_23(OBJ);OBJ __ADArray_23; /* empty? */
extern OBJ _ADArray_25(OBJ,OBJ);OBJ __ADArray_25; /* def? */
extern OBJ _ADArray_31(OBJ,OBJ,OBJ,OBJ);OBJ __ADArray_31; /* extend,2 */
OBJ __ADArray_32; /* init,3'32 */
extern OBJ _ADArray_33(OBJ);OBJ __ADArray_33; /* init,3'33 */
extern OBJ _ADArray_34(OBJ,OBJ,OBJ);OBJ __ADArray_34; /* init,3'34 */
extern OBJ _ADArray_35(OBJ,OBJ);OBJ __ADArray_35; /* init,2'35 */
extern OBJ _ADArray_36(OBJ);OBJ __ADArray_36; /* empty,1'36 */
extern OBJ _ADArray_37(OBJ);OBJ __ADArray_37; /* empty,1'37 */
extern OBJ _ADArray_38(OBJ);OBJ __ADArray_38; /* :='38 */
extern OBJ _ADArray_39(OBJ,OBJ,OBJ);OBJ __ADArray_39; /* :='39 */

extern OBJ _ADArray_2(OBJ x1,OBJ x2,OBJ x3) /* abs */
{OBJ r;
 PRD1(3,r);FLD1(r,1)=x1;FLD1(r,2)=x2;FLD1(r,3)=x3;
 return r;}

extern OBJ _ADArray_3(OBJ x1) /* abs? */
{OBJ r;
 FRPRD(x1,1);
 r=__ABUILTIN_5;
 return r;}

extern OBJ _ADArray_4(OBJ x1) /* new */
{OBJ r;
 {OBJ x4=FLD1(x1,3);
  if(EXPRD(x1,1)){
   r=x4;
   DSPRD(x1);
  }else{
   r=x4;
   FRPRD(x1,1);}}
 return r;}

extern OBJ _ADArray_5(OBJ x1) /* occ */
{OBJ r;
 {OBJ x3=FLD1(x1,2);
  if(EXPRD(x1,1)){
   r=x3;
   FRPRD(FLD1(x1,1),1);DSPRDF(x1);
  }else{
   CPPRD(x3,1);
   r=x3;
   FRPRD(x1,1);}}
 return r;}

extern OBJ _ADArray_6(OBJ x1) /* rep */
{OBJ r;
 {OBJ x2=FLD1(x1,1);
  if(EXPRD(x1,1)){
   r=x2;
   FRPRD(FLD1(x1,2),1);DSPRDF(x1);
  }else{
   CPPRD(x2,1);
   r=x2;
   FRPRD(x1,1);}}
 return r;}

extern OBJ _ADArray_8(OBJ x1,OBJ x2) /* init */
{OBJ r;
 CPCLS(__ADArray_35,1);
 {OBJ x3;OBJ x4;
  ANat_70(x1,x3);
  x4=(*(OBJ(*)(OBJ,OBJ))METHOD(__ADArray_35,1))(__ADArray_35,x2);
  r=_ADArray_11(x3,x1,x4);}
 return r;}

extern OBJ _ADArray_9(OBJ x1,OBJ x2) /* init,1 */
{OBJ r;
 {OBJ x3;
  ANat_70(x1,x3);
  r=_ADArray_11(x3,x1,x2);}
 return r;}

extern OBJ _ADArray_10(OBJ x1,OBJ x2,OBJ x3) /* init,2 */
{OBJ r;
 CPCLS(__ADArray_35,1);
 {OBJ x4;
  x4=(*(OBJ(*)(OBJ,OBJ))METHOD(__ADArray_35,1))(__ADArray_35,x3);
  r=_ADArray_11(x1,x2,x4);}
 return r;}

extern OBJ _ADArray_11(OBJ x1,OBJ x2,OBJ x3) /* init,3 */
{OBJ r;
 {OBJ x4;
  ANat_6(x2,x4);
  if(ISTGPRM(x4,1)){
   FRCLS(x3,1);
   CPPRD(__ADArray_32,1);
   r=__ADArray_32;
  }else{
   CPCLS(__ADArray_34,1);
   CPCLS(__AIdentity_2,1);
   {OBJ x5;OBJ x6;OBJ x7;
    ANat_4(x2,x5);
    ABitset_14(__ANat_5,x5,__AIdentity_2,x6);
    x7=(*(OBJ(*)(OBJ,OBJ,OBJ))METHOD(__ADArray_34,2))(__ADArray_34,x2,x3);
    PRD1(3,r);FLD1(r,2)=x6;FLD1(r,3)=x2;
    AArray_4(x1,x7,FLD1(r,1));}}}
 return r;}

extern OBJ _ADArray_13(OBJ x1) /* empty,1 */
{OBJ r;
 CPCLS(__ADArray_37,1);
 {OBJ x3;
  x3=(*(OBJ(*)(OBJ,OBJ))METHOD(__ADArray_37,1))(__ADArray_37,__ABUILTIN_20);
  r=_ADArray_11(x1,__ANat_5,x3);}
 return r;}

extern OBJ _ADArray_14(OBJ x1,OBJ x2,OBJ x3) /* upd */
{OBJ r;
 r=_ADArray_15(x3,x1,x2);
 return r;}

extern OBJ _ADArray_15(OBJ x1,OBJ x2,OBJ x3) /* := */
{OBJ r;
 {OBJ x27=FLD1(x1,1);OBJ x28=FLD1(x1,2);OBJ x29=FLD1(x1,3);FLAG x_x1=EXPRD(x1,1);
  if(x_x1){
   CPPRD(x27,1);
  }else{
   CPPRD(x27,2);CPPRD(x28,1);}
  {OBJ x30;OBJ x31;OBJ x32;OBJ x33;OBJ x34;
   AArray_16(x27,x30);
   ANat_79(x2,x29,x31);
   ABitset_3(x2,x28,x32);
   if(ISTGPRM(x31,1)){
    ANat_2(x2,x33);
   }else{
    x33=x29;}
   ANat_78(x33,x30,x34);
   if(ISTGPRM(x34,1)){
    {
     if(x_x1){
      RSOME(x1,r);FLD1(r,2)=x32;FLD1(r,3)=x33;
     }else{
      FRPRD(x1,1);PRD1(3,r);FLD1(r,2)=x32;FLD1(r,3)=x33;}
     AArray_8(x27,x2,x3,FLD1(r,1));}
   }else{
    CPCLS(__ADArray_39,1);
    {OBJ x36;OBJ x37;OBJ x38;OBJ x39;
     ANat_70(x33,x36);
     x37=(*(OBJ(*)(OBJ,OBJ,OBJ))METHOD(__ADArray_39,2))(__ADArray_39,x27,x30);
     ANat_2(x36,x38);
     AArray_4(x38,x37,x39);
     if(x_x1){
      RSOME(x1,r);FLD1(r,2)=x32;FLD1(r,3)=x33;
     }else{
      FRPRD(x1,1);PRD1(3,r);FLD1(r,2)=x32;FLD1(r,3)=x33;}
     AArray_8(x39,x2,x3,FLD1(r,1));}}}}
 return r;}

extern OBJ _ADArray_16(OBJ x1,OBJ x2,OBJ x3) /* upd,1 */
{OBJ r;
 {OBJ x18=FLD1(x3,1);OBJ x19=FLD1(x3,2);OBJ x20=FLD1(x3,3);FLAG x_x3=EXPRD(x3,1);
  if(x_x3){
   CPPRD(x19,1);
  }else{
   CPPRD(x18,1);CPPRD(x19,2);}
  {OBJ x21;
   ABitset_21(x1,x19,x21);
   if(ISTGPRM(x21,1)){
    {
     if(x_x3){
      RSOME(x3,r);
     }else{
      FRPRD(x3,1);PRD1(3,r);FLD1(r,2)=x19;FLD1(r,3)=x20;}
     AArray_9(x1,x2,x18,FLD1(r,1));}
   }else{
    HLT("upd\'DArray: index out of range or undefined");}}}
 return r;}

extern OBJ _ADArray_17(OBJ x1,OBJ x2,OBJ x3) /* swap */
{OBJ r;
 {OBJ x19=FLD1(x1,1);OBJ x20=FLD1(x1,2);OBJ x21=FLD1(x1,3);FLAG x_x1=EXPRD(x1,1);
  if(x_x1){
   CPPRD(x20,1);
  }else{
   CPPRD(x19,1);CPPRD(x20,2);}
  {OBJ x22;OBJ x23;
   ABitset_21(x2,x20,x22);
   if(ISTGPRM(x22,1)){
    CPPRD(x20,1);
    ABitset_21(x3,x20,x23);
   }else{
    x23=__ABUILTIN_3;}
   if(ISTGPRM(x23,1)){
    {
     if(x_x1){
      RSOME(x1,r);
     }else{
      FRPRD(x1,1);PRD1(3,r);FLD1(r,2)=x20;FLD1(r,3)=x21;}
     AArray_10(x19,x2,x3,FLD1(r,1));}
   }else{
    HLT("swap\'DArray: index out of range or undefined");}}}
 return r;}

extern OBJ _ADArray_18(register OBJ x1,register OBJ x2,register OBJ x3) /* extend */
{OBJ r;
 for(;;){
  {OBJ x4;
   ANat_6(x2,x4);
   if(ISTGPRM(x4,1)){
    FREE(x3,1);
    r=x1;
   }else{
    {OBJ x9;
     ANat_4(x2,x9);
     {OBJ x7=FLD1(x1,3);
      COPY(x3,1);
      {OBJ x8;OBJ x10;
       x8=x7;
       x10=_ADArray_15(x1,x8,x3);
       x1=x10;x2=x9;continue;}}}}}
  break;}
 return r;}

extern OBJ _ADArray_19(OBJ x1,OBJ x2,OBJ x3) /* extend,1 */
{OBJ r;
 r=_ADArray_31(x1,x2,__ANat_5,x3);
 return r;}

extern OBJ _ADArray_20(OBJ x1,OBJ x2) /* ! */
{OBJ r;
 {OBJ x16=FLD1(x1,1);OBJ x17=FLD1(x1,2);
  if(EXPRD(x1,1)){
   DSPRDF(x1);
  }else{
   CPPRD(x16,1);CPPRD(x17,1);
   FRPRD(x1,1);}
  {OBJ x19;
   ABitset_21(x2,x17,x19);
   if(ISTGPRM(x19,1)){
    AArray_15(x16,x2,r);
   }else{
    HLT("!\'DArray: index out of range or undefined");}}}
 return r;}

extern OBJ _ADArray_21(OBJ x1,OBJ x2) /* !? */
{OBJ r;
 {OBJ x17=FLD1(x1,1);OBJ x18=FLD1(x1,2);
  if(EXPRD(x1,1)){
   DSPRDF(x1);
  }else{
   CPPRD(x17,1);CPPRD(x18,1);
   FRPRD(x1,1);}
  {OBJ x20;
   ABitset_21(x2,x18,x20);
   if(ISTGPRM(x20,1)){
    {
     PRD1(1,r);
     AArray_15(x17,x2,FLD1(r,1));}
   }else{
    FRPRD(x17,1);
    r=__AOption_5;}}}
 return r;}

extern OBJ _ADArray_22(OBJ x1) /* # */
{OBJ r;
 {OBJ x15=FLD1(x1,2);
  if(EXPRD(x1,1)){
   FRPRD(FLD1(x1,1),1);DSPRDF(x1);
  }else{
   CPPRD(x15,1);
   FRPRD(x1,1);}
  ABitset_22(x15,r);}
 return r;}

extern OBJ _ADArray_23(OBJ x1) /* empty? */
{OBJ r;
 {OBJ x15=FLD1(x1,2);
  if(EXPRD(x1,1)){
   FRPRD(FLD1(x1,1),1);DSPRDF(x1);
  }else{
   CPPRD(x15,1);
   FRPRD(x1,1);}
  ABitset_20(x15,r);}
 return r;}

extern OBJ _ADArray_25(OBJ x1,OBJ x2) /* def? */
{OBJ r;
 {OBJ x16=FLD1(x2,2);
  if(EXPRD(x2,1)){
   FRPRD(FLD1(x2,1),1);DSPRDF(x2);
  }else{
   CPPRD(x16,1);
   FRPRD(x2,1);}
  ABitset_21(x1,x16,r);}
 return r;}

extern OBJ _ADArray_31(register OBJ x1,register OBJ x2,register OBJ x3,register OBJ x4) /* extend,2 */
{OBJ r;
 for(;;){
  {OBJ x5;
   ANat_6(x2,x5);
   if(ISTGPRM(x5,1)){
    FRCLS(x4,1);
    r=x1;
   }else{
    CPCLS(x4,1);
    {OBJ x10;OBJ x11;OBJ x12;
     x10=(*(OBJ(*)(OBJ,OBJ))METHOD(x4,1))(x4,x3);
     ANat_4(x2,x11);
     ANat_2(x3,x12);
     {OBJ x8=FLD1(x1,3);
      {OBJ x9;OBJ x13;
       x9=x8;
       x13=_ADArray_15(x1,x9,x10);
       x1=x13;x2=x11;x3=x12;continue;}}}}}
  break;}
 return r;}

extern OBJ _ADArray_33(OBJ x1) /* init,3'33 */
{OBJ r;
 r=_ACAST_3(__ANat_5);
 return r;}

extern OBJ _ADArray_34(OBJ x1,OBJ x2,OBJ x3) /* init,3'34 */
{OBJ r;
 {OBJ x4;
  ANat_80(x3,x1,x4);
  if(ISTGPRM(x4,1)){
   r=(*(OBJ(*)(OBJ,OBJ))METHOD(x2,1))(x2,x3);
  }else{
   FRCLS(x2,1);
   CPCLS(__ADArray_33,1);
   r=(*(OBJ(*)(OBJ,OBJ))METHOD(__ADArray_33,1))(__ADArray_33,__ABUILTIN_20);}}
 return r;}

extern OBJ _ADArray_35(OBJ x1,OBJ x2) /* init,2'35 */
{OBJ r;
 r=x1;
 return r;}

extern OBJ _ADArray_36(OBJ x1) /* empty,1'36 */
{OBJ r;
 r=_ACAST_3(__ANat_5);
 return r;}

extern OBJ _ADArray_37(OBJ x1) /* empty,1'37 */
{OBJ r;
 CPCLS(__ADArray_35,1);
 CPCLS(__ADArray_36,1);
 {OBJ x2;
  x2=(*(OBJ(*)(OBJ,OBJ))METHOD(__ADArray_36,1))(__ADArray_36,__ABUILTIN_20);
  r=(*(OBJ(*)(OBJ,OBJ))METHOD(__ADArray_35,1))(__ADArray_35,x2);}
 return r;}

extern OBJ _ADArray_38(OBJ x1) /* :='38 */
{OBJ r;
 r=_ACAST_3(__ANat_5);
 return r;}

extern OBJ _ADArray_39(OBJ x1,OBJ x2,OBJ x3) /* :='39 */
{OBJ r;
 {OBJ x4;
  ANat_80(x3,x2,x4);
  if(ISTGPRM(x4,1)){
   AArray_15(x1,x3,r);
  }else{
   FRPRD(x1,1);
   CPCLS(__ADArray_38,1);
   r=(*(OBJ(*)(OBJ,OBJ))METHOD(__ADArray_38,1))(__ADArray_38,__ABUILTIN_20);}}
 return r;}

static void ___ADArray_12()
{
 CPCLS(__ADArray_35,1);
 {OBJ x1;OBJ x2;
  x1=_ACAST_3(__ANat_5);
  x2=(*(OBJ(*)(OBJ,OBJ))METHOD(__ADArray_35,1))(__ADArray_35,x1);
  __ADArray_12=_ADArray_11(__ANat_23,__ANat_5,x2);}}


static OBJ _mt_1_0_2(OBJ t,OBJ t1,OBJ t2) 
{OBJ r;
 {OBJ t3;
  DCCLS(t,1);
  t3=(*(OBJ(*)(OBJ))ENTRY(t))(t1);
  r=(*(OBJ(*)(OBJ,OBJ))METHOD(t3,1))(t3,t2);}
 return r;}

init_ADArray()
{
 static int visited=0; if(visited) return; visited=1;
 init_ANat();
 init_AOption();
 init_ABitset();
 init_AArray();
 init_ACAST();
 init_AIdentity();
 CLS(4,_ADArray_31,__ADArray_31);
 CLS(2,_ADArray_25,__ADArray_25);
 CLS(1,_ADArray_23,__ADArray_23);
 CLS(1,_ADArray_22,__ADArray_22);
 CLS(2,_ADArray_21,__ADArray_21);
 CLS(2,_ADArray_20,__ADArray_20);
 CLS(3,_ADArray_19,__ADArray_19);
 CLS(3,_ADArray_18,__ADArray_18);
 CLS(3,_ADArray_17,__ADArray_17);
 CLS(3,_ADArray_16,__ADArray_16);
 CLS(3,_ADArray_15,__ADArray_15);
 CLS(3,_ADArray_14,__ADArray_14);
 CLS(1,_ADArray_13,__ADArray_13);
 CLS(3,_ADArray_11,__ADArray_11);
 CLS(3,_ADArray_10,__ADArray_10);
 CLS(2,_ADArray_9,__ADArray_9);
 CLS(2,_ADArray_8,__ADArray_8);
 CLS(3,_ADArray_39,__ADArray_39);
 LCLS(1,_ADArray_38,__ADArray_38);
 CLS(1,_ADArray_6,__ADArray_6);
 LCLS(1,_ADArray_37,__ADArray_37);
 CLS(1,_ADArray_5,__ADArray_5);
 LCLS(1,_ADArray_36,__ADArray_36);
 CLS(1,_ADArray_4,__ADArray_4);
 CLS(2,_ADArray_35,__ADArray_35);
 CLS(1,_ADArray_3,__ADArray_3);
 CLS(3,_ADArray_34,__ADArray_34);
 CLS(3,_ADArray_2,__ADArray_2);
 LCLS(1,_ADArray_33,__ADArray_33);
 MTH(1,0,2,_mt_1_0_2);LZYMTH(1,0,2,_mt_1_0_2);
 CPPRD(__ABitset_2,1);
 CPPRD(__AArray_5,1);
 PRD1(3,__ADArray_32);FLD1(__ADArray_32,1)=__AArray_5;FLD1(__ADArray_32,2)=__ABitset_2;FLD1(__ADArray_32,3)=__ANat_5;
 ___ADArray_12();}

