with Instrument;
use Instrument;

procedure Sieva2 is

    -- PRAGMA SUPPRESS (ACCESS_CHECK);
    -- PRAGMA SUPPRESS (DISCRIMINANT_CHECK);
    -- PRAGMA SUPPRESS (INDEX_CHECK);
    -- PRAGMA SUPPRESS (LENGTH_CHECK);
    -- PRAGMA SUPPRESS (RANGE_CHECK);
    -- PRAGMA SUPPRESS (DIVISION_CHECK);
    -- PRAGMA SUPPRESS (OVERFLOW_CHECK);
    -- PRAGMA SUPPRESS (STORAGE_CHECK);

    Size : constant Integer := 8_190;
    Flags : array (0 .. Size) of Boolean;
    Count : Integer := 0;
    Times : constant Integer := 1000;

    procedure Primes is
        Prime, K : Integer;
    begin
        for I in 0 .. Size loop
            Flags (I) := True;
        end loop;
        Count := 2;

        for I in 0 .. Size loop
            if Flags (I) = True then
                Prime := I + I + 3;
                K := I + Prime;
                while K <= Size loop
                    Flags (K) := False;
                    K := K + Prime;
                end loop;
                Count := Count + 1;
            end if;
        end loop;
        null;
    end Primes;

begin
    Start ("SIEVA2", "Sieve of Eratosthenes (test)");
    for I in 1 .. Times loop
        Primes;
    end loop;
    Stop;
end Sieva2;