Determining the number of ways a number can be written as sum of three squares

I was going through Erich Friedman's "What's Special About This Number?" and there some numbers are classified based on the number of ways we can write them as sum of squares. I want to prove the following claim by Friedman:

129 is the smallest number that can be written as the sum of 3 squares in 4 ways.

Indeed, as given in Wikipedia, $$11^2+2^2+2^2 = 10^2+5^2+2^2 = 8^2+8^2+1^2 = 8^2+7^2+4^2 = 129$$ So what remains to prove is that this is the smallest such number.

Is it possible to write a proof for this fact using some insights along with brute force/cases? How can we solve this problem using only brute-force?

Also, since I know the proof of Legendre's three-square theorem. I am also curious to know:

How can we determine the number of ways we can write a non-negative integer which satisfies Legendre's three-square theorem as sum of three squares?

Edit1: Related discussions on MathOverflow:

  • Is there a simple way to compute the number of ways to write a positive integer as the sum of three squares?: Note that this is not answer of my question since $r_k(n)$ counts the number of representations of $n$ by $k$ squares, allowing zeros and distinguishing signs and order.
  • Efficient computation of integer representation as sum of three squares

Edit2: Related discussions on ComputerScience.SE

  • Listing integers as the sum of three squares $m=x^2+y^2+z^2$

Edit3: Related discussions on Mathematics.SE

  • When is a rational number a sum of three squares?

  • Why can't this number be written as a sum of three squares of rationals?

  • Sum of one, two, and three squares


Legendre gave the following answer, which he could not prove (Gauss gave the first proof of the 3-squares theorem). For the sake of simplicity I will only cover the case of numbers $c \equiv 5 \bmod 8$. In this case consider the equivalence classes of forms with discriminant $-4c$; like Legendre, we will consider equivalence with respect to the action of GL$_2({\mathbb Z})$. Let $P$ denote the form classes that represent primes $p \equiv 1 \bmod 4$, and $Q$ those that represent primes $q \equiv 3 \bmod 4$. Then the number of classes $P$ is equal to that of classes $Q$, and to the number of ways in which $c$ can be written as a sum of three squares.

If $c = 29$, the classes $P$ are $x^2 + 29y^2$ and $5x^2 + 2xy + 6y^2$, and these correspond to the two distinct ways of writing $29$ as a sum of three squares: $29 = 0^2 + 2^2 + 5^2 = 2^2 + 3^2 + 4^2$.

Legendre conjectured similar formulas for other values of $c$, which were later proved by Gauss, but using classes with respect to the action of SL$_2({\mathbb Z})$.