1-- { dg-do compile }
2-- { dg-options "-O2" }
3
4with Ada.Containers; use Ada.Containers;
5with Ada.Containers.Vectors;
6
7function Opt32 return Natural is
8
9   package My_Vectors
10      is new Vectors (Index_Type => Natural, Element_Type => Integer);
11   use My_Vectors;
12
13   V : Vector;
14
15   function Sign_Changes return Natural is
16      Cur      : Cursor := To_Cursor (V, 0);
17      R        : Natural := 0;
18      Negative : Boolean;
19   begin
20      Negative := Element (Cur) < 0;
21
22      loop
23         Cur := Next (Cur);
24         exit when R > 100;
25
26         if (Element (Cur) < 0) /= Negative then
27            Negative := not Negative;
28            R := R + 1;
29         end if;
30      end loop;
31
32      return R;
33   end;
34
35begin
36   return Sign_Changes;
37end;
38