original c code as the base