I compile this simple C code with GCC:
int foo(int *a, int *b)
{
*a += 1;
*b += 1;
*a += 1;
}
int foo2(int *a, int *b)
{
*a += 1;
*b += 1;
*a += 1;
}
and it produces the following assembly code:
foo:
add DWORD PTR [rdi], 1
add DWORD PTR [rsi], 1
add DWORD PTR [rdi], 1
ret
foo2:
add DWORD PTR [rdi], 1
xor eax, eax
add DWORD PTR [rsi], 1
add DWORD PTR [rdi], 1
ret
see godbolt
What is the point of this xor
instruction?
In C++, GCC does not insert it and clang never does.