Verification and Fence Insertion under the TSO Memory Model