

#include "BUILTIN.h"
extern OBJ __ASeq_6;
extern TUP2 _ASeq_33(OBJ,OBJ);extern OBJ __ASeq_33;
extern OBJ _ASeq_52(OBJ,OBJ);extern OBJ __ASeq_52;

#include "Nat.h"
extern OBJ _ASeqSort_2(OBJ,OBJ);OBJ __ASeqSort_2; /* msort */
extern OBJ _ASeqSort_3(OBJ,OBJ,OBJ);OBJ __ASeqSort_3; /* merge */
extern OBJ _ASeqSort_4(OBJ,OBJ,OBJ);OBJ __ASeqSort_4; /* ms */

extern OBJ _ASeqSort_2(OBJ x1,OBJ x2) /* msort */
{OBJ r;
 COPY(x2,1);
 {OBJ x3;
  x3=_ASeq_52(x2,__ANat_5);
  r=_ASeqSort_4(x1,x2,x3);}
 return r;}

extern OBJ _ASeqSort_3(register OBJ x1,register OBJ x2,register OBJ x3) /* merge */
{OBJ r;OBJ* p1=&r;
 for(;;){
  if(ISPRM(x2)){
   FRCLS(x1,1);
   *p1=x3;
  }else{
   {OBJ x36=FLD1(x2,1);OBJ x37=FLD1(x2,2);
    COPY(x36,1);COPY(x37,1);
    if(ISPRM(x3)){
     FRCLS(x1,1);
     FREE(x36,1);
     FREE(x37,1);
     *p1=x2;
    }else{
     {OBJ x38=FLD1(x3,1);OBJ x39=FLD1(x3,2);
      COPY(x38,2);COPY(x39,1);
      CPCLS(x1,1);
      COPY(x36,1);
      {OBJ x40;
       x40=(*(OBJ(*)(OBJ,OBJ,OBJ))METHOD(x1,2))(x1,x36,x38);
       if(ISTGPRM(x40,1)){
	if(EXPRD(x2,1)){
	 DSPRD(x2);
	}else{
	 DCPRD(x2,1);}
	FREE(x38,1);
	FREE(x39,1);
	{
	 PRD1(2,*p1);FLD1(*p1,1)=x36;
	 x2=x37;p1=&FLD1(*p1,2);continue;}
       }else{
	if(EXPRD(x3,1)){
	 DSPRD(x3);
	}else{
	 DCPRD(x3,1);}
	FREE(x36,1);
	FREE(x37,1);
	{
	 PRD1(2,*p1);FLD1(*p1,1)=x38;
	 x3=x39;p1=&FLD1(*p1,2);continue;}}}}}}}
  break;}
 return r;}

extern OBJ _ASeqSort_4(OBJ x1,OBJ x2,OBJ x3) /* ms */
{OBJ r;
 if(ISPRM(x2)){
  FRCLS(x1,1);
  r=__ASeq_6;
 }else{
  {OBJ x30=FLD1(x2,2);
   COPY(x30,1);
   if(ISPRM(x30)){
    FRCLS(x1,1);
    r=x2;
   }else{
    if(EXPRD(x30,1)){
     DSPRD(x30);
    }else{
     DCPRD(x30,1);}
    CPCLS(x1,2);
    {OBJ x33;OBJ x34;TUP2 x36;OBJ x38;OBJ x39;
     ANat_89(x3,__ANat_9,x33);
     ANat_62(x3,x33,x34);
     x36=_ASeq_33(x33,x2);
     x38=_ASeqSort_4(x1,x36.c1,x33);
     x39=_ASeqSort_4(x1,x36.c2,x34);
     r=_ASeqSort_3(x1,x38,x39);}}}}
 return r;}

static OBJ _mt_2_0_1(OBJ t,OBJ t1) 
{OBJ r;
 DPCLS(t,r);
 INCCLS(r,0,1);
 FLDCLS(r,1)=t1;
 return r;}

static OBJ _mt_2_1_1(OBJ t,OBJ t1) 
{OBJ r;
 if(EXCLS(t)){
  DSCLSF(t);
 }else{
  COPY(FLDCLS(t,1),1);
  DCCLS(t,1);}
 r=(*(OBJ(*)(OBJ,OBJ))ENTRY(t))(FLDCLS(t,1),t1);
 return r;}
static OBJ _mt_2_1_1_l(OBJ t,OBJ t1) 
{OBJ r;
 r=(*(OBJ(*)(OBJ,OBJ))ENTRY(t))(FLDCLS(t,1),t1);
 if(EXCLS(t)){
  DSCLSF(t);
 }else{
  DCCLS(t,1);
  FLDCLS(t,1)=NIL;
  COPY(r,1);LZYCLS(t,r);}
 return r;}

init_ASeqSort()
{
 static int visited=0; if(visited) return; visited=1;
 init_ASeq();
 init_ANat();
 init_AOption();
 CLS(3,_ASeqSort_4,__ASeqSort_4);
 CLS(3,_ASeqSort_3,__ASeqSort_3);
 CLS(2,_ASeqSort_2,__ASeqSort_2);
 MTH(2,0,1,_mt_2_0_1);LZYMTH(2,0,1,_mt_2_0_1);
 MTH(2,1,1,_mt_2_1_1);LZYMTH(2,1,1,_mt_2_1_1_l);}

