

#include "BUILTIN.h"
extern OBJ _ATree_6(OBJ);extern OBJ __ATree_6;
extern OBJ __ATree_7;
extern OBJ _ATree_12(OBJ,OBJ);extern OBJ __ATree_12;

#include "Nat.h"
extern OBJ __AOption_5;
extern OBJ _AOptionMap_3(OBJ,OBJ);extern OBJ __AOptionMap_3;

#include "Denotation.h"
extern OBJ _AIndexingOfTrees_6(OBJ);extern OBJ __AIndexingOfTrees_6;
extern OBJ _AIndexingOfTrees_7(OBJ);extern OBJ __AIndexingOfTrees_7;
extern OBJ _AIndexingOfTrees_8(OBJ);extern OBJ __AIndexingOfTrees_8;
extern OBJ _AIndexingOfTrees_9(OBJ);extern OBJ __AIndexingOfTrees_9;

#include "Char.h"

#include "Int.h"
extern TUP2 _ATreeIndex_2(OBJ,OBJ);OBJ __ATreeIndex_2; /* step */
extern OBJ _ATreeIndex_3(OBJ,OBJ);OBJ __ATreeIndex_3; /* ! */
extern OBJ _ATreeIndex_4(OBJ,OBJ);OBJ __ATreeIndex_4; /* !? */
extern OBJ _ATreeIndex_5(OBJ,OBJ,OBJ);OBJ __ATreeIndex_5; /* upd */
extern OBJ _ATreeIndex_6(OBJ,OBJ,OBJ);OBJ __ATreeIndex_6; /* upd,1 */
extern OBJ _ATreeIndex_7(OBJ,OBJ);OBJ __ATreeIndex_7; /* !,1 */
extern OBJ _ATreeIndex_8(OBJ,OBJ);OBJ __ATreeIndex_8; /* !?,1 */
extern OBJ _ATreeIndex_9(OBJ,OBJ,OBJ);OBJ __ATreeIndex_9; /* repl */
extern OBJ _ATreeIndex_10(OBJ,OBJ,OBJ);OBJ __ATreeIndex_10; /* repl,1 */
extern OBJ _ATreeIndex_11(OBJ,OBJ,OBJ);OBJ __ATreeIndex_11; /* insert */
extern OBJ _ATreeIndex_12(OBJ,OBJ);OBJ __ATreeIndex_12; /* delete */
extern OBJ _ATreeIndex_24(OBJ,OBJ,OBJ,OBJ);OBJ __ATreeIndex_24; /* repl,2 */
OBJ __ATreeIndex_25; /* repl,2'25 */
extern OBJ _ATreeIndex_26(OBJ,OBJ);OBJ __ATreeIndex_26; /* upd'26 */
OBJ __ATreeIndex_27; /* upd'27 */
extern OBJ _ATreeIndex_28(OBJ,OBJ);OBJ __ATreeIndex_28; /* upd,1'28 */
extern OBJ _ATreeIndex_29(OBJ,OBJ);OBJ __ATreeIndex_29; /* repl'29 */
OBJ __ATreeIndex_30; /* repl'30 */
extern OBJ _ATreeIndex_31(OBJ,OBJ);OBJ __ATreeIndex_31; /* insert'31 */
OBJ __ATreeIndex_32; /* insert'32 */
extern OBJ _ATreeIndex_33(OBJ);OBJ __ATreeIndex_33; /* delete'33 */
OBJ __ATreeIndex_34; /* delete'34 */

extern TUP2 _ATreeIndex_2(OBJ x1,OBJ x2) /* step */
{TUP2 r;
 if(ISPRM(x1)){
  HLT("step\'TreeIndex: cannot step from empty tree");
 }else{
  {OBJ x32=FLD1(x1,2);OBJ x33=FLD1(x1,3);
   COPY(x32,1);COPY(x33,1);
   {OBJ x34;
    ANat_6(x2,x34);
    if(ISTGPRM(x34,1)){
     FREE(x32,1);
     FREE(x33,1);
     r.c1=x1;r.c2=__ANat_5;
    }else{
     if(EXPRD(x1,1)){
      DSPRD(x1);
     }else{
      DCPRD(x1,1);}
     {OBJ x36;
      x36=_AIndexingOfTrees_6(x2);
      if(ISTGPRM(x36,1)){
       r.c1=x32;
       FREE(x33,1);
       r.c2=_AIndexingOfTrees_8(x2);
      }else{
       FREE(x32,1);
       {OBJ x38;
	x38=_AIndexingOfTrees_7(x2);
	if(ISTGPRM(x38,1)){
	 r.c1=x33;
	 r.c2=_AIndexingOfTrees_9(x2);
	}else{
	 HLT("TreeIndex at <28,8-30,33> : missing else in step\'TreeIndex:tree**nat->tree**nat");}}}}}}}}
 return r;}
