Freezing-in and freezing-out dark matter