

#include "BUILTIN.h"
extern OBJ _AHeap_2(OBJ,OBJ,OBJ,OBJ);extern OBJ __AHeap_2;
extern OBJ _AHeap_6(OBJ,OBJ);extern OBJ __AHeap_6;
extern OBJ _AHeap_23(OBJ,OBJ,OBJ);extern OBJ __AHeap_23;
extern OBJ _AHeap_47(OBJ,OBJ);extern OBJ __AHeap_47;

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

#include "Denotation.h"
extern OBJ _ATreeIndex_8(OBJ,OBJ);extern OBJ __ATreeIndex_8;
extern OBJ __ATreeIndex_30;
extern OBJ __ATreeIndex_34;
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 _AHeapIndex_3(OBJ,OBJ,OBJ);OBJ __AHeapIndex_3; /* step */
extern OBJ _AHeapIndex_4(OBJ,OBJ,OBJ);OBJ __AHeapIndex_4; /* ! */
extern OBJ _AHeapIndex_5(OBJ,OBJ,OBJ);OBJ __AHeapIndex_5; /* !? */
extern OBJ _AHeapIndex_6(OBJ,OBJ,OBJ,OBJ);OBJ __AHeapIndex_6; /* upd */
extern OBJ _AHeapIndex_7(OBJ,OBJ,OBJ,OBJ);OBJ __AHeapIndex_7; /* upd,1 */
extern OBJ _AHeapIndex_8(OBJ,OBJ,OBJ);OBJ __AHeapIndex_8; /* !,1 */
extern OBJ _AHeapIndex_9(OBJ,OBJ,OBJ);OBJ __AHeapIndex_9; /* !?,1 */
extern OBJ _AHeapIndex_10(OBJ,OBJ,OBJ,OBJ);OBJ __AHeapIndex_10; /* repl */
extern OBJ _AHeapIndex_11(OBJ,OBJ,OBJ,OBJ);OBJ __AHeapIndex_11; /* repl,1 */
extern OBJ _AHeapIndex_12(OBJ,OBJ,OBJ,OBJ);OBJ __AHeapIndex_12; /* insert */
extern OBJ _AHeapIndex_13(OBJ,OBJ,OBJ);OBJ __AHeapIndex_13; /* delete */
extern OBJ _AHeapIndex_25(OBJ,OBJ,OBJ,OBJ,OBJ);OBJ __AHeapIndex_25; /* repl,2 */
OBJ __AHeapIndex_26; /* repl,2'26 */
extern OBJ _AHeapIndex_27(OBJ,OBJ,OBJ);OBJ __AHeapIndex_27; /* upd'27 */
OBJ __AHeapIndex_28; /* upd'28 */
extern OBJ _AHeapIndex_29(OBJ,OBJ,OBJ);OBJ __AHeapIndex_29; /* upd,1'29 */
extern OBJ _AHeapIndex_30(OBJ,OBJ);OBJ __AHeapIndex_30; /* repl'30 */
extern OBJ _AHeapIndex_31(OBJ,OBJ);OBJ __AHeapIndex_31; /* insert'31 */
OBJ __AHeapIndex_32; /* insert'32 */
extern OBJ _AHeapIndex_33(OBJ);OBJ __AHeapIndex_33; /* delete'33 */

extern TUP2 _AHeapIndex_3(OBJ x1,OBJ x2,OBJ x3) /* step */
{TUP2 r;
 FRCLS(x1,1);
 if(ISPRM(x2)){
  HLT("step\'HeapIndex: cannot step from empty heap");
 }else{
  {OBJ x33=FLD1(x2,2);OBJ x34=FLD1(x2,3);
   COPY(x33,1);COPY(x34,1);
   {OBJ x35;
    ANat_6(x3,x35);
    if(ISTGPRM(x35,1)){
     FREE(x33,1);
     FREE(x34,1);
     r.c1=x2;r.c2=__ANat_5;
    }else{
     if(EXPRD(x2,1)){
      DSPRD(x2);
     }else{
      DCPRD(x2,1);}
     {OBJ x37;
      x37=_AIndexingOfTrees_6(x3);
      if(ISTGPRM(x37,1)){
       r.c1=x33;
       FREE(x34,1);
       r.c2=_AIndexingOfTrees_8(x3);
      }else{
       FREE(x33,1);
       {OBJ x39;
	x39=_AIndexingOfTrees_7(x3);
	if(ISTGPRM(x39,1)){
	 r.c1=x34;
	 r.c2=_AIndexingOfTrees_9(x3);
	}else{
	 HLT("HeapIndex at <28,8-30,33> : missing else in step\'HeapIndex:heap**nat->heap**nat");}}}}}}}}
 return r;}
extern OBJ _AHeapIndex_3_c(OBJ x1,OBJ x2,OBJ x3) /* step */
{OBJ r;
 {TUP2 t=_AHeapIndex_3(x1,x2,x3);
  PRD1(2,r);
  FLD1(r,1)=t.c1;
  FLD1(r,2)=t.c2;}
 return r;}

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

extern OBJ _AHeapIndex_5(OBJ x1,OBJ x2,OBJ x3) /* !? */
{OBJ r;
 CPCLS(__AHeap_6,1);
 CPCLS(x1,1);
 {OBJ x4;OBJ x5;
  x4=(*(OBJ(*)(OBJ,OBJ))METHOD(__AHeap_6,1))(__AHeap_6,x1);
  x5=_AHeapIndex_9(x1,x2,x3);
  r=_AOptionMap_3(x4,x5);}
 return r;}

extern OBJ _AHeapIndex_6(OBJ x1,OBJ x2,OBJ x3,OBJ x4) /* upd */
{OBJ r;
 CPCLS(__AHeapIndex_27,1);
 CPPRD(__AHeapIndex_28,1);
 CPCLS(x1,1);
 {OBJ x5;
  x5=(*(OBJ(*)(OBJ,OBJ,OBJ))METHOD(__AHeapIndex_27,2))(__AHeapIndex_27,x1,x3);
  r=_AHeapIndex_25(x1,__AHeapIndex_28,x4,x2,x5);}
 return r;}

extern OBJ _AHeapIndex_7(OBJ x1,OBJ x2,OBJ x3,OBJ x4) /* upd,1 */
{OBJ r;
 CPPRD(__AHeapIndex_28,1);
 CPCLS(__AHeapIndex_29,1);
 CPCLS(x1,1);
 {OBJ x5;
  x5=(*(OBJ(*)(OBJ,OBJ,OBJ))METHOD(__AHeapIndex_29,2))(__AHeapIndex_29,x1,x3);
  r=_AHeapIndex_25(x1,__AHeapIndex_28,x4,x2,x5);}
 return r;}

extern OBJ _AHeapIndex_8(OBJ x1,OBJ x2,OBJ x3) /* !,1 */
{OBJ r;
 {OBJ x4;
  x4=_AHeapIndex_9(x1,x2,x3);
  if(ISPRM(x4)){
   HLT("!\'HeapIndex: index does not exist");
  }else{
   {OBJ x8=FLD1(x4,1);
    if(EXPRD(x4,1)){
     r=x8;
     DSPRDF(x4);
    }else{
     COPY(x8,1);
     r=x8;
     FRPRD(x4,1);}}}}
 return r;}

extern OBJ _AHeapIndex_9(OBJ x1,OBJ x2,OBJ x3) /* !?,1 */
{OBJ r;
 CPCLS(__AHeap_47,1);
 {OBJ x4;OBJ x5;
  x4=(*(OBJ(*)(OBJ,OBJ))METHOD(__AHeap_47,1))(__AHeap_47,x1);
  x5=_ATreeIndex_8(x2,x3);
  r=_AOptionMap_3(x4,x5);}
 return r;}

extern OBJ _AHeapIndex_10(OBJ x1,OBJ x2,OBJ x3,OBJ x4) /* repl */
{OBJ r;
 CPCLS(__AHeapIndex_30,1);
 CPPRD(__ATreeIndex_30,1);
 {OBJ x5;
  x5=(*(OBJ(*)(OBJ,OBJ))METHOD(__AHeapIndex_30,1))(__AHeapIndex_30,x4);
  r=_AHeapIndex_25(x1,__ATreeIndex_30,x2,x3,x5);}
 return r;}

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

extern OBJ _AHeapIndex_12(OBJ x1,OBJ x2,OBJ x3,OBJ x4) /* insert */
{OBJ r;
 CPCLS(__AHeapIndex_31,1);
 CPPRD(__AHeapIndex_32,1);
 {OBJ x5;
  x5=(*(OBJ(*)(OBJ,OBJ))METHOD(__AHeapIndex_31,1))(__AHeapIndex_31,x4);
  r=_AHeapIndex_25(x1,__AHeapIndex_32,x2,x3,x5);}
 return r;}

extern OBJ _AHeapIndex_13(OBJ x1,OBJ x2,OBJ x3) /* delete */
{OBJ r;
 CPCLS(__AHeapIndex_33,1);
 CPPRD(__ATreeIndex_34,1);
 r=_AHeapIndex_25(x1,__ATreeIndex_34,x2,x3,__AHeapIndex_33);
 return r;}