extern OBJ _ATreeIndex_2_c(OBJ x1,OBJ x2) /* step */
{OBJ r;
 {TUP2 t=_ATreeIndex_2(x1,x2);
  PRD1(2,r);
  FLD1(r,1)=t.c1;
  FLD1(r,2)=t.c2;}
 return r;}

extern OBJ _ATreeIndex_3(OBJ x1,OBJ x2) /* ! */
{OBJ r;
 {OBJ x3;OBJ x5;
  x3=_ATreeIndex_8(x1,x2);
  if(ISPRM(x3)){
   HLT("!\'TreeIndex: index does not exist");
  }else{
   {OBJ x4=FLD1(x3,1);
    if(EXPRD(x3,1)){
     x5=x4;
     DSPRDF(x3);
    }else{
     COPY(x4,1);
     x5=x4;
     FRPRD(x3,1);}}}
  if(ISPRM(x5)){
   HLT("Tree at <unknown> : undefined selection val\'Tree:tree->data");
  }else{
   {OBJ x6=FLD1(x5,1);
    if(EXPRD(x5,1)){
     r=x6;
     FLD1(x5,1)=NIL;DSPRD(x5);
    }else{
     COPY(x6,1);
     r=x6;
     FRPRD(x5,1);}}}}
 return r;}

extern OBJ _ATreeIndex_4(OBJ x1,OBJ x2) /* !? */
{OBJ r;
 CPCLS(__ATree_6,1);
 {OBJ x3;
  x3=_ATreeIndex_8(x1,x2);
  r=_AOptionMap_3(__ATree_6,x3);}
 return r;}

extern OBJ _ATreeIndex_5(OBJ x1,OBJ x2,OBJ x3) /* upd */
{OBJ r;
 CPCLS(__ATreeIndex_26,1);
 CPPRD(__ATreeIndex_27,1);
 {OBJ x4;
  x4=(*(OBJ(*)(OBJ,OBJ))METHOD(__ATreeIndex_26,1))(__ATreeIndex_26,x2);
  r=_ATreeIndex_24(__ATreeIndex_27,x3,x1,x4);}
 return r;}

extern OBJ _ATreeIndex_6(OBJ x1,OBJ x2,OBJ x3) /* upd,1 */
{OBJ r;
 CPPRD(__ATreeIndex_27,1);
 CPCLS(__ATreeIndex_28,1);
 {OBJ x4;
  x4=(*(OBJ(*)(OBJ,OBJ))METHOD(__ATreeIndex_28,1))(__ATreeIndex_28,x2);
  r=_ATreeIndex_24(__ATreeIndex_27,x3,x1,x4);}
 return r;}

extern OBJ _ATreeIndex_7(OBJ x1,OBJ x2) /* !,1 */
{OBJ r;
 {OBJ x3;
  x3=_ATreeIndex_8(x1,x2);
  if(ISPRM(x3)){
   HLT("!\'TreeIndex: index does not exist");
  }else{
   {OBJ x7=FLD1(x3,1);
    if(EXPRD(x3,1)){
     r=x7;
     DSPRDF(x3);
    }else{
     COPY(x7,1);
     r=x7;
     FRPRD(x3,1);}}}}
 return r;}

