#include <perms.h>

                                                                //      1  %begin
int main(int argc, char **argv) {
  _imp_initialise(argc, argv);
                                                                //      2  
                                                                //      3    ! First the shortinteger -> integer case, which has always worked:
                                                                //      4  
                                                                //      5    %shortinteger smax = 16_7FFF * 2
short SMAX;
SMAX = (((int)(32767)) * (2));
                                                                //      6    ! Should either give an integer overflow error if overflow trapping is enabled or evaluate to an erroneous negative value
                                                                //      7    write(smax, 0) ; newline
_imp_WRITE(SMAX, 0);
_imp_NEWLINE();
                                                                //      8  
                                                                //      9    ! Unlike the similar case with %longinteger, this is OK because all int constants are evaluated as %integer
                                                                //     10    ! and not one of the smaller integer types.  It's only integer types *larger* than default %integer which
                                                                //     11    ! cause problems with propogating their type upwards.
                                                                //     12    %integer ismax1 = 16_7FFF * 2
int ISMAX1;
ISMAX1 = (((int)(32767)) * (2));
                                                                //     13    write(ismax1, 0) ; newline
_imp_WRITE(ISMAX1, 0);
_imp_NEWLINE();
                                                                //     14  
                                                                //     15    ! So this works too.
                                                                //     16    %integer ismax2 = 16_7FFF ; ismax2 = ismax2 * 2
int ISMAX2;
ISMAX2 = 32767;
ISMAX2 = (((int)(ISMAX2)) * (2));
                                                                //     17    write(ismax2, 0) ; newline
_imp_WRITE(ISMAX2, 0);
_imp_NEWLINE();
                                                                //     18  
                                                                //     19  
                                                                //     20    ! and then the integer -> longinteger case, which I'm not so sure about.  This must have been
                                                                //     21    ! seen on EMAS 2900 which also supported %longinteger - Bob, what did EMAS do?
                                                                //     22  
                                                                //     23  
                                                                //     24    %integer max = 16_7FFFFFFF * 2
int MAX;
MAX = (((int)(2147483647)) * (2));
                                                                //     25    ! Should either give an integer overflow error if overflow trapping is enabled or evaluate to an erroneous negative value
                                                                //     26    write(max, 0) ; newline
_imp_WRITE(MAX, 0);
_imp_NEWLINE();
                                                                //     27  
                                                                //     28    ! Unfortunately imp does type coercion bottom up so int X int -> int, which is then assigned to a longinteger and truncated.
                                                                //     29    %longinteger imax1 = 16_7FFFFFFF * 2
long long int IMAX1;
IMAX1 = (((int)(2147483647)) * (2));
                                                                //     30    write(imax1, 0) ; newline
_imp_WRITE(IMAX1, 0);
_imp_NEWLINE();
                                                                //     31  
                                                                //     32    ! This workaround is needed in order to do what is expected.   Not a bug but due to the way Imp77 is defined.
                                                                //     33    %longinteger imax2 = 16_7FFFFFFF ; imax2 = imax2 * 2
long long int IMAX2;
IMAX2 = 2147483647;
IMAX2 = ((IMAX2) * ((long long)(2)));
                                                                //     34    write(imax2, 0) ; newline
_imp_WRITE(IMAX2, 0);
_imp_NEWLINE();
                                                                //     35  
                                                                //     36  
                                                                //     37  %endofprogram
/* Remove %on %event handler here if present for this block */
return 0;
} // End of block _imp_main at level 1
// End of file