extern OBJ _AHeapIndex_25(OBJ x1,OBJ x2,OBJ x3,OBJ x4,OBJ x5) /* repl,2 */
{OBJ r;
 if(ISPRM(x3)){
  FRCLS(x1,1);
  {OBJ x42;
   ANat_6(x4,x42);
   if(ISTGPRM(x42,1)){
    FRPRD(x2,1);
    r=(*(OBJ(*)(OBJ,OBJ))METHOD(x5,1))(x5,__ATree_7);
   }else{
    FRCLS(x5,1);
    CPPRD(__AHeapIndex_26,1);
    {OBJ x43;
     ADenotation_4(x2,__AHeapIndex_26,x43);
     ABUILTIN_12(x43,r);}}}
 }else{
  {OBJ x44=FLD1(x3,1);OBJ x45=FLD1(x3,2);OBJ x46=FLD1(x3,3);
   COPY(x44,1);COPY(x45,1);COPY(x46,1);
   {OBJ x47;
    ANat_6(x4,x47);
    if(ISTGPRM(x47,1)){
     FRCLS(x1,1);
     FRPRD(x2,1);
     FREE(x44,1);
     FREE(x45,1);
     FREE(x46,1);
     r=(*(OBJ(*)(OBJ,OBJ))METHOD(x5,1))(x5,x3);
    }else{
     if(EXPRD(x3,1)){
      DSPRD(x3);
     }else{
      DCPRD(x3,1);}
     {OBJ x49;
      x49=_AIndexingOfTrees_6(x4);
      if(ISTGPRM(x49,1)){
       CPCLS(x1,1);
       {OBJ x50;OBJ x51;
	x50=_AIndexingOfTrees_8(x4);
	x51=_AHeapIndex_25(x1,x2,x45,x50,x5);
	r=_AHeap_2(x1,x44,x51,x46);}
      }else{
       {OBJ x52;
	x52=_AIndexingOfTrees_7(x4);
	if(ISTGPRM(x52,1)){
	 CPCLS(x1,1);
	 {OBJ x53;OBJ x54;
	  x53=_AIndexingOfTrees_9(x4);
	  x54=_AHeapIndex_25(x1,x2,x46,x53,x5);
	  r=_AHeap_2(x1,x44,x45,x54);}
	}else{
	 HLT("HeapIndex at <103,8-105,37> : missing else in repl\'HeapIndex:denotation**heap**nat**(heap->heap)->heap");}}}}}}}}
 return r;}

extern OBJ _AHeapIndex_27(OBJ x1,OBJ x2,OBJ x3) /* upd'27 */
{OBJ r;
 if(ISPRM(x3)){
  HLT("upd\'HeapIndex: cannot update empty heap");
 }else{
  r=_AHeap_23(x1,x3,x2);}
 return r;}

extern OBJ _AHeapIndex_29(OBJ x1,OBJ x2,OBJ x3) /* upd,1'29 */
{OBJ r;
 if(ISPRM(x3)){
  HLT("upd\'HeapIndex: cannot update empty heap");
 }else{
  {OBJ x13=FLD1(x3,1);
   COPY(x13,1);
   {OBJ x16;
    x16=(*(OBJ(*)(OBJ,OBJ))METHOD(x2,1))(x2,x13);
    r=_AHeap_23(x1,x3,x16);}}}
 return r;}

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

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

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

init_AHeapIndex()
{
 static int visited=0; if(visited) return; visited=1;
 init_AHeap();
 init_ANat();
 init_AOption();
 init_ASeq();
 init_ATree();
 init_AOptionMap();
 init_ADenotation();
 init_ACompose();
 init_ATreeIndex();
 init_AIndexingOfTrees();
 init_AChar();
 init_ARelCmp();
 init_AInt();
 CLS(2,_AHeapIndex_31,__AHeapIndex_31);
 CLS(2,_AHeapIndex_30,__AHeapIndex_30);
 CLS(3,_AHeapIndex_29,__AHeapIndex_29);
 DEN("upd",__AHeapIndex_28);
 CLS(3,_AHeapIndex_27,__AHeapIndex_27);
 DEN("\'HeapIndex: index does not exist",__AHeapIndex_26);
 CLS(5,_AHeapIndex_25,__AHeapIndex_25);
 CLS(3,_AHeapIndex_13,__AHeapIndex_13);
 CLS(4,_AHeapIndex_12,__AHeapIndex_12);
 CLS(4,_AHeapIndex_11,__AHeapIndex_11);
 CLS(4,_AHeapIndex_10,__AHeapIndex_10);
 CLS(3,_AHeapIndex_9,__AHeapIndex_9);
 CLS(3,_AHeapIndex_8,__AHeapIndex_8);
 CLS(4,_AHeapIndex_7,__AHeapIndex_7);
 CLS(4,_AHeapIndex_6,__AHeapIndex_6);
 CLS(3,_AHeapIndex_5,__AHeapIndex_5);
 CLS(3,_AHeapIndex_4,__AHeapIndex_4);
 CLS(3,_AHeapIndex_3_c,__AHeapIndex_3);
 CLS(1,_AHeapIndex_33,__AHeapIndex_33);
 DEN("insert",__AHeapIndex_32);}

