Please provide a compilable replacement for e.g. pinMode() as to how you think it can work; it needs to support two processors (e.g. 328P for Uno and 2560 for Mega).
There really is not that much bloat in pinMode(), at least not for AVR based processors.
- Determine the bit in the register that needs to be changed.
- Determine the register to be changed.
- Write the register based on the required mode.
There is a little additional stuff to harden the code.