how does links__system_main_menu() work? How does the below code work at a high level?

print theme('links__system_main_menu', array(
  'links' =&gt; $main_menu,
  'attributes' =&gt; array(
    'id' =&gt; 'main-menu-links',
    'class' =&gt; array('links', 'clearfix'),
  ),
  'heading' =&gt; array(
    'text' =&gt; t('Main menu'),
    'level' =&gt; 'h2',
    'class' =&gt; array('element-invisible'),
  ),
));
Drupal renders the array argument you passed by looking up a suitable theme hook for links__system_main_menu.

The meaning of the argument should be documented in the module that provides the theme hook.