Translate estimate_phi, make it compile and run without dumping core