I don't know how to evaluate whether a code is optimizable by the compiler, but I tested another version (should be a version of the strcpy function):
#include <stdio.h>
const char * Copy(const char *restrict pRet, const char *restric pSrc)
{
char *pr = (char*)pRet;
while (*pr++ = *pSrc++)
*pr = '\0';
return pRet;
}
int main(int argc, char *argv[])
{
static char sBuffer[64];
Copy(sBuffer, "This is a string!\n");
printf(sBuffer);
return 0;
}
...and here came a small optimization:
push rax
add [r8], r8b
xchg fs:[rax+rax], al
xchg [rax+0x5712], ecx
instead of (without restrict):
push rax
add [r8], r8b
xchg fs:[rax+rax], al
db 0xc5
mov [rdx], dl
push rdi