How does AddComponent work from the inside?

Hello everyone I would like to know how AddComponent works from the inside. Is there a check on GetComponent (to display a message that there is already such a component). And the second question - where can I find out such information - what is inside the Unity method?

With great respect, and thank you in advance!

hope this helps, almost similar to what you have asked: