def compute_overdose_deaths(run, start_year, end_year, config, intervention):
    """Compute number of opioid overdose deaths from start_year to end_year.

    Parameters
    ----------
        run: whynot.dynamics.Run
            Run object produced by running simulate for the opioid simulator
        start_year: int
            Year to start counting overdose deaths
        end_year: int
            Final year included in overdose death count
        config: whynot.simulator.opioid.Config
            Configuration used to generate `run`
        intervention: whynot.simulator.opioid.Intervention
            Intervention object to generate `run` when calling `simulate`

    Returns
    -------
        deaths: int
            Total number of overdose deaths across nonmedical users, users with
            OUD, and illicit opioid users.

    """
    if intervention:
        config = config.update(intervention)

    deaths = 0.0
    for outcome_year in range(start_year, end_year + 1):
        state = run[outcome_year]
        nonmedical_deaths = state.nonmedical_users * config.nonmedical_overdose
        oud_deaths = state.oud_users * config.oud_overdose[outcome_year]
        illicit_deaths = state.illicit_users * config.illicit_overdose[outcome_year]
        deaths += nonmedical_deaths + oud_deaths + illicit_deaths
    return deaths