

#include "BUILTIN.h"

#include "Nat.h"
extern OBJ __ASeq_6;
extern OBJ _ASeq_26(OBJ,OBJ);extern OBJ __ASeq_26;
extern OBJ _ASeq_31(OBJ,OBJ);extern OBJ __ASeq_31;
extern OBJ _ASeq_32(OBJ,OBJ);extern OBJ __ASeq_32;
extern TUP2 _ASeq_33(OBJ,OBJ);extern OBJ __ASeq_33;
extern OBJ _ASeq_52(OBJ,OBJ);extern OBJ __ASeq_52;
extern OBJ __AOption_5;
extern OBJ _AOptionMap_3(OBJ,OBJ);extern OBJ __AOptionMap_3;
extern OBJ _ASeqIndex_2(OBJ,OBJ);OBJ __ASeqIndex_2; /* ! */
extern OBJ _ASeqIndex_3(OBJ,OBJ);OBJ __ASeqIndex_3; /* pos */
extern OBJ _ASeqIndex_4(OBJ,OBJ,OBJ);OBJ __ASeqIndex_4; /* slice */
extern OBJ _ASeqIndex_5(OBJ,OBJ,OBJ);OBJ __ASeqIndex_5; /* upd */
extern OBJ _ASeqIndex_6(OBJ,OBJ,OBJ);OBJ __ASeqIndex_6; /* upd,1 */
extern OBJ _ASeqIndex_7(OBJ,OBJ,OBJ);OBJ __ASeqIndex_7; /* swap */
extern OBJ _ASeqIndex_8(OBJ,OBJ,OBJ);OBJ __ASeqIndex_8; /* repl */
extern OBJ _ASeqIndex_9(OBJ,OBJ,OBJ);OBJ __ASeqIndex_9; /* insert */
extern OBJ _ASeqIndex_10(OBJ,OBJ,OBJ);OBJ __ASeqIndex_10; /* delete */
OBJ __ASeqIndex_11; /* pos'11 */

extern OBJ _ASeqIndex_2(register OBJ x1,register OBJ x2) /* ! */
{OBJ r;
 for(;;){
  if(ISPRM(x1)){
   HLT("!\'SeqIndex: index out of range");
  }else{
   {OBJ x17=FLD1(x1,1);OBJ x18=FLD1(x1,2);
    if(EXPRD(x1,1)){
     DSPRDF(x1);
    }else{
     COPY(x17,1);COPY(x18,1);
     FRPRD(x1,1);}
    {OBJ x19;
     ANat_6(x2,x19);
     if(ISTGPRM(x19,1)){
      r=x17;
      FREE(x18,1);
     }else{
      FREE(x17,1);
      {OBJ x20;
       ANat_3(x2,x20);
       if(ISTGPRM(x20,1)){
	{OBJ x21;
	 ANat_4(x2,x21);
	 x1=x18;x2=x21;continue;}
       }else{
	HLT("SeqIndex at <unknown> : missing else in !\'SeqIndex:seq**nat->data");}}}}}}
  break;}
 return r;}

extern OBJ _ASeqIndex_3(OBJ x1,OBJ x2) /* pos */
{OBJ r;
 if(ISPRM(x2)){
  FRCLS(x1,1);
  r=__AOption_5;
 }else{
  {OBJ x22=FLD1(x2,1);OBJ x23=FLD1(x2,2);
   if(EXPRD(x2,1)){
    DSPRDF(x2);
   }else{
    COPY(x22,1);COPY(x23,1);
    FRPRD(x2,1);}
   CPCLS(x1,1);
   {OBJ x25;
    x25=(*(OBJ(*)(OBJ,OBJ))METHOD(x1,1))(x1,x22);
    if(ISTGPRM(x25,1)){
     FRCLS(x1,1);
     FREE(x23,1);
     COPY(__ASeqIndex_11,1);
     r=__ASeqIndex_11;
    }else{
     CPCLS(__ANat_2,1);
     {OBJ x26;
      x26=_ASeqIndex_3(x1,x23);
      r=_AOptionMap_3(__ANat_2,x26);}}}}}
 return r;}

extern OBJ _ASeqIndex_4(OBJ x1,OBJ x2,OBJ x3) /* slice */
{OBJ r;
 {OBJ x4;
  ANat_81(x2,x3,x4);
  if(ISTGPRM(x4,1)){
   FREE(x1,1);
   r=__ASeq_6;
  }else{
   {OBJ x5;OBJ x6;OBJ x7;
    ANat_62(x3,x2,x5);
    x6=_ASeq_32(x2,x1);
    ANat_61(x5,__ANat_8,x7);
    r=_ASeq_31(x7,x6);}}}
 return r;}

