Global hybrid simulation of hot flow anomalies near the bow shock and in the magnetosheath