#include #include void *ft_memchr(const void *s, int c, size_t n) { const unsigned char *p = s; unsigned char uc = (unsigned char)c; while (n && ((uintptr_t)p % sizeof(size_t))) { if (*p == uc) return ((void *)p); ++p; --n; } size_t mask = 0; for (size_t i = 0; i < sizeof(size_t); ++i) mask |= (size_t)uc << (i * 8); while (n >= sizeof(size_t)) { size_t word = *(const size_t *)p; size_t cmp = word ^ mask; for (size_t i = 0; i < sizeof(size_t); ++i) { if (((cmp >> (i * 8)) & 0xFF) == 0) return ((void *)(p + i)); } p += sizeof(size_t); n -= sizeof(size_t); } while (n--) { if (*p == uc) return ((void *)p); ++p; } return (NULL); }