c implementation with duplication error