I'm not sure how to answer that question.

Generically, it converts the epub into a flattened subset of html 3.2 and packs it into a proprietary binary database container that can be read by Kindle devices/apps. If it's building KF8s, it's more or less creating a binary ePub embedded in a PRC container (
generically, I did mention... for those looking to contest my description

).
Specifically... there is no source code available for kindlegen; it's proprietary software (as mentioned above) so your guess is as good as anybody's as to what, exactly, it's "doing."