Where is the merge function for CiviMail located in code?
Well I think the dirty work is done here in a sql statement using a group by clause. I don't know the code base at all however. I am on win7 and use the grepWin program.

..\civicrm\civicrm\CRM\Mailing\BAO\Mailing.php

Line 558

  // CRM-3975
  $groupBy = $groupJoin = '';
  if ($dedupeEmail) {
    $groupJoin = " INNER JOIN civicrm_email e ON e.id = i.email_id";
    $groupBy = " GROUP BY e.email ";
  }


CiviMail should have the option of not sending duplicate emails
https://issues.civicrm.org/jira/browse/CRM-3975