Bitcoin GetBlockWork() function
This appears to be a function to calculate the average number of hashes needed to generate a particular block. (This is different from difficulty.)

I think this function is correct. To explain why, imagine that Bitcoin used 4 bit hashes instead of 256 bit hashes. This would make the range of possible values 0 to 15.

If the target were 15, that would mean that any hash would be valid. Therefore, it should take 1 hash on average to find a valid proof of work:

= (maximum possible hash + 1) / (target + 1)
= (15 + 1) / (15 + 1)
= 1


If the target were 7, that would mean that half of the hashes would be valid. Therefore, it should take 2 hashes on average to find a valid proof of work:

= (maximum possible hash + 1) / (target + 1)
= (15 + 1) / (7 + 1)
= 2


Remember, a proof of work is valid if it is less than or equal to the target. See also CheckProofOfWork().

I can't tell if this is used anywhere. This function appears to have been removed in the latest version.