De Bruijn conversion for terms with sharing recovery