Add missing extern "C" blocks and move to after headers.

If extern "C" blocks are before external includes, you can end up with broken
interfaces if the external include is doing anything C++ specific.
Move standard includes to before any local includes

This prevents any "side effects" from the internal includes breaking the
standard libraries.