The most general function for linear regression, fitting 1 vector to a sum of 1 or more other vectors, in AFNI is THD_fitter() in file thd_fitter.c. For fitting a single vector (below, avec) to another single vector (bvec), the call would be something like so
int npt ; /* length of vectors */
float *avec , *bvec ; /* vectors of length npt */
floatvec *beta ; /* output from THD_fitter */
float bval ; /* the coefficient you want */
....
beta = THD_fitter( npt , avec , 1 , bvec , 2 , NULL ) ;
bval = beta->ar[0] ; /* your goal */
KILL_floatavec(beta) ; /* toss the trash */
The advantage of this function is that it's easy to add more components to bvec, and get more beta values. This function also allows for sign constraints on the beta values, and for L1 fitting as well as L2 fitting. This function is the core of the program 3dTfitter.