Ported line_search to C