#include <perms.h>

                                                                //      1  %begin
#line 1 "regression-bugs-tmp/nsqrt.imp"
int main(int argc, char **argv) {
  __label__ _imp_endofblock;
  _imp_initialise(argc, argv);
                                                                //      2  
                                                                //      3  %constreal M SQRT2 = 1.4
_imp_current_line = 3; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 3 "regression-bugs-tmp/nsqrt.imp"
const float MSQRT2 = 1.4;
                                                                //      4  
                                                                //      5  %real %fn sqrt(%long %real X)
_imp_current_line = 5; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 5 "regression-bugs-tmp/nsqrt.imp"
float SQRT( double X )
#line 5 "regression-bugs-tmp/nsqrt.imp"
{
  __label__ _imp_endofblock;
                                                                //      6  
                                                                //      7    %integer %fn isqrt(%integer X)
_imp_current_line = 7; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 7 "regression-bugs-tmp/nsqrt.imp"
int ISQRT( int X )
#line 7 "regression-bugs-tmp/nsqrt.imp"
{
  __label__ _imp_endofblock;
                                                                //      8      %integer k = 1, result = 1
_imp_current_line = 8; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 8 "regression-bugs-tmp/nsqrt.imp"
int K;
#line 8 "regression-bugs-tmp/nsqrt.imp"
K = 1;
#line 8 "regression-bugs-tmp/nsqrt.imp"
int RESULT;
#line 8 "regression-bugs-tmp/nsqrt.imp"
RESULT = 1;
                                                                //      9      k = k+1 %and result = k*k %while result <= X
_imp_current_line = 9; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 9 "regression-bugs-tmp/nsqrt.imp"
L_0002:;
#line 9 "regression-bugs-tmp/nsqrt.imp"
if (((RESULT) > (X))) goto L_0003;
#line 9 "regression-bugs-tmp/nsqrt.imp"
K = (((int)(K)) + (1));
#line 9 "regression-bugs-tmp/nsqrt.imp"
RESULT = (((int)(K)) * (K));
#line 9 "regression-bugs-tmp/nsqrt.imp"
goto L_0002;
#line 9 "regression-bugs-tmp/nsqrt.imp"
L_0003:;
                                                                //     10      %result = k-1
_imp_current_line = 10; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 10 "regression-bugs-tmp/nsqrt.imp"
return (((int)(K)) - (1));
                                                                //     11    %end
_imp_current_line = 11; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 11 "regression-bugs-tmp/nsqrt.imp"
_imp_endofblock: ;
} // End of block ISQRT at level 3
                                                                //     12    
                                                                //     13    %integer I
_imp_current_line = 13; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 13 "regression-bugs-tmp/nsqrt.imp"
int I;
                                                                //     14    %long %real A prev, A
_imp_current_line = 14; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 14 "regression-bugs-tmp/nsqrt.imp"
double APREV;
#line 14 "regression-bugs-tmp/nsqrt.imp"
double A;
                                                                //     15    %long %real epsilon = X / 100000000.0
_imp_current_line = 15; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 15 "regression-bugs-tmp/nsqrt.imp"
double EPSILON;
#line 15 "regression-bugs-tmp/nsqrt.imp"
EPSILON = (double)((double)((double)(X)) / (double)((double)(100000000.0)));
                                                                //     16    %result = M SQRT2 %if X = 2.0
_imp_current_line = 16; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 16 "regression-bugs-tmp/nsqrt.imp"
if (((X) != (2.0))) goto L_0005;
#line 16 "regression-bugs-tmp/nsqrt.imp"
return MSQRT2;
#line 16 "regression-bugs-tmp/nsqrt.imp"
L_0005:;
                                                                //     17    I = isqrt(INT PT(X))
_imp_current_line = 17; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 17 "regression-bugs-tmp/nsqrt.imp"
I = ISQRT(_imp_INTPT(X));
                                                                //     18    %result = I %if X = I*I { exact root }
_imp_current_line = 18; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 18 "regression-bugs-tmp/nsqrt.imp"
if (((X) != ((((int)(I)) * (I))))) goto L_0006;
#line 18 "regression-bugs-tmp/nsqrt.imp"
return I;
#line 18 "regression-bugs-tmp/nsqrt.imp"
L_0006:;
                                                                //     19    ! Newton's method: A{n} = (A{n-1} + X/A{n-1})/2
                                                                //     20    A prev = I ; A = A PREV
_imp_current_line = 20; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 20 "regression-bugs-tmp/nsqrt.imp"
APREV = I;
_imp_current_line = 20; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 20 "regression-bugs-tmp/nsqrt.imp"
A = APREV;
                                                                //     21    %cycle
_imp_current_line = 21; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 21 "regression-bugs-tmp/nsqrt.imp"
L_0007:;
                                                                //     22      A prev = A
_imp_current_line = 22; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 22 "regression-bugs-tmp/nsqrt.imp"
APREV = A;
                                                                //     23      A = (A + X/A)/2.0
_imp_current_line = 23; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 23 "regression-bugs-tmp/nsqrt.imp"
A = (double)((double)((((A) + (((double)((double)((double)(X)) / (double)((double)(A)))))))) / (double)((double)(2.0)));
                                                                //     24    %repeat %until A prev - epsilon <= A <= A prev + epsilon
_imp_current_line = 24; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 24 "regression-bugs-tmp/nsqrt.imp"
if (((((((double)(APREV)) - (EPSILON))) > (A))) || (((A) <= ((((double)(APREV)) + (EPSILON)))))) goto L_0008;
#line 24 "regression-bugs-tmp/nsqrt.imp"
L_0009:;
#line 24 "regression-bugs-tmp/nsqrt.imp"
goto L_0007;
#line 24 "regression-bugs-tmp/nsqrt.imp"
L_0008:;
                                                                //     25    %result = A
_imp_current_line = 25; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 25 "regression-bugs-tmp/nsqrt.imp"
return A;
                                                                //     26  %end
_imp_current_line = 26; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 26 "regression-bugs-tmp/nsqrt.imp"
_imp_endofblock: ;
} // End of block SQRT at level 2
                                                                //     27  
                                                                //     28  %endofprogram
_imp_current_line = 28; _imp_current_file = "regression-bugs-tmp/nsqrt.imp";
#line 28 "regression-bugs-tmp/nsqrt.imp"
return 0;
_imp_endofblock: ;
} // End of block _imp_main at level 1
#line 28 "regression-bugs-tmp/nsqrt.imp"
// End of file
