My vision of the situation:
Case 1: with "if dword(@result) = 0 then".
Case 2: without.
In the first case, the compiler does everything right:
1. Initialize temp variable for Result before call B with nil.
2. Do Result.bar := 'foo';
3. Initialize temp variable for Result before call A with nil.
4. Call A (Result equal ' bar').
and so on.
In the second case, compiler decides to optimize, and does not do step 3, but simply reuses the same register.
The result is unexpected behavior ('foo bar').
Step 3 is almost always used by the compiler to avoid side effects, for example, when Result := Format('...%s...', [...Result...]) is called.
As you can see, with some types of optimization, it forgets this.