Without any libs required, without any gross assembly (with questionable portability - the answer submitted gets the wrong answer on my system), and without any parsing of files:
https://man7.org/linux/man-pages/man3/get_nprocs_conf.3.html