Spill: Move data from a Register to Memory.
Fill: Move data from Memory to a Register.
Although, I couldn't find actual definition of fill, taking it from Arjun sir's answer.
Since question mentions
Assume that all variables are dead after this code segment
d & e needs to be calculated only in the else block, so we move it there.
ignoring obvious loads
c = a + b; // R2{c} <- R1{a} + R2{b}
x = c * c; // Need 'a' next, so spill c in memory. And then R2{x} <- R2{c} * R2 {c}
// above if you spill 'a' to memory, you need to spill c to memory again later (to load x), so to minimize spill c into memory
// also, a is never modifed in the program, so we can 'fill' it anytime.
if (x > a) { // CMP R2{x}, R1{a}
y = a * a; // R2{} <- R1{a}*R1{a}
}
else {
//since question says minimum spill to memory, c can be read (or fill'ed) multiple times
d = c * a; // load R2,c; R2{d} <- R2{c}*R1{a}
d = d * d; // R2{d} <- R2{d} * R2{d}
e = c + a; // load R2,c; R2{e} <- R2{c} + R1{a}
e = e * e; // R2{e} <- R2{e} * R2 {e}
}