Umpires keep track of time lost to 'Good Cause' - this means any time the ball gets lost, the batsmen ask for new gloves, a decision gets sent to the third umpires, or any other reason when play is halted for which the bowling side isn't to blame. This time lost is basically time forgiven to the bowling side. For example, if the innings ends 15 minutes later than it should, but the umpires have recorded down 15 minutes lost to 'Good Cause', the bowling side is considered to have finished the innings on time.
Now I can't answer this part for certain, but as far as my umpiring experience has gone, we don't penalise teams for being slow if they happen to bowl the other side out before scheduled close of play. IE, if they're starting the 46th over at the time they should be starting the 50th, but pick up the 10th wicket, and we go off the field for the change of innings at the scheduled time, then there is no punishment. But that's club cricket in HK, I'm pretty sure International cricket will be far stricter.
My guess would be that they'll see how many overs should have been bowled at the time the innings ended, how many were actually bowled, factor in the 'Good Cause' time, and then figure out how far behind the overrate the bowling side is. There would be some protocol in play (probably something in the ICC playing conditions) about how slow the side must be to incur a penalty. Since all slow overrate penalties are outside of the game, this may actually not even be in the playing conditions, but be in some other set of rules/guidelines that the match referee/tournament organiser/whoever decides on these penalties will refer to.
It's an interesting question. I'll ask around and get back to you all if I find an answer. I'm sure some clever googling might be able to provide an answer too.