I have a simple function which counts the letter t in a string:
#include <stdio.h>
#include <string.h>
static int count_t_letters(const char *t) {
int r;
r = 0;
while(*t) {
if(*t == 't') {
++r;
}
++t;
}
return r;
}
int main() {
printf("%i", count_t_letters("test"));
}
here's the optimization I was expecting:
int main() {
printf("%i", 2);
}
Why is this simple function not optimized like I expected in neither gcc nor clang? (godbolt)
What I figured out so far: