#include <perms.h>

                                                                //      1  !* Program Name : Logic
                                                                //      2  
                                                                //      3  !*   Title      :  XV     Logic                      
                                                                //      4  !*   Version    :  II
                                                                //      5  !*   Date       :  24 August 1985
                                                                //      6  !*   Description:  Test the bit vector facilities that use logical operators
                                                                //      7  
                                                                //      8  %Begin
int main(int argc, char **argv) {
  _imp_initialise(argc, argv);
                                                                //      9  
                                                                //     10     %string(255) param    { Used to get input from CLI}
_imp_string /*%string(255)*/ PARAM;
                                                                //     11  
                                                                //     12     !*  Note that some of the following bit maps are variable
                                                                //     13     !*  and some are constant.  This allows us to test both 
                                                                //     14     !*  in the logical operators.
                                                                //     15  
                                                                //     16     %Constant %Integer  Bits1 = 2_00000000000000000000000000000000
                                                                //     17               %Integer  Bits2 = 2_01010101010101010101010101010101
int BITS2;
BITS2 = 1431655765;
                                                                //     18     %Constant %Integer  Bits3 = 2_00001111000011110000111100001111
                                                                //     19               %Integer  Bits4 = 2_11111111111111111111111111111111
int BITS4;
BITS4 = (-1);
                                                                //     20               %Integer  Bits5 = 2_10110111100001010011110010101000
int BITS5;
BITS5 = (-1216004952);
                                                                //     21     %Constant %Integer  Bits6 = 2_00100110111100101010100111110111
                                                                //     22               %Integer  LMask = 2_10000000000000000000000000000000
int LMASK;
LMASK = (-2147483648);
                                                                //     23               %Integer  RMask = 2_00000000000000000000000000000001
int RMASK;
RMASK = 1;
                                                                //     24  
                                                                //     25  
                                                                //     26  %owninteger failures=0
static int FAILURES = 0;
                                                                //     27  
                                                                //     28  %routine pass
void PASS( void )
{
                                                                //     29    printstring("Pass")
_imp_PRINTSTRING(_imp_str_literal("Pass"));
                                                                //     30    New Line
_imp_NEWLINE();
                                                                //     31  %end
/* Remove %on %event handler here if present for this block */
return;
} // End of block PASS at level 2
                                                                //     32  %routine fail
void FAIL( void )
{
                                                                //     33    printstring("FAIL")
_imp_PRINTSTRING(_imp_str_literal("FAIL"));
                                                                //     34    New line
_imp_NEWLINE();
                                                                //     35    failures = failures+1
FAILURES = (((int)(FAILURES)) + (1));
                                                                //     36  %end
/* Remove %on %event handler here if present for this block */
return;
} // End of block FAIL at level 2
                                                                //     37     
                                                                //     38  
                                                                //     39  
                                                                //     40     ! Code to find out where the output is to be sent
                                                                //     41     ! -----------------------------------------------
                                                                //     42     ! Where the output goes to depends on the parameter after the
                                                                //     43     ! name used to run the program.
                                                                //     44     !                       Parameter   |   Result
                                                                //     45     !                       ------------|-------------
                                                                //     46     !                     No parameter  |  No output
                                                                //     47     !                          "s"      |  The screen
                                                                //     48     !                          "j"      |  "journal"
                                                                //     49     !                     anything else |  file name entered
                                                                //     50  
                                                                //     51     ! NOTE THAT THIS CODE USES STRING COMPARISONS, WHICH MAY NOT HAVE BEEN
                                                                //     52     ! TESTED YET. IF THE PROGRAM FAILS CHECK IT WAS NOT IN THIS PART.
                                                                //     53  
                                                                //     54     param=cliparam
PARAM = _imp_CLIPARAM();
                                                                //     55     %if param = "" %then select output (2) %c
if ((_imp_strcmp(PARAM, _imp_str_literal("")) != 0)) goto L_0002;
_imp_SELECTOUTPUT(2);
goto L_0003;
L_0002:;
if ((_imp_strcmp(PARAM, _imp_str_literal("s")) == 0)) goto L_0004;
if ((_imp_strcmp(PARAM, _imp_str_literal("S")) != 0)) goto L_0005;
L_0004:;
_imp_SELECTOUTPUT(1);
goto L_0003;
L_0005:;
if ((_imp_strcmp(PARAM, _imp_str_literal("j")) == 0)) goto L_0006;
if ((_imp_strcmp(PARAM, _imp_str_literal("J")) != 0)) goto L_0007;
L_0006:;
_imp_OPENOUTPUT(2, _imp_str_literal("journal"));
_imp_SELECTOUTPUT(2);
goto L_0003;
L_0007:;
_imp_OPENOUTPUT(2, PARAM);
_imp_SELECTOUTPUT(2);
L_0003:;
                                                                //     56     %else %if param="s" %or param="S" %then select output(1) %c
                                                                //     57     %else %if param="j" %or param="J" %then  %c
                                                                //     58        open output(2,"journal") %and select output (2) %c
                                                                //     59     %else open output(2,param) %and select output (2)
                                                                //     60     
                                                                //     61  
                                                                //     62     New Lines(2)
_imp_NEWLINES(2);
                                                                //     63     Print String ("Logical Operation Validation");   New Line
_imp_PRINTSTRING(_imp_str_literal("Logical Operation Validation"));
_imp_NEWLINE();
                                                                //     64     Print String ("============================");   New Lines (3)
_imp_PRINTSTRING(_imp_str_literal("============================"));
_imp_NEWLINES(3);
                                                                //     65  
                                                                //     66  
                                                                //     67  
                                                                //     68     Print String ("Test the Bit Vector Operations.");   New Line
_imp_PRINTSTRING(_imp_str_literal("Test the Bit Vector Operations."));
_imp_NEWLINE();
                                                                //     69     Print String ("-------------------------------");   New Line
_imp_PRINTSTRING(_imp_str_literal("-------------------------------"));
_imp_NEWLINE();
                                                                //     70  
                                                                //     71  
                                                                //     72     %if bits1=0 %then pass %else fail
if (((0) != (0))) goto L_0008;
PASS();
goto L_0009;
L_0008:;
FAIL();
L_0009:;
                                                                //     73     %if bits2=1431655765 %then pass %else fail
if (((BITS2) != (1431655765))) goto L_000a;
PASS();
goto L_000b;
L_000a:;
FAIL();
L_000b:;
                                                                //     74     %if bits3=252645135 %then pass %else fail
if (((252645135) != (252645135))) goto L_000c;
PASS();
goto L_000d;
L_000c:;
FAIL();
L_000d:;
                                                                //     75     %if bits4=-1 %then pass %else fail
if (((BITS4) != ((-1)))) goto L_000e;
PASS();
goto L_000f;
L_000e:;
FAIL();
L_000f:;
                                                                //     76  
                                                                //     77     !*  Test the Logical AND
                                                                //     78  
                                                                //     79     %if bits2 & bits3=84215045 %then pass %else fail
if (((((BITS2) & (252645135))) != (84215045))) goto L_0010;
PASS();
goto L_0011;
L_0010:;
FAIL();
L_0011:;
                                                                //     80  
                                                                //     81     !*  Test the Logical Inclusive OR
                                                                //     82  
                                                                //     83     %if bits2 ! bits3 = 1600085855 %then pass %else fail
if (((((BITS2) | (252645135))) != (1600085855))) goto L_0012;
PASS();
goto L_0013;
L_0012:;
FAIL();
L_0013:;
                                                                //     84  
                                                                //     85     !*  Test the Logical Exclusive OR
                                                                //     86  
                                                                //     87     %if bits2!!bits3 = 1515870810 %then pass %else fail
if (((((BITS2) ^ (252645135))) != (1515870810))) goto L_0014;
PASS();
goto L_0015;
L_0014:;
FAIL();
L_0015:;
                                                                //     88  
                                                                //     89     !*  Test the Logical Unary NOT
                                                                //     90  
                                                                //     91     %if \bits2 = -1431655766 %then pass %else fail
if ((((~(BITS2))) != ((-1431655766)))) goto L_0016;
PASS();
goto L_0017;
L_0016:;
FAIL();
L_0017:;
                                                                //     92  
                                                                //     93     !*  Test the Left Shift
                                                                //     94  
                                                                //     95     %if bits3 << 4 = -252645136 %then pass %else fail
if (((((252645135) << (4))) != ((-252645136)))) goto L_0018;
PASS();
goto L_0019;
L_0018:;
FAIL();
L_0019:;
                                                                //     96  
                                                                //     97     !*  Test the Right Shift
                                                                //     98  
                                                                //     99     %if bits2 >> 4 = 89478485 %then pass %else fail
if ((((int)((((unsigned int)(BITS2)) >> (4)))) != (89478485))) goto L_001a;
PASS();
goto L_001b;
L_001a:;
FAIL();
L_001b:;
                                                                //    100  
                                                                //    101     New Lines (2)
_imp_NEWLINES(2);
                                                                //    102  
                                                                //    103  
                                                                //    104     !*     Test the priority of the operators
                                                                //    105  
                                                                //    106     Print String ("Test the Precedence of the Logical Operators.");  New Line
_imp_PRINTSTRING(_imp_str_literal("Test the Precedence of the Logical Operators."));
_imp_NEWLINE();
                                                                //    107     Print String ("---------------------------------------------");  New Line
_imp_PRINTSTRING(_imp_str_literal("---------------------------------------------"));
_imp_NEWLINE();
                                                                //    108  
                                                                //    109     %if ((((\Bits6) & (Bits3 >> 6)) !! Bits5)) = (\Bits6 & Bits3 >> 6 !! Bits5) %c
if ((((((((~(653437431))) & ((int)((((unsigned int)(252645135)) >> (6)))))) ^ (BITS5))) != ((((((~(653437431))) & ((int)((((unsigned int)(252645135)) >> (6)))))) ^ (BITS5))))) goto L_001c;
PASS();
goto L_001d;
L_001c:;
FAIL();
L_001d:;
                                                                //    110     %then pass %else fail
                                                                //    111  
                                                                //    112     %if ((\Bits6) & Bits5) = (\Bits6 & Bits5) %then pass %else fail
if ((((((~(653437431))) & (BITS5))) != ((((~(653437431))) & (BITS5))))) goto L_001e;
PASS();
goto L_001f;
L_001e:;
FAIL();
L_001f:;
                                                                //    113  
                                                                //    114     %if ((\Bits5) >> 5) = (\Bits5 >> 5) %then pass %else fail
if ((((((((~(BITS5)))) >> (5)))) != ((((((~(BITS5)))) >> (5)))))) goto L_0020;
PASS();
goto L_0021;
L_0020:;
FAIL();
L_0021:;
                                                                //    115  
                                                                //    116     %if ((\Bits6) ! Bits5) = (\Bits6 ! Bits5) %then pass %else fail
if ((((((~(653437431))) | (BITS5))) != ((((~(653437431))) | (BITS5))))) goto L_0022;
PASS();
goto L_0023;
L_0022:;
FAIL();
L_0023:;
                                                                //    117  
                                                                //    118     %if ((\Bits6) !! Bits5) = (\Bits6 !! Bits5) %then pass %else fail
if ((((((~(653437431))) ^ (BITS5))) != ((((~(653437431))) ^ (BITS5))))) goto L_0024;
PASS();
goto L_0025;
L_0024:;
FAIL();
L_0025:;
                                                                //    119  
                                                                //    120     %if (Bits6 & (Bits5 >> 4)) = (Bits6 & Bits5 >> 4) %then pass %else fail
if (((((653437431) & ((int)((((unsigned int)(BITS5)) >> (4)))))) != (((653437431) & ((int)((((unsigned int)(BITS5)) >> (4)))))))) goto L_0026;
PASS();
goto L_0027;
L_0026:;
FAIL();
L_0027:;
                                                                //    121  
                                                                //    122     %if (Bits6 ! (Bits5 >> 4)) = (Bits6 ! Bits5 >> 4) %then pass %else fail
if (((((653437431) | ((int)((((unsigned int)(BITS5)) >> (4)))))) != (((653437431) | ((int)((((unsigned int)(BITS5)) >> (4)))))))) goto L_0028;
PASS();
goto L_0029;
L_0028:;
FAIL();
L_0029:;
                                                                //    123  
                                                                //    124     %if (Bits6 !! (Bits5 >> 4)) = (Bits6 !! Bits5 >> 4) %then pass %else fail
if (((((653437431) ^ ((int)((((unsigned int)(BITS5)) >> (4)))))) != (((653437431) ^ ((int)((((unsigned int)(BITS5)) >> (4)))))))) goto L_002a;
PASS();
goto L_002b;
L_002a:;
FAIL();
L_002b:;
                                                                //    125  
                                                                //    126     %if (Bits6 & (Bits5 << 4)) = (Bits6 & Bits5 << 4) %then pass %else fail
if (((((653437431) & (((BITS5) << (4))))) != (((653437431) & (((BITS5) << (4))))))) goto L_002c;
PASS();
goto L_002d;
L_002c:;
FAIL();
L_002d:;
                                                                //    127  
                                                                //    128     %if (Bits6 ! (Bits5 << 4)) = (Bits6 ! Bits5 << 4) %then pass %else fail
if (((((653437431) | (((BITS5) << (4))))) != (((653437431) | (((BITS5) << (4))))))) goto L_002e;
PASS();
goto L_002f;
L_002e:;
FAIL();
L_002f:;
                                                                //    129  
                                                                //    130     %if (Bits6 !! (Bits5 << 4)) = (Bits6 !! Bits5 << 4) %then pass %else fail
if (((((653437431) ^ (((BITS5) << (4))))) != (((653437431) ^ (((BITS5) << (4))))))) goto L_0030;
PASS();
goto L_0031;
L_0030:;
FAIL();
L_0031:;
                                                                //    131  
                                                                //    132     %if (Bits6 ! (Bits5 & Bits3)) = (Bits6 ! Bits5 & Bits3)   %then pass %else fail
if (((((653437431) | (((BITS5) & (252645135))))) != (((653437431) | (((BITS5) & (252645135))))))) goto L_0032;
PASS();
goto L_0033;
L_0032:;
FAIL();
L_0033:;
                                                                //    133  
                                                                //    134     %if (Bits6 !! (Bits5 & Bits3)) = (Bits6 !! Bits5 & Bits3)   %then pass %else fail
if (((((653437431) ^ (((BITS5) & (252645135))))) != (((653437431) ^ (((BITS5) & (252645135))))))) goto L_0034;
PASS();
goto L_0035;
L_0034:;
FAIL();
L_0035:;
                                                                //    135  
                                                                //    136     %if ((Bits6 ! Bits5) !! Bits3) = (Bits6 ! Bits5 !! Bits3) %then pass %else fail
if (((((((653437431) | (BITS5))) ^ (252645135))) != (((((653437431) | (BITS5))) ^ (252645135))))) goto L_0036;
PASS();
goto L_0037;
L_0036:;
FAIL();
L_0037:;
                                                                //    137  
                                                                //    138     %if ((Bits6 !! Bits5) ! Bits3) = (Bits6 !! Bits5 ! Bits3) %then pass %else fail
if (((((((653437431) ^ (BITS5))) | (252645135))) != (((((653437431) ^ (BITS5))) | (252645135))))) goto L_0038;
PASS();
goto L_0039;
L_0038:;
FAIL();
L_0039:;
                                                                //    139  
                                                                //    140  
                                                                //    141  
                                                                //    142  
                                                                //    143     !*   Assorted Tests on the Logical Operators
                                                                //    144  
                                                                //    145     New Lines (2)
_imp_NEWLINES(2);
                                                                //    146     Print String ("Assorted Tests on the Logical Operators.");  New Line
_imp_PRINTSTRING(_imp_str_literal("Assorted Tests on the Logical Operators."));
_imp_NEWLINE();
                                                                //    147     Print String ("----------------------------------------");  New Line
_imp_PRINTSTRING(_imp_str_literal("----------------------------------------"));
_imp_NEWLINE();
                                                                //    148  
                                                                //    149  
                                                                //    150     %If  Bits6 !! Bits3 !! Bits3 = Bits6 %then pass %else fail
if (((((((653437431) ^ (252645135))) ^ (252645135))) != (653437431))) goto L_003a;
PASS();
goto L_003b;
L_003a:;
FAIL();
L_003b:;
                                                                //    151  
                                                                //    152     %If  \(\Bits6) = Bits6 %then pass %else fail
if ((((~((~(653437431))))) != (653437431))) goto L_003c;
PASS();
goto L_003d;
L_003c:;
FAIL();
L_003d:;
                                                                //    153     
                                                                //    154     %If  \Bits1 = Bits4 %then pass %else fail
if ((((~(0))) != (BITS4))) goto L_003e;
PASS();
goto L_003f;
L_003e:;
FAIL();
L_003f:;
                                                                //    155     
                                                                //    156     %If (RMask >> 10) << 10 = RMask %then fail %else pass
if ((((((int)((((unsigned int)(RMASK)) >> (10)))) << (10))) != (RMASK))) goto L_0040;
FAIL();
goto L_0041;
L_0040:;
PASS();
L_0041:;
                                                                //    157     
                                                                //    158     %If  (LMask >> 10) << 10 = LMask %then pass %else fail
if ((((((int)((((unsigned int)(LMASK)) >> (10)))) << (10))) != (LMASK))) goto L_0042;
PASS();
goto L_0043;
L_0042:;
FAIL();
L_0043:;
                                                                //    159     
                                                                //    160     %If Bits6 >> 0 = Bits6 << 0 %then pass %else fail
if ((((int)((((unsigned int)(653437431)) >> (0)))) != (((653437431) << (0))))) goto L_0044;
PASS();
goto L_0045;
L_0044:;
FAIL();
L_0045:;
                                                                //    161     
                                                                //    162     
                                                                //    163  
                                                                //    164  select output(1)
_imp_SELECTOUTPUT(1);
                                                                //    165  write(failures,1);  printstring(" failure(s)");  newline
_imp_WRITE(FAILURES, 1);
_imp_PRINTSTRING(_imp_str_literal(" failure(s)"));
_imp_NEWLINE();
                                                                //    166  %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
