  Time-integrated $CP$ asymmetries in $D^0$ decays to the final states $K^-
K^+$ and $\pi^- \pi^+$ are measured using proton-proton collisions
corresponding to $3\mathrm{\,fb}^{-1}$ of integrated luminosity collected at
centre-of-mass energies of $7\mathrm{\,Te\kern -0.1em V}$ and
$8\mathrm{\,Te\kern -0.1em V}$. The $D^0$ mesons are produced in semileptonic
$b$-hadron decays, where the charge of the accompanying muon is used to
determine the initial flavour of the charm meson. The difference in $CP$
asymmetries between the two final states is measured to be \begin{align}
  \Delta A_{CP} = A_{CP}(K^-K^+)-A_{CP}(\pi^-\pi^+) = (+0.14 \pm
0.16\mathrm{\,(stat)} \pm 0.08\mathrm{\,(syst)})\% \ . \nonumber \end{align} A
measurement of $A_{CP}(K^-K^+)$ is obtained assuming negligible $CP$ violation
in charm mixing and in Cabibbo-favoured $D$ decays. It is found to be
\begin{align}
  A_{CP}(K^-K^+) = (-0.06 \pm 0.15\mathrm{\,(stat)} \pm 0.10\mathrm{\,(syst)})
\% \ ,\nonumber \end{align} where the correlation coefficient between $\Delta
A_{CP}$ and $A_{CP}(K^-K^+)$ is $\rho=0.28$. By combining these results, the
$CP$ asymmetry in the $D^0\rightarrow\pi^-\pi^+$ channel is
$A_{CP}(\pi^-\pi^+)=(-0.20\pm0.19\mathrm{\,(stat)}\pm0.10\mathrm{\,(syst)})\%$.
