# C, 38 bytes

    g(x,y){while(x^=y^=x^=y%=x);return y;}