This is definitely caused by loop unrolling now being enabled by default in FPC at O3. There's a bug in the compiler code relating to unrolling itself currently that leads to invalid assembly being generated. You can leave O3 in the optimized IDE settings if you add OoNOLOOPUNROLL.
EDIT: there's now a working patch for this, proposed on the dev mailing list and submitted to the bugtracker. In the compiler folder of your FPC sources, in the file optloop.pas, change line 79 from this:
if n.nodetype in [breakn,continuen] then
to this:
if n.nodetype in [breakn,continuen,exitn,goton,raisen] then
Making that change and then rebuilding FPC and Lazarus fixes the bug (meaning you can use O3, and do not need OoNOLOOPUNROLL.) Hopefully it gets merged to trunk sooner than later.