extern OBJ _ATreeIndex_8(register OBJ x1,register OBJ x2) /* !?,1 */
{OBJ r;
 for(;;){
  if(ISPRM(x1)){
   r=__AOption_5;
  }else{
   {OBJ x32=FLD1(x1,2);OBJ x33=FLD1(x1,3);
    COPY(x32,1);COPY(x33,1);
    {OBJ x34;
     ANat_6(x2,x34);
     if(ISTGPRM(x34,1)){
      FREE(x32,1);
      FREE(x33,1);
      PRD1(1,r);FLD1(r,1)=x1;
     }else{
      if(EXPRD(x1,1)){
       DSPRD(x1);
      }else{
       DCPRD(x1,1);}
      {OBJ x36;
       x36=_AIndexingOfTrees_6(x2);
       if(ISTGPRM(x36,1)){
	FREE(x33,1);
	{OBJ x37;
	 x37=_AIndexingOfTrees_8(x2);
	 x1=x32;x2=x37;continue;}
       }else{
	FREE(x32,1);
	{OBJ x38;
	 x38=_AIndexingOfTrees_7(x2);
	 if(ISTGPRM(x38,1)){
	  {OBJ x39;
	   x39=_AIndexingOfTrees_9(x2);
	   x1=x33;x2=x39;continue;}
	 }else{
	  HLT("TreeIndex at <73,8-75,37> : missing else in !\?\'TreeIndex:tree**nat->option");}}}}}}}}
  break;}
 return r;}

extern OBJ _ATreeIndex_9(OBJ x1,OBJ x2,OBJ x3) /* repl */
{OBJ r;
 CPCLS(__ATreeIndex_29,1);
 CPPRD(__ATreeIndex_30,1);
 {OBJ x4;
  x4=(*(OBJ(*)(OBJ,OBJ))METHOD(__ATreeIndex_29,1))(__ATreeIndex_29,x3);
  r=_ATreeIndex_24(__ATreeIndex_30,x1,x2,x4);}
 return r;}

extern OBJ _ATreeIndex_10(OBJ x1,OBJ x2,OBJ x3) /* repl,1 */
{OBJ r;
 CPPRD(__ATreeIndex_30,1);
 r=_ATreeIndex_24(__ATreeIndex_30,x1,x2,x3);
 return r;}

extern OBJ _ATreeIndex_11(OBJ x1,OBJ x2,OBJ x3) /* insert */
{OBJ r;
 CPCLS(__ATreeIndex_31,1);
 CPPRD(__ATreeIndex_32,1);
 {OBJ x4;
  x4=(*(OBJ(*)(OBJ,OBJ))METHOD(__ATreeIndex_31,1))(__ATreeIndex_31,x3);
  r=_ATreeIndex_24(__ATreeIndex_32,x1,x2,x4);}
 return r;}

extern OBJ _ATreeIndex_12(OBJ x1,OBJ x2) /* delete */
{OBJ r;
 CPCLS(__ATreeIndex_33,1);
 CPPRD(__ATreeIndex_34,1);
 r=_ATreeIndex_24(__ATreeIndex_34,x1,x2,__ATreeIndex_33);
 return r;}

extern OBJ _ATreeIndex_24(register OBJ x1,register OBJ x2,register OBJ x3,register OBJ x4) /* repl,2 */
{OBJ r;OBJ* p1=&r;
 for(;;){
  if(ISPRM(x2)){
   {OBJ x41;
    ANat_6(x3,x41);
    if(ISTGPRM(x41,1)){
     FRPRD(x1,1);
     *p1=(*(OBJ(*)(OBJ,OBJ))METHOD(x4,1))(x4,__ATree_7);
    }else{
     FRCLS(x4,1);
     CPPRD(__ATreeIndex_25,1);
     {OBJ x42;
      ADenotation_4(x1,__ATreeIndex_25,x42);
      ABUILTIN_12(x42,*p1);}}}
  }else{
   {OBJ x43=FLD1(x2,1);OBJ x44=FLD1(x2,2);OBJ x45=FLD1(x2,3);
    COPY(x43,1);COPY(x44,1);COPY(x45,1);
    {OBJ x46;
     ANat_6(x3,x46);
     if(ISTGPRM(x46,1)){
      FRPRD(x1,1);
      FREE(x43,1);
      FREE(x44,1);
      FREE(x45,1);
      *p1=(*(OBJ(*)(OBJ,OBJ))METHOD(x4,1))(x4,x2);
     }else{
      if(EXPRD(x2,1)){
       DSPRD(x2);
      }else{
       DCPRD(x2,1);}
      {OBJ x48;
       x48=_AIndexingOfTrees_6(x3);
       if(ISTGPRM(x48,1)){
	{OBJ x49;
	 x49=_AIndexingOfTrees_8(x3);
	 PRD1(3,*p1);FLD1(*p1,1)=x43;FLD1(*p1,3)=x45;
	 x2=x44;x3=x49;p1=&FLD1(*p1,2);continue;}
       }else{
	{OBJ x51;
	 x51=_AIndexingOfTrees_7(x3);
	 if(ISTGPRM(x51,1)){
	  {OBJ x52;
	   x52=_AIndexingOfTrees_9(x3);
	   PRD1(3,*p1);FLD1(*p1,1)=x43;FLD1(*p1,2)=x44;
	   x2=x45;x3=x52;p1=&FLD1(*p1,3);continue;}
	 }else{
	  HLT("TreeIndex at <107,8-109,37> : missing else in repl\'TreeIndex:denotation**tree**nat**(tree->tree)->tree");}}}}}}}}
  break;}
 return r;}

