Here's what goes on; there are three different cases:
- If $x<y$, you pass from $(x,y,z)$ to $(x+1, y, z)$ and add 1 to the eventually returned result.
- If $x\ge y$ and $y<z$, you pass from $(x,y,z)$ to $(x,y+1, z)$ and add 2 to the result.
- If $x\ge y$ and $y\ge z$ you return z (plus all the additions you made in cases (1) and (2).
Suppose, for simplicity's sake, we start with $(2,4,6)$. First, we're in case (1), so we pass from $(2,4,6)$ to $(3,4,6)$ and add 1. We then pass to $(4,4,6)$, adding another 1 and pass to case (2). In general, we'll add $1\cdot(y-x)$ in this case.
Now we alternate between case (2) and case (1). In this example, we'll go from $(4,4,6)$ to $(4, 5,6)$ (case 2) and add 2 and then from $(4,5,6)$ (case 1), add 1, and go to $(5,5,6)$, so we've gone from $(4,4,6)$ to $(5,5,6)$ and added 3. Another case (2), case (1) will get us to $(6,6,6)$ In general, we'll add $3\cdot(z-y)$ in this case.
Finally, we arrive at $(6,6,6)$ and find ourselves in case (3) where we return 6 plus the adds we made earlier, namely 2 to get from $(2,4,6)$ to $(4,4,6)$, 6 more to get from $(4,4,6)$ to $(6,6,6)$ for a grand total of $f(2,4,6)=2+6+6=14$.
In general, when $x\le y\le z$ we'll have
$$
f(x,y,z)=1\cdot(y-x)+3\cdot(z-y)+z=4z-2y-x
$$
It's not hard to establish similar results in the cases where $x,y,z$ aren't sorted in increasing order.
[By the way, $f(12,14,20)=4\cdot20-2\cdot14-12=80-28-12=40$.]