PORTED CODE COMPLETELY FROM C TO XC