Who knows? -pg
causes gcc
to insert code in the prologue of every routine B. That code looks at the stack to try to figure out who the caller A is. Then it increments a count of how many times A called B.
You can see how easy it is for this process to get confused. It locates routines by looking up their addresses in what amounts to a linker map (hashed, of course). If there's any sort of mismatch between that map and the actual code, the results will make even less sense than they normally do.
Look, if you're trying to see how to make the code go faster, here's the method I use.
If you're just trying to run a profiler for whatever reason, there are plenty of options, including oprofile, Zoom, etc.