Elon Musk has sold the social media platform X, formerly Twitter, to his artificial intelligence company, XAI, in a $33 billion all-stock deal.