How to change the output of a theme function?
To override the output of a theme function in a theme, you simply take the name of your theme, and the name of the theme function, and join them together with an underscore.

So for your example, the function would be called:

function MYTHEME_links__system_main_menu($variables) {
  $html = '&lt;ul&gt;';

  // Loop over links

  $html .= '&lt;/ul&gt;';

  return $html;
}


Your function should return the HTML string that you want to be rendered when this theme is used, any variables that have been passed to the theme() function will be available to you in $variables.

Usually it's enough to look at the original theme function to find out what's available to build your HTML, but sometimes you'll need to get the Devel module installed and inspect vars with dpm to properly see what's going on.