What function publishes a post when you click the publish button?

Normally, posts are published by the wp_insert_post() function. Essentially, the post_status is changed from draft to publish. Nothing more to it than that, really.

There is also the wp_publish_post() function, which is really only used for scheduled posts. It does the basic job of transitioning a post from “future” to “publish”, and also calls the same various action hooks that wp_insert_post() would normally call, so that plugins and other functions which take actions on publishing of posts behave correctly.