This doesn't look legitimate. A search for one of the strings in the code reveals that its likely purpose is to add links to your site only when a selection of search engines visit.
Thus, it'll look fine when you go to the site itself, but it'll be full of spam-type advertising for the search engines, who in turn will see your site as endorsing a variety of links designed to boost their page ranking.
In any case, if you don't specifically recognise the code, keep your users safe and get rid of it. If you didn't install it, you should work out how the code got installed, so it doesn't happen again.