Ported fmincg to C