https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90271
--- Comment #1 from Eyal Rozenberg <eyalroz at technion dot ac.il> --- Can also reproduce this in C, with slightly different code: int replace_bytes_3(int v1 ,char v2) { memcpy( (void*) (((char*)&v1)+1) , &v2 , sizeof(v2) ); return v1; } int foo3() { int x = 3; char c = 1; return replace_bytes_3(x,c); } GodBolt: https://godbolt.org/z/1K89xh Again, clang optimizes this correctly. Note specifically the way it handles the non-inlined replace_bytes_3.