//
// memchr from 0x180124890 to 0x1801248fe (110 bytes)
//
// 2 xrefs:
// > sub_18004C1A0 @ 0x18004c312
// > ??> @ 0x180202678
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
void *__cdecl memchr(const void *Buf, int Val, size_t MaxCount)
{
__m128i v3; // xmm0
__m128i v4; // xmm1
__int64 v6; // rax
unsigned __int8 v7; // al
if ( MaxCount < 0x10 )
{
tail_loop_start:
if ( MaxCount )
{
while ( 1 )
{
v7 = *(_BYTE *)Buf;
Buf = (char *)Buf + 1;
if ( (unsigned __int8)Val == v7 )
break;
if ( !--MaxCount )
return nullptr;
}
return (char *)Buf - 1;
}
else
{
return nullptr;
}
}
else
{
Val = 16843009 * (unsigned __int8)Val;
v3 = _mm_shuffle_epi32(_mm_cvtsi32_si128(Val), 0);
while ( 1 )
{
v4 = _mm_loadu_si128((const __m128i *)Buf);
Buf = (char *)Buf + 16;
MaxCount -= 16LL;
if ( _BitScanForward64((unsigned __int64 *)&v6, (unsigned int)_mm_movemask_epi8(_mm_cmpeq_epi8(v4, v3))) )
return (char *)Buf + v6 - 16;
if ( MaxCount < 0x10 )
goto tail_loop_start;
}
}
}