Good question and not something we can usually train for. Having an idea what to do in advance is a good thing for all of us to know.
Any answer other than the first could put you and others around you at grave risk. It'll run out of ammo soon enough and then you can explain it to the RSO, pack it up and send or take it to the appropriate gunsmith. Trying to stop the action by dropping the mag, hitting the safety, etc. could make you lose control.