I work as a ship inspector.
I test the control systems in ships with Dynamic Positioning systems as my speciality, but I also occasionaly inspect tanks, including ballast tanks
I thought I might give a bit of general background to the type of inspections that go on with vessels, and who does them.
In addition to the Flag State, there is the Port State, and the Classification Society, so there are actually three sets of inspections that can happen to a ship.
The Flag State's job is to interperate the International Maritime Organisation IMO rules for the vessel. These are the rules which have been agreed by all members of the IMO, so this will include SOLAS for basic safety, and IOPP which sets rules designed to limit oil polution as two examples.
The Classification Society predates the IMO regulations, it started with Lloyds of London in the 18th century, and soon after it was required to have the stamp from a classification society in order to be able to insure your vessel/cargo. The classification have their own rules and encompass all the major systems and structures that make a vessel sound.
In addition there is the port state who can ask for a spot inspection of any vessel that comes into the country's port, and detain any that does not come up to scratch.
Detention is the nightmare for any trading ship owner, so this is the stick that they most fear.
Port state is informed of any vessel coming into their harbours, and if the flag state, or class society has any oustanding deficiencies related to the vessel, or if the flag state or class society are not top rated, then they will board and inspect the vessel, and likely detain it.
Both Flag and Class require wide ranging annual inspections, and larger scopes every 5 years (on what is refered to a 'renewal' survey)
Panama by the way is not a bad flag as they go, it is in my humble opinion as good as the MCA or UK flag state.
Hope this explains how it all works, must go I have a ship to inspect ...