#include <perms.h>

                                                                //      1  %integer %function %spec i77pODDCOLLATZ(%integer %array %name i77callerdisplay,%integer I)
int I77PODDCOLLATZ( int /*arrayname*/*I77CALLERDISPLAY, int I );
                                                                //      2  %record %format i77arfmSHOWCOLLATZLENGTH(%integer %name MAX,
typedef struct I77ARFMSHOWCOLLATZLENGTH I77ARFMSHOWCOLLATZLENGTH;
struct I77ARFMSHOWCOLLATZLENGTH {
  int /*name*/*MAX;
  int BASEVALUE;
};
                                                                //      3  %integer BASEVALUE)
                                                                //      4  %record %format i77arfmBLOCK(%integer ODD1,
typedef struct I77ARFMBLOCK I77ARFMBLOCK;
struct I77ARFMBLOCK {
  int ODD1;
  int ODD2;
};
                                                                //      5  %integer ODD2)
                                                                //      6  
                                                                //      7  %integer %function i77pEVENCOLLATZ(%integer %array %name i77callerdisplay,%integer I)
int I77PEVENCOLLATZ( int /*arrayname*/*I77CALLERDISPLAY, int I )
{
                                                                //      8  %integer %array i77display(1:3)
int I77DISPLAY[3];
                                                                //      9  %integer i77
int I77;
                                                                //     10  i77display(i77)=i77callerdisplay(i77) %for i77=1,1,2
I77 = 0;
if ((((2)-(1)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle I77 = 1, 1, 2");
L_0002:;
if (I77 == 2) goto L_0003;
I77 += 1;
I77DISPLAY[(((int)(I77)) - (1))] = I77CALLERDISPLAY[I77];
goto L_0002;
L_0003:;
                                                                //     11  i77display(3)=0
I77DISPLAY[2] = 0;
                                                                //     12  %record(i77arfmBLOCK)%name i77arBLOCK==record(i77display(1))
 I77ARFMBLOCK /*name*/*I77ARBLOCK;
I77ARBLOCK =  (I77ARFMBLOCK *) _imp_RECORD(I77DISPLAY[0]);
                                                                //     13  %record(i77arfmSHOWCOLLATZLENGTH)%name i77arSHOWCOLLATZLENGTH==record(i77display(2))
 I77ARFMSHOWCOLLATZLENGTH /*name*/*I77ARSHOWCOLLATZLENGTH;
I77ARSHOWCOLLATZLENGTH =  (I77ARFMSHOWCOLLATZLENGTH *) _imp_RECORD(I77DISPLAY[1]);
                                                                //     14  %if I{level 3}>=1 %then ->i77L1
if (((I) < (1))) goto L_0005;
goto U_1000;
L_0005:;
                                                                //     15  %result=0
/* Remove %on %event handler here if present for this block */
return 0;
                                                                //     16  i77L1:
U_1000:;
                                                                //     17  %if I{level 3}<=i77arSHOWCOLLATZLENGTH_MAX{level 2} %then ->i77L2
if (((I) > (*I77ARSHOWCOLLATZLENGTH->MAX))) goto L_0006;
goto U_1001;
L_0006:;
                                                                //     18  i77arSHOWCOLLATZLENGTH_MAX{level 2}=I{level 3}
*I77ARSHOWCOLLATZLENGTH->MAX = I;
                                                                //     19  i77L2:
U_1001:;
                                                                //     20  %if I{level 3}&i77arBLOCK_ODD2{level 1}=0 %then ->i77L3
if (((((I) & (I77ARBLOCK->ODD2))) != (0))) goto L_0007;
goto U_1002;
L_0007:;
                                                                //     21  %result=i77arSHOWCOLLATZLENGTH_BASEVALUE{level 2}+(i77pODDCOLLATZ(i77display,I{level 3}>>1))
/* Remove %on %event handler here if present for this block */
return (((int)(I77ARSHOWCOLLATZLENGTH->BASEVALUE)) + (I77PODDCOLLATZ(&I77DISPLAY[-(1)], (int)((((unsigned int)(I)) >> (1))))));
                                                                //     22  i77L3:
U_1002:;
                                                                //     23  %result=i77arSHOWCOLLATZLENGTH_BASEVALUE{level 2}+(i77pEVENCOLLATZ(i77display,I{level 3}>>1))
/* Remove %on %event handler here if present for this block */
return (((int)(I77ARSHOWCOLLATZLENGTH->BASEVALUE)) + (I77PEVENCOLLATZ(&I77DISPLAY[-(1)], (int)((((unsigned int)(I)) >> (1))))));
                                                                //     24  %end
} // End of block I77PEVENCOLLATZ at level 1
                                                                //     25  
                                                                //     26  %integer %function i77pODDCOLLATZ(%integer %array %name i77callerdisplay,%integer I)
int I77PODDCOLLATZ( int /*arrayname*/*I77CALLERDISPLAY, int I )
{
                                                                //     27  %integer %array i77display(1:3)
int I77DISPLAY[3];
                                                                //     28  %integer i77
int I77;
                                                                //     29  i77display(i77)=i77callerdisplay(i77) %for i77=1,1,2
I77 = 0;
if ((((2)-(1)) % (1)) != 0) _imp_signal(5,1,0,"Illegal cycle I77 = 1, 1, 2");
L_0008:;
if (I77 == 2) goto L_0009;
I77 += 1;
I77DISPLAY[(((int)(I77)) - (1))] = I77CALLERDISPLAY[I77];
goto L_0008;
L_0009:;
                                                                //     30  i77display(3)=0
I77DISPLAY[2] = 0;
                                                                //     31  %record(i77arfmSHOWCOLLATZLENGTH)%name i77arSHOWCOLLATZLENGTH==record(i77display(2))
 I77ARFMSHOWCOLLATZLENGTH /*name*/*I77ARSHOWCOLLATZLENGTH;
I77ARSHOWCOLLATZLENGTH =  (I77ARFMSHOWCOLLATZLENGTH *) _imp_RECORD(I77DISPLAY[1]);
                                                                //     32  %if I{level 3}>1 %then ->i77L4
if (((I) <= (1))) goto L_000b;
goto U_1003;
L_000b:;
                                                                //     33  %result=0
/* Remove %on %event handler here if present for this block */
return 0;
                                                                //     34  i77L4:
U_1003:;
                                                                //     35  %if I{level 3}<=i77arSHOWCOLLATZLENGTH_MAX{level 2} %then ->i77L5
if (((I) > (*I77ARSHOWCOLLATZLENGTH->MAX))) goto L_000c;
goto U_1000;
L_000c:;
                                                                //     36  i77arSHOWCOLLATZLENGTH_MAX{level 2}=I{level 3}
*I77ARSHOWCOLLATZLENGTH->MAX = I;
                                                                //     37  i77L5:
U_1000:;
                                                                //     38  %if I{level 3}<=715827882 %then ->i77L6
if (((I) > (715827882))) goto L_000d;
goto U_1001;
L_000d:;
                                                                //     39  %signal 15,1,1
_imp_signal(15, 1, 1, "");
                                                                //     40  i77L6:
U_1001:;
                                                                //     41  %result=i77arSHOWCOLLATZLENGTH_BASEVALUE{level 2}+(i77pEVENCOLLATZ(i77display,((I{level 3}<<1)+I{level 3})+1))
/* Remove %on %event handler here if present for this block */
return (((int)(I77ARSHOWCOLLATZLENGTH->BASEVALUE)) + (I77PEVENCOLLATZ(&I77DISPLAY[-(1)], (((int)((((int)(((I) << (1)))) + (I)))) + (1)))));
                                                                //     42  %end
} // End of block I77PODDCOLLATZ at level 1
                                                                //     43  
                                                                //     44  %routine i77pSHOWCOLLATZLENGTH(%integer %array %name i77callerdisplay,%integer I,%integer %name MAX)
void I77PSHOWCOLLATZLENGTH( int /*arrayname*/*I77CALLERDISPLAY, int I, int /*name*/*MAX )
{
                                                                //     45  %record(i77arfmSHOWCOLLATZLENGTH) i77ar
 I77ARFMSHOWCOLLATZLENGTH I77AR;
                                                                //     46  %integer %array i77display(1:2)
int I77DISPLAY[2];
                                                                //     47  i77display(1)=i77callerdisplay(1)
I77DISPLAY[0] = I77CALLERDISPLAY[1];
                                                                //     48  i77display(2)=addr(i77ar)
I77DISPLAY[1] = _imp_ADDR(&I77AR);
                                                                //     49  %record(i77arfmBLOCK)%name i77arBLOCK==record(i77display(1))
 I77ARFMBLOCK /*name*/*I77ARBLOCK;
I77ARBLOCK =  (I77ARFMBLOCK *) _imp_RECORD(I77DISPLAY[0]);
                                                                //     50  i77ar_MAX==MAX
I77AR.MAX = MAX;
                                                                //     51  i77ar_BASEVALUE{level 2}=0+1
I77AR.BASEVALUE = 1;
                                                                //     52  PRINTSTRING("The Collatz sequence for")
_imp_PRINTSTRING(_imp_str_literal("The Collatz sequence for"));
                                                                //     53  WRITE(I{level 2},1)
_imp_WRITE(I, 1);
                                                                //     54  PRINTSTRING(" takes")
_imp_PRINTSTRING(_imp_str_literal(" takes"));
                                                                //     55  %if I{level 2}&i77arBLOCK_ODD1{level 1}=0 %then ->i77L7
if (((((I) & (I77ARBLOCK->ODD1))) != (0))) goto L_000e;
goto U_1001;
L_000e:;
                                                                //     56  WRITE(i77pODDCOLLATZ(i77display,I{level 2}),1)
_imp_WRITE(I77PODDCOLLATZ(&I77DISPLAY[-(1)], I), 1);
                                                                //     57  ->i77L8
goto U_1002;
                                                                //     58  i77L7:
U_1001:;
                                                                //     59  WRITE(i77pEVENCOLLATZ(i77display,I{level 2}),1)
_imp_WRITE(I77PEVENCOLLATZ(&I77DISPLAY[-(1)], I), 1);
                                                                //     60  i77L8:
U_1002:;
                                                                //     61  PRINTSTRING(" steps and the largest value reached was")
_imp_PRINTSTRING(_imp_str_literal(" steps and the largest value reached was"));
                                                                //     62  WRITE(i77ar_MAX{level 2},1)
_imp_WRITE(*I77AR.MAX, 1);
                                                                //     63  NEWLINE
_imp_NEWLINE();
                                                                //     64  %end
/* Remove %on %event handler here if present for this block */
return;
} // End of block I77PSHOWCOLLATZLENGTH at level 1
                                                                //     65  
                                                                //     66  %begin
int main(int argc, char **argv) {
  _imp_initialise(argc, argv);
                                                                //     67  %record(i77arfmBLOCK) i77ar
 I77ARFMBLOCK I77AR;
                                                                //     68  %integer %array i77display(1:1)
int I77DISPLAY[1];
                                                                //     69  i77display(1)=addr(i77ar)
I77DISPLAY[0] = _imp_ADDR(&I77AR);
                                                                //     70  %integer HIGHEST
int HIGHEST;
                                                                //     71  %integer SEED
int SEED;
                                                                //     72  i77ar_ODD1{level 1}=1
I77AR.ODD1 = 1;
                                                                //     73  i77ar_ODD2{level 1}=2
I77AR.ODD2 = 2;
                                                                //     74  PROMPT("Integer seed value: ")
_imp_PROMPT(_imp_str_literal("Integer seed value: "));
                                                                //     75  READ(SEED{level 1})
_imp_READ(&SEED);
                                                                //     76  %if SEED{level 1}>=0 %then ->i77L9
if (((SEED) < (0))) goto L_000f;
goto U_1003;
L_000f:;
                                                                //     77  PRINTSTRING("Parameter must be a positive integer.")
_imp_PRINTSTRING(_imp_str_literal("Parameter must be a positive integer."));
                                                                //     78  NEWLINE
_imp_NEWLINE();
                                                                //     79  %signal 0,0,0
_imp_signal(0, 0, 0, "");
                                                                //     80  i77L9:
U_1003:;
                                                                //     81  HIGHEST{level 1}=0
HIGHEST = 0;
                                                                //     82  i77pSHOWCOLLATZLENGTH(i77display,SEED{level 1}-1,HIGHEST{level 1})
I77PSHOWCOLLATZLENGTH(&I77DISPLAY[-(1)], (((int)(SEED)) - (1)), &HIGHEST);
                                                                //     83  HIGHEST{level 1}=0
HIGHEST = 0;
                                                                //     84  i77pSHOWCOLLATZLENGTH(i77display,SEED{level 1},HIGHEST{level 1})
I77PSHOWCOLLATZLENGTH(&I77DISPLAY[-(1)], SEED, &HIGHEST);
                                                                //     85  HIGHEST{level 1}=0
HIGHEST = 0;
                                                                //     86  i77pSHOWCOLLATZLENGTH(i77display,SEED{level 1}+1,HIGHEST{level 1})
I77PSHOWCOLLATZLENGTH(&I77DISPLAY[-(1)], (((int)(SEED)) + (1)), &HIGHEST);
                                                                //     87  %end %of %program
/* Remove %on %event handler here if present for this block */
return 0;
} // End of block _imp_main at level 1
// End of file
