A gcc does little optimizations, just constant arguments. And why gcc doesnt optimize memmem as arguments are constant and with size 1 needle it could use memchr? #include <string.h> int foo(char *x) { return memmem ("tauhtatu", 4, "f", 1); }