#ifndef __RXODE2PTR_H__
#define __RXODE2PTR_H__

#include "rxode2.h"

#if defined(__cplusplus)
extern "C" {
#endif

  typedef SEXP (*_rxode2_rxRmvnSEXP_t)(SEXP nSSEXP, SEXP muSSEXP, SEXP sigmaSSEXP, SEXP lowerSSEXP, SEXP upperSSEXP, SEXP ncoresSSEXP, SEXP isCholSSEXP, SEXP keepNamesSSEXP, SEXP aSSEXP, SEXP tolSSEXP, SEXP nlTolSSEXP, SEXP nlMaxiterSSEXP);
  extern _rxode2_rxRmvnSEXP_t _rxode2_rxRmvnSEXP_;

  // Adjoint objective-gradient backward sweep (src/adjoint.cpp); installed into
  // the downstream package's function-pointer table by iniRxodePtrs().
  typedef void (*rxode2AdjointSweep_t)(double *tg, double *J, double *dP, double *cover, int *obsK, int ns, int np, int nt, int nobs, double *out, int nCj, int *cjK, int *cjCmt, double *cjAlpha, int nDual, int *dualK, double *dualW, double *dualC);
  extern rxode2AdjointSweep_t rxode2AdjointSweep;

  // Full-trajectory adjoint sweep: dy_k(t_i)/dp for every state of interest,
  // output time, and parameter (adjoint counterpart of forward sensitivity's
  // rx__sens_<state>_BY_<param>__ columns); see src/adjoint.cpp for the layout.
  typedef void (*rxode2AdjointTrajSweep_t)(double *tg, double *J, double *dP, int ns, int np, int nt, int *outK, int nOut, int *stateIdx, int nStates, double *result, int nCj, int *cjK, int *cjCmt, double *cjAlpha, int nDual, int *dualK, double *dualW, double *dualC);
  extern rxode2AdjointTrajSweep_t rxode2AdjointTrajSweep;

  // Set / get the current solve's exact ODE atol/rtol (for tightening the cov step).
  typedef void (*rxSetSolveAtolRtol_t)(double atol, double rtol);
  extern rxSetSolveAtolRtol_t rxSetSolveAtolRtol;
  typedef void (*rxGetSolveAtolRtol_t)(double *atol, double *rtol);
  extern rxGetSolveAtolRtol_t rxGetSolveAtolRtol;

  // threefry RNG engine entry points (src/rxthreefry.cpp); downstream packages
  // seed a per-subject stream with setSeedEng1(getRxSeed1(cores) + id) -- after
  // setRxThreadId() sets the OpenMP thread -- then draw with rxNormEng().
  typedef uint32_t (*getRxSeed1_t)(int ncores);
  extern getRxSeed1_t getRxSeed1;
  typedef void (*setSeedEng1_t)(uint32_t seed);
  extern setSeedEng1_t setSeedEng1;
  typedef void (*seedEng_t)(int ncores);
  extern seedEng_t seedEng;
  typedef double (*rxNormEng_t)(double mean, double sd);
  extern rxNormEng_t rxNormEng;
  typedef double (*rxUnifEng_t)(double low, double hi);
  extern rxUnifEng_t rxUnifEng;
  // Per-observation CMT.  Returns 1 when the model has no CMT covariate (every
  // observation is compartment 1) but NA_INTEGER when the covariate is present and
  // this row's value is missing -- so "no compartment recorded" is distinguishable
  // from "compartment 1".  For the old lenient behaviour, map NA_INTEGER to 1.
  typedef int (*getIndCmt_t)(rx_solving_options* op, rx_solving_options_ind* ind, int kk);
  extern getIndCmt_t getIndCmt;
  // Writer for the CMT covariate (inverse of getIndCmt); lets a downstream
  // package re-base the CMT column without touching op->cmtCov / ind->cov_ptr.
  typedef void (*setIndCmt_t)(rx_solving_options* op, rx_solving_options_ind* ind, int kk, int cmt);
  extern setIndCmt_t setIndCmt;

  // Event ("jump") sensitivity shape.  A shape is one model's six dims
  // (active/nState/nParam/nParam2/nParam3/useCalcJac) plus its dosing-derivative
  // function pointers; rxode2 holds exactly one installed at a time.  To solve
  // peer models with different shapes through a shared solve pool, save the
  // installed shape into a caller-owned buffer of rxode2EventSensShapeSize()
  // bytes, install the batch's shape (rxode2EventSensLoadFull() from the model's
  // `trans`, or a previously saved buffer), solve, then restore:
  //
  //   std::vector<char> saved(rxode2EventSensShapeSize());
  //   rxode2EventSensShapeSave(saved.data(), saved.size());
  //   rxode2EventSensShapeRestore(peer.data(), peer.size());  // solve the batch
  //   rxode2EventSensShapeRestore(saved.data(), saved.size());
  //
  // Both take the buffer's capacity and refuse to touch a buffer that is too
  // small, so a mis-sized allocation fails cleanly instead of running off its
  // end.  The layout is opaque and may change between rxode2 versions: a buffer
  // rxode2 does not recognize is rejected rather than installed, and a buffer
  // must never be serialized or reused across sessions.  A saved shape also
  // holds pointers INTO the model's shared library, so unloading that model
  // (rxUnload()) invalidates it -- re-install with rxode2EventSensLoadFull()
  // rather than restoring a shape saved before the unload.  These globals are
  // read inside the OpenMP solve loops, so install and restore only at batch
  // boundaries, never from a parallel region or while a solve is running.
  // Neither calls Rf_error, so a C++ caller is not longjmp'd past its
  // destructors; both return 1 on success and 0 if the buffer was rejected.
  typedef int (*rxode2EventSensShapeSize_t)(void);
  extern rxode2EventSensShapeSize_t rxode2EventSensShapeSize;
  typedef int (*rxode2EventSensShapeSave_t)(void *buf, int bufSize);
  extern rxode2EventSensShapeSave_t rxode2EventSensShapeSave;
  typedef int (*rxode2EventSensShapeRestore_t)(const void *buf, int bufSize);
  extern rxode2EventSensShapeRestore_t rxode2EventSensShapeRestore;
  // Install a model's shape from its `trans` vector (all six dims).
  typedef void (*rxode2EventSensLoadFull_t)(SEXP trans, int active, int nState, int nParam, int nParam2, int nParam3, int useCalcJac);
  extern rxode2EventSensLoadFull_t rxode2EventSensLoadFull;
  // Read / write the dims only (any getter pointer may be NULL to skip it).
  typedef void (*rxode2EventSensGetDims_t)(int *active, int *nState, int *nParam, int *nParam2, int *nParam3, int *useCalcJac);
  extern rxode2EventSensGetDims_t rxode2EventSensGetDims;
  typedef void (*rxode2EventSensSetDims_t)(int active, int nState, int nParam, int nParam2, int nParam3, int useCalcJac);
  extern rxode2EventSensSetDims_t rxode2EventSensSetDims;
  // Toggle the active flag only / turn the jumps off and zero the dims.
  typedef void (*rxode2EventSensSetActive_t)(int active);
  extern rxode2EventSensSetActive_t rxode2EventSensSetActive;
  typedef void (*rxode2EventSensDeactivate_t)(void);
  extern rxode2EventSensDeactivate_t rxode2EventSensDeactivate;

  // Per-individual ODE solve buffer-pointer swap (nlmixr2est impmap gradient):
  // save the originals, install private larger buffers for a higher-state
  // sensitivity solve (with setOpNeq), then restore.  getIndSolve() already
  // returns ind->solve.
  typedef void (*setIndSolvePtr_t)(rx_solving_options_ind* ind, double* solve);
  extern setIndSolvePtr_t setIndSolvePtr;
  typedef double *(*getIndSolveSave_t)(rx_solving_options_ind* ind);
  extern getIndSolveSave_t getIndSolveSave;
  typedef void (*setIndSolveSave_t)(rx_solving_options_ind* ind, double* solveSave);
  extern setIndSolveSave_t setIndSolveSave;
  typedef double *(*getIndSolveLast_t)(rx_solving_options_ind* ind);
  extern getIndSolveLast_t getIndSolveLast;
  typedef void (*setIndSolveLast_t)(rx_solving_options_ind* ind, double* solveLast);
  extern setIndSolveLast_t setIndSolveLast;
  typedef double *(*getIndSolveLast2_t)(rx_solving_options_ind* ind);
  extern getIndSolveLast2_t getIndSolveLast2;
  typedef void (*setIndSolveLast2_t)(rx_solving_options_ind* ind, double* solveLast2);
  extern setIndSolveLast2_t setIndSolveLast2;

  typedef int (*par_progress_t)(int c, int n, int d, int cores, clock_t t0, int stop);
  extern par_progress_t par_progress;

  typedef rx_solve *(*getRxSolve_t)(void);
  extern getRxSolve_t getRxSolve_;

  typedef void (*ind_solve_t)(rx_solve *rx, unsigned int cid, t_dydt_liblsoda dydt_lls,
                              t_dydt_lsoda_dum dydt_lsoda, t_jdum_lsoda jdum,
                              t_dydt c_dydt, t_update_inis u_inis, int jt);
  extern ind_solve_t ind_solve;

  typedef double (*getTime_t)(int idx, rx_solving_options_ind *ind);
  extern getTime_t getTime;

  typedef int (*isRstudio_t)(void);
  extern isRstudio_t isRstudio;

  typedef int (*iniSubjectE_t)(int solveid, int inLhs, rx_solving_options_ind *ind, rx_solving_options *op, rx_solve *rx,
                               t_update_inis u_inis);
  extern iniSubjectE_t iniSubjectE;

  typedef void (*sortIds_t)(rx_solve* rx, int ini);
  extern sortIds_t sortIds;

  typedef rx_solving_options* (*getSolvingOptions_t)(rx_solve* rx);
  extern getSolvingOptions_t getSolvingOptions;

  typedef rx_solving_options_ind *(*getSolvingOptionsInd_t)(rx_solve *rx, int id);
  extern getSolvingOptionsInd_t getSolvingOptionsInd;

  typedef SEXP (*_rxode2_rxModelVars_t)(SEXP);
  extern _rxode2_rxModelVars_t _rxode2_rxModelVars_;

  typedef void (*par_solve_t)(rx_solve *rx);
  extern par_solve_t par_solve;

  typedef const char *(*rxGetId_t)(int id);
  extern rxGetId_t rxGetId;

  typedef double (*getIndLambda_t)(rx_solving_options_ind* ind);
  extern getIndLambda_t getIndLambda;

  typedef int (*getIndLambdaYj_t)(rx_solving_options_ind* ind);
  extern getIndLambdaYj_t getIndLambdaYj;

  typedef double (*getIndLogitLow_t)(rx_solving_options_ind* ind);
  extern getIndLogitLow_t getIndLogitLow;

  typedef double (*getIndLogitHi_t)(rx_solving_options_ind* ind);
  extern getIndLogitHi_t getIndLogitHi;

  typedef void (*setIndParPtr_t)(rx_solving_options_ind* ind, int i, double val);
  extern setIndParPtr_t setIndParPtr;

  typedef double (*getIndParPtr_t)(rx_solving_options_ind* ind, int i);
  extern getIndParPtr_t getIndParPtr;

  typedef int (*getIndNallTimes_t)(rx_solving_options_ind* ind);
  extern getIndNallTimes_t getIndNallTimes;

  typedef void (*setIndIdx_t)(rx_solving_options_ind* ind, int j);
  extern setIndIdx_t setIndIdx;

  typedef int (*getIndIx_t)(rx_solving_options_ind* ind, int j);
  extern getIndIx_t getIndIx;

  typedef int (*getIndEvid_t)(rx_solving_options_ind* ind, int kk);
  extern getIndEvid_t getIndEvid;

  typedef double *(*getIndLhs_t)(rx_solving_options_ind* ind);
  extern getIndLhs_t getIndLhs;

  typedef int (*getIndNdoses_t)(rx_solving_options_ind* ind);
  extern getIndNdoses_t getIndNdoses;

  typedef int (*getIndNevid2_t)(rx_solving_options_ind* ind);
  extern getIndNevid2_t getIndNevid2;

  typedef void (*setIndSolve_t)(rx_solving_options_ind* ind, int solve);
  extern setIndSolve_t setIndSolve;

  typedef double *(*getIndSolve_t)(rx_solving_options_ind* ind);
  extern getIndSolve_t getIndSolve;

  typedef double (*getIndDv_t)(rx_solving_options_ind* ind, int j);
  extern getIndDv_t getIndDv;

  typedef int (*getIndYj_t)(rx_solving_options_ind* ind);
  extern getIndYj_t getIndYj;

  typedef double (*getIndLimit_t)(rx_solving_options_ind* ind, int kk);
  extern getIndLimit_t getIndLimit;

  typedef int (*getIndCens_t)(rx_solving_options_ind* ind, int kk);
  extern getIndCens_t getIndCens;

  typedef int (*getIndIdx_t)(rx_solving_options_ind* ind);
  extern getIndIdx_t getIndIdx;

  typedef int (*getOpNeq_t)(rx_solving_options* op);
  extern getOpNeq_t getOpNeq;

#define getRxNeq(rx) getOpNeq(getSolvingOptions(rx))

  typedef void (*setOpNeq_t)(rx_solving_options* op, int neq);
  extern setOpNeq_t setOpNeq;

#define setRxNeq(rx, neq)  setOpNeq(getSolvingOptions(rx), neq)

  typedef int (*hasOpBadSolve_t)(rx_solving_options* op);
  extern hasOpBadSolve_t hasOpBadSolve;
#define hasRxBadSolve(rx)  hasOpBadSolve(getSolvingOptions(rx))

  typedef int (*getOpNlin_t)(rx_solving_options* op);
  extern getOpNlin_t getOpNlin;
#define getRxNlin(rx) getOpNlin(getSolvingOptions(rx))

  typedef int (*getOpCores_t)(rx_solving_options* op);
  extern getOpCores_t getOpCores;
#define getRxCores(rx) getOpCores(getSolvingOptions(rx))

  typedef int (*getOpNlhs_t)(rx_solving_options* op);
  extern getOpNlhs_t getOpNlhs;
#define getRxNlhs(rx) getOpNlhs(getSolvingOptions(rx))

  typedef int (*getOpStiff_t)(rx_solving_options* op);
  extern getOpStiff_t getOpStiff;
#define getRxStiff(rx) getOpStiff(getSolvingOptions(rx))

  typedef void (*resetOpBadSolve_t)(rx_solving_options* op);
  extern resetOpBadSolve_t resetOpBadSolve;
#define resetRxBadSolve(rx) resetOpBadSolve(getSolvingOptions(rx))

  typedef int (*getRxNsub_t)(rx_solve *rx);
  extern getRxNsub_t getRxNsub;

  typedef int (*hasRxLimit_t)(rx_solve *rx);
  extern hasRxLimit_t hasRxLimit;

  typedef int (*hasRxCens_t)(rx_solve *rx);
  extern hasRxCens_t hasRxCens;

  typedef int (*getRxNall_t)(rx_solve *rx);
  extern getRxNall_t getRxNall;

  typedef int (*getRxNobs_t)(rx_solve *rx);
  extern getRxNobs_t getRxNobs;

  typedef int (*getRxNobs2_t)(rx_solve *rx);
  extern getRxNobs2_t getRxNobs2;

  typedef double * (*getOpIndSolve_t)(rx_solving_options* op, rx_solving_options_ind* ind, int idx);
  extern getOpIndSolve_t getOpIndSolve;

  typedef int (*getRxNpars_t)(rx_solve *rx);
  extern getRxNpars_t getRxNpars;

  typedef int (*getIndMixest_t)(rx_solving_options_ind* ind);
  extern getIndMixest_t getIndMixest;

  typedef void (*setIndMixest_t)(rx_solving_options_ind* ind, int mixest);
  extern setIndMixest_t setIndMixest;

  typedef void (*mexpit_t)(double *x, double *p, int n);
  extern mexpit_t mexpit;

  typedef int (*getRxMixnum_t)(rx_solve *rx);
  extern getRxMixnum_t getRxMixnum;

  typedef void (*setRxMixnum_t)(rx_solve *rx, int mixnum);
  extern setRxMixnum_t setRxMixnum;

  // Get the per-individual sticky tolerance factor
  typedef double (*getIndTolFactor_t)(rx_solving_options_ind *ind);
  extern getIndTolFactor_t getIndTolFactor;

  // Set the per-individual sticky tolerance factor
  typedef void (*setIndTolFactor_t)(rx_solving_options_ind *ind, double tolFactor);
  extern setIndTolFactor_t setIndTolFactor;

  // Get the per-individual neq override (-1 = use op->neq)
  typedef int (*getIndNeqOverride_t)(rx_solving_options_ind *ind);
  extern getIndNeqOverride_t getIndNeqOverride;

  // Set the per-individual neq override (pass -1 to clear)
  typedef void (*setIndNeqOverride_t)(rx_solving_options_ind *ind, int neq);
  extern setIndNeqOverride_t setIndNeqOverride;

  typedef void (*rxSetSilentErr_t)(int silent);
  extern rxSetSilentErr_t rxSetSilentErr;

  typedef int (*getOrdId_t)(rx_solve *rx, int solveid);
  extern getOrdId_t getOrdId;

  typedef int (*solveMethodThreadSafe_t)(rx_solving_options* op);
  extern solveMethodThreadSafe_t solveMethodThreadSafe;
  // Thread-safe C-level tolerance adjustment -- no Rcpp/PROTECT overhead, safe from OMP threads
  typedef void (*atolRtolFactor_t)(double factor);
  extern atolRtolFactor_t atolRtolFactor_;

  typedef int (*rxInt_t)(SEXP x, R_xlen_t i);
  extern rxInt_t rxInt;

  typedef double (*rxReal_t)(SEXP x, R_xlen_t i);
  extern rxReal_t rxReal;

  typedef int (*getRxNsim_t)(rx_solve *rx);
  extern getRxNsim_t getRxNsim;

  typedef void (*setRxThreadId_t)(int id);
  extern setRxThreadId_t setRxThreadId;

  static inline SEXP iniRxodePtrs0(SEXP p) {
    if (_rxode2_rxRmvnSEXP_ == NULL) {
      _rxode2_rxRmvnSEXP_ = (_rxode2_rxRmvnSEXP_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 0));
      par_progress = (par_progress_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 1));
      getRxSolve_ = (getRxSolve_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 2));
      ind_solve = (ind_solve_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 3));
      getTime = (getTime_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 4));
      isRstudio = (isRstudio_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 5));
      iniSubjectE = (iniSubjectE_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 6));
      sortIds = (sortIds_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 7));
      getSolvingOptions = (getSolvingOptions_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 8));
      getSolvingOptionsInd = (getSolvingOptionsInd_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 9));
      _rxode2_rxModelVars_ = (_rxode2_rxModelVars_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 10));
      par_solve = (par_solve_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 11));
      rxGetId = (rxGetId_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 12));
      getIndLambda = (getIndLambda_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 13));
      getIndLambdaYj = (getIndLambdaYj_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 14));
      getIndLogitLow = (getIndLogitLow_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 15));
      getIndLogitHi = (getIndLogitHi_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 16));
      setIndParPtr =  (setIndParPtr_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 17));
      getIndParPtr = (getIndParPtr_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 18));
      getIndNallTimes = (getIndNallTimes_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 19));
      setIndIdx = (setIndIdx_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 20));
      getIndIx = (getIndIx_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 21));
      getIndEvid= (getIndEvid_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 22));
      getIndLhs = (getIndLhs_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 23));
      getIndNdoses = (getIndNdoses_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 24));
      getIndNevid2 = (getIndNevid2_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 25));
      setIndSolve = (setIndSolve_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 26));
      getIndSolve = (getIndSolve_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 27));
      getIndDv = (getIndDv_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 28));
      getIndYj = (getIndYj_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 29));
      getIndLimit = (getIndLimit_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 30));
      getIndCens = (getIndCens_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 31));
      getIndIdx = (getIndIdx_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 32));
      getOpNeq = (getOpNeq_t)  R_ExternalPtrAddrFn(VECTOR_ELT(p, 33));
      setOpNeq= (setOpNeq_t)  R_ExternalPtrAddrFn(VECTOR_ELT(p, 34));
      hasOpBadSolve = (hasOpBadSolve_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 35));
      getOpNlin = (getOpNlin_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 36));
      getOpCores = (getOpCores_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 37));
      getOpNlhs = (getOpNlhs_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 38));
      getOpStiff = (getOpStiff_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 39));
      resetOpBadSolve = (resetOpBadSolve_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 40));
      getRxNsub = (getRxNsub_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 41));
      hasRxLimit = (hasRxLimit_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 42));
      hasRxCens = (hasRxCens_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 43));
      getRxNall = (getRxNall_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 44));
      getRxNobs = (getRxNobs_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 45));
      getRxNobs2 = (getRxNobs2_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 46));
      getOpIndSolve = (getOpIndSolve_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 47));
      getRxNpars = (getRxNpars_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 48));
      getIndMixest = (getIndMixest_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 49));
      setIndMixest = (setIndMixest_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 50));
      mexpit = (mexpit_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 51));
      getRxMixnum = (getRxMixnum_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 52));
      setRxMixnum = (setRxMixnum_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 53));
      getIndTolFactor = (getIndTolFactor_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 54));
      setIndTolFactor = (setIndTolFactor_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 55));
      getIndNeqOverride = (getIndNeqOverride_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 56));
      setIndNeqOverride = (setIndNeqOverride_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 57));
      rxSetSilentErr = (rxSetSilentErr_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 58));
      getOrdId       = (getOrdId_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 59));
      solveMethodThreadSafe = (solveMethodThreadSafe_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 60));
      atolRtolFactor_ = (atolRtolFactor_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 61));
      rxInt = (rxInt_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 62));
      rxReal = (rxReal_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 63));
      getRxNsim = (getRxNsim_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 64));
      setRxThreadId = (setRxThreadId_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 65));
      rxode2AdjointSweep = (rxode2AdjointSweep_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 66));
      rxode2AdjointTrajSweep = (rxode2AdjointTrajSweep_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 67));
      rxSetSolveAtolRtol = (rxSetSolveAtolRtol_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 68));
      rxGetSolveAtolRtol = (rxGetSolveAtolRtol_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 69));
      getRxSeed1 = (getRxSeed1_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 70));
      setSeedEng1 = (setSeedEng1_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 71));
      seedEng = (seedEng_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 72));
      rxNormEng = (rxNormEng_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 73));
      setIndSolvePtr = (setIndSolvePtr_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 74));
      getIndSolveSave = (getIndSolveSave_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 75));
      setIndSolveSave = (setIndSolveSave_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 76));
      getIndSolveLast = (getIndSolveLast_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 77));
      setIndSolveLast = (setIndSolveLast_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 78));
      getIndSolveLast2 = (getIndSolveLast2_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 79));
      setIndSolveLast2 = (setIndSolveLast2_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 80));
      rxUnifEng = (rxUnifEng_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 81));
      getIndCmt = (getIndCmt_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 82));
      setIndCmt = (setIndCmt_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 83));
      rxode2EventSensShapeSize = (rxode2EventSensShapeSize_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 84));
      rxode2EventSensShapeSave = (rxode2EventSensShapeSave_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 85));
      rxode2EventSensShapeRestore = (rxode2EventSensShapeRestore_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 86));
      rxode2EventSensLoadFull = (rxode2EventSensLoadFull_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 87));
      rxode2EventSensGetDims = (rxode2EventSensGetDims_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 88));
      rxode2EventSensSetDims = (rxode2EventSensSetDims_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 89));
      rxode2EventSensSetActive = (rxode2EventSensSetActive_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 90));
      rxode2EventSensDeactivate = (rxode2EventSensDeactivate_t) R_ExternalPtrAddrFn(VECTOR_ELT(p, 91));
    }
    return R_NilValue;
  }

