Replace calc_ctr function with an inline function