COSMIT translate lgamma replacement to C and clean it up