It is a bit hard to spot. Here's the original algorithm. Try to compute the next value of 2 * q * y near all the return points. For now don't worry about actually returning the value.
divide(x, y):
if (y > x) {
next2qy = // compute the next 2 * q * y
return 0
}
q = divide(x, 2 * y)
if ((x - 2 * q * y) < y) {
next2qy = // compute the next 2 * q * y
return 2 * q
} else {
next2qy = // compute the next 2 * q * y
return 2 * q + 1
}
Now imagine that we can return several values at the same time (some languages like Python support this). Then the algorithm can look like this:
divide(x, y):
if (y > x) {
next2qy = // compute the next 2 * q * y
return 0, next2qy
}
q, qy2 = divide(x, 2 * y)
if ((x - qy2) < y) {
next2qy = // compute the next 2 * q * y
return 2 * q, next2qy
} else {
next2qy = // compute the next 2 * q * y
return 2 * q + 1, next2qy
}