#define iniRxode2ptr                                    \
  _rxode2_rxRmvnSEXP_t _rxode2_rxRmvnSEXP_ = NULL;      \
  par_progress_t par_progress = NULL;                   \
  getRxSolve_t getRxSolve_ = NULL;                      \
  ind_solve_t ind_solve = NULL;                         \
  par_solve_t par_solve = NULL;                         \
  getTime_t getTime = NULL;                             \
  isRstudio_t isRstudio = NULL;                         \
  iniSubjectE_t iniSubjectE = NULL;                     \
  sortIds_t sortIds = NULL;                             \
  getSolvingOptions_t getSolvingOptions = NULL;         \
  getSolvingOptionsInd_t getSolvingOptionsInd = NULL;   \
  _rxode2_rxModelVars_t _rxode2_rxModelVars_ = NULL;    \
  getIndLambda_t getIndLambda = NULL;                   \
  getIndLambdaYj_t getIndLambdaYj = NULL;               \
  getIndLogitLow_t getIndLogitLow = NULL;               \
  getIndLogitHi_t getIndLogitHi = NULL;                 \
  rxGetId_t rxGetId = NULL;                             \
  setIndParPtr_t setIndParPtr = NULL;                   \
  getIndParPtr_t getIndParPtr = NULL;                   \
  getIndNallTimes_t getIndNallTimes = NULL;             \
  setIndIdx_t setIndIdx = NULL;                         \
  getIndIx_t getIndIx = NULL;                           \
  getIndEvid_t getIndEvid = NULL;                       \
  getIndLhs_t getIndLhs = NULL;                         \
  getIndNdoses_t getIndNdoses = NULL;                   \
  getIndNevid2_t getIndNevid2 = NULL;                   \
  setIndSolve_t setIndSolve = NULL;                     \
  getIndSolve_t getIndSolve = NULL;                     \
  getIndDv_t getIndDv = NULL;                           \
  getIndYj_t getIndYj = NULL;                           \
  getIndLimit_t getIndLimit = NULL;                     \
  getIndCens_t getIndCens = NULL;                       \
  getIndIdx_t getIndIdx = NULL;                         \
  getOpNeq_t getOpNeq = NULL;                           \
  setOpNeq_t setOpNeq = NULL;                           \
  hasOpBadSolve_t hasOpBadSolve = NULL;                 \
  getOpNlin_t getOpNlin = NULL;                         \
  getOpCores_t getOpCores = NULL;                       \
  getOpNlhs_t getOpNlhs = NULL;                         \
  getOpStiff_t getOpStiff = NULL;                       \
  resetOpBadSolve_t resetOpBadSolve = NULL;             \
  getRxNsub_t getRxNsub = NULL;                         \
  hasRxLimit_t hasRxLimit = NULL;                       \
  hasRxCens_t hasRxCens = NULL;                         \
  getRxNall_t getRxNall = NULL;                         \
  getRxNobs_t getRxNobs = NULL;                         \
  getRxNobs2_t getRxNobs2 = NULL;                       \
  getOpIndSolve_t getOpIndSolve = NULL;                 \
  getRxNpars_t getRxNpars = NULL;                       \
  getIndMixest_t getIndMixest = NULL;                   \
  setIndMixest_t setIndMixest = NULL;                   \
  mexpit_t mexpit = NULL;                               \
  getRxMixnum_t getRxMixnum = NULL;                     \
  setRxMixnum_t setRxMixnum = NULL;                     \
  getIndTolFactor_t getIndTolFactor = NULL;             \
  setIndTolFactor_t setIndTolFactor = NULL;             \
  getIndNeqOverride_t getIndNeqOverride = NULL;         \
  setIndNeqOverride_t setIndNeqOverride = NULL;         \
  rxSetSilentErr_t rxSetSilentErr = NULL;               \
  getOrdId_t getOrdId = NULL;                           \
  solveMethodThreadSafe_t solveMethodThreadSafe = NULL; \
  atolRtolFactor_t atolRtolFactor_ = NULL;              \
  rxInt_t rxInt = NULL;                                 \
  rxReal_t rxReal = NULL;                               \
  getRxNsim_t getRxNsim = NULL;                         \
  setRxThreadId_t setRxThreadId = NULL;                 \
  rxode2AdjointSweep_t rxode2AdjointSweep = NULL;        \
  rxode2AdjointTrajSweep_t rxode2AdjointTrajSweep = NULL; \
  rxSetSolveAtolRtol_t rxSetSolveAtolRtol = NULL;        \
  rxGetSolveAtolRtol_t rxGetSolveAtolRtol = NULL;        \
  getRxSeed1_t getRxSeed1 = NULL;                       \
  setSeedEng1_t setSeedEng1 = NULL;                     \
  seedEng_t seedEng = NULL;                             \
  rxNormEng_t rxNormEng = NULL;                         \
  rxUnifEng_t rxUnifEng = NULL;                         \
  getIndCmt_t getIndCmt = NULL;                         \
  setIndSolvePtr_t setIndSolvePtr = NULL;               \
  getIndSolveSave_t getIndSolveSave = NULL;             \
  setIndSolveSave_t setIndSolveSave = NULL;             \
  getIndSolveLast_t getIndSolveLast = NULL;             \
  setIndSolveLast_t setIndSolveLast = NULL;             \
  getIndSolveLast2_t getIndSolveLast2 = NULL;           \
  setIndSolveLast2_t setIndSolveLast2 = NULL;           \
  setIndCmt_t setIndCmt = NULL;                         \
  rxode2EventSensShapeSize_t rxode2EventSensShapeSize = NULL;       \
  rxode2EventSensShapeSave_t rxode2EventSensShapeSave = NULL;       \
  rxode2EventSensShapeRestore_t rxode2EventSensShapeRestore = NULL; \
  rxode2EventSensLoadFull_t rxode2EventSensLoadFull = NULL;         \
  rxode2EventSensGetDims_t rxode2EventSensGetDims = NULL;           \
  rxode2EventSensSetDims_t rxode2EventSensSetDims = NULL;           \
  rxode2EventSensSetActive_t rxode2EventSensSetActive = NULL;       \
  rxode2EventSensDeactivate_t rxode2EventSensDeactivate = NULL;     \
  SEXP iniRxodePtrs(SEXP ptr) {                         \
    return iniRxodePtrs0(ptr);                          \
  }                                                     \

#if defined(__cplusplus)
}
#endif

#endif
