--  `and` and `or` whose right operand Codegen evaluates whatever the left one is (D196): only
--  where that is harmless. A right operand guarded by the left (an index or a divisor the left
--  one checks) still gives the left one's answer when it would not be defined; components at
--  indices beyond the bounds are read within them, and their values not used.
with Ada.Text_IO;
procedure Main is
   type Table is array (1 .. 8) of Integer;
   type Flags is array (1 .. 40) of Boolean;
   T : constant Table := (2, 4, 6, 8, 10, 12, 14, 16);
   A : Flags := (for I in 1 .. 40 => I mod 3 = 0);
   B : constant Flags := (for I in 1 .. 40 => I mod 2 = 0);
   C : Flags;
   Count : Natural := 0;

   function Has (K : Integer) return Boolean is
     (K in T'Range and then T (K) > 5);

   function Divides (J, K : Integer) return Boolean is
     (J /= 0 and then K mod J = 0);

   function Outside (K : Integer) return Boolean is
     (K not in T'Range or else T (K) < 5);
begin
   Ada.Text_IO.Put_Line (Boolean'Image (Has (0)) & " " & Boolean'Image (Has (3)) & " " & Boolean'Image (Has (1_000_000)) & " " & Boolean'Image (Has (-7)));
   Ada.Text_IO.Put_Line (Boolean'Image (Divides (0, 5)) & " " & Boolean'Image (Divides (5, 10)) & " " & Boolean'Image (Divides (3, 10)));
   Ada.Text_IO.Put_Line (Boolean'Image (Outside (99)) & " " & Boolean'Image (Outside (1)) & " " & Boolean'Image (Outside (4)));
   C := A and B;
   A := A or B;
   for I in C'Range loop
      if C (I) then
         Count := Count + 1;
      end if;
      pragma Loop_Invariant (Count <= I);
   end loop;
   Ada.Text_IO.Put_Line (Natural'Image (Count) & " " & Boolean'Image (A (9)) & " " & Boolean'Image (A (7)) & " " & Boolean'Image (C (12)));
end Main;
