<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def api_reference(root_url, service, version):
 """Generate URL for a Taskcluster api reference."""

    root_url = root_url.rstrip('/')
    if root_url == OLD_ROOT_URL:
        return 'https://references.taskcluster.net/{}/{}/api.json'.format(service, version)
    else:
        return '{}/references/{}/{}/api.json'.format(root_url, service, version)