extern OBJ _ATreeIndex_26(OBJ x1,OBJ x2) /* upd'26 */
{OBJ r;
 if(ISPRM(x2)){
  HLT("upd\'TreeIndex: cannot update empty tree");
 }else{
  r=_ATree_12(x2,x1);}
 return r;}

extern OBJ _ATreeIndex_28(OBJ x1,OBJ x2) /* upd,1'28 */
{OBJ r;
 if(ISPRM(x2)){
  HLT("upd\'TreeIndex: cannot update empty tree");
 }else{
  {OBJ x12=FLD1(x2,1);
   COPY(x12,1);
   {OBJ x15;
    x15=(*(OBJ(*)(OBJ,OBJ))METHOD(x1,1))(x1,x12);
    r=_ATree_12(x2,x15);}}}
 return r;}

extern OBJ _ATreeIndex_29(OBJ x1,OBJ x2) /* repl'29 */
{OBJ r;
 FREE(x2,1);
 r=x1;
 return r;}

extern OBJ _ATreeIndex_31(OBJ x1,OBJ x2) /* insert'31 */
{OBJ r;
 if(ISPRM(x2)){
  r=x1;
 }else{
  HLT("insert\'TreeIndex: must replace an empty tree");}
 return r;}

extern OBJ _ATreeIndex_33(OBJ x1) /* delete'33 */
{OBJ r;
 FREE(x1,1);
 r=__ATree_7;
 return r;}

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

init_ATreeIndex()
{
 static int visited=0; if(visited) return; visited=1;
 init_ATree();
 init_ANat();
 init_AOption();
 init_ASeq();
 init_AOptionMap();
 init_ADenotation();
 init_ACompose();
 init_AIndexingOfTrees();
 init_AChar();
 init_ARelCmp();
 init_AInt();
 CLS(2,_ATreeIndex_31,__ATreeIndex_31);
 DEN("repl",__ATreeIndex_30);
 CLS(2,_ATreeIndex_29,__ATreeIndex_29);
 CLS(2,_ATreeIndex_28,__ATreeIndex_28);
 DEN("upd",__ATreeIndex_27);
 CLS(2,_ATreeIndex_26,__ATreeIndex_26);
 DEN("\'TreeIndex: index does not exist",__ATreeIndex_25);
 CLS(4,_ATreeIndex_24,__ATreeIndex_24);
 CLS(2,_ATreeIndex_12,__ATreeIndex_12);
 CLS(3,_ATreeIndex_11,__ATreeIndex_11);
 CLS(3,_ATreeIndex_10,__ATreeIndex_10);
 CLS(3,_ATreeIndex_9,__ATreeIndex_9);
 CLS(2,_ATreeIndex_8,__ATreeIndex_8);
 CLS(2,_ATreeIndex_7,__ATreeIndex_7);
 CLS(3,_ATreeIndex_6,__ATreeIndex_6);
 CLS(3,_ATreeIndex_5,__ATreeIndex_5);
 CLS(2,_ATreeIndex_4,__ATreeIndex_4);
 CLS(2,_ATreeIndex_3,__ATreeIndex_3);
 DEN("delete",__ATreeIndex_34);
 CLS(2,_ATreeIndex_2_c,__ATreeIndex_2);
 CLS(1,_ATreeIndex_33,__ATreeIndex_33);
 DEN("insert",__ATreeIndex_32);
 MTH(4,0,4,_mt_4_0_4);LZYMTH(4,0,4,_mt_4_0_4);}