extern OBJ _ASeqIndex_5(OBJ x1,OBJ x2,OBJ x3) /* upd */
{OBJ r;
 COPY(x3,1);
 {OBJ x4;OBJ x5;
  x4=_ASeq_52(x3,__ANat_5);
  ANat_80(x1,x4,x5);
  if(ISTGPRM(x5,1)){
   COPY(x3,1);
   {OBJ x6;OBJ x7;OBJ x8;OBJ x9;
    x6=_ASeq_31(x1,x3);
    ANat_2(x1,x7);
    x8=_ASeq_32(x7,x3);
    PRD1(2,x9);FLD1(x9,1)=x2;FLD1(x9,2)=x8;
    r=_ASeq_26(x6,x9);}
  }else{
   FREE(x2,1);
   r=x3;}}
 return r;}

extern OBJ _ASeqIndex_6(OBJ x1,OBJ x2,OBJ x3) /* upd,1 */
{OBJ r;
 COPY(x3,1);
 {OBJ x4;OBJ x5;
  x4=_ASeq_52(x3,__ANat_5);
  ANat_80(x1,x4,x5);
  if(ISTGPRM(x5,1)){
   COPY(x3,2);
   {OBJ x6;OBJ x7;OBJ x8;OBJ x9;OBJ x10;OBJ x11;
    x6=_ASeq_31(x1,x3);
    x7=_ASeqIndex_2(x3,x1);
    ANat_2(x1,x8);
    x9=(*(OBJ(*)(OBJ,OBJ))METHOD(x2,1))(x2,x7);
    x10=_ASeq_32(x8,x3);
    PRD1(2,x11);FLD1(x11,1)=x9;FLD1(x11,2)=x10;
    r=_ASeq_26(x6,x11);}
  }else{
   FRCLS(x2,1);
   r=x3;}}
 return r;}

extern OBJ _ASeqIndex_7(OBJ x1,OBJ x2,OBJ x3) /* swap */
{OBJ r;
 COPY(x3,1);
 {OBJ x4;OBJ x5;OBJ x6;
  x4=_ASeq_52(x3,__ANat_5);
  ANat_79(x1,x4,x5);
  if(ISTGPRM(x5,1)){
   x6=__ABUILTIN_5;
  }else{
   ANat_79(x2,x4,x6);}
  if(ISTGPRM(x6,0)){
   COPY(x3,2);
   {OBJ x7;OBJ x8;OBJ x9;
    x7=_ASeqIndex_2(x3,x2);
    x8=_ASeqIndex_2(x3,x1);
    x9=_ASeqIndex_5(x2,x8,x3);
    r=_ASeqIndex_5(x1,x7,x9);}
  }else{
   HLT("swap\'SeqIndex: index out of range");}}
 return r;}

extern OBJ _ASeqIndex_8(OBJ x1,OBJ x2,OBJ x3) /* repl */
{OBJ r;
 COPY(x1,1);
 COPY(x3,1);
 {OBJ x5;OBJ x6;TUP2 x7;OBJ x9;OBJ x10;OBJ x11;
  x5=_ASeq_52(x3,__ANat_5);
  x6=_ASeq_52(x1,__ANat_5);
  x7=_ASeq_33(x2,x1);
  x9=_ASeq_32(x5,x7.c2);
  x10=_ASeq_26(x3,x9);
  x11=_ASeq_26(x7.c1,x10);
  r=_ASeq_31(x6,x11);}
 return r;}

extern OBJ _ASeqIndex_9(OBJ x1,OBJ x2,OBJ x3) /* insert */
{OBJ r;
 {TUP2 x5;OBJ x7;
  x5=_ASeq_33(x2,x1);
  x7=_ASeq_26(x3,x5.c2);
  r=_ASeq_26(x5.c1,x7);}
 return r;}

extern OBJ _ASeqIndex_10(OBJ x1,OBJ x2,OBJ x3) /* delete */
{OBJ r;
 {OBJ x4;
  ANat_80(x3,x2,x4);
  if(ISTGPRM(x4,1)){
   r=x1;
  }else{
   {OBJ x6;OBJ x7;TUP2 x8;OBJ x10;
    ANat_62(x3,x2,x6);
    ANat_2(x6,x7);
    x8=_ASeq_33(x2,x1);
    x10=_ASeq_32(x7,x8.c2);
    r=_ASeq_26(x8.c1,x10);}}}
 return r;}


init_ASeqIndex()
{
 static int visited=0; if(visited) return; visited=1;
 init_ANat();
 init_ASeq();
 init_AOption();
 init_AOptionMap();
 CLS(3,_ASeqIndex_10,__ASeqIndex_10);
 CLS(3,_ASeqIndex_9,__ASeqIndex_9);
 CLS(3,_ASeqIndex_8,__ASeqIndex_8);
 CLS(3,_ASeqIndex_7,__ASeqIndex_7);
 CLS(3,_ASeqIndex_6,__ASeqIndex_6);
 CLS(3,_ASeqIndex_5,__ASeqIndex_5);
 CLS(3,_ASeqIndex_4,__ASeqIndex_4);
 CLS(2,_ASeqIndex_3,__ASeqIndex_3);
 CLS(2,_ASeqIndex_2,__ASeqIndex_2);
 PRD1F(1,__ASeqIndex_11);FLD1(__ASeqIndex_11,1)=__ANat_5;}

