function [Aineq,Bineq,Aeq,Beq,LB,UB,X,EXITFLAG,options,OUTPUT,optimState,restoreData] = ...
    pscommon(caller,FUN,X,Aineq,Bineq,Aeq,Beq,LB,UB,nonlcon,options,OUTPUT,optimState)
%

% Copyright 2020-2021 The MathWorks, Inc.

numberOfVariables = numel(X);
% Bound correction
[LB,UB,msg,EXITFLAG] = globaloptim.internal.validate.checkbound(LB,UB,numel(X));
if EXITFLAG < 0
    OUTPUT.message = msg;
    if options.Verbosity > 0
        fprintf('%s\n',msg)
    end
    restoreData = globaloptim.internal.createLinearConstrRestoreData(Aineq, Aeq);
    return
end

if strcmpi(caller,'Patternsearch')
  tolCon = options.TolCon;
elseif strcmpi(caller,'Paretosearch')
  tolCon = options.ConstraintTolerance;
end

% Linear constraints correction
[X,Aineq,Bineq,Aeq,Beq,LB,UB,msg,EXITFLAG,restoreData] = ...
    globaloptim.internal.preProcessLinearConstr(X,Aineq,Bineq,Aeq,Beq,LB,UB,tolCon, ...
    numberOfVariables,optimState.linconstrtype,options.Verbosity);

if EXITFLAG < 0
    OUTPUT.message = msg;
    if options.Verbosity > 0
        fprintf('%s\n',msg)
    end
    return
end

% Print some diagnostic information if verbosity > 2
if options.Verbosity > 2
    % Number of constraints
    globaloptim.patternsearch.internal.diagnose(caller, FUN,nonlcon,optimState.nineqcstr,optimState.neqcstr,optimState.ncstr);
end
