C implementation of searchsorted