anchor.diff:   result:=DFAFail;
    Input:=ThreadLocalState.Input;
    InputLength:=ThreadLocalState.InputLength;
  - State:=DFAReversedStartState;
  + State:=ThreadLocalState.DFAReversedStartState;
    for Position:=StartPosition downto UntilIncludingPosition do begin
     LastState:=State;
     State:=State^.NextStates[ByteMap[byte(ansichar(Input[Position]))]];
     if not assigned(State) then begin
  -   State:=DFAProcessNextState(LastState,Input[Position],true);
  +   State:=ThreadLocalState.DFAProcessNextState(LastState,Input[Position],true);
      if not assigned(State) then begin
       result:=DFAError;
       exit;
  
positive.code:  DFAStatePoolFree:=nil;
   DFAStatePoolSize:=0;
   DFAStatePoolSizePowerOfTwo:=0;
   DFANeedVerification:=false;
  
   BeginningJump:=false;
   BeginningSplit:=false;
   BeginningWildCard:=false;
   BeginningAnchor:=false;
  
   NamedGroupStringList:=TStringList.Create;
   NamedGroupStringIntegerPairHashMap:=TFLREStringIntegerPairHashMap.Create;
  
   ThreadLocalStateCriticalSection:=TCriticalSection.Create;
  
   ThreadLocalStates:=nil;
   FreeThreadLocalStates:=nil;
  
   try
  
    try
  
     Parse;
  
     Compile;
  
    finally
     SetLength(CharClasses,CountCharClasses);
    end;
  
    CountSubMatches:=(CountParens+1)*2;
  
    SetLength(ThreadLists[0].Threads,(CountForwardInstructions+1)*4);
    SetLength(ThreadLists[1].Threads,(CountForwardInstructions+1)*4);
  
    CompilePrefix;
  
    CompileFixedStringSearch;
  
    CompilePrefixCharClasses;
  
    CompileByteMapForOnePassNFAAndDFA;
  
    CompileOnePassNFA;
  
    if OnePassNFAReady then begin
     SetLength(OnePassNFAWorkCaptures,CountParens*2);
     SetLength(OnePassNFAMatchCaptures,CountParens*2);
    end;
  
    BitStateNFAReady:=(CountForwardInstructions>0) and (CountForwardInstructions<512);
    if BitStateNFAReady then begin
     SetLength(BitStateNFAWorkCaptures,CountParens*2);
     SetLength(BitStateNFAMatchCaptures,CountParens*2);
    end;
  
    begin
     DFACountStatesCached:=0;
  
     DFAStackInstructions:=nil;
     SetLength(DFAStackInstructions,(CountForwardInstructions+1) shl 1);
  
     DFAStatePoolUsed:=nil;
     DFAStatePoolFree:=nil;
  
     DFANextStatesSize:=ByteMapCount*sizeof(PFLREDFAState);
     DFAStateSize:=ptrint(ptruint(pointer(@FLREDFAStateCreateTempDFAState.NextStates))-ptruint(pointer(@FLREDFAStateCreateTempDFAState)))+DFANextStatesSize;
  
     DFAStatePoolSize:=(65536 div DFAStateSize)*DFAStateSize;
     if DFAStatePoolSize=0 then begin
      DFAStatePoolSize:=DFAStateSize*64;
     end;
  
     DFAStatePoolSizePowerOfTwo:=RoundUpToPowerOfTwo(DFAStatePoolSize);
  
     DFAAllocateNewStatePool;
  
     FillChar(DFATemporaryState,SizeOf(TFLREDFAState),AnsiChar(#0));
     FillChar(DFANewState,SizeOf(TFLREDFAState),AnsiChar(#0));
  
     inc(Generation);
     GetMem(DFAAnchoredStartState,DFAStateSize);
     FillChar(DFAAnchoredStartState^,DFAStateSize,AnsiChar(#0));
     DFAAddInstructionThread(DFAAnchoredStartState,AnchoredStartInstruction);
     DFAAnchoredStartState^.Flags:=DFAAnchoredStartState^.Flags or sfDFAStart;
     DFAStateCache.Add(DFAAnchoredStartState);
     inc(DFACountStatesCached);
  
     inc(Generation);
     GetMem(DFAUnanchoredStartState,DFAStateSize);
     FillChar(DFAUnanchoredStartState^,DFAStateSize,AnsiChar(#0));
     DFAAddInstructionThread(DFAUnanchoredStartState,UnanchoredStartInstruction);
     DFAUnanchoredStartState^.Flags:=DFAUnanchoredStartState^.Flags or sfDFAStart;
     DFAStateCache.Add(DFAUnanchoredStartState);
     inc(DFACountStatesCached);
  
     inc(Generation);
     GetMem(DFAReversedStartState,DFAStateSize);
     FillChar(DFAReversedStartState^,DFAStateSize,AnsiChar(#0));
     DFAAddInstructionThread(DFAReversedStartState,ReversedStartInstruction);
     DFAReversedStartState^.Flags:=DFAReversedStartState^.Flags or sfDFAStart;
     DFAStateCache.Add(DFAReversedStartState);
     inc(DFACountStatesCached);
  
     inc(Generation);
     GetMem(DFADeadState,DFAStateSize);
     FillChar(DFADeadState^,DFAStateSize,AnsiChar(#0));
     DFAAddInstructionThread(DFADeadState,AnchoredStartInstruction);
     DFADeadState^.Flags:=DFADeadState^.Flags or sfDFADead;
     DFAStateCache.Add(DFADeadState);
     inc(DFACountStatesCached);
  
    end;
  
    BeginningWildcardLoop:=BeginningJump and BeginningSplit and BeginningWildcard;
    if rfLAZY in Flags then begin
     DoUnanchoredStart:=false;
    end else if rfGREEDY in Flags then begin
     DoUnanchoredStart:=not BeginningAnchor;
    end else begin
     DoUnanchoredStart:=(FixedStringLength=0) and (CountObviousPrefixCharClasses<CountPrefixCharClasses) and not BeginningAnchor;
    end;
  
   finally
   end;
  
  end;
  
  destructor TFLRE.Destroy;
  var Index:longint;
      SubMatches:PFLRESubMatches;
      NextCharClassAction:PFLREOnePassNFAStateCharClassAction;
      Flags:longword;
      ThreadLocalState,NextThreadLocalState:TFLREThreadLocalState;
  begin
  
   ThreadLocalState:=ThreadLocalStates;
   ThreadLocalStates:=nil;
   while assigned(ThreadLocalState) do begin
    NextThreadLocalState:=ThreadLocalState.AllNext;
    ThreadLocalState.Free;
    ThreadLocalState:=NextThreadLocalState;
   end;
  
   for Index:=0 to Nodes.Count-1 do begin
    FreeMem(Nodes[Index]);
   end;
   FreeAndNil(Nodes);
  
   SetLength(ForwardInstructions,0);
  
   SetLength(BackwardInstructions,0);
  
   for Index:=0 to CountCharClasses-1 do begin
    FreeMem(CharClasses[Index]);
   end;
   SetLength(CharClasses,0);
   CountCharClasses:=0;
  
   SetLength(ThreadLists[0].Threads,0);
   SetLength(ThreadLists[1].Threads,0);
  
   while assigned(FreeSubMatches) do begin
    SubMatches:=FreeSubMatches;
    FreeSubMatches:=FreeSubMatches^.Next;
    SetLength(SubMatches^.SubMatches,0);
    Finalize(SubMatches^);
    FreeMem(SubMatches);
   end;
   FreeSubMatches:=nil;
  
   FreeAndNil(AllSubMatches);
  
   if assigned(OnePassNFANodes) then begin
    FreeMem(OnePassNFANodes);
    OnePassNFANodes:=nil;
   end;
   OnePassNFANodesCount:=0;
   OnePassNFAStart:=nil;
   OnePassNFAStateSize:=0;
   SetLength(OnePassNFAWorkCaptures,0);
   SetLength(OnePassNFAMatchCaptures,0);
  
   while assigned(OnePassNFACharClassActions) do begin
    NextCharClassAction:=OnePassNFACharClassActions^.AllNext;
    FreeMem(OnePassNFACharClassActions);
    OnePassNFACharClassActions:=NextCharClassAction;
   end;
   OnePassNFACharClassActions:=nil;
  
   SetLength(BitStateNFAJobs,0);
   SetLength(BitStateNFAWorkCaptures,0);
   SetLength(BitStateNFAMatchCaptures,0);
  
   SetLength(FixedStringBoyerMooreNext,0);
  
   DFADestroyStatePool(DFAStatePoolUsed);
   DFADestroyStatePool(DFAStatePoolFree);
  
negative.code:  Input:=ThreadLocalState.Input;
   InputLength:=ThreadLocalState.InputLength;
  
   CurrentThreadList:=@ThreadLocalState.ThreadLists[0];
   NewThreadList:=@ThreadLocalState.ThreadLists[1];
  
   CurrentThreadList^.Count:=0;
   NewThreadList^.Count:=0;
  
   SubMatches:=NewSubMatches(CountSubMatches,0);
  
   inc(ThreadLocalState.Generation);
   if UnanchoredStart then begin
    AddThread(ThreadLocalState,CurrentThreadList,UnanchoredStartInstruction,SubMatches,StartPosition);
   end else begin
  