

#include "BUILTIN.h"

#include "Nat.h"
extern OBJ _ASeqFold_2(OBJ,OBJ);OBJ __ASeqFold_2; /* / */
extern OBJ _ASeqFold_3(OBJ,OBJ);OBJ __ASeqFold_3; /* \ */
extern OBJ _ASeqFold_4(OBJ,OBJ,OBJ);OBJ __ASeqFold_4; /* ifoldl */

extern OBJ _ASeqFold_2(OBJ x1,OBJ x2) /* / */
{OBJ r;
 if(ISPRM(x2)){
  HLT("/\'SeqFold applied to empty sequence");
 }else{
  {OBJ x46=FLD1(x2,1);OBJ x47=FLD1(x2,2);
   if(EXPRD(x2,1)){
    DSPRDF(x2);
   }else{
    COPY(x46,1);COPY(x47,1);
    FRPRD(x2,1);}
   if(ISPRM(x47)){
    r=x46;
    FRCLS(x1,1);
   }else{
    {OBJ x48;OBJ x49;FLAG x_x47=EXPRD(x47,1);
     if(x_x47){
     }else{
      x48=FLD1(x47,1);x49=FLD1(x47,2);COPY(x48,1);COPY(x49,1);}
     CPCLS(x1,1);
     {OBJ x51;OBJ x52;
      if(x_x47){
       RSOME(x47,x51);
      }else{
       FRPRD(x47,1);PRD1(2,x51);FLD1(x51,1)=x48;FLD1(x51,2)=x49;}
      x52=_ASeqFold_2(x1,x51);
      r=(*(OBJ(*)(OBJ,OBJ,OBJ))METHOD(x1,2))(x1,x46,x52);}}}}}
 return r;}

extern OBJ _ASeqFold_3(OBJ x1,OBJ x2) /* \ */
{OBJ r;
 if(ISPRM(x2)){
  HLT("\\\'SeqFold applied to empty sequence");
 }else{
  {OBJ x44=FLD1(x2,1);OBJ x45=FLD1(x2,2);
   if(EXPRD(x2,1)){
    DSPRDF(x2);
   }else{
    COPY(x44,1);COPY(x45,1);
    FRPRD(x2,1);}
   if(ISPRM(x45)){
    r=x44;
    FRCLS(x1,1);
   }else{
    {OBJ x46;OBJ x47;FLAG x_x45=EXPRD(x45,1);
     if(x_x45){
     }else{
      x46=FLD1(x45,1);x47=FLD1(x45,2);COPY(x46,1);COPY(x47,1);}
     {OBJ x49;
      if(x_x45){
       RSOME(x45,x49);
      }else{
       FRPRD(x45,1);PRD1(2,x49);FLD1(x49,1)=x46;FLD1(x49,2)=x47;}
      r=_ASeqFold_4(x1,x44,x49);}}}}}
 return r;}

extern OBJ _ASeqFold_4(register OBJ x1,register OBJ x2,register OBJ x3) /* ifoldl */
{OBJ r;
 for(;;){
  if(ISPRM(x3)){
   FRCLS(x1,1);
   r=x2;
  }else{
   {OBJ x22=FLD1(x3,1);OBJ x23=FLD1(x3,2);
    if(EXPRD(x3,1)){
     DSPRDF(x3);
    }else{
     COPY(x22,1);COPY(x23,1);
     FRPRD(x3,1);}
    CPCLS(x1,1);
    {OBJ x25;
     x25=(*(OBJ(*)(OBJ,OBJ,OBJ))METHOD(x1,2))(x1,x2,x22);
     x2=x25;x3=x23;continue;}}}
  break;}
 return r;}

init_ASeqFold()
{
 static int visited=0; if(visited) return; visited=1;
 init_ASeq();
 init_ANat();
 init_AOption();
 CLS(3,_ASeqFold_4,__ASeqFold_4);
 CLS(2,_ASeqFold_3,__ASeqFold_3);
 CLS(2,_ASeqFold_2,__ASeqFold_2);}

