anchor.diff:    Inc(Header);
     Result := PK64PoolMedium(NativeInt(Header) and MASK_K64_CLEAR).ThreadHeap.PenaltyFreeMedium(Pointer(Header));
   end;
  +{$else}
  +asm
  +  // if (not Self.Allocated) or (not Prev.Allocated) or
  +  //  (not Next.Allocated) then PenaltyFreeMedium
  +  {$ifdef CPUX86}
  +    mov eax, [EDX - 16].THeaderMedium.Flags
  +    mov ecx, MASK_MEDIUM_ALLOCATED_TEST
  +    and ecx, eax
  +    cmp ecx, MASK_MEDIUM_ALLOCATED_VALUE
  +    jne @penalty_freemem
  +
  +    lea ecx, [edx - 32]
  +    sub ecx, [EDX - 16].THeaderMedium.PreviousSize
  +    movzx eax, ax
  +    mov ecx, [ECX].THeaderMedium.Flags
  +    shl eax, 4
  +    and ecx, MASK_MEDIUM_ALLOCATED_TEST
  +    add edx, eax
  +    cmp ecx, MASK_MEDIUM_ALLOCATED_VALUE
  +    jne @penalty_freemem_restore
  +
  +    mov ecx, [EDX].THeaderMedium.Flags
  +    test ecx, MASK_MEDIUM_EMPTY_TEST
  +    jnz @penalty_freemem_restore
  +    shl ecx, 4
  +    cmp eax, [EDX].THeaderMedium.PreviousSize
  +    jne @penalty_freemem_restore
  +  {$else .CPUX64}
  +    mov rcx, [RDX - 16].THeaderMedium.Flags
  +    mov r8, MASK_MEDIUM_ALLOCATED_TEST
  +    and r8, rcx
  +    cmp r8, MASK_MEDIUM_ALLOCATED_VALUE
  +    jne @penalty_freemem
  +
  +    lea r8, [rdx - 32]
  +    sub r8, [RDX - 16].THeaderMedium.PreviousSize
  +    movzx rcx, cx
  +    mov r8, [R8].THeaderMedium.Flags
  +    shl rcx, 4
  +    and r8, MASK_MEDIUM_ALLOCATED_TEST
  +    add rdx, rcx
  +    cmp r8, MASK_MEDIUM_ALLOCATED_VALUE
  +    jne @penalty_freemem_restore
  +
  +    mov r8, [RDX].THeaderMedium.Flags
  +    test r8, MASK_MEDIUM_EMPTY_TEST
  +    jnz @penalty_freemem_restore
  +    shl r8, 4
  +    cmp rcx, [RDX].THeaderMedium.PreviousSize
  +    jne @penalty_freemem_restore
  +  {$endif}
  +
  +  // if (MediumEmpty.Size + Size + 16 = MAX_MEDIUMEMPTY_SIZE) then
  +  //   Pool.ThreadHeap.DisposeK64PoolMedium(Pool)
  +  {$ifdef CPUX86}
  +    add eax, ecx
  +    add edx, ecx
  +    cmp eax, MAX_MEDIUMEMPTY_SIZE - 16
  +    lea eax, [eax + 16]
  +  {$else .CPUX64}
  +    add rcx, r8
  +    add rdx, r8
  +    cmp rcx, MAX_MEDIUMEMPTY_SIZE - 16
  +    lea rcx, [rcx + 16]
  +  {$endif}
  +  je @dispose_pool
  +
  +  // result
  +  {$ifdef CPUX86}
  +    mov [EDX].THeaderMediumEmptyEx.Size, eax
  +    sub edx, eax
  +    shr eax, 4
  +    mov [EDX].THeaderMedium.Flags, eax
  +
  +    mov eax, FREEMEM_DONE
  +  {$else .CPUX64}
  +    mov [RDX].THeaderMediumEmptyEx.Size, rcx
  +    sub rdx, rcx
  +    shr rcx, 4
  +    mov [RDX].THeaderMedium.Flags, rcx
  +
  +    mov rax, FREEMEM_DONE
  +  {$endif}
  +
  +  // Exit
  +  ret
  +@dispose_pool:
  +  {$ifdef CPUX86}
  +    and edx, MASK_K64_CLEAR
  +    mov eax, [EDX].TK64PoolMedium.ThreadHeap
  +  {$else .CPUX64}
  +    and rdx, MASK_K64_CLEAR
  +    mov rcx, [RDX].TK64PoolMedium.ThreadHeap
  +  {$endif}
  +  jmp TThreadHeap.DisposeK64PoolMedium
  +@penalty_freemem_restore:
  +  {$ifdef CPUX86}
  +    sub edx, eax
  +  {$else .CPUX64}
  +    sub rdx, rcx
  +  {$endif}
  +@penalty_freemem:
  +  {$ifdef CPUX86}
  +    mov eax, MASK_K64_CLEAR
  +    and eax, edx
  +    mov eax, [EAX].TK64PoolMedium.ThreadHeap
  +  {$else .CPUX64}
  +    mov rcx, MASK_K64_CLEAR
  +    and rcx, rdx
  +    mov rcx, [RCX].TK64PoolMedium.ThreadHeap
  +  {$endif}
  +  jmp TThreadHeap.PenaltyFreeMedium
  +end;
  +{$endif}
   
   function TThreadHeap.PenaltyFreeMedium(P: Pointer): Integer;
   var
  
positive.code: 
    Result := PK64PoolMedium(NativeInt(Header) and MASK_K64_CLEAR).ThreadHeap.PenaltyReallocMediumToMedium(Pointer(Header), NewB16Count);
  end;
  
  function TThreadHeap.PenaltyReallocMediumToMedium(P: Pointer;
    NewB16Count: NativeUInt): Pointer;
  
negative.code: end;
  
  function TThreadHeap.ReduceMedium(P: Pointer; NewB16Count: NativeUInt): Pointer;
  {$ifdef PUREPASCAL}
  var
    Header: PHeaderMedium;
    Flags, EmptyFlags: NativeUInt;
  