Comment
Comment by UkrainianJew
That's because you are explicitly telling the compiler to create a copy of your shared pointer, that involves incrementing/decrementing the counter:
Try this:
You'll get 4 instructions (don't forget to put __attribute__((noinline)) on add_numbers()):
The only difference is that Rust physically placed the structure in 2 registers (hence just 1 instruction), while C++ physically placed it into memory (hence the need to 2 extra instructions fetching the values).