#include <perms.h>

//          Edinburgh IMP77 Compiler - Version 8.4
//
//     1  %begin

int main(int argc, char **argv) { /*%begin*/
  _imp_initialise(argc, argv);

  //     2    %external %real %fn %spec floaty sqrt %alias "sqrtf" (%real n)  {should be in prims. Using Linux/C's external here.}

  extern float FLOATYSQRT(float N) __asm__("sqrtf");

  //     3
  //     4    %routine TPK(%real %array %name a, b)

  void TPK(float *A, float *B) {
    //     5      ! given 11 input values a(0),...,a(10), this routine
    //     6      ! produces 22 output values b(0),...b(21), according
    //     7      ! to the classical TPK algorithm
    //     8      %real %fn f(%real t)

    float F(float T) {
      //     9        %result = floaty sqrt(|t|) + 5 * t^3

      return FLOATYSQRT(_imp_MOD(T)) + 5 * (_imp_REXP(T, 3));

      //    10      %end

    } /* end of F */

    //    11      %real y

    float Y;

    //    12      %integer i

    int I;

    //    13      %cycle i = 10, -1, 0

    // %for I = 10,  -1, 0 %cycle
    {
      I = 11;
    L_0001:
      if (I == 0) goto L_0002;
      I -= 1;

      //    14        y = f(a(i))

      Y = F([/*BUG*/ 0]);

      //    15        y = 999 %if y > 400

      if (Y <= 400) goto L_0004;
      Y = 999;
    L_0004:;

    //    16        b(20-2*i) = i

      [/*BUG*/ 0] = I;

      //    17        b(21-2*i) = y

      [/*BUG*/ 0] = Y;

      //    18      %repeat

      goto L_0001;
    }

  L_0002:;

  //    19    %end; ! TPK

    return;
  } /* end of TPK */

  //    20
  //    21    %real %array a(0:10), b(0:21)

  float A[11];
  float B[22];

  //    22
  //    23    TPK(a,b)

  TPK(A, B);

  //    24
  //    25  %endofprogram

  _imp_stop(0);
  return 0;
end_0:;
}