Let $x$ be a real number between 0 and $\tfrac{\pi}{2}$ for which the function  $3\sin^2 x + 8\sin x \cos x + 9\cos^2 x$ obtains its maximum value, $M$. Find the value of $M + 100\cos^2x$.

Let's think step by step and output the final answer within \boxed{}.
user