There are some controls, voters are counted as they sign in and the machines have vote count odometers on them. This way if a machine has 5000 votes on the counter but only 3000 voters came to the polling place at that point in the day, there is a mismatch that indicates a problem.
... and if past history serves as a predictor, they count all 5000 anyway, then come up with another 1000 that were somehow lost and count those as well.