#include <perms.h>

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

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

  //     2    %integer %function ackermann(%integer m,n)

  int ACKERMANN(int M, int N) {
    //     3      %result = n+1 %if m = 0

    if (M != 0) goto L_0001;
    return N + 1;
  L_0001:;

  //     4      %result = ackermann(m-1,1) %if n = 0

    if (N != 0) goto L_0002;
    return ACKERMANN(M - 1, 1);
  L_0002:;

  //     5      %result = ackermann(m-1,ackermann(m,n-1))

    return ACKERMANN(M - 1, ACKERMANN(M, N - 1));

    //     6    %end

  } /* end of ACKERMANN */

  //     7
  //     8    %owninteger i,j,k,k1,t1,t2

  static int I;
  static int J;
  static int K;
  static int K1;
  static int T1;
  static int T2;

  //     9
  //    10    k = 16;  k1 = 1

  K = 16;
  K1 = 1;

  //    11    %for i = 1,1,6 %cycle

  // %for I = 1, 1, 6 %cycle
  {
    I = 0;
  L_0003:
    if (I == 6) goto L_0004;
    I += 1;

    //    12      t1 = cputime            ;! cputime is in clocks_per_tick which is 1000000

    T1 = _imp_CPUTIME();

    //    13      j = ackermann(3,i)

    J = ACKERMANN(3, I);

    //    14      t2 = cputime

    T2 = _imp_CPUTIME();

    //    15      %if j # k-3 %then printstring("Wrong result!  ") %and newline

    if (J == K - 3) goto L_0006;
    _imp_PRINTSTRING(_imp_str_literal("Wrong result!  "));
    _imp_NEWLINE();
  L_0006:;

  //    16      print((t2-t1){/1000},7,3)

    _imp_PRINT(T2 - T1, 7, 3);

    //    17      print(3000*(t2-t1)/(512*k1-15*k+9*i+37),7,3)

    _imp_PRINT((double)((3000 * (T2 - T1)) / (512 * K1 - 15 * K + 9 * I + 37)), 7, 3);

    //    18      newline

    _imp_NEWLINE();

    //    19      k1 = 4*k1;  k = 2*k

    K1 = 4 * K1;
    K = 2 * K;

    //    20    %repeat

    goto L_0003;
  }

L_0004:;

//    21    printstring("Done."); newline

  _imp_PRINTSTRING(_imp_str_literal("Done."));
  _imp_NEWLINE();

  //    22  %endofprogram

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