Extended Euclidean algorithm

Explanation
Function parameters $$X, Y$$ are by reference and are used to return values, $$Xprime, Yprime, res $$ are helper variables. All division is integer $${a \over b}=floor({a \over b})$$. The goal of algorithm, is to find $$X$$ and $$Y$$, such that $$aX + bY = \gcd(a,b)$$. It works basicaly in the same way as Euclidean algorithm Simply $$aX + bY = \gcd(a,b)$$, holds when $$X=1, Y=0$$, since $$gcd(a,0)=a$$ $$bX^\prime + (a\mod b)Y^\prime = gcd(a,b)$$. From this valus, we can can compute values $$X$$ and $$Y$$, such that $$aX + bY = gcd(a,b)$$. Imagine if we put,
 * When b = 0
 * Otherwise recursion is used, and $$Xprime$$ and $$Yprime$$, are comuted such that,

$$X=Y^\prime, Y=X^\prime$$. We would get such equation $$aX + bY =aY^\prime+bX^\prime = (a \bmod b+{a \over b}bY^\prime + bX^\prime = bX^\prime + (a \bmod b)Y^\prime + ({a \over b}bY^\prime=gcd(a,b)+{a \over b}Y^\prime b$$, important is that $$aY^\prime+bX^\prime = gcd(a,b)+{a \over b}Y^\prime b $$, where we can move $${a \over b}Y^\prime b$$ to the left side, and then take out $$b$$, to get $$aY^\prime+b(X^\prime-{a \over b}Y^\prime)=gcd(a,b) $$. So if we put $$X=Y^\prime$$ and $$Y=X^\prime-{a \over b}Y^\prime$$, $$aX + bY=gcd(a,b)$$ will hold.